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)
CPPFLAGS = -I../include -I/usr/X11R6/include -pipe
# CXXFLAGS += -O3
CXXFLAGS += -Wall -g -D_DEBUG
CXXFLAGS += -Wall -O1 -g -D_DEBUG
ifeq ($(HOSTTYPE), x86_64)
LIBSELECT=64
......
......@@ -15,30 +15,25 @@
#include <time.h>
#include <vector>
typedef struct _STestDefinition
struct STestDefinition
{
//! The test entry point function
bool(*testSignature)(void);
//! A descriptive name for the test
const char * testName;
} STestDefinition;
};
//! This is the main entry point for the Irrlicht test suite.
/** \return The number of test that failed, i.e. 0 is success. */
int main(int argumentCount, char * arguments[])
{
bool logFileOpened = openTestLog(1 == argumentCount);
assert(logFileOpened);
if(argumentCount > 3)
{
logTestString("\nUsage: %s [testNumber] [totalFails]\n");
closeTestLog();
logTestString("\nUsage: %s [testNumber] [testCount]\n");
return 9999;
}
#define TEST(x)\
{\
extern bool x(void);\
......@@ -103,56 +98,93 @@ int main(int argumentCount, char * arguments[])
TEST(terrainSceneNode);
TEST(lightMaps);
const unsigned int numberOfTests = tests.size();
unsigned int numberOfTests = tests.size();
unsigned int testToRun = 0;
unsigned int fails = 0;
bool firstRun=true;
const bool spawn=true;
// args: [testNumber] [testCount]
if(argumentCount > 1)
{
testToRun = (unsigned int)atoi(arguments[1]);
if(testToRun >= numberOfTests)
if (!strcmp(arguments[1],"--list"))
{
logTestString("\nError: invalid test %d (maximum %d)\n",
testToRun, numberOfTests - 1);
closeTestLog();
return 9999;
for (unsigned int i=0; i<tests.size(); ++i)
{
printf("%3d: %s\n", i, tests[i].testName);
}
printf("\n");
return 0;
}
}
if(argumentCount > 2)
fails = (unsigned int)atoi(arguments[2]);
logTestString("\nStarting test %d, '%s'\n",
testToRun + 1, tests[testToRun].testName);
int tmp = atoi(arguments[1]);
firstRun = (tmp>=0);
testToRun=abs(tmp);
bool success = tests[testToRun].testSignature();
if(!success)
{
logTestString("\n******** Test failure ********\nTest %d '%s' failed\n"\
"******** Test failure ********\n",
testToRun + 1, tests[testToRun].testName);
fails++;
if(argumentCount > 2)
{
numberOfTests = testToRun + abs(atoi(arguments[2]));
if (numberOfTests>=tests.size())
numberOfTests=tests.size();
}
}
testToRun++;
if(testToRun < numberOfTests)
if(testToRun >= numberOfTests)
{
closeTestLog();
char runNextTest[256];
(void)sprintf(runNextTest, "\"%s\" %d %d", arguments[0], testToRun, fails);
fails = system(runNextTest); // Spawn the next test in a new process.
logTestString("\nError: invalid test %d (maximum %d)\n",
testToRun, numberOfTests-testToRun);
return 9999;
}
else
const unsigned int testCount = numberOfTests-testToRun;
const bool logFileOpened = openTestLog(firstRun);
assert(logFileOpened);
if (firstRun)
{
(void)openTestLog(false);
const int passed = numberOfTests - fails;
if (numberOfTests)
{
for (unsigned int i=testToRun; i<numberOfTests; ++i)
{
logTestString("\nStarting test %d, '%s'\n",
i, tests[i].testName);
if (spawn)
{
closeTestLog();
char runNextTest[256];
(void)sprintf(runNextTest, "\"%s\" %d", arguments[0], -i);
// 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
(void)openTestLog(false);
}
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",
passed, 1 == passed ? "" : "s", numberOfTests);
logTestString("\nTests finished. %d test%s of %d passed.\n\n",
passed, 1 == passed ? "" : "s", testCount);
if(0 == fails)
if(0 == fails && testCount==tests.size())
{
time_t rawtime;
struct tm * timeinfo;
......@@ -172,8 +204,13 @@ int main(int argumentCount, char * arguments[])
#else
(void)system("$PAGER tests.log");
#endif
return fails;
}
else
{
const bool res = tests[testToRun].testSignature();
closeTestLog();
return res?0:1;
}
return fails;
}
......@@ -49,6 +49,25 @@ bool matrices(void)
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
bool rotations(void)
{
......@@ -106,7 +125,8 @@ bool rotations(void)
rot4.transformVect(vec3);rot5.transformVect(vec32);
result &= (vec1.equals(vec12));
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);
vec1.set(1,2,3);vec12.set(1,2,3);
......@@ -124,7 +144,8 @@ bool rotations(void)
rot4.transformVect(vec3);rot5.transformVect(vec32);
result &= (vec1.equals(vec12));
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);
return result;
......@@ -174,6 +195,7 @@ bool matrixOps(void)
result &= matrices();
result &= rotations();
result &= isOrthogonal();
result &= transformations();
return result;
}
......@@ -237,7 +237,7 @@ bool openTestLog(bool startNewLog, const char * filename)
void closeTestLog(void)
{
if(logFile)
if (logFile)
{
(void)fclose(logFile);
logFile = 0;
......
......@@ -78,7 +78,7 @@ static bool doTests()
EQUAL_VECTORS(vec, vector3d<T>(0, (T)7.0710678118654755, 0));
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);
center.set(5, 5, 10);
......@@ -189,20 +189,20 @@ static bool doTests()
values cast to (T), as we need to test <f64>. */
bool testVector3d(void)
{
bool f32Success = doTests<f32>();
if(f32Success)
const bool f32Success = doTests<f32>();
if (f32Success)
logTestString("vector3df tests passed\n\n");
else
logTestString("\n*** vector3df tests failed ***\n\n");
bool f64Success = doTests<f64>();
if(f64Success)
const bool f64Success = doTests<f64>();
if (f64Success)
logTestString("vector3d<f64> tests passed\n\n");
else
logTestString("\n*** vector3d<f64> tests failed ***\n\n");
bool s32Success = doTests<s32>();
if(s32Success)
const bool s32Success = doTests<s32>();
if (s32Success)
logTestString("vector3di tests passed\n\n");
else
logTestString("\n*** vector3di tests failed ***\n\n");
......
......@@ -59,12 +59,24 @@ bool vectorPositionDimension2d(void)
{
bool result = true;
logTestString("vector,position,dimesion test with s32\n\n");
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>();
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>();
if(!result)
assert(false);
if (result)
logTestString("tests passed\n\n");
else
logTestString("\ntests failed\n\n");
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