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
2e8932b1
Commit
2e8932b1
authored
Jun 26, 2011
by
Markus Kauppila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Logging system added to harness. Logging system doesn't
yet utilize all the given parameters.
parent
e2799bbb
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
268 additions
and
71 deletions
+268
-71
Makefile.am
test/test-automation/Makefile.am
+1
-6
SDL_test.c
test/test-automation/SDL_test.c
+30
-10
SDL_test.h
test/test-automation/SDL_test.h
+3
-1
logger.c
test/test-automation/logger.c
+41
-22
logger.h
test/test-automation/logger.h
+18
-2
plain_logger.c
test/test-automation/plain_logger.c
+19
-7
plain_logger.h
test/test-automation/plain_logger.h
+5
-1
runner.c
test/test-automation/runner.c
+58
-8
xml.c
test/test-automation/xml.c
+3
-3
xml_logger.c
test/test-automation/xml_logger.c
+86
-10
xml_logger.h
test/test-automation/xml_logger.h
+4
-1
No files found.
test/test-automation/Makefile.am
View file @
2e8932b1
...
@@ -3,15 +3,10 @@ ACLOCAL_AMFLAGS = -I acinclude -I build-scripts
...
@@ -3,15 +3,10 @@ ACLOCAL_AMFLAGS = -I acinclude -I build-scripts
SUBDIRS
=
testdummy testrect testplatform
SUBDIRS
=
testdummy testrect testplatform
bin_PROGRAMS
=
runner
bin_PROGRAMS
=
runner
runner_SOURCES
=
runner.c SDL_test.c
runner_SOURCES
=
runner.c SDL_test.c
logger.c xml_logger.c plain_logger.c xml.c
runner_CLAGS
=
-W
-Wall
-Wextra
-g
`
sdl-config
--cflags
`
-DSDL_NO_COMPAT
runner_CLAGS
=
-W
-Wall
-Wextra
-g
`
sdl-config
--cflags
`
-DSDL_NO_COMPAT
runner_LDFLAGS
=
`
sdl-config
--libs
`
runner_LDFLAGS
=
`
sdl-config
--libs
`
bin_PROGRAMS
=
logger
logger_SOURCES
=
xml_logger.c xml.c plain_logger.c logger.c
logger_CLAGS
=
-W
-Wall
-Wextra
-g
`
sdl-config
--cflags
`
-DSDL_NO_COMPAT
logger_LDFLAGS
=
`
sdl-config
--libs
`
install
:
install-tests
install
:
install-tests
install-tests
:
install-tests
:
-
mkdir
tests
-
mkdir
tests
...
...
test/test-automation/SDL_test.c
View file @
2e8932b1
...
@@ -24,6 +24,8 @@
...
@@ -24,6 +24,8 @@
#include <stdio.h>
/* printf/fprintf */
#include <stdio.h>
/* printf/fprintf */
#include <stdarg.h>
/* va_list */
#include <stdarg.h>
/* va_list */
#include "logger.h"
#include "SDL_test.h"
#include "SDL_test.h"
/*! \brief return value of test case. Non-zero value means that the test failed */
/*! \brief return value of test case. Non-zero value means that the test failed */
...
@@ -36,8 +38,16 @@ int _testAssertsFailed;
...
@@ -36,8 +38,16 @@ int _testAssertsFailed;
int
_testAssertsPassed
;
int
_testAssertsPassed
;
void
void
_TestCaseInit
()
_TestCaseInit
(
const
int
enable_xml_logging
)
{
{
// setup logging functions
// rather afwul way to do it, but function pointers didn't work
if
(
enable_xml_logging
)
{
SetupXMLLogger
();
}
else
{
SetupPlainLogger
();
}
_testReturnValue
=
0
;
_testReturnValue
=
0
;
_testAssertsFailed
=
0
;
_testAssertsFailed
=
0
;
_testAssertsPassed
=
0
;
_testAssertsPassed
=
0
;
...
@@ -46,8 +56,9 @@ _TestCaseInit()
...
@@ -46,8 +56,9 @@ _TestCaseInit()
int
int
_TestCaseQuit
()
_TestCaseQuit
()
{
{
//! \todo make the test fail, if it does not contain any asserts
//printf("Asserts: passed %d, failed %d\n", _testAssertsPassed, _testAssertsFailed);
printf
(
"Asserts: passed %d, failed %d
\n
"
,
_testAssertsPassed
,
_testAssertsFailed
);
AssertSummary
(
_testAssertsFailed
+
_testAssertsPassed
,
_testAssertsFailed
,
_testAssertsPassed
);
if
(
_testAssertsFailed
==
0
&&
_testAssertsPassed
==
0
)
{
if
(
_testAssertsFailed
==
0
&&
_testAssertsPassed
==
0
)
{
_testReturnValue
=
2
;
_testReturnValue
=
2
;
...
@@ -66,11 +77,15 @@ AssertEquals(Uint32 expected, Uint32 actual, char* message, ...)
...
@@ -66,11 +77,15 @@ AssertEquals(Uint32 expected, Uint32 actual, char* message, ...)
va_start
(
args
,
message
);
va_start
(
args
,
message
);
SDL_vsnprintf
(
buf
,
sizeof
(
buf
),
message
,
args
);
SDL_vsnprintf
(
buf
,
sizeof
(
buf
),
message
,
args
);
va_end
(
args
);
va_end
(
args
);
printf
(
"AssertEquals failed: expected %d, got %d; %s
\n
"
,
expected
,
actual
,
buf
);
//printf("AssertEquals failed: expected %d, got %d; %s\n", expected, actual, buf);
Assert
(
"AssertEquals"
,
0
,
buf
,
0
);
_testReturnValue
=
1
;
_testReturnValue
=
1
;
_testAssertsFailed
++
;
_testAssertsFailed
++
;
}
else
{
}
else
{
printf
(
"AssertEquals passed
\n
"
);
//printf("AssertEquals passed\n");
Assert
(
"AssertEquals"
,
1
,
"AssertEquals passed"
,
0
);
_testAssertsPassed
++
;
_testAssertsPassed
++
;
}
}
}
}
...
@@ -86,12 +101,15 @@ AssertTrue(int condition, char *message, ...)
...
@@ -86,12 +101,15 @@ AssertTrue(int condition, char *message, ...)
SDL_vsnprintf
(
buf
,
sizeof
(
buf
),
message
,
args
);
SDL_vsnprintf
(
buf
,
sizeof
(
buf
),
message
,
args
);
va_end
(
args
);
va_end
(
args
);
printf
(
"AssertTrue failed: %s
\n
"
,
buf
);
//printf("AssertTrue failed: %s\n", buf);
Assert
(
"AssertTrue"
,
0
,
buf
,
0
);
_testReturnValue
=
1
;
_testReturnValue
=
1
;
_testAssertsFailed
++
;
_testAssertsFailed
++
;
}
else
{
}
else
{
printf
(
"AssertTrue passed
\n
"
);
//printf("AssertTrue passed\n");
_testAssertsPassed
++
;
Assert
(
"AssertTrue"
,
1
,
"AssertTrue passed"
,
0
);
_testAssertsPassed
++
;
}
}
}
}
...
@@ -105,7 +123,8 @@ AssertPass(char *message, ...)
...
@@ -105,7 +123,8 @@ AssertPass(char *message, ...)
SDL_vsnprintf
(
buf
,
sizeof
(
buf
),
message
,
args
);
SDL_vsnprintf
(
buf
,
sizeof
(
buf
),
message
,
args
);
va_end
(
args
);
va_end
(
args
);
printf
(
"AssertPass: %s
\n
"
,
buf
);
//printf("AssertPass: %s\n", buf);
Assert
(
"AssertPass"
,
1
,
buf
,
0
);
_testAssertsPassed
++
;
_testAssertsPassed
++
;
}
}
...
@@ -120,7 +139,8 @@ AssertFail(char *message, ...)
...
@@ -120,7 +139,8 @@ AssertFail(char *message, ...)
SDL_vsnprintf
(
buf
,
sizeof
(
buf
),
message
,
args
);
SDL_vsnprintf
(
buf
,
sizeof
(
buf
),
message
,
args
);
va_end
(
args
);
va_end
(
args
);
printf
(
"AssertFail: %s
\n
"
,
buf
);
//printf("AssertFail: %s\n", buf);
Assert
(
"AssertFail"
,
0
,
buf
,
0
);
_testAssertsFailed
++
;
_testAssertsFailed
++
;
}
}
...
...
test/test-automation/SDL_test.h
View file @
2e8932b1
...
@@ -23,6 +23,8 @@
...
@@ -23,6 +23,8 @@
#include <SDL/SDL.h>
#include <SDL/SDL.h>
#include "logger.h"
extern
int
_testReturnValue
;
extern
int
_testReturnValue
;
extern
int
_testAssertsFailed
;
extern
int
_testAssertsFailed
;
extern
int
_testAssertsPassed
;
extern
int
_testAssertsPassed
;
...
@@ -52,7 +54,7 @@ typedef struct TestCaseReference {
...
@@ -52,7 +54,7 @@ typedef struct TestCaseReference {
* the beginning of every test case, before doing
* the beginning of every test case, before doing
* anything else.
* anything else.
*/
*/
void
_TestCaseInit
();
void
_TestCaseInit
(
const
int
enable_xml_logging
);
/*! \fn _TestCaseQuit
/*! \fn _TestCaseQuit
* Deinitializes and exits the test case
* Deinitializes and exits the test case
...
...
test/test-automation/logger.c
View file @
2e8932b1
...
@@ -18,8 +18,45 @@ SuiteEndedFp SuiteEnded = 0;
...
@@ -18,8 +18,45 @@ SuiteEndedFp SuiteEnded = 0;
TestStartedFp
TestStarted
=
0
;
TestStartedFp
TestStarted
=
0
;
TestEndedFp
TestEnded
=
0
;
TestEndedFp
TestEnded
=
0
;
AssertFp
Assert
=
0
;
AssertFp
Assert
=
0
;
AssertSummaryFp
AssertSummary
=
0
;
LogFp
Log
=
0
;
LogFp
Log
=
0
;
int
SetupXMLLogger
()
{
RunStarted
=
XMLRunStarted
;
RunEnded
=
XMLRunEnded
;
SuiteStarted
=
XMLSuiteStarted
;
SuiteEnded
=
XMLSuiteEnded
;
TestStarted
=
XMLTestStarted
;
TestEnded
=
XMLTestEnded
;
Assert
=
XMLAssert
;
AssertSummary
=
XMLAssertSummary
;
Log
=
XMLLog
;
}
int
SetupPlainLogger
()
{
RunStarted
=
PlainRunStarted
;
RunEnded
=
PlainRunEnded
;
SuiteStarted
=
PlainSuiteStarted
;
SuiteEnded
=
PlainSuiteEnded
;
TestStarted
=
PlainTestStarted
;
TestEnded
=
PlainTestEnded
;
Assert
=
PlainAssert
;
AssertSummary
=
PlainAssertSummary
;
Log
=
PlainLog
;
}
/*!
/*!
* Prints the given message to stderr. Function adds nesting
* Prints the given message to stderr. Function adds nesting
* to the output.
* to the output.
...
@@ -39,6 +76,7 @@ LogGenericOutput(const char *message, ...)
...
@@ -39,6 +76,7 @@ LogGenericOutput(const char *message, ...)
fflush
(
stderr
);
fflush
(
stderr
);
}
}
#if 0
/*!
/*!
* Test app for logging functionality
* Test app for logging functionality
*/
*/
...
@@ -48,29 +86,9 @@ main(int argc, char *argv[])
...
@@ -48,29 +86,9 @@ main(int argc, char *argv[])
int xml_enabled = 1;
int xml_enabled = 1;
if(xml_enabled) {
if(xml_enabled) {
RunStarted
=
XMLRunStarted
;
SetupXMLLogger();
RunEnded
=
XMLRunEnded
;
SuiteStarted
=
XMLSuiteStarted
;
SuiteEnded
=
XMLSuiteEnded
;
TestStarted
=
XMLTestStarted
;
TestEnded
=
XMLTestEnded
;
Assert
=
XMLAssert
;
Log
=
XMLLog
;
} else {
} else {
RunStarted
=
PlainRunStarted
;
SetupPlainLogger();
RunEnded
=
PlainRunEnded
;
SuiteStarted
=
PlainSuiteStarted
;
SuiteEnded
=
PlainSuiteEnded
;
TestStarted
=
PlainTestStarted
;
TestEnded
=
PlainTestEnded
;
Assert
=
PlainAssert
;
Log
=
PlainLog
;
}
}
RunStarted(LogGenericOutput, "some_<data_>here&here", 0);
RunStarted(LogGenericOutput, "some_<data_>here&here", 0);
...
@@ -84,3 +102,4 @@ main(int argc, char *argv[])
...
@@ -84,3 +102,4 @@ main(int argc, char *argv[])
return 0;
return 0;
}
}
#endif
test/test-automation/logger.h
View file @
2e8932b1
...
@@ -26,7 +26,6 @@
...
@@ -26,7 +26,6 @@
// Function pointer to function which handles to output
// Function pointer to function which handles to output
typedef
int
(
*
LogOutputFp
)(
const
char
*
,
...);
typedef
int
(
*
LogOutputFp
)(
const
char
*
,
...);
/*!
/*!
* Generic logger interface
* Generic logger interface
*
*
...
@@ -42,12 +41,29 @@ typedef void (*SuiteEndedFp)(int testsPassed, int testsFailed, int testsSkipped,
...
@@ -42,12 +41,29 @@ typedef void (*SuiteEndedFp)(int testsPassed, int testsFailed, int testsSkipped,
typedef
void
(
*
TestStartedFp
)(
const
char
*
testName
,
const
char
*
suiteName
,
typedef
void
(
*
TestStartedFp
)(
const
char
*
testName
,
const
char
*
suiteName
,
const
char
*
testDescription
,
time_t
startTime
);
const
char
*
testDescription
,
time_t
startTime
);
typedef
void
(
*
TestEndedFp
)(
const
char
*
testName
,
const
char
*
suiteName
,
int
testResult
,
typedef
void
(
*
TestEndedFp
)(
const
char
*
testName
,
const
char
*
suiteName
,
int
testResult
,
int
numAsserts
,
time_t
endTime
,
time_t
totalRuntime
);
time_t
endTime
,
time_t
totalRuntime
);
/*!
* Note: for assertResult, non-zero == pass, zero == failure
*
*/
typedef
void
(
*
AssertFp
)(
const
char
*
assertName
,
int
assertResult
,
const
char
*
assertMessage
,
typedef
void
(
*
AssertFp
)(
const
char
*
assertName
,
int
assertResult
,
const
char
*
assertMessage
,
time_t
eventTime
);
time_t
eventTime
);
typedef
void
(
*
AssertSummaryFp
)(
int
numAsserts
,
int
numAssertsFailed
,
int
numAssertsPass
);
typedef
void
(
*
LogFp
)(
const
char
*
logMessage
,
time_t
eventTime
);
typedef
void
(
*
LogFp
)(
const
char
*
logMessage
,
time_t
eventTime
);
int
LogGenericOutput
(
const
char
*
message
,
...);
extern
RunStartedFp
RunStarted
;
extern
RunEndedFp
RunEnded
;
extern
SuiteStartedFp
SuiteStarted
;
extern
SuiteEndedFp
SuiteEnded
;
extern
TestStartedFp
TestStarted
;
extern
TestEndedFp
TestEnded
;
extern
AssertFp
Assert
;
extern
AssertSummaryFp
AssertSummary
;
extern
LogFp
Log
;
#endif
#endif
test/test-automation/plain_logger.c
View file @
2e8932b1
...
@@ -13,39 +13,44 @@ void
...
@@ -13,39 +13,44 @@ void
PlainRunStarted
(
LogOutputFp
outputFn
,
const
char
*
runnerParameters
,
time_t
eventTime
)
PlainRunStarted
(
LogOutputFp
outputFn
,
const
char
*
runnerParameters
,
time_t
eventTime
)
{
{
logger
=
outputFn
;
logger
=
outputFn
;
logger
(
"Test run started"
);
logger
(
"Given command line options: %s"
,
"add options"
);
}
}
void
void
PlainRunEnded
(
int
testCount
,
int
suiteCount
,
int
testPassCount
,
int
testFailCount
,
PlainRunEnded
(
int
testCount
,
int
suiteCount
,
int
testPassCount
,
int
testFailCount
,
time_t
endTime
,
time_t
totalRuntime
)
time_t
endTime
,
time_t
totalRuntime
)
{
{
// \todo add total number of tests, suites, pass/failure test count
logger
(
"Ran %d tests in %0.5f seconds."
,
testCount
,
totalRuntime
);
logger
(
"%d tests passed"
,
testPassCount
);
logger
(
"%d tests failed"
,
testFailCount
);
}
}
void
void
PlainSuiteStarted
(
const
char
*
suiteName
,
time_t
eventTime
)
PlainSuiteStarted
(
const
char
*
suiteName
,
time_t
eventTime
)
{
{
logger
(
"Executing tests in %s
\n
"
,
suiteName
);
logger
(
"Executing tests in %s"
,
suiteName
);
}
}
void
void
PlainSuiteEnded
(
int
testsPassed
,
int
testsFailed
,
int
testsSkipped
,
PlainSuiteEnded
(
int
testsPassed
,
int
testsFailed
,
int
testsSkipped
,
double
endTime
,
time_t
totalRuntime
)
double
endTime
,
time_t
totalRuntime
)
{
{
logger
(
"Suite executed. %d passed, %d failed and %d skipped
\n
"
,
testsPassed
,
testsFailed
,
testsSkipped
);
logger
(
"Suite executed. %d passed, %d failed and %d skipped"
,
testsPassed
,
testsFailed
,
testsSkipped
);
}
}
void
void
PlainTestStarted
(
const
char
*
testName
,
const
char
*
suiteName
,
const
char
*
testDescription
,
time_t
startTime
)
PlainTestStarted
(
const
char
*
testName
,
const
char
*
suiteName
,
const
char
*
testDescription
,
time_t
startTime
)
{
{
logger
(
"test %s (in %s) started"
,
testName
,
suiteName
);
}
}
void
void
PlainTestEnded
(
const
char
*
testName
,
const
char
*
suiteName
,
PlainTestEnded
(
const
char
*
testName
,
const
char
*
suiteName
,
int
testResult
,
int
numAsserts
,
time_t
endTime
,
time_t
totalRuntime
)
int
testResult
,
time_t
endTime
,
time_t
totalRuntime
)
{
{
logger
(
"Asserts:%d
\n
"
,
numAsserts
);
logger
(
"%s: ok"
,
testName
);
logger
(
"%s: ok
\n
"
,
testName
);
}
}
void
void
...
@@ -53,12 +58,19 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
...
@@ -53,12 +58,19 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
time_t
eventTime
)
time_t
eventTime
)
{
{
const
char
*
result
=
(
assertResult
)
?
"passed"
:
"failed"
;
const
char
*
result
=
(
assertResult
)
?
"passed"
:
"failed"
;
logger
(
"%s %d: %s
\n
"
,
assertName
,
assertResult
,
assertMessage
);
logger
(
"%s %d: %s"
,
assertName
,
assertResult
,
assertMessage
);
}
void
PlainAssertSummary
(
int
numAsserts
,
int
numAssertsFailed
,
int
numAssertsPass
)
{
logger
(
"Asserts:%d"
,
numAsserts
);
}
}
void
void
PlainLog
(
const
char
*
logMessage
,
time_t
eventTime
)
PlainLog
(
const
char
*
logMessage
,
time_t
eventTime
)
{
{
logger
(
"%s %d"
,
logMessage
,
eventTime
);
}
}
#endif
#endif
test/test-automation/plain_logger.h
View file @
2e8932b1
...
@@ -17,11 +17,15 @@ void PlainTestStarted(const char *testName, const char *suiteName,
...
@@ -17,11 +17,15 @@ void PlainTestStarted(const char *testName, const char *suiteName,
const
char
*
testDescription
,
time_t
startTime
);
const
char
*
testDescription
,
time_t
startTime
);
void
PlainTestEnded
(
const
char
*
testName
,
const
char
*
suiteName
,
void
PlainTestEnded
(
const
char
*
testName
,
const
char
*
suiteName
,
int
testResult
,
int
numAsserts
,
time_t
endTime
,
time_t
totalRuntime
);
int
testResult
,
time_t
endTime
,
time_t
totalRuntime
);
void
PlainAssert
(
const
char
*
assertName
,
int
assertResult
,
const
char
*
assertMessage
,
void
PlainAssert
(
const
char
*
assertName
,
int
assertResult
,
const
char
*
assertMessage
,
time_t
eventTime
);
time_t
eventTime
);
void
PlainAssertSummary
(
int
numAsserts
,
int
numAssertsFailed
,
int
numAssertsPass
);
void
PlainLog
(
const
char
*
logMessage
,
time_t
eventTime
);
void
PlainLog
(
const
char
*
logMessage
,
time_t
eventTime
);
#endif
#endif
test/test-automation/runner.c
View file @
2e8932b1
...
@@ -29,12 +29,12 @@
...
@@ -29,12 +29,12 @@
#include <sys/types.h>
#include <sys/types.h>
#include "SDL_test.h"
#include "SDL_test.h"
#include "logger.h"
//!< Function pointer to a test case function
//!< Function pointer to a test case function
typedef
void
(
*
TestCaseFp
)(
void
*
arg
);
typedef
void
(
*
TestCaseFp
)(
void
*
arg
);
//!< Function pointer to a test case init function
//!< Function pointer to a test case init function
typedef
void
(
*
TestCaseInitFp
)(
void
);
typedef
void
(
*
TestCaseInitFp
)(
const
int
);
//!< Function pointer to a test case quit function
//!< Function pointer to a test case quit function
typedef
int
(
*
TestCaseQuitFp
)(
void
);
typedef
int
(
*
TestCaseQuitFp
)(
void
);
...
@@ -49,6 +49,8 @@ static int only_selected_test = 0;
...
@@ -49,6 +49,8 @@ static int only_selected_test = 0;
static
int
only_selected_suite
=
0
;
static
int
only_selected_suite
=
0
;
//!< Flag for executing only tests that contain certain string in their name
//!< Flag for executing only tests that contain certain string in their name
static
int
only_tests_with_string
=
0
;
static
int
only_tests_with_string
=
0
;
//!< Flag for enabling XML logging
static
int
xml_enabled
=
0
;
//!< Size of the test and suite name buffers
//!< Size of the test and suite name buffers
...
@@ -86,6 +88,10 @@ typedef struct TestCaseItem {
...
@@ -86,6 +88,10 @@ typedef struct TestCaseItem {
char
*
testName
;
char
*
testName
;
char
*
suiteName
;
char
*
suiteName
;
char
*
description
;
long
requirements
;
long
timeout
;
TestCaseInitFp
testCaseInit
;
TestCaseInitFp
testCaseInit
;
TestCaseFp
testCase
;
TestCaseFp
testCase
;
TestCaseQuitFp
testCaseQuit
;
TestCaseQuitFp
testCaseQuit
;
...
@@ -213,14 +219,24 @@ LoadTestCases(TestSuiteReference *suites)
...
@@ -213,14 +219,24 @@ LoadTestCases(TestSuiteReference *suites)
item
->
testCase
=
testCase
;
item
->
testCase
=
testCase
;
item
->
testCaseQuit
=
testCaseQuit
;
item
->
testCaseQuit
=
testCaseQuit
;
// copy suite name
int
length
=
strlen
(
suiteReference
->
name
)
+
1
;
int
length
=
strlen
(
suiteReference
->
name
)
+
1
;
item
->
suiteName
=
SDL_malloc
(
length
);
item
->
suiteName
=
SDL_malloc
(
length
);
strcpy
(
item
->
suiteName
,
suiteReference
->
name
);
strcpy
(
item
->
suiteName
,
suiteReference
->
name
);
// copy test name
length
=
strlen
(
testReference
->
name
)
+
1
;
length
=
strlen
(
testReference
->
name
)
+
1
;
item
->
testName
=
SDL_malloc
(
length
);
item
->
testName
=
SDL_malloc
(
length
);
strcpy
(
item
->
testName
,
testReference
->
name
);
strcpy
(
item
->
testName
,
testReference
->
name
);
// copy test description
length
=
strlen
(
testReference
->
description
)
+
1
;
item
->
description
=
SDL_malloc
(
length
);
strcpy
(
item
->
testName
,
testReference
->
name
);
item
->
requirements
=
testReference
->
requirements
;
item
->
timeout
=
testReference
->
timeout
;
// prepend the list
// prepend the list
item
->
next
=
testCases
;
item
->
next
=
testCases
;
testCases
=
item
;
testCases
=
item
;
...
@@ -247,6 +263,7 @@ UnloadTestCases(TestCase *testCases)
...
@@ -247,6 +263,7 @@ UnloadTestCases(TestCase *testCases)
while
(
ref
)
{
while
(
ref
)
{
SDL_free
(
ref
->
testName
);
SDL_free
(
ref
->
testName
);
SDL_free
(
ref
->
suiteName
);
SDL_free
(
ref
->
suiteName
);
SDL_free
(
ref
->
description
);
TestCase
*
temp
=
ref
->
next
;
TestCase
*
temp
=
ref
->
next
;
SDL_free
(
ref
);
SDL_free
(
ref
);
...
@@ -482,7 +499,7 @@ int
...
@@ -482,7 +499,7 @@ int
ExecuteTest
(
TestCase
*
testItem
)
{
ExecuteTest
(
TestCase
*
testItem
)
{
int
retVal
=
1
;
int
retVal
=
1
;
if
(
execute_inproc
)
{
if
(
execute_inproc
)
{
testItem
->
testCaseInit
();
testItem
->
testCaseInit
(
xml_enabled
);
testItem
->
testCase
(
0x0
);
testItem
->
testCase
(
0x0
);
...
@@ -490,7 +507,7 @@ ExecuteTest(TestCase *testItem) {
...
@@ -490,7 +507,7 @@ ExecuteTest(TestCase *testItem) {
}
else
{
}
else
{
int
childpid
=
fork
();
int
childpid
=
fork
();
if
(
childpid
==
0
)
{
if
(
childpid
==
0
)
{
testItem
->
testCaseInit
();
testItem
->
testCaseInit
(
xml_enabled
);
testItem
->
testCase
(
0x0
);
testItem
->
testCase
(
0x0
);
...
@@ -517,6 +534,7 @@ printUsage() {
...
@@ -517,6 +534,7 @@ printUsage() {
printf
(
"Options:
\n
"
);
printf
(
"Options:
\n
"
);
printf
(
" --in-proc Executes tests in-process
\n
"
);
printf
(
" --in-proc Executes tests in-process
\n
"
);
printf
(
" --show-tests Prints out all the executable tests
\n
"
);
printf
(
" --show-tests Prints out all the executable tests
\n
"
);
printf
(
" --xml Enables XML logger
\n
"
);
printf
(
" -t --test TEST Executes only tests with given name
\n
"
);
printf
(
" -t --test TEST Executes only tests with given name
\n
"
);
printf
(
" -ts --name-contains SUBSTR Executes only tests that have given
\n
"
);
printf
(
" -ts --name-contains SUBSTR Executes only tests that have given
\n
"
);
printf
(
" substring in test name
\n
"
);
printf
(
" substring in test name
\n
"
);
...
@@ -545,6 +563,9 @@ ParseOptions(int argc, char *argv[])
...
@@ -545,6 +563,9 @@ ParseOptions(int argc, char *argv[])
else
if
(
SDL_strcmp
(
arg
,
"--show-tests"
)
==
0
)
{
else
if
(
SDL_strcmp
(
arg
,
"--show-tests"
)
==
0
)
{
only_print_tests
=
1
;
only_print_tests
=
1
;
}
}
else
if
(
SDL_strcmp
(
arg
,
"--xml"
)
==
0
)
{
xml_enabled
=
1
;
}
else
if
(
SDL_strcmp
(
arg
,
"--test"
)
==
0
||
SDL_strcmp
(
arg
,
"-t"
)
==
0
)
{
else
if
(
SDL_strcmp
(
arg
,
"--test"
)
==
0
||
SDL_strcmp
(
arg
,
"-t"
)
==
0
)
{
only_selected_test
=
1
;
only_selected_test
=
1
;
char
*
testName
=
NULL
;
char
*
testName
=
NULL
;
...
@@ -625,6 +646,11 @@ main(int argc, char *argv[])
...
@@ -625,6 +646,11 @@ main(int argc, char *argv[])
#else
#else
char
*
extension
=
"dylib"
;
char
*
extension
=
"dylib"
;
#endif
#endif
if
(
xml_enabled
)
{
SetupXMLLogger
();
}
else
{
SetupPlainLogger
();
}
const
Uint32
startTicks
=
SDL_GetTicks
();
const
Uint32
startTicks
=
SDL_GetTicks
();
...
@@ -637,29 +663,49 @@ main(int argc, char *argv[])
...
@@ -637,29 +663,49 @@ main(int argc, char *argv[])
if
(
only_print_tests
)
{
if
(
only_print_tests
)
{
TestCase
*
testItem
=
NULL
;
TestCase
*
testItem
=
NULL
;
for
(
testItem
=
testCases
;
testItem
;
testItem
=
testItem
->
next
)
{
for
(
testItem
=
testCases
;
testItem
;
testItem
=
testItem
->
next
)
{
//! \todo This should be handled by the logging system?
printf
(
"%s (in %s)
\n
"
,
testItem
->
testName
,
testItem
->
suiteName
);
printf
(
"%s (in %s)
\n
"
,
testItem
->
testName
,
testItem
->
suiteName
);
}
}
return
0
;
return
0
;
}
}
RunStarted
(
LogGenericOutput
,
NULL
,
0
);
char
*
currentSuiteName
=
NULL
;
TestCase
*
testItem
=
NULL
;
TestCase
*
testItem
=
NULL
;
for
(
testItem
=
testCases
;
testItem
;
testItem
=
testItem
->
next
)
{
for
(
testItem
=
testCases
;
testItem
;
testItem
=
testItem
->
next
)
{
if
(
currentSuiteName
==
NULL
)
{
currentSuiteName
=
testItem
->
suiteName
;
SuiteStarted
(
currentSuiteName
,
0
);
}
TestStarted
(
testItem
->
testName
,
testItem
->
suiteName
,
testItem
->
description
,
0
);
int
retVal
=
ExecuteTest
(
testItem
);
int
retVal
=
ExecuteTest
(
testItem
);
if
(
retVal
)
{
if
(
retVal
)
{
failureCount
++
;
failureCount
++
;
if
(
retVal
==
2
)
{
if
(
retVal
==
2
)
{
printf
(
"%s (in %s): FAILED -> No asserts
\n
"
,
testItem
->
testName
,
testItem
->
suiteName
);
//
printf("%s (in %s): FAILED -> No asserts\n", testItem->testName, testItem->suiteName);
}
else
{
}
else
{
printf
(
"%s (in %s): FAILED
\n
"
,
testItem
->
testName
,
testItem
->
suiteName
);
//
printf("%s (in %s): FAILED\n", testItem->testName, testItem->suiteName);
}
}
}
else
{
}
else
{
passCount
++
;
passCount
++
;
printf
(
"%s (in %s): ok
\n
"
,
testItem
->
testName
,
testItem
->
suiteName
);
//
printf("%s (in %s): ok\n", testItem->testName, testItem->suiteName);
}
}
printf
(
"
\n
"
);
TestEnded
(
testItem
->
testName
,
testItem
->
suiteName
,
retVal
,
0
,
0
);
if
(
strncmp
(
currentSuiteName
,
testItem
->
suiteName
,
100
)
!=
0
)
{
SuiteEnded
(
0
,
0
,
0
,
0
.
0
f
,
0
);
currentSuiteName
=
testItem
->
suiteName
;
SuiteStarted
(
currentSuiteName
,
0
);
}
}
}
UnloadTestCases
(
testCases
);
UnloadTestCases
(
testCases
);
...
@@ -667,10 +713,14 @@ main(int argc, char *argv[])
...
@@ -667,10 +713,14 @@ main(int argc, char *argv[])
const
Uint32
endTicks
=
SDL_GetTicks
();
const
Uint32
endTicks
=
SDL_GetTicks
();
RunEnded
(
passCount
+
failureCount
,
1
/*add suiteCount */
,
passCount
,
failureCount
,
0
,
0
);
/*
printf("Ran %d tests in %0.5f seconds.\n", (passCount + failureCount), (endTicks-startTicks)/1000.0f);
printf("Ran %d tests in %0.5f seconds.\n", (passCount + failureCount), (endTicks-startTicks)/1000.0f);
printf("%d tests passed\n", passCount);
printf("%d tests passed\n", passCount);
printf("%d tests failed\n", failureCount);
printf("%d tests failed\n", failureCount);
*/
return
0
;
return
0
;
}
}
test/test-automation/xml.c
View file @
2e8932b1
...
@@ -55,7 +55,7 @@ AddOpenTag(const char *tag)
...
@@ -55,7 +55,7 @@ AddOpenTag(const char *tag)
const
int
tagSize
=
SDL_strlen
(
tag
)
+
1
;
const
int
tagSize
=
SDL_strlen
(
tag
)
+
1
;
openTag
->
tag
=
SDL_malloc
(
tagSize
);
openTag
->
tag
=
SDL_malloc
(
tagSize
);
strncpy
(
openTag
->
tag
,
tag
,
tagSize
);
strncpy
(
(
char
*
)
openTag
->
tag
,
(
char
*
)
tag
,
tagSize
);
openTag
->
next
=
openTags
;
openTag
->
next
=
openTags
;
...
@@ -86,7 +86,7 @@ RemoveOpenTag(const char *tag)
...
@@ -86,7 +86,7 @@ RemoveOpenTag(const char *tag)
// It prevents opening and ending tag mismatch
// It prevents opening and ending tag mismatch
if
(
SDL_strcmp
(
tempTag
,
tag
)
==
0
)
{
if
(
SDL_strcmp
(
tempTag
,
tag
)
==
0
)
{
TagList
*
openTag
=
openTags
;
TagList
*
openTag
=
openTags
;
SDL_free
(
openTag
->
tag
);
SDL_free
(
(
char
*
)
openTag
->
tag
);
/*
/*
int counter = 0;
int counter = 0;
...
@@ -175,7 +175,7 @@ const char *EscapeString(const char *string) {
...
@@ -175,7 +175,7 @@ const char *EscapeString(const char *string) {
* \return Lower-case version of the given string
* \return Lower-case version of the given string
*/
*/
char
*
char
*
ToLowerCase
(
char
*
string
)
ToLowerCase
(
c
onst
c
har
*
string
)
{
{
const
int
size
=
SDL_strlen
(
string
);
const
int
size
=
SDL_strlen
(
string
);
char
*
ret
=
SDL_malloc
(
size
+
1
);
char
*
ret
=
SDL_malloc
(
size
+
1
);
...
...
test/test-automation/xml_logger.c
View file @
2e8932b1
...
@@ -18,6 +18,9 @@
...
@@ -18,6 +18,9 @@
3. This notice may not be removed or altered from any source distribution.
3. This notice may not be removed or altered from any source distribution.
*/
*/
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL.h>
#include "xml.h"
#include "xml.h"
...
@@ -32,19 +35,19 @@ XMLRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTi
...
@@ -32,19 +35,19 @@ XMLRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTi
{
{
logger
=
outputFn
;
logger
=
outputFn
;
char
*
output
=
XMLOpenDocument
(
"te
ST
tlog"
);
char
*
output
=
XMLOpenDocument
(
"te
s
tlog"
);
logger
(
output
);
logger
(
output
);
SDL_free
(
output
);
SDL_free
(
output
);
output
=
XMLOpenElement
(
"pa
R
ameters"
);
output
=
XMLOpenElement
(
"pa
r
ameters"
);
logger
(
output
);
logger
(
output
);
SDL_free
(
output
);
SDL_free
(
output
);
output
=
XMLAddContent
(
runnerParameters
);
output
=
XMLAddContent
(
"Add: runner parameter"
);
logger
(
output
);
logger
(
output
);
SDL_free
(
output
);
SDL_free
(
output
);
output
=
XMLCloseElement
(
"
P
arameters"
);
output
=
XMLCloseElement
(
"
p
arameters"
);
logger
(
output
);
logger
(
output
);
SDL_free
(
output
);
SDL_free
(
output
);
}
}
...
@@ -53,7 +56,7 @@ void
...
@@ -53,7 +56,7 @@ void
XMLRunEnded
(
int
testCount
,
int
suiteCount
,
int
testPassCount
,
int
testFailCount
,
XMLRunEnded
(
int
testCount
,
int
suiteCount
,
int
testPassCount
,
int
testFailCount
,
time_t
endTime
,
time_t
totalRuntime
)
time_t
endTime
,
time_t
totalRuntime
)
{
{
char
*
output
=
XMLCloseDocument
(
"testl
O
g"
);
char
*
output
=
XMLCloseDocument
(
"testl
o
g"
);
logger
(
output
);
logger
(
output
);
SDL_free
(
output
);
SDL_free
(
output
);
}
}
...
@@ -65,12 +68,12 @@ XMLSuiteStarted(const char *suiteName, time_t eventTime)
...
@@ -65,12 +68,12 @@ XMLSuiteStarted(const char *suiteName, time_t eventTime)
logger
(
output
);
logger
(
output
);
SDL_free
(
output
);
SDL_free
(
output
);
output
=
XMLOpenElement
(
"
EVENTT
ime"
);
output
=
XMLOpenElement
(
"
eventt
ime"
);
logger
(
output
);
logger
(
output
);
SDL_free
(
output
);
SDL_free
(
output
);
//XMLAddContent(evenTime);
//XMLAddContent(evenTime);
output
=
XMLCloseElement
(
"event
TIME
"
);
output
=
XMLCloseElement
(
"event
time
"
);
logger
(
output
);
logger
(
output
);
SDL_free
(
output
);
SDL_free
(
output
);
}
}
...
@@ -130,9 +133,31 @@ XMLTestStarted(const char *testName, const char *suiteName, const char *testDesc
...
@@ -130,9 +133,31 @@ XMLTestStarted(const char *testName, const char *suiteName, const char *testDesc
void
void
XMLTestEnded
(
const
char
*
testName
,
const
char
*
suiteName
,
XMLTestEnded
(
const
char
*
testName
,
const
char
*
suiteName
,
int
testResult
,
int
numAsserts
,
time_t
endTime
,
time_t
totalRuntime
)
int
testResult
,
time_t
endTime
,
time_t
totalRuntime
)
{
{
char
*
output
=
XMLCloseElement
(
"test"
);
char
*
output
=
XMLOpenElement
(
"result"
);
logger
(
output
);
SDL_free
(
output
);
if
(
testResult
)
{
if
(
testResult
==
2
)
{
output
=
XMLAddContent
(
"failed -> no assert"
);
}
else
{
output
=
XMLAddContent
(
"failed"
);
}
logger
(
output
);
SDL_free
(
output
);
}
else
{
output
=
XMLAddContent
(
"passed"
);
logger
(
output
);
SDL_free
(
output
);
}
output
=
XMLCloseElement
(
"result"
);
logger
(
output
);
SDL_free
(
output
);
output
=
XMLCloseElement
(
"test"
);
logger
(
output
);
logger
(
output
);
SDL_free
(
output
);
SDL_free
(
output
);
}
}
...
@@ -153,7 +178,7 @@ XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
...
@@ -153,7 +178,7 @@ XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
logger
(
output
);
logger
(
output
);
SDL_free
(
output
);
SDL_free
(
output
);
output
=
XML
Open
Element
(
"result"
);
output
=
XML
Close
Element
(
"result"
);
logger
(
output
);
logger
(
output
);
SDL_free
(
output
);
SDL_free
(
output
);
...
@@ -162,6 +187,57 @@ XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
...
@@ -162,6 +187,57 @@ XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
SDL_free
(
output
);
SDL_free
(
output
);
}
}
void
XMLAssertSummary
(
int
numAsserts
,
int
numAssertsFailed
,
int
numAssertsPass
)
{
char
*
output
=
XMLOpenElement
(
"assertSummary"
);
logger
(
output
);
SDL_free
(
output
);
output
=
XMLOpenElement
(
"assertCount"
);
logger
(
output
);
SDL_free
(
output
);
//XMLAddContent() \todo add string conversion
output
=
XMLCloseElement
(
"assertCount"
);
logger
(
output
);
SDL_free
(
output
);
output
=
XMLOpenElement
(
"assertsPassed"
);
logger
(
output
);
SDL_free
(
output
);
const
int
bufferSize
=
sizeof
(
int
)
*
8
+
1
;
//char buffer[bufferSize];
char
*
buffer
=
SDL_malloc
(
bufferSize
);
memset
(
buffer
,
'a'
,
bufferSize
);
//SDL_vsnprintf(buffer, bufferSize, "%d", numAssertsPass);
snprintf
(
buffer
,
sizeof
(
buffer
),
"%d"
,
numAssertsPass
);
buffer
[
3
]
=
'a'
;
//printf("DEBUG |%s == %d of size %d", buffer, numAssertsPass, bufferSize);
XMLAddContent
(
buffer
);
output
=
XMLCloseElement
(
"assertsPassed"
);
logger
(
output
);
SDL_free
(
output
);
output
=
XMLOpenElement
(
"assertsFailed"
);
logger
(
output
);
SDL_free
(
output
);
//XMLAddContent() \todo add string conversion
output
=
XMLCloseElement
(
"assertsFailed"
);
logger
(
output
);
SDL_free
(
output
);
output
=
XMLCloseElement
(
"assertSummary"
);
logger
(
output
);
SDL_free
(
output
);
}
void
void
XMLLog
(
const
char
*
logMessage
,
time_t
eventTime
)
XMLLog
(
const
char
*
logMessage
,
time_t
eventTime
)
{
{
...
...
test/test-automation/xml_logger.h
View file @
2e8932b1
...
@@ -16,11 +16,14 @@ void XMLSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
...
@@ -16,11 +16,14 @@ void XMLSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
void
XMLTestStarted
(
const
char
*
testName
,
const
char
*
suiteName
,
const
char
*
testDescription
,
time_t
startTime
);
void
XMLTestStarted
(
const
char
*
testName
,
const
char
*
suiteName
,
const
char
*
testDescription
,
time_t
startTime
);
void
XMLTestEnded
(
const
char
*
testName
,
const
char
*
suiteName
,
void
XMLTestEnded
(
const
char
*
testName
,
const
char
*
suiteName
,
int
testResult
,
int
numAsserts
,
time_t
endTime
,
time_t
totalRuntime
);
int
testResult
,
time_t
endTime
,
time_t
totalRuntime
);
void
XMLAssert
(
const
char
*
assertName
,
int
assertResult
,
const
char
*
assertMessage
,
void
XMLAssert
(
const
char
*
assertName
,
int
assertResult
,
const
char
*
assertMessage
,
time_t
eventTime
);
time_t
eventTime
);
void
XMLAssertSummary
(
int
numAsserts
,
int
numAssertsFailed
,
int
numAssertsPass
);
void
XMLLog
(
const
char
*
logMessage
,
time_t
eventTime
);
void
XMLLog
(
const
char
*
logMessage
,
time_t
eventTime
);
#endif
#endif
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