Commit 4577afdb authored by hybrid's avatar hybrid

Avoid the many hanging processes. Add some more tests and output.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2845 dfc29bdd-3216-0410-991c-e03cc46cb475
parent ef99c270
...@@ -4,7 +4,7 @@ Sources = $(wildcard *.cpp) ...@@ -4,7 +4,7 @@ Sources = $(wildcard *.cpp)
CPPFLAGS = -I../include -I/usr/X11R6/include -pipe CPPFLAGS = -I../include -I/usr/X11R6/include -pipe
# CXXFLAGS += -O3 # CXXFLAGS += -O3
CXXFLAGS += -Wall -g -D_DEBUG CXXFLAGS += -Wall -O1 -g -D_DEBUG
ifeq ($(HOSTTYPE), x86_64) ifeq ($(HOSTTYPE), x86_64)
LIBSELECT=64 LIBSELECT=64
......
...@@ -15,30 +15,25 @@ ...@@ -15,30 +15,25 @@
#include <time.h> #include <time.h>
#include <vector> #include <vector>
typedef struct _STestDefinition struct STestDefinition
{ {
//! The test entry point function //! The test entry point function
bool(*testSignature)(void); bool(*testSignature)(void);
//! A descriptive name for the test //! A descriptive name for the test
const char * testName; const char * testName;
} STestDefinition; };
//! This is the main entry point for the Irrlicht test suite. //! This is the main entry point for the Irrlicht test suite.
/** \return The number of test that failed, i.e. 0 is success. */ /** \return The number of test that failed, i.e. 0 is success. */
int main(int argumentCount, char * arguments[]) int main(int argumentCount, char * arguments[])
{ {
bool logFileOpened = openTestLog(1 == argumentCount);
assert(logFileOpened);
if(argumentCount > 3) if(argumentCount > 3)
{ {
logTestString("\nUsage: %s [testNumber] [totalFails]\n"); logTestString("\nUsage: %s [testNumber] [testCount]\n");
closeTestLog();
return 9999; return 9999;
} }
#define TEST(x)\ #define TEST(x)\
{\ {\
extern bool x(void);\ extern bool x(void);\
...@@ -103,56 +98,93 @@ int main(int argumentCount, char * arguments[]) ...@@ -103,56 +98,93 @@ int main(int argumentCount, char * arguments[])
TEST(terrainSceneNode); TEST(terrainSceneNode);
TEST(lightMaps); TEST(lightMaps);
const unsigned int numberOfTests = tests.size(); unsigned int numberOfTests = tests.size();
unsigned int testToRun = 0; unsigned int testToRun = 0;
unsigned int fails = 0; unsigned int fails = 0;
bool firstRun=true;
const bool spawn=true;
// args: [testNumber] [testCount]
if(argumentCount > 1) if(argumentCount > 1)
{ {
testToRun = (unsigned int)atoi(arguments[1]); if (!strcmp(arguments[1],"--list"))
if(testToRun >= numberOfTests)
{ {
logTestString("\nError: invalid test %d (maximum %d)\n", for (unsigned int i=0; i<tests.size(); ++i)
testToRun, numberOfTests - 1); {
closeTestLog(); printf("%3d: %s\n", i, tests[i].testName);
return 9999;
} }
printf("\n");
return 0;
} }
if(argumentCount > 2) int tmp = atoi(arguments[1]);
fails = (unsigned int)atoi(arguments[2]); firstRun = (tmp>=0);
testToRun=abs(tmp);
logTestString("\nStarting test %d, '%s'\n",
testToRun + 1, tests[testToRun].testName);
bool success = tests[testToRun].testSignature(); if(argumentCount > 2)
{
numberOfTests = testToRun + abs(atoi(arguments[2]));
if (numberOfTests>=tests.size())
numberOfTests=tests.size();
}
}
if(!success) if(testToRun >= numberOfTests)
{ {
logTestString("\n******** Test failure ********\nTest %d '%s' failed\n"\ logTestString("\nError: invalid test %d (maximum %d)\n",
"******** Test failure ********\n", testToRun, numberOfTests-testToRun);
testToRun + 1, tests[testToRun].testName); return 9999;
fails++;
} }
testToRun++; const unsigned int testCount = numberOfTests-testToRun;
if(testToRun < numberOfTests) const bool logFileOpened = openTestLog(firstRun);
assert(logFileOpened);
if (firstRun)
{
if (numberOfTests)
{
for (unsigned int i=testToRun; i<numberOfTests; ++i)
{
logTestString("\nStarting test %d, '%s'\n",
i, tests[i].testName);
if (spawn)
{ {
closeTestLog(); closeTestLog();
char runNextTest[256]; char runNextTest[256];
(void)sprintf(runNextTest, "\"%s\" %d %d", arguments[0], testToRun, fails); (void)sprintf(runNextTest, "\"%s\" %d", arguments[0], -i);
fails = system(runNextTest); // Spawn the next test in a new process. // Spawn the next test in a new process.
if (system(runNextTest))
{
(void)openTestLog(false);
logTestString("\n******** Test failure ********\n"\
"Test %d '%s' failed\n"\
"******** Test failure ********\n",
i, tests[i].testName);
++fails;
} }
else else
{
(void)openTestLog(false); (void)openTestLog(false);
const int passed = numberOfTests - fails; }
else
{
if (!tests[i].testSignature())
{
logTestString("\n******** Test failure ********\n"\
"Test %d '%s' failed\n"\
"******** Test failure ********\n",
i, tests[i].testName);
++fails;
}
}
}
}
const int passed = testCount - fails;
logTestString("\nTests finished. %d test%s of %d passed.\n", logTestString("\nTests finished. %d test%s of %d passed.\n\n",
passed, 1 == passed ? "" : "s", numberOfTests); passed, 1 == passed ? "" : "s", testCount);
if(0 == fails) if(0 == fails && testCount==tests.size())
{ {
time_t rawtime; time_t rawtime;
struct tm * timeinfo; struct tm * timeinfo;
...@@ -172,8 +204,13 @@ int main(int argumentCount, char * arguments[]) ...@@ -172,8 +204,13 @@ int main(int argumentCount, char * arguments[])
#else #else
(void)system("$PAGER tests.log"); (void)system("$PAGER tests.log");
#endif #endif
}
return fails; return fails;
}
else
{
const bool res = tests[testToRun].testSignature();
closeTestLog();
return res?0:1;
}
} }
...@@ -49,6 +49,25 @@ bool matrices(void) ...@@ -49,6 +49,25 @@ bool matrices(void)
return result; return result;
} }
// Test rotations
bool transformations(void)
{
bool result = true;
matrix4 m, s;
m.setRotationDegrees(core::vector3df(30,40,50));
s.setScale(core::vector3df(2,3,4));
m *= s;
m.setTranslation(core::vector3df(5,6,7));
result &= (core::vector3df(5,6,7).equals(m.getTranslation()));
assert(result);
result &= (core::vector3df(2,3,4).equals(m.getScale()));
assert(result);
core::vector3df newRotation = m.getRotationDegrees();
result &= (core::vector3df(30,40,50).equals(newRotation, 0.000004f));
assert(result);
return result;
}
// Test rotations // Test rotations
bool rotations(void) bool rotations(void)
{ {
...@@ -106,7 +125,8 @@ bool rotations(void) ...@@ -106,7 +125,8 @@ bool rotations(void)
rot4.transformVect(vec3);rot5.transformVect(vec32); rot4.transformVect(vec3);rot5.transformVect(vec32);
result &= (vec1.equals(vec12)); result &= (vec1.equals(vec12));
result &= (vec2.equals(vec22)); result &= (vec2.equals(vec22));
result &= (vec3.equals(vec32)); // this one needs higher tolerance due to rounding issues
result &= (vec3.equals(vec32, 0.000002f));
assert(result); assert(result);
vec1.set(1,2,3);vec12.set(1,2,3); vec1.set(1,2,3);vec12.set(1,2,3);
...@@ -124,7 +144,8 @@ bool rotations(void) ...@@ -124,7 +144,8 @@ bool rotations(void)
rot4.transformVect(vec3);rot5.transformVect(vec32); rot4.transformVect(vec3);rot5.transformVect(vec32);
result &= (vec1.equals(vec12)); result &= (vec1.equals(vec12));
result &= (vec2.equals(vec22)); result &= (vec2.equals(vec22));
result &= (vec3.equals(vec32)); // this one needs higher tolerance due to rounding issues
result &= (vec3.equals(vec32, 0.000002f));
assert(result); assert(result);
return result; return result;
...@@ -174,6 +195,7 @@ bool matrixOps(void) ...@@ -174,6 +195,7 @@ bool matrixOps(void)
result &= matrices(); result &= matrices();
result &= rotations(); result &= rotations();
result &= isOrthogonal(); result &= isOrthogonal();
result &= transformations();
return result; return result;
} }
...@@ -237,7 +237,7 @@ bool openTestLog(bool startNewLog, const char * filename) ...@@ -237,7 +237,7 @@ bool openTestLog(bool startNewLog, const char * filename)
void closeTestLog(void) void closeTestLog(void)
{ {
if(logFile) if (logFile)
{ {
(void)fclose(logFile); (void)fclose(logFile);
logFile = 0; logFile = 0;
......
...@@ -78,7 +78,7 @@ static bool doTests() ...@@ -78,7 +78,7 @@ static bool doTests()
EQUAL_VECTORS(vec, vector3d<T>(0, (T)7.0710678118654755, 0)); EQUAL_VECTORS(vec, vector3d<T>(0, (T)7.0710678118654755, 0));
vec.normalize(); vec.normalize();
EQUAL_VECTORS(vec, vector3d<T>(0, (T)1.0000000461060017, 0)); EQUAL_VECTORS(vec, vector3d<T>(0, (T)1.0, 0));
vec.set(10, 10, 10); vec.set(10, 10, 10);
center.set(5, 5, 10); center.set(5, 5, 10);
...@@ -189,20 +189,20 @@ static bool doTests() ...@@ -189,20 +189,20 @@ static bool doTests()
values cast to (T), as we need to test <f64>. */ values cast to (T), as we need to test <f64>. */
bool testVector3d(void) bool testVector3d(void)
{ {
bool f32Success = doTests<f32>(); const bool f32Success = doTests<f32>();
if(f32Success) if (f32Success)
logTestString("vector3df tests passed\n\n"); logTestString("vector3df tests passed\n\n");
else else
logTestString("\n*** vector3df tests failed ***\n\n"); logTestString("\n*** vector3df tests failed ***\n\n");
bool f64Success = doTests<f64>(); const bool f64Success = doTests<f64>();
if(f64Success) if (f64Success)
logTestString("vector3d<f64> tests passed\n\n"); logTestString("vector3d<f64> tests passed\n\n");
else else
logTestString("\n*** vector3d<f64> tests failed ***\n\n"); logTestString("\n*** vector3d<f64> tests failed ***\n\n");
bool s32Success = doTests<s32>(); const bool s32Success = doTests<s32>();
if(s32Success) if (s32Success)
logTestString("vector3di tests passed\n\n"); logTestString("vector3di tests passed\n\n");
else else
logTestString("\n*** vector3di tests failed ***\n\n"); logTestString("\n*** vector3di tests failed ***\n\n");
......
...@@ -59,12 +59,24 @@ bool vectorPositionDimension2d(void) ...@@ -59,12 +59,24 @@ bool vectorPositionDimension2d(void)
{ {
bool result = true; bool result = true;
logTestString("vector,position,dimesion test with s32\n\n");
result &= doTest<dimension2di, vector2di, position2di, s32>(); result &= doTest<dimension2di, vector2di, position2di, s32>();
if (result)
logTestString("tests passed\n\n");
else
logTestString("\ntests failed\n\n");
logTestString("vector,position,dimesion test with f32\n\n");
result &= doTest<dimension2df, vector2df, position2df, f32>(); result &= doTest<dimension2df, vector2df, position2df, f32>();
if (result)
logTestString("tests passed\n\n");
else
logTestString("\ntests failed\n\n");
logTestString("vector,position,dimesion test with f64\n\n");
result &= doTest<dimension2d<f64>, vector2d<f64>, position2d<f64>, f64>(); result &= doTest<dimension2d<f64>, vector2d<f64>, position2d<f64>, f64>();
if (result)
if(!result) logTestString("tests passed\n\n");
assert(false); else
logTestString("\ntests failed\n\n");
return result; return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment