[complement-svn] SF.net SVN: complement: [1721] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-09-04 07:29:30
|
Revision: 1721 http://complement.svn.sourceforge.net/complement/?rev=1721&view=rev Author: complement Date: 2007-09-04 00:29:28 -0700 (Tue, 04 Sep 2007) Log Message: ----------- performance measure feature; libexam version 0.3.0 Modified Paths: -------------- trunk/complement/explore/include/exam/logger.h trunk/complement/explore/include/exam/suite.h trunk/complement/explore/lib/exam/ChangeLog trunk/complement/explore/lib/exam/Makefile.inc trunk/complement/explore/lib/exam/logger.cc trunk/complement/explore/lib/exam/suite.cc trunk/complement/explore/lib/exam/ut/Makefile trunk/complement/explore/lib/exam/ut/dummy_test.cc trunk/complement/explore/lib/exam/ut/exam_test_suite.cc trunk/complement/explore/lib/exam/ut/exam_test_suite.h Modified: trunk/complement/explore/include/exam/logger.h =================================================================== --- trunk/complement/explore/include/exam/logger.h 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/include/exam/logger.h 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:08:25 ptr> +// -*- C++ -*- Time-stamp: <07/09/04 10:38:27 ptr> /* * Copyright (c) 2007 @@ -13,6 +13,8 @@ #include <string> #include <cstdio> #include <ostream> +#include <mt/time.h> +#include <list> namespace exam { @@ -64,6 +66,9 @@ virtual void begin_ts() = 0; virtual void end_ts() = 0; virtual void result( const base_logger::stat&, const std::string& suite_name ) = 0; + virtual void tc_pre() = 0; + virtual void tc_post() = 0; + virtual void tc_break() = 0; virtual void tc( tc_result, const std::string& ) = 0; protected: @@ -89,13 +94,41 @@ virtual void begin_ts(); virtual void end_ts(); virtual void result( const base_logger::stat&, const std::string& ); + virtual void tc_pre() + { } + virtual void tc_post() + { } + virtual void tc_break() + { } virtual void tc( base_logger::tc_result, const std::string& ); - private: + protected: std::ostream *s; FILE *f; }; +class trivial_time_logger : + public trivial_logger +{ + public: + explicit trivial_time_logger( std::ostream& str ) : + trivial_logger( str ) + { } + + explicit trivial_time_logger( FILE *fs ) : + trivial_logger( fs ) + { } + + virtual void tc_pre(); + virtual void tc_post(); + virtual void tc_break(); + virtual void tc( base_logger::tc_result, const std::string& ); + + private: + typedef std::list<xmt::timespec> time_container_t; + time_container_t tst; +}; + } // namespace exam #endif // __logger_h Modified: trunk/complement/explore/include/exam/suite.h =================================================================== --- trunk/complement/explore/include/exam/suite.h 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/include/exam/suite.h 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:07:43 ptr> +// -*- C++ -*- Time-stamp: <07/09/04 11:08:48 ptr> /* * Copyright (c) 2007 @@ -168,8 +168,8 @@ typedef int (*func_type)( test_suite *, int ); typedef vertex_t test_case_type; - test_suite( const std::string& name ); - test_suite( const char *name ); + test_suite( const std::string& name, unsigned n = 1 ); + test_suite( const char *name, unsigned n = 1 ); ~test_suite(); test_case_type add( func_type, const std::string& name ); @@ -227,8 +227,9 @@ test_case_map_type _test; base_logger::stat _stat; std::string _suite_name; + unsigned _iterations; - void run_test_case( vertex_t v ); + void run_test_case( vertex_t v, unsigned n = 1 ); static bool vertices_compare( weight_t, weight_t ); static int _root_func( test_suite *, int = 0 ); Modified: trunk/complement/explore/lib/exam/ChangeLog =================================================================== --- trunk/complement/explore/lib/exam/ChangeLog 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/ChangeLog 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,3 +1,18 @@ +2007-09-04 Petr Ovtchenkov <pt...@is...> + + * logger.h, logger.cc: added trivial_time_logger for performance + measure; added methods tc_pre, tc_post and tc_break for run before + test case, after test case, or after exception within test case; + + * suite.h, suite.cc: add iterations number for each test-case; + this test suite -wide parameter, because mainly intended for + performance measure [statistic] and not useful for problem + detection and tracking; + + * ut/exam_test_suite.cc, ut/dummy_test.cc: test; + + * libexam: version 0.3.0. + 2007-08-03 Petr Ovtchenkov <pt...@is...> * suite.h: remove private keyword for dummy, to make gcc 3.3.6 happy. Modified: trunk/complement/explore/lib/exam/Makefile.inc =================================================================== --- trunk/complement/explore/lib/exam/Makefile.inc 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/Makefile.inc 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,7 +1,7 @@ -# -*- Makefile -*- Time-stamp: <07/07/21 09:21:58 ptr> +# -*- Makefile -*- Time-stamp: <07/09/04 11:12:48 ptr> LIBNAME = exam MAJOR = 0 -MINOR = 2 +MINOR = 3 PATCH = 0 SRC_CC = logger.cc suite.cc Modified: trunk/complement/explore/lib/exam/logger.cc =================================================================== --- trunk/complement/explore/lib/exam/logger.cc 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/logger.cc 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:09:27 ptr> +// -*- C++ -*- Time-stamp: <07/09/04 10:47:22 ptr> /* * Copyright (c) 2007 @@ -115,4 +115,51 @@ } } +void trivial_time_logger::tc_pre() +{ + tst.push_back( xmt::timespec( xmt::timespec::now ) ); +} + +void trivial_time_logger::tc_post() +{ + tst.back() = xmt::timespec( xmt::timespec::now ) - tst.back(); +} + +void trivial_time_logger::tc_break() +{ + tst.pop_back(); +} + +void trivial_time_logger::tc( base_logger::tc_result r, const std::string& name ) +{ + if ( r == pass ) { + // here tst.size() > 0, if test case not throw excepion + time_container_t::const_iterator a = tst.begin(); + if ( a != tst.end() ) { + unsigned n = 1; + double sum(*a); + double sum_sq = sum * sum; + ++a; + for ( ; a != tst.end(); ++a ) { + double v(*a); + sum += v; + sum_sq += v * v; + // mean = ((n + 1) * mean + static_cast<double>(*a)) / (n + 2); + ++n; + } + sum_sq -= sum * sum / n; + sum_sq = max( 0.0, sum_sq ); // clear epsilon (round error) + sum_sq /= n * n; // dispersion + sum /= n; // mean + if ( s != 0 ) { + *s << " " << sum << " " << sum_sq << " " << name << endl; + } else { + fprintf( f, " %f %f %s\n", sum, sum_sq, name.c_str() ); + } + } + } + tst.clear(); + trivial_logger::tc( r, name ); +} + } //namespace exam Modified: trunk/complement/explore/lib/exam/suite.cc =================================================================== --- trunk/complement/explore/lib/exam/suite.cc 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/suite.cc 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:09:43 ptr> +// -*- C++ -*- Time-stamp: <07/09/04 11:10:58 ptr> /* * Copyright (c) 2007 @@ -29,11 +29,12 @@ return -1; } -test_suite::test_suite( const string& name ) : +test_suite::test_suite( const string& name, unsigned n ) : _count(0), _last_state( 0 ), _suite_name( name ), - local_logger( logger ) + local_logger( logger ), + _iterations( n ) { _vertices.push_back( std::make_pair( 0, 0 ) ); _test[0].tc = detail::make_test_case( detail::call( _root_func ) ); @@ -43,11 +44,12 @@ _stack.push( this ); } -test_suite::test_suite( const char *name ) : +test_suite::test_suite( const char *name, unsigned n ) : _count(0), _last_state( 0 ), _suite_name( name ), - local_logger( logger ) + local_logger( logger ), + _iterations( n ) { _vertices.push_back( std::make_pair( 0, 0 ) ); _test[0].tc = detail::make_test_case( detail::call( _root_func ) ); @@ -97,7 +99,7 @@ _test[j->second].state = skip; } } - run_test_case( i->first ); + run_test_case( i->first, _iterations ); } local_logger->end_ts(); @@ -203,12 +205,22 @@ _stack.top()->report( file, line, cnd, expr ); } -void test_suite::run_test_case( test_suite::vertex_t v ) +void test_suite::run_test_case( test_suite::vertex_t v, unsigned n ) { try { ++_stat.total; if ( _test[v].state == 0 ) { - if ( (*_test[v].tc)( this, 0 ) == 0 ) { + int res = 0; + while ( (res == 0) && (n-- > 0) ) { + _lock_ll.lock(); + local_logger->tc_pre(); + _lock_ll.unlock(); + res = (*_test[v].tc)( this, 0 ); + _lock_ll.lock(); + local_logger->tc_post(); + _lock_ll.unlock(); + } + if ( res == 0 ) { if ( _last_state == 0 ) { ++_stat.passed; scoped_lock lk( _lock_ll ); @@ -234,12 +246,16 @@ } } catch ( init_exception& ) { + _lock_ll.lock(); + local_logger->tc_break(); + _lock_ll.unlock(); --_stat.total; } catch ( ... ) { ++_stat.failed; _test[v].state = fail; scoped_lock lk( _lock_ll ); + local_logger->tc_break(); local_logger->tc( base_logger::fail, _test[v].name ); } } Modified: trunk/complement/explore/lib/exam/ut/Makefile =================================================================== --- trunk/complement/explore/lib/exam/ut/Makefile 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/ut/Makefile 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/08/03 22:53:39 ptr> +# -*- Makefile -*- Time-stamp: <07/09/03 22:27:45 ptr> SRCROOT := ../../.. @@ -9,23 +9,24 @@ DEFS += -D__FIT_EXAM LIBEXAM_DIR = ${CoMT_DIR}/lib/exam +LIBXMT_DIR = ${CoMT_DIR}/lib/mt LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR} ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L$(LIBXMT_DIR)/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:$(LIBXMT_DIR)/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif -release-shared : LDLIBS = -lexam -dbg-shared : LDLIBS = -lexamg +release-shared : LDLIBS = -lexam -lxmt +dbg-shared : LDLIBS = -lexamg -lxmtg ifndef WITHOUT_STLPORT -stldbg-shared : LDLIBS = -lexamstlg +stldbg-shared : LDLIBS = -lexamstlg -lxmtstlg endif Modified: trunk/complement/explore/lib/exam/ut/dummy_test.cc =================================================================== --- trunk/complement/explore/lib/exam/ut/dummy_test.cc 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/ut/dummy_test.cc 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:10:32 ptr> +// -*- C++ -*- Time-stamp: <07/09/03 22:22:09 ptr> /* * Copyright (c) 2007 @@ -57,3 +57,14 @@ return EXAM_RESULT; } + +int EXAM_IMPL(loop) +{ + int j = 0; + for ( int i = 0; i < 100000; ++i ) { + j += 2; + } + + return EXAM_RESULT; +} + Modified: trunk/complement/explore/lib/exam/ut/exam_test_suite.cc =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.cc 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.cc 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:10:55 ptr> +// -*- C++ -*- Time-stamp: <07/09/04 11:11:41 ptr> /* * Copyright (c) 2007 @@ -8,6 +8,7 @@ */ #include "exam_test_suite.h" +#include <iostream> #include "dummy_test.cc" @@ -243,6 +244,40 @@ return EXAM_RESULT; } +int EXAM_IMPL(exam_basic_test::perf) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t( "exam self test, time profile", 20 ); + t.set_logger( &tlogger ); + + t.add( loop, "timer" ); + + t.girdle(); + + double mean = -1.0; + double disp = -1.0; + std::string nm; + + buff >> mean >> disp; // >> nm; + + EXAM_CHECK( mean >= 0.0 ); + EXAM_CHECK( disp >= 0.0 ); + + std::getline( buff, nm ); + + EXAM_CHECK( nm == " timer" ); + + std::getline( buff, nm ); + + EXAM_CHECK( nm == "*** PASS exam self test, time profile (+1-0~0/1) ***" ); + + // std::cerr << buff.str() << std::endl; + + return EXAM_RESULT; +} + const std::string exam_basic_test::r0 = "\ *** PASS exam self test, good function (+2-0~0/2) ***\n"; @@ -325,5 +360,7 @@ exam::test_suite::test_case_type d2 = t.add( &exam_basic_test::multiple_dep, exam_basic, "multiple dependencies", d ); t.add( &exam_basic_test::multiple_dep_complex, exam_basic, "complex multiple dependencies", d2 ); + t.add( &exam_basic_test::perf, exam_basic, "performance timer test", d0 ); + return t.girdle(); } Modified: trunk/complement/explore/lib/exam/ut/exam_test_suite.h =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.h 2007-09-03 14:02:41 UTC (rev 1720) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.h 2007-09-04 07:29:28 UTC (rev 1721) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:11:13 ptr> +// -*- C++ -*- Time-stamp: <07/09/03 22:21:36 ptr> /* * Copyright (c) 2007 @@ -16,34 +16,38 @@ class exam_basic_test { - public: - exam_basic_test() : - buff(), - logger( buff ) - { } + public: + exam_basic_test() : + buff(), + logger( buff ), + tlogger( buff ) + { } - int EXAM_DECL(function_good); - int EXAM_DECL(function); - int EXAM_DECL(dep); - int EXAM_DECL(trace); - int EXAM_DECL(dep_test_suite); - int EXAM_DECL(multiple_dep); - int EXAM_DECL(multiple_dep_complex); + int EXAM_DECL(function_good); + int EXAM_DECL(function); + int EXAM_DECL(dep); + int EXAM_DECL(trace); + int EXAM_DECL(dep_test_suite); + int EXAM_DECL(multiple_dep); + int EXAM_DECL(multiple_dep_complex); + int EXAM_DECL(perf); private: - std::stringstream buff; - exam::trivial_logger logger; + std::stringstream buff; + exam::trivial_logger logger; + exam::trivial_time_logger tlogger; + - static const std::string r0; - static const std::string r1; - static const std::string r2; - static const std::string r3; - static const std::string r4; - static const std::string r5; - static const std::string r6; - static const std::string r7; - static const std::string r8; - static const std::string r9; + static const std::string r0; + static const std::string r1; + static const std::string r2; + static const std::string r3; + static const std::string r4; + static const std::string r5; + static const std::string r6; + static const std::string r7; + static const std::string r8; + static const std::string r9; }; int EXAM_DECL(exam_self_test); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |