|
@@ -7,10 +7,19 @@
|
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
#include <cstring>
|
|
#include <cstring>
|
|
|
#include <malloc.h>
|
|
#include <malloc.h>
|
|
|
|
|
+#if ANKI_OS_ANDROID
|
|
|
|
|
+# include <android/log.h>
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
namespace anki
|
|
namespace anki
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
|
|
+#if !ANKI_OS_ANDROID
|
|
|
|
|
+# define ANKI_TEST_LOG(fmt, ...) printf(fmt "\n", __VA_ARGS__)
|
|
|
|
|
+#else
|
|
|
|
|
+# define ANKI_TEST_LOG(fmt, ...) __android_log_print(ANDROID_LOG_INFO, "AnKi Tests", fmt, __VA_ARGS__)
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
TestSuite::~TestSuite()
|
|
TestSuite::~TestSuite()
|
|
|
{
|
|
{
|
|
|
for(Test* t : tests)
|
|
for(Test* t : tests)
|
|
@@ -21,7 +30,7 @@ TestSuite::~TestSuite()
|
|
|
|
|
|
|
|
void Test::run()
|
|
void Test::run()
|
|
|
{
|
|
{
|
|
|
- std::cout << "========\nRunning " << suite->name << " " << name << "\n========" << std::endl;
|
|
|
|
|
|
|
+ ANKI_TEST_LOG("========\nRunning %s %s\n========", suite->name.c_str(), name.c_str());
|
|
|
|
|
|
|
|
#if ANKI_OS_LINUX
|
|
#if ANKI_OS_LINUX
|
|
|
struct mallinfo a = mallinfo();
|
|
struct mallinfo a = mallinfo();
|
|
@@ -35,11 +44,9 @@ void Test::run()
|
|
|
int diff = b.uordblks - a.uordblks;
|
|
int diff = b.uordblks - a.uordblks;
|
|
|
if(diff > 0)
|
|
if(diff > 0)
|
|
|
{
|
|
{
|
|
|
- std::cerr << "Test leaks memory: " << diff << std::endl;
|
|
|
|
|
|
|
+ ANKI_TEST_LOG("Test leaks memory: %d", diff);
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
|
-
|
|
|
|
|
- std::cout << std::endl;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Tester::addTest(const char* name, const char* suiteName, TestCallback callback)
|
|
void Tester::addTest(const char* name, const char* suiteName, TestCallback callback)
|
|
@@ -72,7 +79,7 @@ void Tester::addTest(const char* name, const char* suiteName, TestCallback callb
|
|
|
{
|
|
{
|
|
|
if((*it)->name == name)
|
|
if((*it)->name == name)
|
|
|
{
|
|
{
|
|
|
- std::cerr << "Test already exists: " << name << std::endl;
|
|
|
|
|
|
|
+ ANKI_TEST_LOG("Test already exists: %s", name);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -111,7 +118,7 @@ Options:
|
|
|
}
|
|
}
|
|
|
else if(strcmp(arg, "--help") == 0)
|
|
else if(strcmp(arg, "--help") == 0)
|
|
|
{
|
|
{
|
|
|
- std::cout << helpMessage << std::endl;
|
|
|
|
|
|
|
+ ANKI_TEST_LOG("%s", helpMessage.c_str());
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
else if(strcmp(arg, "--suite") == 0)
|
|
else if(strcmp(arg, "--suite") == 0)
|
|
@@ -119,7 +126,7 @@ Options:
|
|
|
++i;
|
|
++i;
|
|
|
if(i >= argc)
|
|
if(i >= argc)
|
|
|
{
|
|
{
|
|
|
- std::cerr << "<name> is missing after --suite" << std::endl;
|
|
|
|
|
|
|
+ ANKI_TEST_LOG("%s", "<name> is missing after --suite");
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
suiteName = argv[i];
|
|
suiteName = argv[i];
|
|
@@ -129,7 +136,7 @@ Options:
|
|
|
++i;
|
|
++i;
|
|
|
if(i >= argc)
|
|
if(i >= argc)
|
|
|
{
|
|
{
|
|
|
- std::cerr << "<name> is missing after --test" << std::endl;
|
|
|
|
|
|
|
+ ANKI_TEST_LOG("%s", "<name> is missing after --test");
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
testName = argv[i];
|
|
testName = argv[i];
|
|
@@ -139,7 +146,7 @@ Options:
|
|
|
// Sanity check
|
|
// Sanity check
|
|
|
if(testName.length() > 0 && suiteName.length() == 0)
|
|
if(testName.length() > 0 && suiteName.length() == 0)
|
|
|
{
|
|
{
|
|
|
- std::cout << "Specify --suite as well" << std::endl;
|
|
|
|
|
|
|
+ ANKI_TEST_LOG("%s", "Specify --suite as well");
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -180,15 +187,15 @@ Options:
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int failed = run - passed;
|
|
int failed = run - passed;
|
|
|
- std::cout << "========\nRun " << run << " tests, failed " << failed << std::endl;
|
|
|
|
|
|
|
+ ANKI_TEST_LOG("========\nRun %d tests, failed %d", run, failed);
|
|
|
|
|
|
|
|
if(failed == 0)
|
|
if(failed == 0)
|
|
|
{
|
|
{
|
|
|
- std::cout << "SUCCESS!" << std::endl;
|
|
|
|
|
|
|
+ ANKI_TEST_LOG("%s", "SUCCESS!");
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- std::cout << "FAILURE" << std::endl;
|
|
|
|
|
|
|
+ ANKI_TEST_LOG("%s", "FAILURE");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return run - passed;
|
|
return run - passed;
|
|
@@ -200,8 +207,7 @@ int Tester::listTests()
|
|
|
{
|
|
{
|
|
|
for(Test* test : suite->tests)
|
|
for(Test* test : suite->tests)
|
|
|
{
|
|
{
|
|
|
- std::cout << programName << " --suite \"" << suite->name << "\" --test \"" << test->name << "\""
|
|
|
|
|
- << std::endl;
|
|
|
|
|
|
|
+ ANKI_TEST_LOG("%s --suite %s --test %s", programName.c_str(), suite->name.c_str(), test->name.c_str());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|