From: Damir Tomic Date: Sun, 14 Jun 2015 09:56:02 +0000 (+0200) Subject: bug-2803.h~388af97e65bf386e: X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48b7ebc36d230ada34d0f5ec6c50f73b6979afda;p=thirdparty%2Fntp.git bug-2803.h~388af97e65bf386e: Delete: tests/bug-2803/bug-2803.h TestProductionCode_Runner.c~1dd6cbb7f125c42a: Delete: tests/bug-2803/TestProductionCode_Runner.c bug-2803.c~75ddf194e9fda1b8: Delete: tests/bug-2803/bug-2803.c Makefile.am: removed outdated files ut-2803.c: merged with bug-2803.c|h, they are obsolete now bk: 557d4fb2Vpuc3oBog9nCJbs53E4eYA --- diff --git a/tests/bug-2803/Makefile.am b/tests/bug-2803/Makefile.am index 5f49c29a5..db089e8b4 100644 --- a/tests/bug-2803/Makefile.am +++ b/tests/bug-2803/Makefile.am @@ -31,8 +31,6 @@ AM_CPPFLAGS += $(CPPFLAGS_NTP) AM_LDFLAGS = $(LDFLAGS_NTP) bug_2803_SOURCES = \ - bug-2803.c \ - bug-2803.h \ run-bug-2803.c \ ut-2803.c \ $(NULL) diff --git a/tests/bug-2803/TestProductionCode_Runner.c b/tests/bug-2803/TestProductionCode_Runner.c deleted file mode 100644 index 969df8861..000000000 --- a/tests/bug-2803/TestProductionCode_Runner.c +++ /dev/null @@ -1,55 +0,0 @@ -/* AUTOGENERATED FILE. DO NOT EDIT. */ -#include "unity.h" -#include -#include - -char MessageBuffer[50]; - -extern void setUp(void); -extern void tearDown(void); - -extern void test_FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode(void); -extern void test_FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken(void); -extern void test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue(void); -extern void test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain(void); -extern void test_FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed(void); -extern void test_custom(void); -extern void test_main(void); - -void resetTest(void); - -void resetTest(void) -{ - tearDown(); - setUp(); -} - - -int main(void) -{ - UnityBegin("test/TestProductionCode.c"); - UnityBegin("test/test-2803.c"); - - /* - RUN_TEST(test_FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode, 20); - RUN_TEST(test_FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken, 30); - RUN_TEST(test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue, 41); - RUN_TEST(test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain, 51); - RUN_TEST(test_FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed, 57); -*/ - -RUN_TEST(test_main); - -//RUN_TEST(test_FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode); - //RUN_TEST(test_FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken); - //RUN_TEST(test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue); - //RUN_TEST(test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain); - //RUN_TEST(test_FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed); - - -//RUN_TEST(test_FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed); - RUN_TEST(test_custom); - - UnityEnd(); - return 0; -} diff --git a/tests/bug-2803/bug-2803.c b/tests/bug-2803/bug-2803.c deleted file mode 100644 index 1806c6d78..000000000 --- a/tests/bug-2803/bug-2803.c +++ /dev/null @@ -1,99 +0,0 @@ -#include - -#include -#include - -#include -#include - -/* microseconds per second */ -#define MICROSECONDS 1000000 - - -static int verbose = 1; // if not 0, also print results if test passed -static int exit_on_err = 0; // if not 0, exit if test failed - - -/* - * Test function calling the old and new code mentioned in - * http://bugs.ntp.org/show_bug.cgi?id=2803#c22 - */ -static -int do_test( struct timeval timetv, struct timeval tvlast ) -{ - struct timeval tvdiff_old; - struct timeval tvdiff_new; - - int cond_old; - int cond_new; - int failed; - - cond_old = 0; - cond_new = 0; - - // Here is the old code: - tvdiff_old = abs_tval(sub_tval(timetv, tvlast)); - if (tvdiff_old.tv_sec > 0) { - cond_old = 1; - } - - // Here is the new code: - tvdiff_new = sub_tval(timetv, tvlast); - if (tvdiff_new.tv_sec != 0) { - cond_new = 1; - } - - failed = cond_new != cond_old; - - if ( failed || verbose ) - printf( "timetv %lli|%07li, tvlast %lli|%07li: tvdiff_old: %lli|%07li -> %i, tvdiff_new: %lli|%07li -> %i, same cond: %s\n", - (long long) timetv.tv_sec, timetv.tv_usec, - (long long) tvlast.tv_sec, tvlast.tv_usec, - (long long) tvdiff_old.tv_sec, tvdiff_old.tv_usec, cond_old, - (long long) tvdiff_new.tv_sec, tvdiff_new.tv_usec, cond_new, - failed ? "NO <<" : "yes" ); - - return failed ? -1 : 0; -} - - - -/* - * Call the test function in a loop for a given set of parameters. - * Both timetv and tvlast iterate over the given range, in all combinations. - */ -static -int test_loop( long long start_sec, long start_usec, - long long stop_sec, long stop_usec, - long long step_sec, long step_usec ) -{ - struct timeval timetv; - struct timeval tvlast; - - for ( timetv.tv_sec = start_sec; timetv.tv_sec <= stop_sec; timetv.tv_sec += step_sec ) - for ( timetv.tv_usec = start_usec; timetv.tv_usec <= stop_usec; timetv.tv_usec += step_usec ) - for ( tvlast.tv_sec = start_sec; tvlast.tv_sec <= stop_sec; tvlast.tv_sec += step_sec ) - for ( tvlast.tv_usec = start_usec; tvlast.tv_usec <= stop_usec; tvlast.tv_usec += step_usec ) - { - int rc = do_test( timetv, tvlast ); - if (rc < 0 && exit_on_err ) - return rc; - } - - return 0; -} - - - -int main2( void ) -{ - - // loop from {0.0} to {1.1000000} stepping by tv_sec by 1 and tv_usec by 100000 - test_loop( 0, 0, 1, MICROSECONDS, 1, MICROSECONDS / 10 ); - - // test_loop( 0, 0, 5, MICROSECONDS, 1, MICROSECONDS / 1000 ); - // test_loop( 0, 0, -5, -MICROSECONDS, -1, -MICROSECONDS / 1000 ); - - return 0; -} - diff --git a/tests/bug-2803/bug-2803.h b/tests/bug-2803/bug-2803.h deleted file mode 100644 index 4b8469df1..000000000 --- a/tests/bug-2803/bug-2803.h +++ /dev/null @@ -1 +0,0 @@ -int main2( void ); diff --git a/tests/bug-2803/run-bug-2803.c b/tests/bug-2803/run-bug-2803.c index d1fd0e251..7bc90a89c 100644 --- a/tests/bug-2803/run-bug-2803.c +++ b/tests/bug-2803/run-bug-2803.c @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "ut-2803.c"; UnityBegin("ut-2803.c"); - RUN_TEST(test_main, 27); + RUN_TEST(test_main, 117); return (UnityEnd()); } diff --git a/tests/bug-2803/ut-2803.c b/tests/bug-2803/ut-2803.c index c5462b1aa..1bb6bbc15 100644 --- a/tests/bug-2803/ut-2803.c +++ b/tests/bug-2803/ut-2803.c @@ -1,18 +1,94 @@ -#include "bug-2803.h" +#include + +#include +#include + +#include +#include + #include "unity.h" +/* microseconds per second */ +#define MICROSECONDS 1000000 -void setUp(void) +int simpleTest( void ); + + +static int verbose = 1; // if not 0, also print results if test passed +static int exit_on_err = 0; // if not 0, exit if test failed + + +/* + * Test function calling the old and new code mentioned in + * http://bugs.ntp.org/show_bug.cgi?id=2803#c22 + */ +static int do_test( struct timeval timetv, struct timeval tvlast ) { - + struct timeval tvdiff_old; + struct timeval tvdiff_new; + + int cond_old; + int cond_new; + int failed; + + cond_old = 0; + cond_new = 0; + + // Here is the old code: + tvdiff_old = abs_tval(sub_tval(timetv, tvlast)); + if (tvdiff_old.tv_sec > 0) { + cond_old = 1; + } + + // Here is the new code: + tvdiff_new = sub_tval(timetv, tvlast); + if (tvdiff_new.tv_sec != 0) { + cond_new = 1; + } + + failed = cond_new != cond_old; + + if ( failed || verbose ) + printf( "timetv %lli|%07li, tvlast %lli|%07li: tvdiff_old: %lli|%07li -> %i, tvdiff_new: %lli|%07li -> %i, same cond: %s\n", + (long long) timetv.tv_sec, timetv.tv_usec, + (long long) tvlast.tv_sec, tvlast.tv_usec, + (long long) tvdiff_old.tv_sec, tvdiff_old.tv_usec, cond_old, + (long long) tvdiff_new.tv_sec, tvdiff_new.tv_usec, cond_new, + failed ? "NO <<" : "yes" ); + + return failed ? -1 : 0; } -void tearDown(void) + + +/* + * Call the test function in a loop for a given set of parameters. + * Both timetv and tvlast iterate over the given range, in all combinations. + */ +static +int test_loop( long long start_sec, long start_usec, + long long stop_sec, long stop_usec, + long long step_sec, long step_usec ) { + struct timeval timetv; + struct timeval tvlast; + + for ( timetv.tv_sec = start_sec; timetv.tv_sec <= stop_sec; timetv.tv_sec += step_sec ) + for ( timetv.tv_usec = start_usec; timetv.tv_usec <= stop_usec; timetv.tv_usec += step_usec ) + for ( tvlast.tv_sec = start_sec; tvlast.tv_sec <= stop_sec; tvlast.tv_sec += step_sec ) + for ( tvlast.tv_usec = start_usec; tvlast.tv_usec <= stop_usec; tvlast.tv_usec += step_usec ) + { + int rc = do_test( timetv, tvlast ); + if (rc < 0 && exit_on_err ) + return rc; + } + + return 0; } -/* -int main( void ) + + +int simpleTest( void ) { // loop from {0.0} to {1.1000000} stepping by tv_sec by 1 and tv_usec by 100000 @@ -23,8 +99,22 @@ int main( void ) return 0; } -*/ + + + + + +void setUp(void) +{ + +} + +void tearDown(void) +{ +} + + void test_main( void ) { - TEST_ASSERT_EQUAL(0, main2()); + TEST_ASSERT_EQUAL(0, simpleTest()); }