diff options
author | Mark Wenning <wenning@us.ibm.com> | 2011-05-18 15:52:46 -0500 |
---|---|---|
committer | A. Patrick Williams III <iawillia@us.ibm.com> | 2011-06-01 14:07:35 -0500 |
commit | 8509613766f5b1074f89589e653bcb8a4cec2ac0 (patch) | |
tree | e5445f93b2bb1c1a9741b737f217b0385e0e5f96 /src | |
parent | 329be941b1056a3b2e68fcfdf1bc4a9cd5335c84 (diff) | |
download | talos-hostboot-8509613766f5b1074f89589e653bcb8a4cec2ac0.tar.gz talos-hostboot-8509613766f5b1074f89589e653bcb8a4cec2ac0.zip |
CxxTest logs messages to trace buffer
- mark globals with g_
- thread safety
- remove more tabs.
- Add globals and accessors to track totaltests, failedtests, warnings, tracecalls.
- Modify cxxtestgen.pl to add reportTotalTests() call
- uncommented printk's in TestSuite.C
- cxxtestgen.pl just prints out the test suite
- exampletest.H has more descriptive test names, forces a FAIL, WARN, and TRACE
- add a printk() to cxxtest module so that we know it ran.
Change-Id: I3ff25b228f17371b6f84bdb16309015818867266
Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/90
Tested-by: Jenkins Server
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src')
-rwxr-xr-x | src/include/usr/cxxtest/TestSuite.H | 14 | ||||
-rwxr-xr-x | src/usr/cxxtest/TestSuite.C | 147 | ||||
-rw-r--r-- | src/usr/cxxtest/cxxtestexec.C | 3 | ||||
-rwxr-xr-x | src/usr/cxxtest/cxxtestgen.pl | 14 | ||||
-rw-r--r-- | src/usr/example/test/exampletest.H | 67 |
5 files changed, 211 insertions, 34 deletions
diff --git a/src/include/usr/cxxtest/TestSuite.H b/src/include/usr/cxxtest/TestSuite.H index 3cba6eeac..bd152196b 100755 --- a/src/include/usr/cxxtest/TestSuite.H +++ b/src/include/usr/cxxtest/TestSuite.H @@ -3,6 +3,11 @@ #ifndef __cxxtest__TestSuite_h__ #define __cxxtest__TestSuite_h__ +/******************************************************************************/ +// Includes +/******************************************************************************/ +#include <stdint.h> + // // class TestSuite is the base class for all test suites. // To define a test suite, derive from this class and add @@ -18,7 +23,7 @@ namespace CxxTest virtual void setUp(); virtual void tearDown(); }; - + class AbortTest {}; void doTrace( const char *file, unsigned line, const char *message ); @@ -27,6 +32,13 @@ namespace CxxTest void doFailAssert( const char *file, unsigned line, const char *expression, const char *message ); + void reportTotalTests( const char *suitename, uint64_t numtests ); + + // $$ these should be set up as readonly accessors + uint64_t getTotalTests(void); + uint64_t getFailedTests(void); + uint64_t getWarnings(void); + uint64_t getTraceCalls(void); # define _TS_TRY # define ___TSM_CATCH(f,l,m) diff --git a/src/usr/cxxtest/TestSuite.C b/src/usr/cxxtest/TestSuite.C index c42e23a72..17460ae3b 100755 --- a/src/usr/cxxtest/TestSuite.C +++ b/src/usr/cxxtest/TestSuite.C @@ -3,12 +3,38 @@ #ifndef __cxxtest__TestSuite_cpp__ #define __cxxtest__TestSuite_cpp__ -#include <cxxtest/TestSuite.H> #include <stdarg.h> #include <arch/ppc.H> +#include <kernel/console.H> + +#include <cxxtest/TestSuite.H> namespace CxxTest { + /******************************************************************************/ + // Globals/Constants + /******************************************************************************/ + + /** + * @brief global vars to keep track of unit tests. + * + * totaltests - initialized to 0, updated by reporttotaltests() below. + * each test suite will call reporttotaltests after all tests have + * run with the total number of tests for that suite. + * Once all the testsuites have run, the global totaltests will hold + * the total of number of unit test for that run. + * + * Each unit test macro (TS_TRACE, TS_WARN, and TS_FAIL) will update + * the proper variable. At the end the unit tester will print out + * the totals. + * // Global cxxtest values - Keep global so it can be found in syms file + */ + uint64_t g_TotalTests = 0; + uint64_t g_TraceCalls = 0; + uint64_t g_Warnings = 0; + uint64_t g_FailedTests = 0; + + // // TestSuite members // @@ -16,25 +42,126 @@ namespace CxxTest void TestSuite::setUp() {} void TestSuite::tearDown() {} - // - // Some non-template functions - // + /** + * + * @brief Implement trace action in unit tests + * + * @param [in] pointer to filename (not used right now ) + * @param [in] line number + * @param [in] trace message + * + * @return void + * + */ void doTrace( const char *file, unsigned line, const char *message ) { - //tracker().trace( file, line, message ); - //printk("%s %u %s\n",file,line,message); + // tracker().trace( file, line, message ); + printk("TRACE: %s %u %s\n", file, line, message); + __sync_add_and_fetch( &g_TraceCalls, 1 ); } + /** + * + * @brief Implement warn action in unit tests + * + * @param [in] pointer to filename (not used right now ) + * @param [in] line number + * @param [in] warning message + * + * @return void + * + */ void doWarn( const char *file, unsigned line, const char *message ) { - //tracker().warning( file, line, message ); - //printk("%s %u %s\n",file,line,message); + // tracker().warning( file, line, message ); + printk("WARN: %s %u %s\n", file, line, message); + __sync_add_and_fetch( &g_Warnings, 1 ); } + /** + * @brief Implement Fail action in unit tests + * + * @param [in] pointer to filename (not used right now ) + * @param [in] line number + * @param [in] failure message + * + * @return void + */ + void doFailTest( const char *file, unsigned line, const char *message ) { - //tracker().failedTest( file, line, message ); - //TS_ABORT(); + // tracker().failedTest( file, line, message ); + printk("FAIL: %s %u %s\n", file, line, message); + __sync_add_and_fetch( &g_FailedTests, 1 ); + } + + /** + * @brief Report total number of unit tests in a test suite + * + * A unit test suite will call this to report how many tests + * it has. The call itself is autogenerated + * + * @param [in] pointer to filename (not used right now ) + * @param [in] line number + * @param [in] trace message + * + * @return void + */ + void reportTotalTests( const char *suitename, uint64_t numtests ) + { + + // $$TODO do nothing with the suite name for now, later it may be useful + __sync_add_and_fetch( &g_TotalTests, numtests ); + + return; + } + + /** + * @brief accessor to read global totaltests var + * @TODO make these readonly accessors + * + * @return number of total tests + */ + uint64_t getTotalTests(void) + { + + return g_TotalTests; + } + + /** + * @brief accessor to read global failedtests var + * @TODO make these readonly accessors + * + * @return total number off failures executed + */ + uint64_t getFailedTests(void) + { + + return g_FailedTests; + } + + /** + * @brief accessor to read global warnings var + * @TODO make these readonly accessors + * + * @return total number of warnings executed + */ + uint64_t getWarnings(void) + { + + return g_Warnings; + } + + /** + * @brief accessor to read global tracecalls var + * @TODO make these readonly accessors + * + * @return total number of trace calls executed + */ + uint64_t getTraceCalls(void) + { + + return g_TraceCalls; } }; diff --git a/src/usr/cxxtest/cxxtestexec.C b/src/usr/cxxtest/cxxtestexec.C index 371bb1274..274f386ef 100644 --- a/src/usr/cxxtest/cxxtestexec.C +++ b/src/usr/cxxtest/cxxtestexec.C @@ -1,6 +1,7 @@ #include <sys/vfs.h> #include <sys/task.h> #include <string.h> +#include <kernel/console.H> /* Iterate through all modules in the VFS named "libtest*" and create children * tasks to execute them. @@ -10,6 +11,8 @@ void _start(void*) { VfsSystemModule* vfsItr = &VFS_MODULES[0]; + printk( "Executing CxxTestExec module.\n"); + while(vfsItr->module[0] != '\0') { if (0 == memcmp(vfsItr->module, "libtest", 7)) diff --git a/src/usr/cxxtest/cxxtestgen.pl b/src/usr/cxxtest/cxxtestgen.pl index 65a9ac8a4..da7c13356 100755 --- a/src/usr/cxxtest/cxxtestgen.pl +++ b/src/usr/cxxtest/cxxtestgen.pl @@ -618,16 +618,17 @@ sub writeHostBootPreamble() { print "#include <sys/task.h>\n"; print "#include <trace/interface.H>\n"; - ## print "#include <cxxtest/TestSuite.h>\n"; + print "#include <cxxtest/TestSuite.H>\n"; print "\n"; $didHBPreamble = 1; } sub writeHostBootSuites() { - my ( $suitecount, $suitevar ); + my ( $suitecount, $suitevar, $testcount ); $suitecount = 1; # initialize suite count + $testcount = 0; # initialize test count foreach (@suites) { $suite = $_; @@ -663,13 +664,18 @@ sub writeHostBootSuites() { ## run each of the tests in the list foreach (@{suiteTests()}) { $test = $_; - print "\tprintk(\"Executing test module ", testName(), ".\\n\");\n"; + if ( $debug ) { print "\tprintk(\"Executing test module ", testName(), ".\\n\");\n"; } printf "\t$suitevar->%s();\n\n", testName(); + $testcount++; } + print "\n"; ## delete the suite instance print "\tdelete ", $suitevar, ";\n"; + + print "\n"; + print "\tCxxTest::reportTotalTests( \"", suiteName(), "\", $testcount );\n"; $suitecount++; # bump to the next suite } @@ -682,7 +688,7 @@ sub write_start() { print "\n"; print "trace_desc_t *g_trac_test = NULL;\n"; - print "TRAC_INIT(&g_trac_test, \"EXAMPLE\", 4096);\n"; + print "TRAC_INIT(&g_trac_test, \"", suiteName(), "\", 4096);\n"; print "\n\n"; diff --git a/src/usr/example/test/exampletest.H b/src/usr/example/test/exampletest.H index ec2e60dba..f6cad9863 100644 --- a/src/usr/example/test/exampletest.H +++ b/src/usr/example/test/exampletest.H @@ -5,56 +5,85 @@ * @file exampletest.H * * @brief Example for people to use when writing test cases for their module. + * @todo add more doxygen blocks */ #include <cxxtest/TestSuite.H> #include <example/example.H> + class ExampleTest: public CxxTest::TestSuite { public: + /** - * @test Test Description - */ - void testExample1(void) + * @test TS_WARN will run if the example1_function FAILS + * */ + void testExampleWarn(void) { uint64_t l_rc = 0; l_rc = example1_function(); if(l_rc) { - TS_FAIL("Call to example1_function1 failed!"); + TS_WARN("Warning, Call to example1_function1 returned bad value.\n"); } } + /** - * @test Test Description - */ - void testExample2(void) + * @test TS_TRACE will run if the example1_function FAILS + * */ + void testExampleTrace(void) { - // Call functions and validate results - // TS_FAIL("Failed test call to example2 function"); + uint64_t l_rc = 0; + l_rc = example1_function(); + if(l_rc) + { + TS_TRACE("Tracing something in example1_function1\n"); + } } /** - * @test Test Description + * @test TS_FAIL will run if the example1_function FAILS */ - void testExample3(void) + void testExampleFail(void) { - // Call functions and validate results - // TS_FAIL("Failed test call to example3 function"); + uint64_t l_rc = 0; + l_rc = example1_function(); + if(l_rc) + { + TS_FAIL("Call to example1_function1 failed!\n"); + } } - void testExample4(void) + /** + * @test this will always run TS_FAIL + */ + void testExampleForceFail(void) + { + + TS_FAIL("Run TS_FAIL() as part of the example test.\n" ); + } + + /** + * @test this will always run TS_WARN + */ + void testExampleForceWarn(void) { - // Call functions and validate results - // TS_FAIL("Failed test call to example3 function"); + + TS_WARN("Run TS_WARN() as part of the example test\n" ); } - void testExample5(void) + /** + * @test this will always run TS_WARN + */ + void testExampleForceTrace(void) { - // Call functions and validate results - // TS_FAIL("Failed test call to example3 function"); + + TS_TRACE("Run TS_TRACE() as part of the example test\n" ); } + + }; #endif |