From: Harlan Stenn Date: Wed, 25 Nov 2015 11:50:51 +0000 (+0000) Subject: Unity test cleanup. Harlan Stenn. X-Git-Tag: NTP_4_3_83~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e31e23c8f2b589cdaaff31d57e45cdf3bbeeeab;p=thirdparty%2Fntp.git Unity test cleanup. Harlan Stenn. bk: 5655a09b3c9SURZi2MojEfe6xKQzNQ --- diff --git a/sntp/unity/unity_internals.h b/sntp/unity/unity_internals.h index c2aabc3aa..bf1bf3dc9 100644 --- a/sntp/unity/unity_internals.h +++ b/sntp/unity/unity_internals.h @@ -305,6 +305,18 @@ extern int UNITY_OUTPUT_CHAR(int); # undef UNITY_WEAK_PRAGMA #endif +#if !defined(UNITY_NORETURN_ATTRIBUTE) +# ifdef __GNUC__ // includes clang +# if !(defined(__WIN32__) && defined(__clang__)) +# define UNITY_NORETURN_ATTRIBUTE __attribute__((noreturn)) +# endif +# endif +#endif + +#ifndef UNITY_NORETURN_ATTRIBUTE +# define UNITY_NORETURN_ATTRIBUTE +#endif + //------------------------------------------------------- // Internal Structs Needed @@ -465,7 +477,7 @@ void UnityAssertNumbersWithin(const _U_SINT delta, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style); -void UnityFail(const char* message, const UNITY_LINE_TYPE line); +void UnityFail(const char* message, const UNITY_LINE_TYPE line) UNITY_NORETURN_ATTRIBUTE; void UnityIgnore(const char* message, const UNITY_LINE_TYPE line); diff --git a/tests/libntp/calendar.c b/tests/libntp/calendar.c index 0aff0e699..9d25c41b1 100644 --- a/tests/libntp/calendar.c +++ b/tests/libntp/calendar.c @@ -111,9 +111,14 @@ IsEqualCal( expected->second == actual->second) { return TRUE; } else { - printf("expected: %s but was %s", - CalendarFromCalToString(expected), - CalendarFromCalToString(actual)); + char *p_exp = CalendarFromCalToString(expected); + char *p_act = CalendarFromCalToString(actual); + + printf("expected: %s but was %s", p_exp, p_act); + + free(p_exp); + free(p_act); + return FALSE; } } diff --git a/tests/ntpd/leapsec.c b/tests/ntpd/leapsec.c index 37e4398b2..36ecd39c8 100644 --- a/tests/ntpd/leapsec.c +++ b/tests/ntpd/leapsec.c @@ -234,6 +234,7 @@ static const uint32_t lsec2015 = 3644697600u; // +36, 1 Jul 2015, 00:00:00 utc int stringreader(void* farg) { const char ** cpp = (const char**)farg; + if (**cpp) return *(*cpp)++; else @@ -247,6 +248,7 @@ setup_load_table( { int rc; leap_table_t * pt = leapsec_get_table(0); + rc = (pt != NULL) && leapsec_load(pt, stringreader, &cp, blim); rc = rc && leapsec_set_table(pt); return rc; @@ -257,6 +259,7 @@ setup_clear_table(void) { int rc; leap_table_t * pt = leapsec_get_table(0); + if (pt) leapsec_clear(pt); rc = leapsec_set_table(pt); @@ -264,10 +267,13 @@ setup_clear_table(void) } -char * CalendarToString(const struct calendar cal) { +char * +CalendarToString(const struct calendar cal) +{ char * ss = malloc (sizeof (char) * 100); - char buffer[100] =""; + + *ss = '\0'; sprintf(buffer, "%u", cal.year); strcat(ss,buffer); strcat(ss,"-"); @@ -293,34 +299,47 @@ char * CalendarToString(const struct calendar cal) { } -int IsEqual(const struct calendar expected, const struct calendar actual) { - if (expected.year == actual.year && - (expected.yearday == actual.yearday || - (expected.month == actual.month && - expected.monthday == actual.monthday)) && - expected.hour == actual.hour && - expected.minute == actual.minute && - expected.second == actual.second) { +int +IsEqual(const struct calendar expected, const struct calendar actual) +{ + + if ( expected.year == actual.year + && ( expected.yearday == actual.yearday + || ( expected.month == actual.month + && expected.monthday == actual.monthday)) + && expected.hour == actual.hour + && expected.minute == actual.minute + && expected.second == actual.second) { return TRUE; } else { - printf("expected: %s but was %s", CalendarToString(expected) ,CalendarToString(actual)); + char *p_exp = CalendarToString(expected); + char *p_act = CalendarToString(actual); + + printf("expected: %s but was %s", p_exp, p_act); + + free(p_exp); + free(p_act); return FALSE; - } } //------------------------- -void setUp(void) +void +setUp(void) { ntpcal_set_timefunc(timefunc); settime(1970, 1, 1, 0, 0, 0); leapsec_ut_pristine(); + + return; } -void tearDown(void) +void +tearDown(void) { ntpcal_set_timefunc(NULL); + return; } // ===================================================================== @@ -328,45 +347,73 @@ void tearDown(void) // ===================================================================== // ---------------------------------------------------------------------- -void test_ValidateGood(void) { +void +test_ValidateGood(void) +{ const char *cp = leap_ghash; int rc = leapsec_validate(stringreader, &cp); + TEST_ASSERT_EQUAL(LSVALID_GOODHASH, rc); + return; } // ---------------------------------------------------------------------- -void test_ValidateNoHash(void) { +void +test_ValidateNoHash(void) +{ const char *cp = leap2; int rc = leapsec_validate(stringreader, &cp); + TEST_ASSERT_EQUAL(LSVALID_NOHASH, rc); + return; } // ---------------------------------------------------------------------- -void test_ValidateBad(void) { +void +test_ValidateBad(void) +{ const char *cp = leap_bhash; int rc = leapsec_validate(stringreader, &cp); + TEST_ASSERT_EQUAL(LSVALID_BADHASH, rc); + + return; } // ---------------------------------------------------------------------- -void test_ValidateMalformed(void) { +void +test_ValidateMalformed(void) +{ const char *cp = leap_mhash; int rc = leapsec_validate(stringreader, &cp); + TEST_ASSERT_EQUAL(LSVALID_BADFORMAT, rc); + + return; } // ---------------------------------------------------------------------- -void test_ValidateMalformedShort(void) { +void +test_ValidateMalformedShort(void) +{ const char *cp = leap_shash; int rc = leapsec_validate(stringreader, &cp); + TEST_ASSERT_EQUAL(LSVALID_BADFORMAT, rc); + + return; } // ---------------------------------------------------------------------- -void test_ValidateNoLeadZero(void) { +void +test_ValidateNoLeadZero(void) +{ const char *cp = leap_gthash; int rc = leapsec_validate(stringreader, &cp); + TEST_ASSERT_EQUAL(LSVALID_GOODHASH, rc); + + return; } // ===================================================================== @@ -375,7 +422,9 @@ void test_ValidateNoLeadZero(void) { // ---------------------------------------------------------------------- // test table selection -void test_tableSelect(void) { +void +test_tableSelect(void) +{ leap_table_t *pt1, *pt2, *pt3, *pt4; pt1 = leapsec_get_table(0); @@ -406,12 +455,16 @@ void test_tableSelect(void) { pt3 = leapsec_get_table(1); TEST_ASSERT_EQUAL(pt1, pt2); TEST_ASSERT_NOT_EQUAL(pt2, pt3); + + return; } // ---------------------------------------------------------------------- // load file & check expiration -void test_loadFileExpire(void) { +void +test_loadFileExpire(void) +{ const char *cp = leap1; int rc; leap_table_t * pt = leapsec_get_table(0); @@ -423,18 +476,21 @@ void test_loadFileExpire(void) { TEST_ASSERT_EQUAL(0, rc); rc = leapsec_expired(3610569601u, NULL); TEST_ASSERT_EQUAL(1, rc); + + return; } // ---------------------------------------------------------------------- // load file & check time-to-live -void test_loadFileTTL(void) { - const char *cp = leap1; - int rc; - leap_table_t * pt = leapsec_get_table(0); - time_t pivot = 0x70000000u; - - const uint32_t limit = 3610569600u; +void +test_loadFileTTL(void) +{ + const char *cp = leap1; + int rc; + leap_table_t * pt = leapsec_get_table(0); + time_t pivot = 0x70000000u; + const uint32_t limit = 3610569600u; rc = leapsec_load(pt, stringreader, &cp, FALSE) && leapsec_set_table(pt); @@ -442,16 +498,18 @@ void test_loadFileTTL(void) { // exactly 1 day to live rc = leapsec_daystolive(limit - 86400, &pivot); - TEST_ASSERT_EQUAL( 1, rc); + TEST_ASSERT_EQUAL( 1, rc); // less than 1 day to live rc = leapsec_daystolive(limit - 86399, &pivot); - TEST_ASSERT_EQUAL( 0, rc); + TEST_ASSERT_EQUAL( 0, rc); // hit expiration exactly rc = leapsec_daystolive(limit, &pivot); - TEST_ASSERT_EQUAL( 0, rc); + TEST_ASSERT_EQUAL( 0, rc); // expired since 1 sec rc = leapsec_daystolive(limit + 1, &pivot); - TEST_ASSERT_EQUAL(-1, rc); + TEST_ASSERT_EQUAL(-1, rc); + + return; } // ===================================================================== @@ -460,19 +518,25 @@ void test_loadFileTTL(void) { // ---------------------------------------------------------------------- // test query in pristine state (bug#2745 misbehaviour) -void test_lsQueryPristineState(void) { +void +test_lsQueryPristineState(void) +{ int rc; leap_result_t qr; - + rc = leapsec_query(&qr, lsec2012, NULL); TEST_ASSERT_EQUAL(FALSE, rc); TEST_ASSERT_EQUAL(0, qr.warped ); TEST_ASSERT_EQUAL(LSPROX_NOWARN, qr.proximity); + + return; } // ---------------------------------------------------------------------- // ad-hoc jump: leap second at 2009.01.01 -60days -void test_ls2009faraway(void) { +void +test_ls2009faraway(void) +{ int rc; leap_result_t qr; @@ -485,11 +549,15 @@ void test_ls2009faraway(void) { TEST_ASSERT_EQUAL(33, qr.tai_offs); TEST_ASSERT_EQUAL(0, qr.tai_diff); TEST_ASSERT_EQUAL(LSPROX_NOWARN, qr.proximity); + + return; } // ---------------------------------------------------------------------- // ad-hoc jump: leap second at 2009.01.01 -1week -void test_ls2009weekaway(void) { +void +test_ls2009weekaway(void) +{ int rc; leap_result_t qr; @@ -502,11 +570,15 @@ void test_ls2009weekaway(void) { TEST_ASSERT_EQUAL(33, qr.tai_offs); TEST_ASSERT_EQUAL(1, qr.tai_diff); TEST_ASSERT_EQUAL(LSPROX_SCHEDULE, qr.proximity); + + return; } // ---------------------------------------------------------------------- // ad-hoc jump: leap second at 2009.01.01 -1hr -void test_ls2009houraway(void) { +void +test_ls2009houraway(void) +{ int rc; leap_result_t qr; @@ -519,11 +591,15 @@ void test_ls2009houraway(void) { TEST_ASSERT_EQUAL(33, qr.tai_offs); TEST_ASSERT_EQUAL(1, qr.tai_diff); TEST_ASSERT_EQUAL(LSPROX_ANNOUNCE, qr.proximity); + + return; } // ---------------------------------------------------------------------- // ad-hoc jump: leap second at 2009.01.01 -1sec -void test_ls2009secaway(void) { +void +test_ls2009secaway(void) +{ int rc; leap_result_t qr; @@ -536,11 +612,15 @@ void test_ls2009secaway(void) { TEST_ASSERT_EQUAL(33, qr.tai_offs); TEST_ASSERT_EQUAL(1, qr.tai_diff); TEST_ASSERT_EQUAL(LSPROX_ALERT, qr.proximity); + + return; } // ---------------------------------------------------------------------- // ad-hoc jump to leap second at 2009.01.01 -void test_ls2009onspot(void) { +void +test_ls2009onspot(void) +{ int rc; leap_result_t qr; @@ -553,11 +633,15 @@ void test_ls2009onspot(void) { TEST_ASSERT_EQUAL(34, qr.tai_offs); TEST_ASSERT_EQUAL(0, qr.tai_diff); TEST_ASSERT_EQUAL(LSPROX_NOWARN, qr.proximity); + + return; } // ---------------------------------------------------------------------- // test handling of the leap second at 2009.01.01 without table -void test_ls2009nodata(void) { +void +test_ls2009nodata(void) +{ int rc; leap_result_t qr; @@ -570,11 +654,15 @@ void test_ls2009nodata(void) { TEST_ASSERT_EQUAL(0, qr.tai_offs); TEST_ASSERT_EQUAL(0, qr.tai_diff); TEST_ASSERT_EQUAL(LSPROX_NOWARN, qr.proximity); + + return; } // ---------------------------------------------------------------------- // test handling of the leap second at 2009.01.01 with culled data -void test_ls2009limdata(void) { +void +test_ls2009limdata(void) +{ int rc; leap_result_t qr; @@ -591,15 +679,19 @@ void test_ls2009limdata(void) { TEST_ASSERT_TRUE(35 >= qr.tai_offs); TEST_ASSERT_EQUAL(0, qr.tai_diff); TEST_ASSERT_EQUAL(LSPROX_NOWARN, qr.proximity); + + return; } // ---------------------------------------------------------------------- // Far-distance forward jump into a transiton window. -void test_qryJumpFarAhead(void) { +void +test_qryJumpFarAhead(void) +{ int rc; leap_result_t qr; int last, idx; - int mode; + int mode; for (mode=0; mode < 2; ++mode) { leapsec_ut_pristine(); @@ -618,10 +710,10 @@ void test_qryJumpFarAhead(void) { // ---------------------------------------------------------------------- // Forward jump into the next transition window void test_qryJumpAheadToTransition(void) { - int rc; - leap_result_t qr; - int last, idx; - int mode; + int rc; + leap_result_t qr; + int last, idx; + int mode; for (mode=0; mode < 2; ++mode) { leapsec_ut_pristine(); @@ -635,15 +727,19 @@ void test_qryJumpAheadToTransition(void) { rc = leapsec_query(&qr, lsec2009+1, NULL); TEST_ASSERT_EQUAL(TRUE, rc); } + + return; } // ---------------------------------------------------------------------- // Forward jump over the next transition window -void test_qryJumpAheadOverTransition(void) { - int rc; - leap_result_t qr; - int last, idx; - int mode; +void +test_qryJumpAheadOverTransition(void) +{ + int rc; + leap_result_t qr; + int last, idx; + int mode; for (mode=0; mode < 2; ++mode) { leapsec_ut_pristine(); @@ -657,6 +753,8 @@ void test_qryJumpAheadOverTransition(void) { rc = leapsec_query(&qr, lsec2009+5, NULL); TEST_ASSERT_EQUAL(FALSE, rc); } + + return; } // ===================================================================== @@ -665,7 +763,9 @@ void test_qryJumpAheadOverTransition(void) { // ---------------------------------------------------------------------- // add dynamic leap second (like from peer/clock) -void test_addDynamic(void) { +void +test_addDynamic(void) +{ int rc; leap_result_t qr; @@ -683,8 +783,7 @@ void test_addDynamic(void) { rc = setup_load_table(leap2, FALSE); TEST_ASSERT_EQUAL(1, rc); - leap_table_t * pt = leapsec_get_table(0); - int idx; + int idx; for (idx=1; insns[idx]; ++idx) { rc = leapsec_add_dyn(TRUE, insns[idx] - 20*SECSPERDAY - 100, NULL); @@ -693,13 +792,18 @@ void test_addDynamic(void) { // try to slip in a previous entry rc = leapsec_add_dyn(TRUE, insns[0] - 20*SECSPERDAY - 100, NULL); TEST_ASSERT_EQUAL(FALSE, rc); + //leap_table_t * pt = leapsec_get_table(0); //leapsec_dump(pt, (leapsec_dumper)fprintf, stdout); + + return; } // ---------------------------------------------------------------------- // add fixed leap seconds (like from network packet) #if 0 /* currently unused -- possibly revived later */ -void FAILtest_addFixed(void) { +void +FAILtest_addFixed(void) +{ int rc; leap_result_t qr; @@ -716,8 +820,8 @@ void FAILtest_addFixed(void) { rc = setup_load_table(leap2, FALSE); TEST_ASSERT_EQUAL(1, rc); + int idx; - leap_table_t * pt = leapsec_get_table(0); // try to get in BAD time stamps... for (idx=0; insns[idx].tt; ++idx) { rc = leapsec_add_fix( @@ -743,14 +847,19 @@ void FAILtest_addFixed(void) { insns[0].tt + SECSPERDAY, NULL); TEST_ASSERT_EQUAL(FALSE, rc); + //leap_table_t * pt = leapsec_get_table(0); //leapsec_dump(pt, (leapsec_dumper)fprintf, stdout); + + return; } #endif // ---------------------------------------------------------------------- // add fixed leap seconds (like from network packet) #if 0 /* currently unused -- possibly revived later */ -void FAILtest_addFixedExtend(void) { +void +FAILtest_addFixedExtend(void) +{ int rc; leap_result_t qr; int last, idx; @@ -764,7 +873,6 @@ void FAILtest_addFixedExtend(void) { rc = setup_load_table(leap2, FALSE); TEST_ASSERT_EQUAL(1, rc); - leap_table_t * pt = leapsec_get_table(FALSE); for (last=idx=0; insns[idx].tt; ++idx) { last = idx; rc = leapsec_add_fix( @@ -774,7 +882,7 @@ void FAILtest_addFixedExtend(void) { NULL); TEST_ASSERT_EQUAL(TRUE, rc); } - + // try to extend the expiration of the last entry rc = leapsec_add_fix( insns[last].of, @@ -782,7 +890,7 @@ void FAILtest_addFixedExtend(void) { insns[last].tt + 128*SECSPERDAY, NULL); TEST_ASSERT_EQUAL(TRUE, rc); - + // try to extend the expiration of the last entry with wrong offset rc = leapsec_add_fix( insns[last].of+1, @@ -790,7 +898,10 @@ void FAILtest_addFixedExtend(void) { insns[last].tt + 129*SECSPERDAY, NULL); TEST_ASSERT_EQUAL(FALSE, rc); + //leap_table_t * pt = leapsec_get_table(FALSE); //leapsec_dump(pt, (leapsec_dumper)fprintf, stdout); + + return; } #endif @@ -799,7 +910,9 @@ void FAILtest_addFixedExtend(void) { // empty table and test queries before / between /after the tabulated // values. #if 0 /* currently unused -- possibly revived later */ -void FAILtest_setFixedExtend(void) { +void +FAILtest_setFixedExtend(void) +{ int rc; leap_result_t qr; int last, idx; @@ -810,7 +923,6 @@ void FAILtest_setFixedExtend(void) { {0,0} // sentinel }; - leap_table_t * pt = leapsec_get_table(0); for (last=idx=0; insns[idx].tt; ++idx) { last = idx; rc = leapsec_add_fix( @@ -820,7 +932,7 @@ void FAILtest_setFixedExtend(void) { NULL); TEST_ASSERT_EQUAL(TRUE, rc); } - + rc = leapsec_query(&qr, insns[0].tt - 86400, NULL); TEST_ASSERT_EQUAL(28, qr.tai_offs); @@ -833,7 +945,10 @@ void FAILtest_setFixedExtend(void) { rc = leapsec_query(&qr, insns[1].tt + 86400, NULL); TEST_ASSERT_EQUAL(30, qr.tai_offs); + //leap_table_t * pt = leapsec_get_table(0); //leapsec_dump(pt, (leapsec_dumper)fprintf, stdout); + + return; } #endif @@ -846,7 +961,7 @@ void FAILtest_setFixedExtend(void) { void test_taiEmptyTable(void) { int rc; - rc = leapsec_autokey_tai(35, lsec2015-30*86400, NULL); + rc = leapsec_autokey_tai(35, lsec2015-30*86400, NULL); TEST_ASSERT_EQUAL(TRUE, rc); rc = leapsec_autokey_tai(35, lsec2015-29*86400, NULL); @@ -855,7 +970,9 @@ void test_taiEmptyTable(void) { // ---------------------------------------------------------------------- // Check that with fixed entries the operation fails -void test_taiTableFixed(void) { +void +test_taiTableFixed(void) +{ int rc; rc = setup_load_table(leap1, FALSE); @@ -863,11 +980,15 @@ void test_taiTableFixed(void) { rc = leapsec_autokey_tai(35, lsec2015-30*86400, NULL); TEST_ASSERT_EQUAL(FALSE, rc); + + return; } // ---------------------------------------------------------------------- // test adjustment with a dynamic entry already there -void test_taiTableDynamic(void) { +void +test_taiTableDynamic(void) +{ int rc; leap_era_t era; @@ -879,7 +1000,7 @@ void test_taiTableDynamic(void) { leapsec_query_era(&era, lsec2015+10, NULL); TEST_ASSERT_EQUAL(1, era.taiof); - rc = leapsec_autokey_tai(35, lsec2015-19*86400, NULL); + rc = leapsec_autokey_tai(35, lsec2015-19*86400, NULL); TEST_ASSERT_EQUAL(TRUE, rc); rc = leapsec_autokey_tai(35, lsec2015-19*86400, NULL); @@ -889,21 +1010,27 @@ void test_taiTableDynamic(void) { TEST_ASSERT_EQUAL(35, era.taiof); leapsec_query_era(&era, lsec2015+10, NULL); TEST_ASSERT_EQUAL(36, era.taiof); + + return; } // ---------------------------------------------------------------------- // test adjustment with a dynamic entry already there in dead zone -void test_taiTableDynamicDeadZone(void) { +void +test_taiTableDynamicDeadZone(void) +{ int rc; rc = leapsec_add_dyn(TRUE, lsec2015-20*SECSPERDAY, NULL); TEST_ASSERT_EQUAL(TRUE, rc); - rc = leapsec_autokey_tai(35, lsec2015-5, NULL); + rc = leapsec_autokey_tai(35, lsec2015-5, NULL); TEST_ASSERT_EQUAL(FALSE, rc); rc = leapsec_autokey_tai(35, lsec2015+5, NULL); TEST_ASSERT_EQUAL(FALSE, rc); + + return; } @@ -913,7 +1040,9 @@ void test_taiTableDynamicDeadZone(void) { // ---------------------------------------------------------------------- // leap second insert at 2009.01.01, electric mode -void test_ls2009seqInsElectric(void) { +void +test_ls2009seqInsElectric(void) +{ int rc; leap_result_t qr; @@ -952,11 +1081,15 @@ void test_ls2009seqInsElectric(void) { TEST_ASSERT_EQUAL(FALSE, rc); TEST_ASSERT_EQUAL(0, qr.warped ); TEST_ASSERT_EQUAL(LSPROX_NOWARN, qr.proximity); + + return; } // ---------------------------------------------------------------------- // leap second insert at 2009.01.01, dumb mode -void test_ls2009seqInsDumb(void) { +void +test_ls2009seqInsDumb(void) +{ int rc; leap_result_t qr; @@ -999,12 +1132,16 @@ void test_ls2009seqInsDumb(void) { TEST_ASSERT_EQUAL(FALSE, rc); TEST_ASSERT_EQUAL(0, qr.warped ); TEST_ASSERT_EQUAL(LSPROX_NOWARN, qr.proximity); + + return; } // ---------------------------------------------------------------------- // fake leap second remove at 2009.01.01, electric mode -void test_ls2009seqDelElectric(void) { +void +test_ls2009seqDelElectric(void) +{ int rc; leap_result_t qr; @@ -1043,11 +1180,15 @@ void test_ls2009seqDelElectric(void) { TEST_ASSERT_EQUAL(FALSE, rc); TEST_ASSERT_EQUAL(0, qr.warped ); TEST_ASSERT_EQUAL(LSPROX_NOWARN, qr.proximity); + + return; } // ---------------------------------------------------------------------- // fake leap second remove at 2009.01.01. dumb mode -void test_ls2009seqDelDumb(void) { +void +test_ls2009seqDelDumb(void) +{ int rc; leap_result_t qr; @@ -1085,11 +1226,15 @@ void test_ls2009seqDelDumb(void) { TEST_ASSERT_EQUAL(FALSE, rc); TEST_ASSERT_EQUAL(0, qr.warped ); TEST_ASSERT_EQUAL(LSPROX_NOWARN, qr.proximity); + + return; } // ---------------------------------------------------------------------- // leap second insert at 2012.07.01, electric mode -void test_ls2012seqInsElectric(void) { +void +test_ls2012seqInsElectric(void) +{ int rc; leap_result_t qr; @@ -1128,11 +1273,15 @@ void test_ls2012seqInsElectric(void) { TEST_ASSERT_EQUAL(FALSE, rc); TEST_ASSERT_EQUAL(0, qr.warped ); TEST_ASSERT_EQUAL(LSPROX_NOWARN, qr.proximity); + + return; } // ---------------------------------------------------------------------- // leap second insert at 2012.07.01, dumb mode -void test_ls2012seqInsDumb(void) { +void +test_ls2012seqInsDumb(void) +{ int rc; leap_result_t qr; @@ -1177,11 +1326,15 @@ void test_ls2012seqInsDumb(void) { TEST_ASSERT_EQUAL(FALSE, rc); TEST_ASSERT_EQUAL(0, qr.warped ); TEST_ASSERT_EQUAL(LSPROX_NOWARN, qr.proximity); + + return; } // ---------------------------------------------------------------------- // test repeated query on empty table in dumb mode -void test_lsEmptyTableDumb(void) { +void +test_lsEmptyTableDumb(void) +{ int rc; leap_result_t qr; @@ -1189,7 +1342,7 @@ void test_lsEmptyTableDumb(void) { time_t pivot; pivot = lsec2012; // const - //time_t pivot(lsec2012); + //time_t pivot(lsec2012); const uint32_t t0 = lsec2012 - 10; const uint32_t tE = lsec2012 + 10; @@ -1202,20 +1355,24 @@ void test_lsEmptyTableDumb(void) { TEST_ASSERT_EQUAL(0, qr.warped ); TEST_ASSERT_EQUAL(LSPROX_NOWARN, qr.proximity); } + + return; } // ---------------------------------------------------------------------- // test repeated query on empty table in electric mode -void test_lsEmptyTableElectric(void) { +void +test_lsEmptyTableElectric(void) +{ int rc; leap_result_t qr; - + leapsec_electric(1); TEST_ASSERT_EQUAL(1, leapsec_electric(-1)); //const time_t pivot;//(lsec2012); - pivot = lsec2012; + pivot = lsec2012; const uint32_t t0 = lsec2012 - 10; const uint32_t tE = lsec2012 + 10; @@ -1226,4 +1383,6 @@ void test_lsEmptyTableElectric(void) { TEST_ASSERT_EQUAL(0, qr.warped ); TEST_ASSERT_EQUAL(LSPROX_NOWARN, qr.proximity); } + + return; } diff --git a/tests/ntpd/run-leapsec.c b/tests/ntpd/run-leapsec.c index c02cfa896..03b633e1e 100644 --- a/tests/ntpd/run-leapsec.c +++ b/tests/ntpd/run-leapsec.c @@ -84,39 +84,39 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("leapsec.c"); - RUN_TEST(test_ValidateGood, 331); - RUN_TEST(test_ValidateNoHash, 338); - RUN_TEST(test_ValidateBad, 345); - RUN_TEST(test_ValidateMalformed, 352); - RUN_TEST(test_ValidateMalformedShort, 359); - RUN_TEST(test_ValidateNoLeadZero, 366); - RUN_TEST(test_tableSelect, 378); - RUN_TEST(test_loadFileExpire, 414); - RUN_TEST(test_loadFileTTL, 431); - RUN_TEST(test_lsQueryPristineState, 463); - RUN_TEST(test_ls2009faraway, 475); - RUN_TEST(test_ls2009weekaway, 492); - RUN_TEST(test_ls2009houraway, 509); - RUN_TEST(test_ls2009secaway, 526); - RUN_TEST(test_ls2009onspot, 543); - RUN_TEST(test_ls2009nodata, 560); - RUN_TEST(test_ls2009limdata, 577); - RUN_TEST(test_qryJumpFarAhead, 598); - RUN_TEST(test_qryJumpAheadToTransition, 620); - RUN_TEST(test_qryJumpAheadOverTransition, 642); - RUN_TEST(test_addDynamic, 668); - RUN_TEST(test_taiEmptyTable, 846); - RUN_TEST(test_taiTableFixed, 858); - RUN_TEST(test_taiTableDynamic, 870); - RUN_TEST(test_taiTableDynamicDeadZone, 896); - RUN_TEST(test_ls2009seqInsElectric, 916); - RUN_TEST(test_ls2009seqInsDumb, 959); - RUN_TEST(test_ls2009seqDelElectric, 1007); - RUN_TEST(test_ls2009seqDelDumb, 1050); - RUN_TEST(test_ls2012seqInsElectric, 1092); - RUN_TEST(test_ls2012seqInsDumb, 1135); - RUN_TEST(test_lsEmptyTableDumb, 1184); - RUN_TEST(test_lsEmptyTableElectric, 1209); + RUN_TEST(test_ValidateGood, 351); + RUN_TEST(test_ValidateNoHash, 362); + RUN_TEST(test_ValidateBad, 373); + RUN_TEST(test_ValidateMalformed, 385); + RUN_TEST(test_ValidateMalformedShort, 397); + RUN_TEST(test_ValidateNoLeadZero, 409); + RUN_TEST(test_tableSelect, 426); + RUN_TEST(test_loadFileExpire, 466); + RUN_TEST(test_loadFileTTL, 487); + RUN_TEST(test_lsQueryPristineState, 522); + RUN_TEST(test_ls2009faraway, 538); + RUN_TEST(test_ls2009weekaway, 559); + RUN_TEST(test_ls2009houraway, 580); + RUN_TEST(test_ls2009secaway, 601); + RUN_TEST(test_ls2009onspot, 622); + RUN_TEST(test_ls2009nodata, 643); + RUN_TEST(test_ls2009limdata, 664); + RUN_TEST(test_qryJumpFarAhead, 689); + RUN_TEST(test_qryJumpAheadToTransition, 712); + RUN_TEST(test_qryJumpAheadOverTransition, 737); + RUN_TEST(test_addDynamic, 767); + RUN_TEST(test_taiEmptyTable, 961); + RUN_TEST(test_taiTableFixed, 974); + RUN_TEST(test_taiTableDynamic, 990); + RUN_TEST(test_taiTableDynamicDeadZone, 1020); + RUN_TEST(test_ls2009seqInsElectric, 1044); + RUN_TEST(test_ls2009seqInsDumb, 1091); + RUN_TEST(test_ls2009seqDelElectric, 1143); + RUN_TEST(test_ls2009seqDelDumb, 1190); + RUN_TEST(test_ls2012seqInsElectric, 1236); + RUN_TEST(test_ls2012seqInsDumb, 1283); + RUN_TEST(test_lsEmptyTableDumb, 1336); + RUN_TEST(test_lsEmptyTableElectric, 1365); return (UnityEnd()); } diff --git a/tests/ntpd/run-t-ntp_signd.c b/tests/ntpd/run-t-ntp_signd.c index 8c5f23a66..c0979b05e 100644 --- a/tests/ntpd/run-t-ntp_signd.c +++ b/tests/ntpd/run-t-ntp_signd.c @@ -55,12 +55,12 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("t-ntp_signd.c"); - RUN_TEST(test_connect_incorrect_socket, 48); - RUN_TEST(test_connect_correct_socket, 49); - RUN_TEST(test_write_all, 50); - RUN_TEST(test_send_packet, 51); - RUN_TEST(test_recv_packet, 52); - RUN_TEST(test_send_via_ntp_signd, 53); + RUN_TEST(test_connect_incorrect_socket, 53); + RUN_TEST(test_connect_correct_socket, 54); + RUN_TEST(test_write_all, 55); + RUN_TEST(test_send_packet, 56); + RUN_TEST(test_recv_packet, 57); + RUN_TEST(test_send_via_ntp_signd, 58); return (UnityEnd()); } diff --git a/tests/ntpd/t-ntp_signd.c b/tests/ntpd/t-ntp_signd.c index 180d28cab..a7c2f82cb 100644 --- a/tests/ntpd/t-ntp_signd.c +++ b/tests/ntpd/t-ntp_signd.c @@ -9,7 +9,6 @@ #include "test-libntp.h" - #define HAVE_NTP_SIGND #include "ntp_signd.c" @@ -20,19 +19,24 @@ extern int ux_socket_connect(const char *name); //MOCKED FUNCTIONS //this connect function overrides/mocks connect() from -int connect(int socket, const struct sockaddr *address, -socklen_t address_len){ +int +connect(int socket, const struct sockaddr *address, socklen_t address_len) +{ return 1; } //mocked write will only send 4 bytes at a time. This is so write_all can be properly tested -ssize_t write(int fd, void const * buf, size_t len){ - if(len >= 4){return 4;} +ssize_t +write(int fd, void const * buf, size_t len) +{ + if (len >= 4) {return 4;} else return len; } -ssize_t read(int fd, void * buf, size_t len){ - if(len >= 4){return 4;} +ssize_t +read(int fd, void * buf, size_t len) +{ + if (len >= 4) {return 4;} else return len; } @@ -40,8 +44,9 @@ ssize_t read(int fd, void * buf, size_t len){ //END OF MOCKED FUNCTIONS static int -isGE(int a,int b){ - if(a >= b) {return 1;} +isGE(int a,int b) +{ + if (a >= b) {return 1;} else {return 0;} } @@ -57,6 +62,8 @@ void test_connect_incorrect_socket(void) { TEST_ASSERT_EQUAL(-1, ux_socket_connect(NULL)); + + return; } void @@ -74,6 +81,7 @@ test_connect_correct_socket(void) //char *socketName = "Random_Socket_Name"; //int length = strlen(socketName); + return; } @@ -81,10 +89,14 @@ void test_write_all(void) { int fd = ux_socket_connect("/socket"); - TEST_ASSERT_TRUE(isGE(fd,0)); + + TEST_ASSERT_TRUE(isGE(fd, 0)); + char * str = "TEST123"; int temp = write_all(fd, str,strlen(str)); - TEST_ASSERT_EQUAL(strlen(str),temp); + TEST_ASSERT_EQUAL(strlen(str), temp); + + return; } @@ -94,21 +106,30 @@ test_send_packet(void) int fd = ux_socket_connect("/socket"); char * str2 = "PACKET12345"; int temp = send_packet(fd, str2, strlen(str2)); + TEST_ASSERT_EQUAL(0,temp); + + return; } +/* +** HMS: What's going on here? +** Looks like this needs more work. +*/ void test_recv_packet(void) { int fd = ux_socket_connect("/socket"); uint32_t size = 256; char *str = NULL; - int temp = recv_packet(fd, &str, &size); + send_packet(fd, str, strlen(str)); free(str); TEST_ASSERT_EQUAL(0,temp); //0 because nobody sent us anything (yet!) + + return; } void @@ -117,11 +138,17 @@ test_send_via_ntp_signd(void) struct recvbuf *rbufp = (struct recvbuf *) malloc(sizeof(struct recvbuf)); int xmode = 1; keyid_t xkeyid = 12345; - int flags =0; + int flags = 0; struct pkt *xpkt = (struct pkt *) malloc(sizeof(struct pkt)); //defined in ntp.h //send_via_ntp_signd(NULL,NULL,NULL,NULL,NULL); //doesn't work + /* + ** Send the xpkt to Samba, read the response back in rbufp + */ send_via_ntp_signd(rbufp,xmode,xkeyid,flags,xpkt); + free(rbufp); + free(xpkt); + return; } diff --git a/tests/sandbox/smeartest.c b/tests/sandbox/smeartest.c index 6954d9e5d..cc4e50304 100644 --- a/tests/sandbox/smeartest.c +++ b/tests/sandbox/smeartest.c @@ -2,6 +2,7 @@ #include #include +#include /* * we want to test a refid format of: @@ -170,6 +171,8 @@ main() rtoltor(0xfe7fffff); rc = atolfp("-.932087", &l); + INSIST(1 == rc); + ltor(l); rtol(0xfec458b0); printf("%x -> %d.%d.%d.%d\n",