Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
4f8639e4
Commit
4f8639e4
authored
Jun 09, 2011
by
Markus Kauppila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Creating pipeline for test case selection. Work in progress.
parent
d3b50802
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
187 additions
and
89 deletions
+187
-89
runner.c
test/test-automation/runner.c
+184
-89
testdummy.c
test/test-automation/testdummy/testdummy.c
+3
-0
No files found.
test/test-automation/runner.c
View file @
4f8639e4
...
@@ -61,10 +61,22 @@ char selected_suite_name[NAME_BUFFER_SIZE];
...
@@ -61,10 +61,22 @@ char selected_suite_name[NAME_BUFFER_SIZE];
* linked list. \todo write better doc
* linked list. \todo write better doc
*/
*/
typedef
struct
TestSuiteReference
{
typedef
struct
TestSuiteReference
{
char
*
name
;
//<! test suite name
char
*
name
;
//!< test suite name
void
*
library
;
//!< pointer to shared/dynamic library implemeting the suite
struct
TestSuiteReference
*
next
;
//!< Pointer to next item in the list
struct
TestSuiteReference
*
next
;
//!< Pointer to next item in the list
}
TestSuiteReference
;
}
TestSuiteReference
;
typedef
struct
TestCaseItem
{
char
*
testName
;
char
*
suiteName
;
TestCaseInit
testCaseInit
;
TestCase
testCase
;
TestCaseQuit
testCaseQuit
;
struct
TestCaseItem
*
next
;
}
TestCaseItem
;
//!< \todo rename
/*!
/*!
* Scans the tests/ directory and returns the names
* Scans the tests/ directory and returns the names
...
@@ -88,14 +100,15 @@ ScanForTestSuites(char *directoryName, char *extension) {
...
@@ -88,14 +100,15 @@ ScanForTestSuites(char *directoryName, char *extension) {
TestSuiteReference
*
suites
=
NULL
;
TestSuiteReference
*
suites
=
NULL
;
Entry
*
entry
=
NULL
;
Entry
*
entry
=
NULL
;
if
(
directory
)
{
if
(
!
directory
)
{
perror
(
"Couldn't open directory: tests/"
);
}
while
(
entry
=
readdir
(
directory
))
{
while
(
entry
=
readdir
(
directory
))
{
if
(
entry
->
d_namlen
>
2
)
{
// discards . and ..
if
(
entry
->
d_namlen
>
2
)
{
// discards . and ..
char
buffer
[
NAME_BUFFER_SIZE
];
const
char
*
delimiters
=
"."
;
memset
(
buffer
,
0
,
NAME_BUFFER_SIZE
);
char
*
name
=
strtok
(
entry
->
d_name
,
delimiters
);
char
*
ext
=
strtok
(
NULL
,
delimiters
);
char
*
name
=
strtok
(
entry
->
d_name
,
"."
);
char
*
ext
=
strtok
(
NULL
,
"."
);
// filter out all other suites but the selected test suite
// filter out all other suites but the selected test suite
int
ok
=
1
;
int
ok
=
1
;
...
@@ -104,12 +117,15 @@ ScanForTestSuites(char *directoryName, char *extension) {
...
@@ -104,12 +117,15 @@ ScanForTestSuites(char *directoryName, char *extension) {
}
}
if
(
ok
&&
SDL_strcmp
(
ext
,
extension
)
==
0
)
{
if
(
ok
&&
SDL_strcmp
(
ext
,
extension
)
==
0
)
{
char
buffer
[
NAME_BUFFER_SIZE
];
memset
(
buffer
,
0
,
NAME_BUFFER_SIZE
);
strcat
(
buffer
,
directoryName
);
strcat
(
buffer
,
directoryName
);
strcat
(
buffer
,
name
);
strcat
(
buffer
,
name
);
strcat
(
buffer
,
"."
);
strcat
(
buffer
,
"."
);
strcat
(
buffer
,
ext
);
strcat
(
buffer
,
ext
);
// create tes
suite reference
// create test
suite reference
TestSuiteReference
*
reference
=
(
TestSuiteReference
*
)
SDL_malloc
(
sizeof
(
TestSuiteReference
));
TestSuiteReference
*
reference
=
(
TestSuiteReference
*
)
SDL_malloc
(
sizeof
(
TestSuiteReference
));
memset
(
reference
,
0
,
sizeof
(
TestSuiteReference
));
memset
(
reference
,
0
,
sizeof
(
TestSuiteReference
));
...
@@ -119,7 +135,6 @@ ScanForTestSuites(char *directoryName, char *extension) {
...
@@ -119,7 +135,6 @@ ScanForTestSuites(char *directoryName, char *extension) {
strcpy
(
reference
->
name
,
buffer
);
strcpy
(
reference
->
name
,
buffer
);
reference
->
next
=
suites
;
reference
->
next
=
suites
;
suites
=
reference
;
suites
=
reference
;
printf
(
"Reference added to: %s
\n
"
,
buffer
);
printf
(
"Reference added to: %s
\n
"
,
buffer
);
...
@@ -128,9 +143,6 @@ ScanForTestSuites(char *directoryName, char *extension) {
...
@@ -128,9 +143,6 @@ ScanForTestSuites(char *directoryName, char *extension) {
}
}
closedir
(
directory
);
closedir
(
directory
);
}
else
{
perror
(
"Couldn't open directory: tests/"
);
}
return
suites
;
return
suites
;
}
}
...
@@ -281,26 +293,22 @@ HandleTestReturnValue(int stat_lock)
...
@@ -281,26 +293,22 @@ HandleTestReturnValue(int stat_lock)
* \return The return value of the test. Zero means success, non-zero failure.
* \return The return value of the test. Zero means success, non-zero failure.
*/
*/
int
int
ExecuteTest
(
void
*
suite
,
TestCaseReference
*
testReference
)
{
ExecuteTest
(
TestCaseItem
*
testItem
)
{
TestCaseInit
testCaseInit
=
LoadTestCaseInit
(
suite
);
TestCaseQuit
testCaseQuit
=
LoadTestCaseQuit
(
suite
);
TestCase
test
=
(
TestCase
)
LoadTestCase
(
suite
,
testReference
->
name
);
int
retVal
=
1
;
int
retVal
=
1
;
if
(
execute_inproc
)
{
if
(
execute_inproc
)
{
testCaseInit
();
test
Item
->
test
CaseInit
();
test
(
0x0
);
test
Item
->
testCase
(
0x0
);
retVal
=
testCaseQuit
();
retVal
=
test
Item
->
test
CaseQuit
();
}
else
{
}
else
{
int
childpid
=
fork
();
int
childpid
=
fork
();
if
(
childpid
==
0
)
{
if
(
childpid
==
0
)
{
testCaseInit
();
test
Item
->
test
CaseInit
();
test
(
0x0
);
test
Item
->
testCase
(
0x0
);
exit
(
testCaseQuit
());
exit
(
test
Item
->
test
CaseQuit
());
}
else
{
}
else
{
int
stat_lock
=
-
1
;
int
stat_lock
=
-
1
;
int
child
=
wait
(
&
stat_lock
);
int
child
=
wait
(
&
stat_lock
);
...
@@ -387,6 +395,118 @@ ParseOptions(int argc, char *argv[])
...
@@ -387,6 +395,118 @@ ParseOptions(int argc, char *argv[])
}
}
/*!
* \todo add comment
*/
TestCaseItem
*
LoadTestCases
(
TestSuiteReference
*
suites
)
{
TestCaseItem
*
testCases
=
NULL
;
TestSuiteReference
*
suiteReference
=
NULL
;
for
(
suiteReference
=
suites
;
suiteReference
;
suiteReference
=
suiteReference
->
next
)
{
TestCaseReference
**
tests
=
QueryTestCases
(
suiteReference
->
library
);
TestCaseReference
*
testReference
=
NULL
;
int
counter
=
0
;
for
(
testReference
=
tests
[
counter
];
testReference
;
testReference
=
tests
[
++
counter
])
{
void
*
suite
=
suiteReference
->
library
;
// Load test case functions
TestCaseInit
testCaseInit
=
LoadTestCaseInit
(
suiteReference
->
library
);
TestCaseQuit
testCaseQuit
=
LoadTestCaseQuit
(
suiteReference
->
library
);
TestCase
testCase
=
(
TestCase
)
LoadTestCase
(
suiteReference
->
library
,
testReference
->
name
);
// Do the filtering
if
(
FilterTestCase
(
testReference
))
{
//!< \todo deallocate these
TestCaseItem
*
item
=
SDL_malloc
(
sizeof
(
TestCaseItem
));
memset
(
item
,
0
,
sizeof
(
TestCaseItem
));
item
->
testCaseInit
=
testCaseInit
;
item
->
testCase
=
testCase
;
item
->
testCaseQuit
=
testCaseQuit
;
// prepend the list
item
->
next
=
testCases
;
testCases
=
item
;
printf
(
"Added test: %s
\n
"
,
testReference
->
name
);
}
}
}
return
testCases
;
}
/*!
* \todo add comment
*/
void
UnloadTestCases
(
TestCaseItem
*
item
)
{
TestCaseItem
*
ref
=
item
;
while
(
ref
)
{
TestCaseItem
*
temp
=
ref
->
next
;
SDL_free
(
ref
);
ref
=
temp
;
}
item
=
NULL
;
}
/*!
* \todo add comment
*/
int
FilterTestCase
(
TestCaseReference
*
testReference
)
{
//int retVal = 1;
if
(
testReference
->
enabled
==
TEST_DISABLED
)
{
//retVal = 0;
return
0
;
}
if
(
1
&&
strstr
(
testReference
->
name
,
"rect"
)
!=
NULL
)
{
//retVal = 1;
return
1
;
}
else
{
return
0
;
}
return
1
;
}
/*!
* \todo add comment
*/
TestSuiteReference
*
LoadTestSuites
(
TestSuiteReference
*
suites
)
{
TestSuiteReference
*
reference
=
NULL
;
for
(
reference
=
suites
;
reference
;
reference
=
reference
->
next
)
{
reference
->
library
=
LoadTestSuite
(
reference
->
name
);
}
return
suites
;
}
/*!
* \todo add comment
*/
void
UnloadTestSuites
(
TestSuiteReference
*
suites
)
{
TestSuiteReference
*
ref
=
suites
;
while
(
ref
)
{
SDL_free
(
ref
->
name
);
SDL_UnloadObject
(
ref
->
library
);
TestSuiteReference
*
temp
=
ref
->
next
;
SDL_free
(
ref
);
ref
=
temp
;
}
suites
=
NULL
;
}
/*!
/*!
* Entry point for test runner
* Entry point for test runner
*
*
...
@@ -411,52 +531,36 @@ main(int argc, char *argv[])
...
@@ -411,52 +531,36 @@ main(int argc, char *argv[])
#endif
#endif
const
Uint32
startTicks
=
SDL_GetTicks
();
const
Uint32
startTicks
=
SDL_GetTicks
();
TestSuiteReference
*
suites
=
ScanForTestSuites
(
DEFAULT_TEST_DIRECTORY
,
extension
);
TestSuiteReference
*
suites
=
ScanForTestSuites
(
DEFAULT_TEST_DIRECTORY
,
extension
);
suites
=
LoadTestSuites
(
suites
);
// load the suites
// load tests and filter them
// load tests and filter them
// end result: list of tests to run
TestCaseItem
*
testCases
=
LoadTestCases
(
suites
);
TestSuiteReference
*
suiteReference
=
NULL
;
// end result: list of tests to run
for
(
suiteReference
=
suites
;
suiteReference
;
suiteReference
=
suiteReference
->
next
)
{
TestCaseItem
*
testItem
=
NULL
;
char
*
testSuiteName
=
suiteReference
->
name
;
for
(
testItem
=
testCases
;
testItem
;
testItem
=
testItem
->
next
)
{
int
retVal
=
ExecuteTest
(
testItem
);
// if the current suite isn't selected, go to next suite
void
*
suite
=
LoadTestSuite
(
testSuiteName
);
TestCaseReference
**
tests
=
QueryTestCases
(
suite
);
TestCaseReference
*
reference
=
NULL
;
int
counter
=
0
;
for
(
reference
=
tests
[
counter
];
reference
;
reference
=
tests
[
++
counter
])
{
if
(
only_selected_test
&&
SDL_strncmp
(
selected_test_name
,
reference
->
name
,
NAME_BUFFER_SIZE
)
!=
0
)
{
continue
;
}
if
(
reference
->
enabled
==
TEST_DISABLED
)
{
printf
(
"Test %s (in %s) disabled. Omitting...
\n
"
,
reference
->
name
,
testSuiteName
);
}
else
{
printf
(
"Executing %s (in %s):
\n
"
,
reference
->
name
,
testSuiteName
);
int
retVal
=
ExecuteTest
(
suite
,
reference
);
if
(
retVal
)
{
if
(
retVal
)
{
failureCount
++
;
failureCount
++
;
if
(
retVal
==
2
)
{
if
(
retVal
==
2
)
{
printf
(
"%s (in %s): FAILED -> No asserts
\n
"
,
reference
->
name
,
testSuiteName
);
//printf("%s (in %s): FAILED -> No asserts\n", reference->name, testSuiteName);
printf
(
"%s (in %s): FAILED -> No asserts
\n
"
,
"<test name>"
,
"<suite name>"
);
}
else
{
}
else
{
printf
(
"%s (in %s): FAILED
\n
"
,
reference
->
name
,
testSuiteName
);
printf
(
"%s (in %s): FAILED
\n
"
,
"<test name>"
,
"<suite name>"
);
}
}
}
else
{
}
else
{
passCount
++
;
passCount
++
;
printf
(
"%s (in %s): ok
\n
"
,
reference
->
name
,
testSuiteName
);
printf
(
"%s (in %s): ok
\n
"
,
"<test name>"
,
"<suite name>"
);
}
}
}
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
SDL_UnloadObject
(
suite
);
UnloadTestCases
(
testCases
);
}
UnloadTestSuites
(
suites
);
const
Uint32
endTicks
=
SDL_GetTicks
();
const
Uint32
endTicks
=
SDL_GetTicks
();
...
@@ -465,15 +569,6 @@ main(int argc, char *argv[])
...
@@ -465,15 +569,6 @@ main(int argc, char *argv[])
printf
(
"%d tests passed
\n
"
,
passCount
);
printf
(
"%d tests passed
\n
"
,
passCount
);
printf
(
"%d tests failed
\n
"
,
failureCount
);
printf
(
"%d tests failed
\n
"
,
failureCount
);
// Deallocate the memory used by test suites
TestSuiteReference
*
ref
=
suites
;
while
(
ref
)
{
SDL_free
(
ref
->
name
);
TestSuiteReference
*
temp
=
ref
->
next
;
SDL_free
(
ref
);
ref
=
temp
;
}
return
0
;
return
0
;
}
}
test/test-automation/testdummy/testdummy.c
View file @
4f8639e4
...
@@ -60,6 +60,7 @@ void dummycase1(void *arg)
...
@@ -60,6 +60,7 @@ void dummycase1(void *arg)
{
{
const
char
*
revision
=
SDL_GetRevision
();
const
char
*
revision
=
SDL_GetRevision
();
printf
(
"Dummycase 1
\n
"
);
printf
(
"Revision is %s
\n
"
,
revision
);
printf
(
"Revision is %s
\n
"
,
revision
);
AssertEquals
(
3
,
5
,
"fails"
);
AssertEquals
(
3
,
5
,
"fails"
);
...
@@ -69,11 +70,13 @@ void dummycase2(void *arg)
...
@@ -69,11 +70,13 @@ void dummycase2(void *arg)
{
{
char
*
msg
=
"eello"
;
char
*
msg
=
"eello"
;
//msg[0] = 'H';
//msg[0] = 'H';
printf
(
"Dummycase 2
\n
"
);
AssertTrue
(
0
,
"fails"
);
AssertTrue
(
0
,
"fails"
);
}
}
void
dummycase3
(
void
*
arg
)
void
dummycase3
(
void
*
arg
)
{
{
printf
(
"Dummycase 3
\n
"
);
AssertTrue
(
1
,
"passes"
);
AssertTrue
(
1
,
"passes"
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment