From 25e042e43e076b9387ecf0b7faa55e2917f9c9cc Mon Sep 17 00:00:00 2001 From: khizmax Date: Sat, 26 Sep 2015 11:48:28 +0300 Subject: [PATCH] Added -list option to test framework Fixed MultiLevelHashSet/Map print_stat() test function --- tests/cppunit/cppunit_mini.h | 18 +++++---- tests/cppunit/test_main.cpp | 39 +++++++++++++------ tests/unit/map2/map_type_multilevel_hashmap.h | 2 +- tests/unit/set2/set_type_multilevel_hashset.h | 2 +- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/tests/cppunit/cppunit_mini.h b/tests/cppunit/cppunit_mini.h index 7ca40700..a3232162 100644 --- a/tests/cppunit/cppunit_mini.h +++ b/tests/cppunit/cppunit_mini.h @@ -136,7 +136,10 @@ namespace CppUnitMini class TestCase : public TestFixture { public: - TestCase() { registerTestCase(this); } + TestCase() + { + registerTestCase(this); + } void setUp() { m_failed = false; } static int run(Reporter *in_reporter = 0, const char *in_testName = "", bool invert = false); @@ -159,6 +162,7 @@ namespace CppUnitMini m_reporter->error(in_macroName, in_macro, in_file, in_line); } } + virtual char const * test_name() const = 0; static void message(const char *msg) { if (m_reporter) { @@ -193,7 +197,7 @@ namespace CppUnitMini static void print_gc_state(); - static std::vector const& getTestStrings(); + static std::vector const& getTestStrings(); template static void shuffle( RandomIt first, RandomIt last ) @@ -201,6 +205,8 @@ namespace CppUnitMini std::shuffle( first, last, m_RandomGen ); } + static void print_test_list(); + protected: static std::vector m_arrStrings ; // array of test strings @@ -240,16 +246,12 @@ namespace CppUnitMini #define CPPUNIT_TEST_SUITE_(X, cfgBranchName) \ typedef CppUnitMini::TestCase Base; \ + virtual char const * test_name() const { return #X; } \ virtual void myRun(const char *in_name, bool invert = false) { \ const char *className = #X; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(className) \ bool ignoring = false; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(ignoring) \ setUpParams( m_Cfg.get( cfgBranchName )); -#define CPPUNIT_TEST_SUITE_PART(X, func) \ - void X::func(const char *in_name, bool invert /*= false*/) { \ - const char *className = #X; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(className) \ - bool ignoring = false; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(ignoring) - #define CPPUNIT_TEST_SUITE(X) CPPUNIT_TEST_SUITE_(X, #X) #if defined CPPUNIT_MINI_USE_EXCEPTIONS @@ -300,8 +302,8 @@ namespace CppUnitMini #define CPPUNIT_TEST_SUITE_END() endTestCase(); } #define CPPUNIT_TEST_SUITE_END_PART() } -#define CPPUNIT_TEST_SUITE_REGISTRATION(X) static X local #define CPPUNIT_TEST_SUITE_REGISTRATION_(X, NAME) static X NAME +#define CPPUNIT_TEST_SUITE_REGISTRATION(X) CPPUNIT_TEST_SUITE_REGISTRATION_(X, local) #define CPPUNIT_CHECK(X) \ if (!(X)) { \ diff --git a/tests/cppunit/test_main.cpp b/tests/cppunit/test_main.cpp index 7f418671..b004f8c4 100644 --- a/tests/cppunit/test_main.cpp +++ b/tests/cppunit/test_main.cpp @@ -144,6 +144,7 @@ namespace CppUnitMini return !explicit_test && (match == !invert); } do_progress = true; + return !explicit_test; } @@ -158,6 +159,16 @@ namespace CppUnitMini } } + void TestCase::print_test_list() + { + TestCase *tmp = m_root; + std::cout << "Test list:\n"; + while (tmp != 0) { + std::cout << "\t" << tmp->test_name() << "\n"; + tmp = tmp->m_next; + } + } + void Config::load( const char * fileName ) { std::ifstream s; @@ -220,7 +231,7 @@ namespace CppUnitMini s.close(); } - std::vector const & TestCase::getTestStrings() + std::vector const & TestCase::getTestStrings() { if ( m_arrStrings.empty() ) { std::string strTestDir = m_strTestDataDir; @@ -255,15 +266,17 @@ namespace CppUnitMini static void usage(const char* name) { - printf("Usage : %s [-t=[::]] [-x=[::]] [-f=] [-m]\n", name); - printf("\t[-t=[::]] : test class or class::test to execute\n"); - printf("\t[-x=[::]] : test class or class::test to exclude from execution\n"); - printf("\t[-d=dir] : test data directory (default is .)\n"); - printf( "\t[-f=] : output file\n" ); - //printf(";\n\t[-m] : monitor test execution, display time duration for each test\n"); - printf( "\t[-exact-match] : class::test should be exactly matched to existing test\n" ); - printf("\t[-gc_state] : print gc state after each test\n"); - printf("\t[-cfg=] : config file name for tests\n"); + std::cout << "Usage: " << name << " [options] [-t=[::]] [-x=[::]] [-f=]\n" + "\t[-t=[::]] : test class or class::test to execute\n" + "\t[-d=dir] : test data directory (default is .)\n" + "\t[-f=] : output file\n" + "Options:\n" + "\t-exact-match - class::test should be exactly matched to existing test\n" + "\t-gc_state - print gc state after each test\n" + "\t-cfg= - config file name for tests\n" + "\t-list - list all tests\n" + "\t" + << std::endl; } int main(int argc, char** argv) @@ -322,6 +335,10 @@ int main(int argc, char** argv) CppUnitMini::TestCase::m_bExactMatch = true; continue; } + else if (strncmp(argv[i], "-list", 5) == 0) { + CppUnitMini::TestCase::print_test_list(); + return 0; + } else if ( strncmp(argv[i], "-gc_state", 9) == 0 ) { CppUnitMini::TestCase::m_bPrintGCState = true; continue; @@ -394,7 +411,7 @@ int main(int argc, char** argv) { std::cout << "System topology:\n" - << " Logical processor count: " << cds::OS::topology::processor_count() << "\n"; + << " Logical processor count: " << std::thread::hardware_concurrency() << "\n"; std::cout << std::endl; } diff --git a/tests/unit/map2/map_type_multilevel_hashmap.h b/tests/unit/map2/map_type_multilevel_hashmap.h index 623cfbc8..71d6091b 100644 --- a/tests/unit/map2/map_type_multilevel_hashmap.h +++ b/tests/unit/map2/map_type_multilevel_hashmap.h @@ -113,7 +113,7 @@ namespace map2 { }; template - static inline void print_stat( cc::MultiLevelHashMap< GC, K, T, Traits > const& m ) + static inline void print_stat( MultiLevelHashMap< GC, K, T, Traits > const& m ) { CPPUNIT_MSG( m.statistics() ); } diff --git a/tests/unit/set2/set_type_multilevel_hashset.h b/tests/unit/set2/set_type_multilevel_hashset.h index 46941016..d35ae0e4 100644 --- a/tests/unit/set2/set_type_multilevel_hashset.h +++ b/tests/unit/set2/set_type_multilevel_hashset.h @@ -176,7 +176,7 @@ namespace set2 { }; template - static inline void print_stat( cc::MultiLevelHashSet< GC, T, Traits > const& s ) + static inline void print_stat( MultiLevelHashSet< GC, T, Traits > const& s ) { CPPUNIT_MSG( s.statistics() ); } -- 2.34.1