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
Hide 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];
* linked list. \todo write better doc
*/
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
}
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
...
...
@@ -88,50 +100,50 @@ ScanForTestSuites(char *directoryName, char *extension) {
TestSuiteReference
*
suites
=
NULL
;
Entry
*
entry
=
NULL
;
if
(
directory
)
{
while
(
entry
=
readdir
(
directory
))
{
if
(
entry
->
d_namlen
>
2
)
{
// discards . and ..
char
buffer
[
NAME_BUFFER_SIZE
];
memset
(
buffer
,
0
,
NAME_BUFFER_SIZE
);
if
(
!
directory
)
{
perror
(
"Couldn't open directory: tests/"
);
}
char
*
name
=
strtok
(
entry
->
d_name
,
"."
);
char
*
ext
=
strtok
(
NULL
,
"."
);
while
(
entry
=
readdir
(
directory
))
{
if
(
entry
->
d_namlen
>
2
)
{
// discards . and ..
const
char
*
delimiters
=
"."
;
char
*
name
=
strtok
(
entry
->
d_name
,
delimiters
);
char
*
ext
=
strtok
(
NULL
,
delimiters
);
// filter out all other suites but the selected test suite
int
ok
=
1
;
if
(
only_selected_suite
)
{
ok
=
SDL_strncmp
(
selected_suite_name
,
name
,
NAME_BUFFER_SIZE
)
==
0
;
}
// filter out all other suites but the selected test suite
int
ok
=
1
;
if
(
only_selected_suite
)
{
ok
=
SDL_strncmp
(
selected_suite_name
,
name
,
NAME_BUFFER_SIZE
)
==
0
;
}
if
(
ok
&&
SDL_strcmp
(
ext
,
extension
)
==
0
)
{
strcat
(
buffer
,
directoryName
);
strcat
(
buffer
,
name
);
strcat
(
buffer
,
"."
);
strcat
(
buffer
,
ext
);
if
(
ok
&&
SDL_strcmp
(
ext
,
extension
)
==
0
)
{
char
buffer
[
NAME_BUFFER_SIZE
];
memset
(
buffer
,
0
,
NAME_BUFFER_SIZE
);
// create tes suite reference
TestSuiteReference
*
reference
=
(
TestSuiteReference
*
)
SDL_malloc
(
sizeof
(
TestSuiteReference
));
memset
(
reference
,
0
,
sizeof
(
TestSuiteReference
));
strcat
(
buffer
,
directoryName
);
strcat
(
buffer
,
name
);
strcat
(
buffer
,
"."
);
strcat
(
buffer
,
ext
);
int
length
=
strlen
(
buffer
)
+
1
;
// + 1 for '\0'?
reference
->
name
=
SDL_malloc
(
length
*
sizeof
(
char
));
// create test suite reference
TestSuiteReference
*
reference
=
(
TestSuiteReference
*
)
SDL_malloc
(
sizeof
(
TestSuiteReference
));
memset
(
reference
,
0
,
sizeof
(
TestSuiteReference
));
strcpy
(
reference
->
name
,
buffer
);
int
length
=
strlen
(
buffer
)
+
1
;
// + 1 for '\0'?
reference
->
name
=
SDL_malloc
(
length
*
sizeof
(
char
));
reference
->
next
=
suites
;
strcpy
(
reference
->
name
,
buffer
)
;
suites
=
reference
;
reference
->
next
=
suites
;
suites
=
reference
;
printf
(
"Reference added to: %s
\n
"
,
buffer
);
}
printf
(
"Reference added to: %s
\n
"
,
buffer
);
}
}
closedir
(
directory
);
}
else
{
perror
(
"Couldn't open directory: tests/"
);
}
closedir
(
directory
);
return
suites
;
}
...
...
@@ -281,26 +293,22 @@ HandleTestReturnValue(int stat_lock)
* \return The return value of the test. Zero means success, non-zero failure.
*/
int
ExecuteTest
(
void
*
suite
,
TestCaseReference
*
testReference
)
{
TestCaseInit
testCaseInit
=
LoadTestCaseInit
(
suite
);
TestCaseQuit
testCaseQuit
=
LoadTestCaseQuit
(
suite
);
TestCase
test
=
(
TestCase
)
LoadTestCase
(
suite
,
testReference
->
name
);
ExecuteTest
(
TestCaseItem
*
testItem
)
{
int
retVal
=
1
;
if
(
execute_inproc
)
{
testCaseInit
();
test
Item
->
test
CaseInit
();
test
(
0x0
);
test
Item
->
testCase
(
0x0
);
retVal
=
testCaseQuit
();
retVal
=
test
Item
->
test
CaseQuit
();
}
else
{
int
childpid
=
fork
();
if
(
childpid
==
0
)
{
testCaseInit
();
test
Item
->
test
CaseInit
();
test
(
0x0
);
test
Item
->
testCase
(
0x0
);
exit
(
testCaseQuit
());
exit
(
test
Item
->
test
CaseQuit
());
}
else
{
int
stat_lock
=
-
1
;
int
child
=
wait
(
&
stat_lock
);
...
...
@@ -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
*
...
...
@@ -411,53 +531,37 @@ main(int argc, char *argv[])
#endif
const
Uint32
startTicks
=
SDL_GetTicks
();
TestSuiteReference
*
suites
=
ScanForTestSuites
(
DEFAULT_TEST_DIRECTORY
,
extension
);
suites
=
LoadTestSuites
(
suites
);
// load the suites
// load tests and filter them
// end result: list of tests to run
TestSuiteReference
*
suiteReference
=
NULL
;
for
(
suiteReference
=
suites
;
suiteReference
;
suiteReference
=
suiteReference
->
next
)
{
char
*
testSuiteName
=
suiteReference
->
name
;
// 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
;
}
TestCaseItem
*
testCases
=
LoadTestCases
(
suites
);
if
(
reference
->
enabled
==
TEST_DISABLED
)
{
printf
(
"Test %s (in %s) disabled. Omitting...
\n
"
,
reference
->
name
,
testSuiteName
);
// end result: list of tests to run
TestCaseItem
*
testItem
=
NULL
;
for
(
testItem
=
testCases
;
testItem
;
testItem
=
testItem
->
next
)
{
int
retVal
=
ExecuteTest
(
testItem
);
if
(
retVal
)
{
failureCount
++
;
if
(
retVal
==
2
)
{
//printf("%s (in %s): FAILED -> No asserts\n", reference->name, testSuiteName);
printf
(
"%s (in %s): FAILED -> No asserts
\n
"
,
"<test name>"
,
"<suite name>"
);
}
else
{
printf
(
"Executing %s (in %s):
\n
"
,
reference
->
name
,
testSuiteName
);
int
retVal
=
ExecuteTest
(
suite
,
reference
);
if
(
retVal
)
{
failureCount
++
;
if
(
retVal
==
2
)
{
printf
(
"%s (in %s): FAILED -> No asserts
\n
"
,
reference
->
name
,
testSuiteName
);
}
else
{
printf
(
"%s (in %s): FAILED
\n
"
,
reference
->
name
,
testSuiteName
);
}
}
else
{
passCount
++
;
printf
(
"%s (in %s): ok
\n
"
,
reference
->
name
,
testSuiteName
);
}
printf
(
"%s (in %s): FAILED
\n
"
,
"<test name>"
,
"<suite name>"
);
}
printf
(
"
\n
"
);
}
else
{
passCount
++
;
printf
(
"%s (in %s): ok
\n
"
,
"<test name>"
,
"<suite name>"
);
}
SDL_UnloadObject
(
suite
);
printf
(
"
\n
"
);
}
UnloadTestCases
(
testCases
);
UnloadTestSuites
(
suites
);
const
Uint32
endTicks
=
SDL_GetTicks
();
printf
(
"Ran %d tests in %0.5f seconds.
\n
"
,
(
passCount
+
failureCount
),
(
endTicks
-
startTicks
)
/
1000
.
0
f
);
...
...
@@ -465,15 +569,6 @@ main(int argc, char *argv[])
printf
(
"%d tests passed
\n
"
,
passCount
);
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
;
}
test/test-automation/testdummy/testdummy.c
View file @
4f8639e4
...
...
@@ -60,6 +60,7 @@ void dummycase1(void *arg)
{
const
char
*
revision
=
SDL_GetRevision
();
printf
(
"Dummycase 1
\n
"
);
printf
(
"Revision is %s
\n
"
,
revision
);
AssertEquals
(
3
,
5
,
"fails"
);
...
...
@@ -69,11 +70,13 @@ void dummycase2(void *arg)
{
char
*
msg
=
"eello"
;
//msg[0] = 'H';
printf
(
"Dummycase 2
\n
"
);
AssertTrue
(
0
,
"fails"
);
}
void
dummycase3
(
void
*
arg
)
{
printf
(
"Dummycase 3
\n
"
);
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