diff options
author | delphij <delphij@FreeBSD.org> | 2016-01-08 15:53:48 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2016-01-08 15:53:48 +0000 |
commit | 31ece5769d393d00720a55b05dd7b3e85c2fcc52 (patch) | |
tree | eb428181ad7f992dbbff39c2be903eaab7149cfb /contrib/ntp/tests | |
parent | 72bd55ca76570ee190062912e8f0350831baca6f (diff) | |
parent | 8518518f8f222e4d58e27928a988f034b82bbb77 (diff) | |
download | FreeBSD-src-31ece5769d393d00720a55b05dd7b3e85c2fcc52.zip FreeBSD-src-31ece5769d393d00720a55b05dd7b3e85c2fcc52.tar.gz |
MFV r293415:
ntp 4.2.8p5
Reviewed by: cy, roberto
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4828
Diffstat (limited to 'contrib/ntp/tests')
63 files changed, 1607 insertions, 680 deletions
diff --git a/contrib/ntp/tests/bug-2803/bug-2803.c b/contrib/ntp/tests/bug-2803/bug-2803.c index 4ee6f02..df9dcde 100644 --- a/contrib/ntp/tests/bug-2803/bug-2803.c +++ b/contrib/ntp/tests/bug-2803/bug-2803.c @@ -15,7 +15,7 @@ int simpleTest(void); void setUp(void); void tearDown(void); -//void test_main(void); +void test_main(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 diff --git a/contrib/ntp/tests/bug-2803/run-bug-2803.c b/contrib/ntp/tests/bug-2803/run-bug-2803.c index 05e6a5d..f4066f2 100644 --- a/contrib/ntp/tests/bug-2803/run-bug-2803.c +++ b/contrib/ntp/tests/bug-2803/run-bug-2803.c @@ -31,6 +31,7 @@ //=======External Functions This Runner Calls===== extern void setUp(void); extern void tearDown(void); +extern void test_main(void); extern void test_main(void ); @@ -51,6 +52,7 @@ int main(int argc, char *argv[]) progname = argv[0]; UnityBegin("bug-2803.c"); RUN_TEST(test_main, 18); + RUN_TEST(test_main, 18); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/a_md5encrypt.c b/contrib/ntp/tests/libntp/a_md5encrypt.c index f46376e..d8e7ab9 100644 --- a/contrib/ntp/tests/libntp/a_md5encrypt.c +++ b/contrib/ntp/tests/libntp/a_md5encrypt.c @@ -16,14 +16,25 @@ u_long current_time = 4; * Example packet with MD5 hash calculated manually. */ const int keytype = KEY_TYPE_MD5; -const char *key = "abcdefgh"; +const u_char *key = (const u_char*)"abcdefgh"; const u_short keyLength = 8; -const char *packet = "ijklmnopqrstuvwx"; +const u_char *packet = (const u_char*)"ijklmnopqrstuvwx"; #define packetLength 16 #define keyIdLength 4 #define digestLength 16 -const int totalLength = packetLength + keyIdLength + digestLength; -const char *expectedPacket = "ijklmnopqrstuvwx\0\0\0\0\x0c\x0e\x84\xcf\x0b\xb7\xa8\x68\x8e\x52\x38\xdb\xbc\x1c\x39\x53"; +#define totalLength (packetLength + keyIdLength + digestLength) +union { + u_char u8 [totalLength]; + uint32_t u32[1]; +} expectedPacket = { + "ijklmnopqrstuvwx\0\0\0\0\x0c\x0e\x84\xcf\x0b\xb7\xa8\x68\x8e\x52\x38\xdb\xbc\x1c\x39\x53" +}; +union { + u_char u8 [totalLength]; + uint32_t u32[1]; +} invalidPacket = { + "ijklmnopqrstuvwx\0\0\0\0\x0c\x0e\x84\xcf\x0b\xb7\xa8\x68\x8e\x52\x38\xdb\xbc\x1c\x39\x54" +}; void test_Encrypt(void); @@ -35,7 +46,7 @@ void test_IPv6AddressToRefId(void); void test_Encrypt(void) { - char *packetPtr; + u_int32 *packetPtr; int length; packetPtr = emalloc(totalLength * sizeof(*packetPtr)); @@ -45,12 +56,12 @@ test_Encrypt(void) { cache_secretsize = keyLength; - length = MD5authencrypt(keytype, (u_char*)key, (u_int32*)packetPtr, packetLength); + length = MD5authencrypt(keytype, key, packetPtr, packetLength); - TEST_ASSERT_TRUE(MD5authdecrypt(keytype, (u_char*)key, (u_int32*)packetPtr, packetLength, length)); + TEST_ASSERT_TRUE(MD5authdecrypt(keytype, key, packetPtr, packetLength, length)); TEST_ASSERT_EQUAL(20, length); - TEST_ASSERT_EQUAL_MEMORY(expectedPacket, packetPtr, totalLength); + TEST_ASSERT_EQUAL_MEMORY(expectedPacket.u8, packetPtr, totalLength); free(packetPtr); } @@ -58,17 +69,13 @@ test_Encrypt(void) { void test_DecryptValid(void) { cache_secretsize = keyLength; - - TEST_ASSERT_TRUE(MD5authdecrypt(keytype, (u_char*)key, (u_int32*)expectedPacket, packetLength, 20)); + TEST_ASSERT_TRUE(MD5authdecrypt(keytype, key, expectedPacket.u32, packetLength, 20)); } void test_DecryptInvalid(void) { cache_secretsize = keyLength; - - const char *invalidPacket = "ijklmnopqrstuvwx\0\0\0\0\x0c\x0e\x84\xcf\x0b\xb7\xa8\x68\x8e\x52\x38\xdb\xbc\x1c\x39\x54"; - - TEST_ASSERT_FALSE(MD5authdecrypt(keytype, (u_char*)key, (u_int32*)invalidPacket, packetLength, 20)); + TEST_ASSERT_FALSE(MD5authdecrypt(keytype, key, invalidPacket.u32, packetLength, 20)); } void @@ -87,23 +94,24 @@ test_IPv4AddressToRefId(void) { void test_IPv6AddressToRefId(void) { - const struct in6_addr address = { + const int expected = 0x75cffd52; + const struct in6_addr address = { { { 0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x08, 0xd3, 0x13, 0x19, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34 - }; + } } }; sockaddr_u addr; addr.sa6.sin6_family = AF_INET6; addr.sa6.sin6_addr = address; - const int expected = 0x75cffd52; #if 0 TEST_ASSERT_EQUAL(expected, addr2refid(&addr)); #else + (void)expected; TEST_IGNORE_MESSAGE("Skipping because of big endian problem?"); #endif } diff --git a/contrib/ntp/tests/libntp/authkeys.c b/contrib/ntp/tests/libntp/authkeys.c index 6a10c01..2ddbce5 100644 --- a/contrib/ntp/tests/libntp/authkeys.c +++ b/contrib/ntp/tests/libntp/authkeys.c @@ -51,18 +51,21 @@ setUp(void) cache_flags = 0; cache_secret = NULL; cache_secretsize = 0; + + return; } void tearDown(void) { - + return; } static const int KEYTYPE = KEY_TYPE_MD5; void -AddTrustedKey(keyid_t keyno) { +AddTrustedKey(keyid_t keyno) +{ /* * We need to add a MD5-key in addition to setting the * trust, because authhavekey() requires type != 0. @@ -70,15 +73,21 @@ AddTrustedKey(keyid_t keyno) { MD5auth_setkey(keyno, KEYTYPE, NULL, 0); authtrust(keyno, TRUE); + + return; } void -AddUntrustedKey(keyid_t keyno) { +AddUntrustedKey(keyid_t keyno) +{ authtrust(keyno, FALSE); + + return; } void -test_AddTrustedKeys(void) { +test_AddTrustedKeys(void) +{ const keyid_t KEYNO1 = 5; const keyid_t KEYNO2 = 8; @@ -87,48 +96,65 @@ test_AddTrustedKeys(void) { TEST_ASSERT_TRUE(authistrusted(KEYNO1)); TEST_ASSERT_TRUE(authistrusted(KEYNO2)); + + return; } void -test_AddUntrustedKey(void) { +test_AddUntrustedKey(void) +{ const keyid_t KEYNO = 3; AddUntrustedKey(KEYNO); TEST_ASSERT_FALSE(authistrusted(KEYNO)); + + return; } void -test_HaveKeyCorrect(void) { +test_HaveKeyCorrect(void) +{ const keyid_t KEYNO = 3; AddTrustedKey(KEYNO); TEST_ASSERT_TRUE(auth_havekey(KEYNO)); TEST_ASSERT_TRUE(authhavekey(KEYNO)); + + return; } void -test_HaveKeyIncorrect(void) { +test_HaveKeyIncorrect(void) +{ const keyid_t KEYNO = 2; TEST_ASSERT_FALSE(auth_havekey(KEYNO)); TEST_ASSERT_FALSE(authhavekey(KEYNO)); + + return; } void -test_AddWithAuthUseKey(void) { +test_AddWithAuthUseKey(void) +{ const keyid_t KEYNO = 5; const char* KEY = "52a"; - TEST_ASSERT_TRUE(authusekey(KEYNO, KEYTYPE, (u_char*)KEY)); + TEST_ASSERT_TRUE(authusekey(KEYNO, KEYTYPE, (const u_char*)KEY)); + + return; } void -test_EmptyKey(void) { +test_EmptyKey(void) +{ const keyid_t KEYNO = 3; const char* KEY = ""; - TEST_ASSERT_FALSE(authusekey(KEYNO, KEYTYPE, (u_char*)KEY)); + TEST_ASSERT_FALSE(authusekey(KEYNO, KEYTYPE, (const u_char*)KEY)); + + return; } diff --git a/contrib/ntp/tests/libntp/buftvtots.c b/contrib/ntp/tests/libntp/buftvtots.c index efde009..b6b81a2 100644 --- a/contrib/ntp/tests/libntp/buftvtots.c +++ b/contrib/ntp/tests/libntp/buftvtots.c @@ -18,7 +18,8 @@ void test_AlwaysFalseOnWindows(void); void -test_ZeroBuffer(void) { +test_ZeroBuffer(void) +{ #ifndef SYS_WINNT const struct timeval input = {0, 0}; const l_fp expected = {{0 + JAN_1970}, 0}; @@ -30,10 +31,14 @@ test_ZeroBuffer(void) { #else TEST_IGNORE_MESSAGE("Test only for Windows, skipping..."); #endif + + return; } + void -test_IntegerAndFractionalBuffer(void) { +test_IntegerAndFractionalBuffer(void) +{ #ifndef SYS_WINNT const struct timeval input = {5, 500000}; /* 5.5 */ const l_fp expected = {{5 + JAN_1970}, HALF}; @@ -53,24 +58,30 @@ test_IntegerAndFractionalBuffer(void) { #else TEST_IGNORE_MESSAGE("Test only for Windows, skipping..."); #endif + + return; } void -test_IllegalMicroseconds(void) { +test_IllegalMicroseconds(void) +{ #ifndef SYS_WINNT const struct timeval input = {0, 1100000}; /* > 999 999 microseconds. */ - + l_fp actual; TEST_ASSERT_FALSE(buftvtots((const char*)(&input), &actual)); #else TEST_IGNORE_MESSAGE("Test only for Windows, skipping..."); #endif + + return; } void -test_AlwaysFalseOnWindows(void) { +test_AlwaysFalseOnWindows(void) +{ #ifdef SYS_WINNT /* * Under Windows, buftvtots will just return @@ -81,5 +92,6 @@ test_AlwaysFalseOnWindows(void) { #else TEST_IGNORE_MESSAGE("Non-Windows test, skipping..."); #endif -} + return; +} diff --git a/contrib/ntp/tests/libntp/calendar.c b/contrib/ntp/tests/libntp/calendar.c index 2c8a2d5..9d25c41 100644 --- a/contrib/ntp/tests/libntp/calendar.c +++ b/contrib/ntp/tests/libntp/calendar.c @@ -8,31 +8,42 @@ static int leapdays(int year); -int isGT(int first, int second); -int leapdays(int year); -char * CalendarFromCalToString(const struct calendar *cal); -char * CalendarFromIsoToString(const struct isodate *iso); -int IsEqualCal(const struct calendar *expected, const struct calendar *actual); -int IsEqualIso(const struct isodate *expected, const struct isodate *actual); -char * DateFromCalToString(const struct calendar *cal); -char * DateFromIsoToString(const struct isodate *iso); -int IsEqualDateCal(const struct calendar *expected, const struct calendar *actual); -int IsEqualDateIso(const struct isodate *expected, const struct isodate *actual); -void test_DaySplitMerge(void); -void test_SplitYearDays1(void); -void test_SplitYearDays2(void); -void test_RataDie1(void); -void test_LeapYears1(void); -void test_LeapYears2(void); -void test_RoundTripDate(void); -void test_RoundTripYearStart(void); -void test_RoundTripMonthStart(void); -void test_RoundTripWeekStart(void); -void test_RoundTripDayStart(void); -void test_IsoCalYearsToWeeks(void); -void test_IsoCalWeeksToYearStart(void); -void test_IsoCalWeeksToYearEnd(void); -void test_DaySecToDate(void); +void setUp(void); +int isGT(int first, int second); +int leapdays(int year); +char * CalendarFromCalToString(const struct calendar *cal); +char * CalendarFromIsoToString(const struct isodate *iso); +int IsEqualCal(const struct calendar *expected, const struct calendar *actual); +int IsEqualIso(const struct isodate *expected, const struct isodate *actual); +char * DateFromCalToString(const struct calendar *cal); +char * DateFromIsoToString(const struct isodate *iso); +int IsEqualDateCal(const struct calendar *expected, const struct calendar *actual); +int IsEqualDateIso(const struct isodate *expected, const struct isodate *actual); +void test_DaySplitMerge(void); +void test_SplitYearDays1(void); +void test_SplitYearDays2(void); +void test_RataDie1(void); +void test_LeapYears1(void); +void test_LeapYears2(void); +void test_RoundTripDate(void); +void test_RoundTripYearStart(void); +void test_RoundTripMonthStart(void); +void test_RoundTripWeekStart(void); +void test_RoundTripDayStart(void); +void test_IsoCalYearsToWeeks(void); +void test_IsoCalWeeksToYearStart(void); +void test_IsoCalWeeksToYearEnd(void); +void test_DaySecToDate(void); + + +void +setUp(void) +{ + init_lib(); + + return; +} + /* * --------------------------------------------------------------------- @@ -42,7 +53,7 @@ void test_DaySecToDate(void); int isGT(int first, int second) { - if(first > second) { + if(first > second) { return TRUE; } else { return FALSE; @@ -100,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; } } @@ -215,8 +231,10 @@ static const u_short real_month_days[2][14] = { * the 'vint64' is definitely needed. */ void -test_DaySplitMerge(void) { +test_DaySplitMerge(void) +{ int32 day,sec; + for (day = -1000000; day <= 1000000; day += 100) { for (sec = -100000; sec <= 186400; sec += 10000) { vint64 merge; @@ -242,11 +260,15 @@ test_DaySplitMerge(void) { TEST_ASSERT_EQUAL(esec, split.lo); } } + + return; } void -test_SplitYearDays1(void) { +test_SplitYearDays1(void) +{ int32 eyd; + for (eyd = -1; eyd <= 365; eyd++) { ntpcal_split split = ntpcal_split_yeardays(eyd, 0); if (split.lo >= 0 && split.hi >= 0) { @@ -257,11 +279,15 @@ test_SplitYearDays1(void) { } else TEST_ASSERT_TRUE(eyd < 0 || eyd > 364); } + + return; } - + void -test_SplitYearDays2(void) { +test_SplitYearDays2(void) +{ int32 eyd; + for (eyd = -1; eyd <= 366; eyd++) { ntpcal_split split = ntpcal_split_yeardays(eyd, 1); if (split.lo >= 0 && split.hi >= 0) { @@ -274,21 +300,27 @@ test_SplitYearDays2(void) { } else TEST_ASSERT_TRUE(eyd < 0 || eyd > 365); } + + return; } - + void -test_RataDie1(void) { +test_RataDie1(void) +{ int32 testDate = 1; /* 0001-01-01 (proleptic date) */ struct calendar expected = { 1, 1, 1, 1 }; struct calendar actual; ntpcal_rd_to_date(&actual, testDate); TEST_ASSERT_TRUE(IsEqualDateCal(&expected, &actual)); + + return; } /* check last day of february for first 10000 years */ void -test_LeapYears1(void) { +test_LeapYears1(void) +{ struct calendar dateIn, dateOut; for (dateIn.year = 1; dateIn.year < 10000; ++dateIn.year) { @@ -300,11 +332,14 @@ test_LeapYears1(void) { TEST_ASSERT_TRUE(IsEqualDateCal(&dateIn, &dateOut)); } + + return; } /* check first day of march for first 10000 years */ void -test_LeapYears2(void) { +test_LeapYears2(void) +{ struct calendar dateIn, dateOut; for (dateIn.year = 1; dateIn.year < 10000; ++dateIn.year) { @@ -315,6 +350,8 @@ test_LeapYears2(void) { ntpcal_rd_to_date(&dateOut, ntpcal_date_to_rd(&dateIn)); TEST_ASSERT_TRUE(IsEqualDateCal(&dateIn, &dateOut)); } + + return; } /* Full roundtrip from 1601-01-01 to 2400-12-31 @@ -324,7 +361,8 @@ test_LeapYears2(void) { * invalid output can occur.) */ void -test_RoundTripDate(void) { +test_RoundTripDate(void) +{ struct calendar truDate, expDate = { 1600, 0, 12, 31 };; int leaps; int32 truRdn, expRdn = ntpcal_date_to_rd(&expDate); @@ -335,7 +373,7 @@ test_RoundTripDate(void) { expDate.yearday = 0; leaps = leapdays(expDate.year); while (expDate.month < 12) { - expDate.month++; + expDate.month++; expDate.monthday = 0; while (expDate.monthday < real_month_days[leaps][expDate.month]) { expDate.monthday++; @@ -350,11 +388,14 @@ test_RoundTripDate(void) { } } } + + return; } /* Roundtrip testing on calyearstart */ void -test_RoundTripYearStart(void) { +test_RoundTripYearStart(void) +{ static const time_t pivot = 0; u_int32 ntp, expys, truys; struct calendar date; @@ -367,11 +408,14 @@ test_RoundTripYearStart(void) { expys = ntpcal_date_to_ntp(&date); TEST_ASSERT_EQUAL(expys, truys); } -} + + return; +} /* Roundtrip testing on calmonthstart */ void -test_RoundTripMonthStart(void) { +test_RoundTripMonthStart(void) +{ static const time_t pivot = 0; u_int32 ntp, expms, trums; struct calendar date; @@ -384,11 +428,14 @@ test_RoundTripMonthStart(void) { expms = ntpcal_date_to_ntp(&date); TEST_ASSERT_EQUAL(expms, trums); } -} + + return; +} /* Roundtrip testing on calweekstart */ void -test_RoundTripWeekStart(void) { +test_RoundTripWeekStart(void) +{ static const time_t pivot = 0; u_int32 ntp, expws, truws; struct isodate date; @@ -401,11 +448,14 @@ test_RoundTripWeekStart(void) { expws = isocal_date_to_ntp(&date); TEST_ASSERT_EQUAL(expws, truws); } -} + + return; +} /* Roundtrip testing on caldaystart */ void -test_RoundTripDayStart(void) { +test_RoundTripDayStart(void) +{ static const time_t pivot = 0; u_int32 ntp, expds, truds; struct calendar date; @@ -417,6 +467,8 @@ test_RoundTripDayStart(void) { expds = ntpcal_date_to_ntp(&date); TEST_ASSERT_EQUAL(expds, truds); } + + return; } /* --------------------------------------------------------------------- @@ -444,6 +496,7 @@ refimpl_WeeksInIsoYears( int32_t years) { int32_t days, weeks; + days = ntpcal_weekday_close( ntpcal_days_in_years(years) + 1, CAL_MONDAY) - 1; @@ -455,6 +508,7 @@ refimpl_WeeksInIsoYears( weeks = days / 7; days = days % 7; TEST_ASSERT_EQUAL(0, days); /* paranoia check... */ + return weeks; } @@ -462,9 +516,11 @@ refimpl_WeeksInIsoYears( * they are not, the calendar needs a better implementation... */ void -test_IsoCalYearsToWeeks(void) { +test_IsoCalYearsToWeeks(void) +{ int32_t years; int32_t wref, wcal; + for (years = -1000; years < 4000; ++years) { /* get number of weeks before years (reference) */ wref = refimpl_WeeksInIsoYears(years); @@ -472,13 +528,17 @@ test_IsoCalYearsToWeeks(void) { wcal = isocal_weeks_in_years(years); TEST_ASSERT_EQUAL(wref, wcal); } + + return; } void -test_IsoCalWeeksToYearStart(void) { +test_IsoCalWeeksToYearStart(void) +{ int32_t years; int32_t wref; ntpcal_split ysplit; + for (years = -1000; years < 4000; ++years) { /* get number of weeks before years (reference) */ wref = refimpl_WeeksInIsoYears(years); @@ -488,13 +548,17 @@ test_IsoCalWeeksToYearStart(void) { TEST_ASSERT_EQUAL(years, ysplit.hi); TEST_ASSERT_EQUAL(0, ysplit.lo); } + + return; } void -test_IsoCalWeeksToYearEnd(void) { +test_IsoCalWeeksToYearEnd(void) +{ int32_t years; int32_t wref; ntpcal_split ysplit; + for (years = -1000; years < 4000; ++years) { /* get last week of previous year */ wref = refimpl_WeeksInIsoYears(years) - 1; @@ -504,10 +568,13 @@ test_IsoCalWeeksToYearEnd(void) { TEST_ASSERT_EQUAL(years-1, ysplit.hi); TEST_ASSERT(ysplit.lo == 51 || ysplit.lo == 52); } + + return; } void -test_DaySecToDate(void) { +test_DaySecToDate(void) +{ struct calendar cal; int32_t days; @@ -538,4 +605,6 @@ test_DaySecToDate(void) { days = ntpcal_daysec_to_date(&cal, 86400); TEST_ASSERT_MESSAGE((days==1 && cal.hour==0 && cal.minute==0 && cal.second==0), "failed for 86400"); + + return; } diff --git a/contrib/ntp/tests/libntp/caljulian.c b/contrib/ntp/tests/libntp/caljulian.c index ecf5d9255..b25f8ac 100644 --- a/contrib/ntp/tests/libntp/caljulian.c +++ b/contrib/ntp/tests/libntp/caljulian.c @@ -20,10 +20,12 @@ void test_uLongWrapped(void); char * -CalendarToString(const struct calendar cal) { +CalendarToString(const struct calendar cal) +{ char * str = emalloc (sizeof (char) * 100); - char buffer[100] =""; + + *str = '\0'; snprintf(buffer, 100, "%u", cal.year); strcat(str, buffer); strcat(str, "-"); @@ -48,19 +50,25 @@ CalendarToString(const struct calendar cal) { } int // technically boolean -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) { +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, *p_act; + + p_exp = CalendarToString(expected); + p_act = CalendarToString(actual); + printf("expected: %s but was %s", p_exp, p_act); + free(p_exp); + free(p_act); return FALSE; - } } @@ -70,17 +78,23 @@ setUp() { ntpcal_set_timefunc(timefunc); settime(1970, 1, 1, 0, 0, 0); + init_lib(); + + return; } void tearDown() { ntpcal_set_timefunc(NULL); + + return; } void -test_RegularTime(void) { +test_RegularTime(void) +{ u_long testDate = 3485080800UL; // 2010-06-09 14:00:00 struct calendar expected = {2010,160,6,9,14,0,0}; @@ -89,10 +103,13 @@ test_RegularTime(void) { caljulian(testDate, &actual); TEST_ASSERT_TRUE(IsEqual(expected, actual)); + + return; } void -test_LeapYear(void) { +test_LeapYear(void) +{ u_long input = 3549902400UL; // 2012-06-28 20:00:00Z struct calendar expected = {2012, 179, 6, 28, 20, 0, 0}; @@ -101,28 +118,36 @@ test_LeapYear(void) { caljulian(input, &actual); TEST_ASSERT_TRUE(IsEqual(expected, actual)); + + return; } void -test_uLongBoundary(void) { - u_long time = 4294967295UL; // 2036-02-07 6:28:15 +test_uLongBoundary(void) +{ + u_long enc_time = 4294967295UL; // 2036-02-07 6:28:15 struct calendar expected = {2036,0,2,7,6,28,15}; struct calendar actual; - caljulian(time, &actual); + caljulian(enc_time, &actual); TEST_ASSERT_TRUE(IsEqual(expected, actual)); + + return; } void -test_uLongWrapped(void) { - u_long time = 0; +test_uLongWrapped(void) +{ + u_long enc_time = 0; struct calendar expected = {2036,0,2,7,6,28,16}; struct calendar actual; - caljulian(time, &actual); + caljulian(enc_time, &actual); TEST_ASSERT_TRUE(IsEqual(expected, actual)); + + return; } diff --git a/contrib/ntp/tests/libntp/clocktime.c b/contrib/ntp/tests/libntp/clocktime.c index 67ca401..ed2d4b2 100644 --- a/contrib/ntp/tests/libntp/clocktime.c +++ b/contrib/ntp/tests/libntp/clocktime.c @@ -30,14 +30,18 @@ void test_AlwaysInLimit(void); void setUp() { - ntpcal_set_timefunc(timefunc); - settime(2000, 1, 1, 0, 0, 0); + ntpcal_set_timefunc(timefunc); + settime(2000, 1, 1, 0, 0, 0); + + return; } void tearDown() { - ntpcal_set_timefunc(NULL); + ntpcal_set_timefunc(NULL); + + return; } /* --------------------------------------------------------------------- @@ -45,23 +49,27 @@ tearDown() */ void -test_CurrentYear(void) { +test_CurrentYear(void) +{ /* Timestamp: 2010-06-24 12:50:00Z */ const u_int32 timestamp = 3486372600UL; const u_int32 expected = timestamp; /* exactly the same. */ const int yday=175, hour=12, minute=50, second=0, tzoff=0; - u_long yearstart=0; + u_long yearstart = 0; u_int32 actual; - TEST_ASSERT_TRUE(clocktime(yday, hour, minute, second, tzoff, timestamp, - &yearstart, &actual)); + TEST_ASSERT_TRUE(clocktime(yday, hour, minute, second, tzoff, + timestamp, &yearstart, &actual)); TEST_ASSERT_EQUAL(expected, actual); + + return; } void -test_CurrentYearFuzz(void) { +test_CurrentYearFuzz(void) +{ /* * Timestamp (rec_ui) is: 2010-06-24 12:50:00 * Time sent into function is 12:00:00. @@ -78,13 +86,16 @@ test_CurrentYearFuzz(void) { u_long yearstart=0; u_int32 actual; - TEST_ASSERT_TRUE(clocktime(yday, hour, minute, second, tzoff, timestamp, - &yearstart, &actual)); + TEST_ASSERT_TRUE(clocktime(yday, hour, minute, second, tzoff, + timestamp, &yearstart, &actual)); TEST_ASSERT_EQUAL(expected, actual); + + return; } void -test_TimeZoneOffset(void) { +test_TimeZoneOffset(void) +{ /* * Timestamp (rec_ui) is: 2010-06-24 12:00:00 +0800 * (which is 2010-06-24 04:00:00Z) @@ -105,7 +116,8 @@ test_TimeZoneOffset(void) { } void -test_WrongYearStart(void) { +test_WrongYearStart(void) +{ /* * Timestamp (rec_ui) is: 2010-01-02 11:00:00Z * Time sent into function is 11:00:00. @@ -125,7 +137,8 @@ test_WrongYearStart(void) { } void -test_PreviousYear(void) { +test_PreviousYear(void) +{ /* * Timestamp is: 2010-01-01 01:00:00Z * Time sent into function is 23:00:00 @@ -145,7 +158,8 @@ test_PreviousYear(void) { } void -test_NextYear(void) { +test_NextYear(void) +{ /* * Timestamp is: 2009-12-31 23:00:00Z * Time sent into function is 01:00:00 @@ -158,28 +172,35 @@ test_NextYear(void) { u_long yearstart = 0; u_int32 actual; - TEST_ASSERT_TRUE(clocktime(yday, hour, minute, second, tzoff, timestamp, - &yearstart, &actual)); + TEST_ASSERT_TRUE(clocktime(yday, hour, minute, second, tzoff, + timestamp, &yearstart, &actual)); TEST_ASSERT_EQUAL(expected, actual); + + return; } void -test_NoReasonableConversion(void) { +test_NoReasonableConversion(void) +{ /* Timestamp is: 2010-01-02 11:00:00Z */ const u_int32 timestamp = 3471418800UL; - + const int yday=100, hour=12, minute=0, second=0, tzoff=0; u_long yearstart = 0; u_int32 actual; - TEST_ASSERT_FALSE(clocktime(yday, hour, minute, second, tzoff, timestamp, - &yearstart, &actual)); + TEST_ASSERT_FALSE(clocktime(yday, hour, minute, second, tzoff, + timestamp, &yearstart, &actual)); + + return; } int/*BOOL*/ -isLE(u_int32 diff,u_int32 actual){ - if(diff <= actual){ +isLE(u_int32 diff,u_int32 actual) +{ + + if (diff <= actual) { return TRUE; } else return FALSE; @@ -187,7 +208,8 @@ isLE(u_int32 diff,u_int32 actual){ void -test_AlwaysInLimit(void) { +test_AlwaysInLimit(void) +{ /* Timestamp is: 2010-01-02 11:00:00Z */ const u_int32 timestamp = 3471418800UL; const u_short prime_incs[] = { 127, 151, 163, 179 }; @@ -210,7 +232,8 @@ test_AlwaysInLimit(void) { for (hour = -204; hour < 204; hour += 2) { for (minute = -60; minute < 60; minute++) { clocktime(yday, hour, minute, 30, 0, - timestamp, &yearstart, &actual); + timestamp, &yearstart, + &actual); diff = actual - timestamp; if (diff >= 0x80000000UL) diff = ~diff + 1; @@ -219,4 +242,5 @@ test_AlwaysInLimit(void) { } } } + return; } diff --git a/contrib/ntp/tests/libntp/decodenetnum.c b/contrib/ntp/tests/libntp/decodenetnum.c index 0e9bc34..0d2b0b5 100644 --- a/contrib/ntp/tests/libntp/decodenetnum.c +++ b/contrib/ntp/tests/libntp/decodenetnum.c @@ -4,6 +4,7 @@ #include "unity.h" +void setUp(void); extern void test_IPv4AddressOnly(void); extern void test_IPv4AddressWithPort(void); //#ifdef ISC_PLATFORM_HAVEIPV6 @@ -15,6 +16,15 @@ extern void test_IllegalCharInPort(void); void +setUp(void) +{ + init_lib(); + + return; +} + + +void test_IPv4AddressOnly(void) { const char *str = "192.0.2.1"; sockaddr_u actual; diff --git a/contrib/ntp/tests/libntp/humandate.c b/contrib/ntp/tests/libntp/humandate.c index 3a28f59..de3c751 100644 --- a/contrib/ntp/tests/libntp/humandate.c +++ b/contrib/ntp/tests/libntp/humandate.c @@ -5,11 +5,21 @@ #include "unity.h" +void setUp(void); void test_RegularTime(void); void test_CurrentTime(void); void +setUp(void) +{ + init_lib(); + + return; +} + + +void test_RegularTime(void) { time_t sample = 1276601278; @@ -17,11 +27,13 @@ test_RegularTime(void) struct tm* tm; tm = localtime(&sample); - TEST_ASSERT_TRUE(time != NULL); + TEST_ASSERT_TRUE(tm != NULL); snprintf(expected, 15, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec); TEST_ASSERT_EQUAL_STRING(expected, humantime(sample)); + + return; } void @@ -34,9 +46,11 @@ test_CurrentTime(void) time(&sample); tm = localtime(&sample); - TEST_ASSERT_TRUE(time != NULL); + TEST_ASSERT_TRUE(tm != NULL); snprintf(expected, 15, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec); TEST_ASSERT_EQUAL_STRING(expected, humantime(sample)); + + return; } diff --git a/contrib/ntp/tests/libntp/lfpfunc.c b/contrib/ntp/tests/libntp/lfpfunc.c index 1a13f37..cedbb60 100644 --- a/contrib/ntp/tests/libntp/lfpfunc.c +++ b/contrib/ntp/tests/libntp/lfpfunc.c @@ -9,17 +9,18 @@ #include <math.h> -/* replaced TEST_ASSERT_EQUAL_MEMORY(&a, &b, sizeof(a)) with TEST_ASSERT_EQUAL_l_fp(a, b). - It's safer this way, because structs can be compared even if they aren't initiated - with memset (due to padding bytes). +/* + replaced: TEST_ASSERT_EQUAL_MEMORY(&a, &b, sizeof(a)) + with: TEST_ASSERT_EQUAL_l_fp(a, b). + It's safer this way, because structs can be compared even if they + aren't initiated with memset (due to padding bytes). */ -#define TEST_ASSERT_EQUAL_l_fp(a, b) { \ - TEST_ASSERT_EQUAL_MESSAGE(a.l_i, b.l_i, "Field l_i"); \ - TEST_ASSERT_EQUAL_UINT_MESSAGE(a.l_uf, b.l_uf, "Field l_uf"); \ +#define TEST_ASSERT_EQUAL_l_fp(a, b) { \ + TEST_ASSERT_EQUAL_MESSAGE(a.l_i, b.l_i, "Field l_i"); \ + TEST_ASSERT_EQUAL_UINT_MESSAGE(a.l_uf, b.l_uf, "Field l_uf"); \ } - typedef int bool; // typedef enum { FALSE, TRUE } boolean; -> can't use this because TRUE and FALSE are already defined @@ -28,23 +29,23 @@ typedef struct { } lfp_hl; -int l_fp_scmp(const l_fp first, const l_fp second); -int l_fp_ucmp(const l_fp first, l_fp second ); -l_fp l_fp_init(int32 i, u_int32 f); -l_fp l_fp_add(const l_fp first, const l_fp second); -l_fp l_fp_subtract(const l_fp first, const l_fp second); -l_fp l_fp_negate(const l_fp first); -l_fp l_fp_abs(const l_fp first); -int l_fp_signum(const l_fp first); -double l_fp_convert_to_double(const l_fp first); -l_fp l_fp_init_from_double( double rhs); -void l_fp_swap(l_fp * first, l_fp *second); -bool l_isgt(const l_fp first, const l_fp second); -bool l_isgtu(const l_fp first, const l_fp second); -bool l_ishis(const l_fp first, const l_fp second); -bool l_isgeq(const l_fp first, const l_fp second); -bool l_isequ(const l_fp first, const l_fp second); -double eps(double d); +int l_fp_scmp(const l_fp first, const l_fp second); +int l_fp_ucmp(const l_fp first, l_fp second); +l_fp l_fp_init(int32 i, u_int32 f); +l_fp l_fp_add(const l_fp first, const l_fp second); +l_fp l_fp_subtract(const l_fp first, const l_fp second); +l_fp l_fp_negate(const l_fp first); +l_fp l_fp_abs(const l_fp first); +int l_fp_signum(const l_fp first); +double l_fp_convert_to_double(const l_fp first); +l_fp l_fp_init_from_double( double rhs); +void l_fp_swap(l_fp * first, l_fp *second); +bool l_isgt(const l_fp first, const l_fp second); +bool l_isgtu(const l_fp first, const l_fp second); +bool l_ishis(const l_fp first, const l_fp second); +bool l_isgeq(const l_fp first, const l_fp second); +bool l_isequ(const l_fp first, const l_fp second); +double eps(double d); void test_AdditionLR(void); @@ -58,7 +59,6 @@ void test_SignedRelOps(void); void test_UnsignedRelOps(void); - static int cmp_work(u_int32 a[3], u_int32 b[3]); //---------------------------------------------------------------------- @@ -72,10 +72,10 @@ int l_fp_scmp(const l_fp first, const l_fp second) { u_int32 a[3], b[3]; - + const l_fp op1 = first; const l_fp op2 = second; - + a[0] = op1.l_uf; a[1] = op1.l_ui; a[2] = 0; b[0] = op2.l_uf; b[1] = op2.l_ui; b[2] = 0; @@ -86,12 +86,12 @@ l_fp_scmp(const l_fp first, const l_fp second) } int -l_fp_ucmp(const l_fp first, l_fp second ) +l_fp_ucmp(const l_fp first, l_fp second) { u_int32 a[3], b[3]; const l_fp op1 = first; const l_fp op2 = second; - + a[0] = op1.l_uf; a[1] = op1.l_ui; a[2] = 0; b[0] = op2.l_uf; b[1] = op2.l_ui; b[2] = 0; @@ -142,7 +142,7 @@ l_fp_subtract(const l_fp first, const l_fp second) { l_fp temp = first; L_SUB(&temp, &second); - + return temp; } @@ -151,7 +151,7 @@ l_fp_negate(const l_fp first) { l_fp temp = first; L_NEG(&temp); - + return temp; } @@ -189,11 +189,14 @@ l_fp_init_from_double( double rhs) } void -l_fp_swap(l_fp * first, l_fp *second){ +l_fp_swap(l_fp * first, l_fp *second) +{ l_fp temp = *second; *second = *first; *first = temp; + + return; } //---------------------------------------------------------------------- @@ -204,27 +207,37 @@ l_fp_swap(l_fp * first, l_fp *second){ bool -l_isgt (const l_fp first, const l_fp second) { +l_isgt (const l_fp first, const l_fp second) +{ + return L_ISGT(&first, &second); } bool -l_isgtu(const l_fp first, const l_fp second) { +l_isgtu(const l_fp first, const l_fp second) +{ + return L_ISGTU(&first, &second); } bool -l_ishis(const l_fp first, const l_fp second) { +l_ishis(const l_fp first, const l_fp second) +{ + return L_ISHIS(&first, &second); } bool -l_isgeq(const l_fp first, const l_fp second) { +l_isgeq(const l_fp first, const l_fp second) +{ + return L_ISGEQ(&first, &second); } bool -l_isequ(const l_fp first, const l_fp second) { +l_isequ(const l_fp first, const l_fp second) +{ + return L_ISEQU(&first, &second); } @@ -275,6 +288,7 @@ static const size_t addsub_tot = (sizeof(addsub_tab)/sizeof(addsub_tab[0][0])); double eps(double d) { + return fmax(ldexp(1.0, -31), ldexp(fabs(d), -53)); } @@ -282,61 +296,71 @@ eps(double d) // test addition //---------------------------------------------------------------------- void -test_AdditionLR(void) { - +test_AdditionLR(void) +{ size_t idx = 0; + for (idx = 0; idx < addsub_cnt; ++idx) { l_fp op1 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l); l_fp op2 = l_fp_init(addsub_tab[idx][1].h, addsub_tab[idx][1].l); - l_fp exp = l_fp_init(addsub_tab[idx][2].h, addsub_tab[idx][2].l); - l_fp res = l_fp_add(op1, op2); + l_fp e_res = l_fp_init(addsub_tab[idx][2].h, addsub_tab[idx][2].l); + l_fp res = l_fp_add(op1, op2); - TEST_ASSERT_EQUAL_l_fp(exp, res); - } + TEST_ASSERT_EQUAL_l_fp(e_res, res); + } + return; } void -test_AdditionRL(void) { +test_AdditionRL(void) +{ size_t idx = 0; + for (idx = 0; idx < addsub_cnt; ++idx) { l_fp op2 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l); l_fp op1 = l_fp_init(addsub_tab[idx][1].h, addsub_tab[idx][1].l); - l_fp exp = l_fp_init(addsub_tab[idx][2].h, addsub_tab[idx][2].l); + l_fp e_res = l_fp_init(addsub_tab[idx][2].h, addsub_tab[idx][2].l); l_fp res = l_fp_add(op1, op2); - TEST_ASSERT_EQUAL_l_fp(exp, res); - } + TEST_ASSERT_EQUAL_l_fp(e_res, res); + } + return; } - //---------------------------------------------------------------------- // test subtraction //---------------------------------------------------------------------- void -test_SubtractionLR(void) { +test_SubtractionLR(void) +{ size_t idx = 0; + for (idx = 0; idx < addsub_cnt; ++idx) { l_fp op2 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l); - l_fp exp = l_fp_init(addsub_tab[idx][1].h, addsub_tab[idx][1].l); + l_fp e_res = l_fp_init(addsub_tab[idx][1].h, addsub_tab[idx][1].l); l_fp op1 = l_fp_init(addsub_tab[idx][2].h, addsub_tab[idx][2].l); l_fp res = l_fp_subtract(op1, op2); - - TEST_ASSERT_EQUAL_l_fp(exp, res); - } + + TEST_ASSERT_EQUAL_l_fp(e_res, res); + } + return; } void -test_SubtractionRL(void) { +test_SubtractionRL(void) +{ size_t idx = 0; + for (idx = 0; idx < addsub_cnt; ++idx) { - l_fp exp = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l); + l_fp e_res = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l); l_fp op2 = l_fp_init(addsub_tab[idx][1].h, addsub_tab[idx][1].l); l_fp op1 = l_fp_init(addsub_tab[idx][2].h, addsub_tab[idx][2].l); l_fp res = l_fp_subtract(op1, op2); - TEST_ASSERT_EQUAL_l_fp(exp, res); - } + TEST_ASSERT_EQUAL_l_fp(e_res, res); + } + return; } //---------------------------------------------------------------------- @@ -344,18 +368,20 @@ test_SubtractionRL(void) { //---------------------------------------------------------------------- void -test_Negation(void) { - +test_Negation(void) +{ size_t idx = 0; + for (idx = 0; idx < addsub_cnt; ++idx) { l_fp op1 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l); l_fp op2 = l_fp_negate(op1); l_fp sum = l_fp_add(op1, op2); - + l_fp zero = l_fp_init(0, 0); TEST_ASSERT_EQUAL_l_fp(zero, sum); - } + } + return; } @@ -364,21 +390,23 @@ test_Negation(void) { // test absolute value //---------------------------------------------------------------------- void -test_Absolute(void) { +test_Absolute(void) +{ size_t idx = 0; + for (idx = 0; idx < addsub_cnt; ++idx) { l_fp op1 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l); l_fp op2 = l_fp_abs(op1); - TEST_ASSERT_TRUE(l_fp_signum(op2) >= 0); + TEST_ASSERT_TRUE(l_fp_signum(op2) >= 0); if (l_fp_signum(op1) >= 0) - op1 = l_fp_subtract(op1, op2); + op1 = l_fp_subtract(op1, op2); else op1 = l_fp_add(op1, op2); - + l_fp zero = l_fp_init(0, 0); - + TEST_ASSERT_EQUAL_l_fp(zero, op1); } @@ -390,6 +418,8 @@ test_Absolute(void) { TEST_ASSERT_EQUAL(-1, l_fp_signum(minVal)); TEST_ASSERT_EQUAL_l_fp(minVal, minAbs); + + return; } @@ -397,14 +427,17 @@ test_Absolute(void) { // fp -> double -> fp rountrip test //---------------------------------------------------------------------- void -test_FDF_RoundTrip(void) { +test_FDF_RoundTrip(void) +{ + size_t idx = 0; + // since a l_fp has 64 bits in it's mantissa and a double has // only 54 bits available (including the hidden '1') we have to // make a few concessions on the roundtrip precision. The 'eps()' // function makes an educated guess about the avilable precision // and checks the difference in the two 'l_fp' values against // that limit. - size_t idx = 0; + for (idx = 0; idx < addsub_cnt; ++idx) { l_fp op1 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l); double op2 = l_fp_convert_to_double(op1); @@ -412,8 +445,10 @@ test_FDF_RoundTrip(void) { l_fp temp = l_fp_subtract(op1, op3); double d = l_fp_convert_to_double(temp); - TEST_ASSERT_DOUBLE_WITHIN(eps(op2), 0.0, fabs(d)); - } + TEST_ASSERT_DOUBLE_WITHIN(eps(op2), 0.0, fabs(d)); + } + + return; } @@ -424,14 +459,16 @@ test_FDF_RoundTrip(void) { // macros in 'ntp_fp.h' produce mathing results. // ---------------------------------------------------------------------- void -test_SignedRelOps(void) { +test_SignedRelOps(void) +{ const lfp_hl * tv = (&addsub_tab[0][0]); size_t lc ; + for (lc = addsub_tot - 1; lc; --lc, ++tv) { l_fp op1 = l_fp_init(tv[0].h, tv[0].l); l_fp op2 = l_fp_init(tv[1].h, tv[1].l); - int cmp = l_fp_scmp(op1, op2); - + int cmp = l_fp_scmp(op1, op2); + switch (cmp) { case -1: //printf("op1:%d %d, op2:%d %d\n",op1.l_uf,op1.l_ui,op2.l_uf,op2.l_ui); @@ -458,15 +495,19 @@ test_SignedRelOps(void) { TEST_ASSERT_TRUE (l_isequ(op2, op1)); break; default: - TEST_FAIL_MESSAGE("unexpected UCMP result: " ); + TEST_FAIL_MESSAGE("unexpected UCMP result: "); } } + + return; } void -test_UnsignedRelOps(void) { - const lfp_hl * tv =(&addsub_tab[0][0]); +test_UnsignedRelOps(void) +{ + const lfp_hl * tv =(&addsub_tab[0][0]); size_t lc; + for (lc = addsub_tot - 1; lc; --lc, ++tv) { l_fp op1 = l_fp_init(tv[0].h, tv[0].l); l_fp op2 = l_fp_init(tv[1].h, tv[1].l); @@ -492,10 +533,13 @@ test_UnsignedRelOps(void) { TEST_ASSERT_TRUE (l_ishis(op2, op1)); break; default: - TEST_FAIL_MESSAGE("unexpected UCMP result: " ); + TEST_FAIL_MESSAGE("unexpected UCMP result: "); } } + + return; } + /* */ diff --git a/contrib/ntp/tests/libntp/lfptostr.c b/contrib/ntp/tests/libntp/lfptostr.c index 142e6c7..ed32853 100644 --- a/contrib/ntp/tests/libntp/lfptostr.c +++ b/contrib/ntp/tests/libntp/lfptostr.c @@ -20,6 +20,7 @@ static const int HALF_PROMILLE_UP = 2147484; /* slightly more than 0.0005 */ static const int HALF_PROMILLE_DOWN = 2147483; /* slightly less than 0.0005 */ +void setUp(void); void test_PositiveInteger(void); void test_NegativeInteger(void); void test_PositiveIntegerWithFraction(void); @@ -33,6 +34,14 @@ void test_MillisecondsRoundingDown(void); void test_UnsignedInteger(void); +void +setUp(void) +{ + init_lib(); + + return; +} + void test_PositiveInteger(void) { diff --git a/contrib/ntp/tests/libntp/modetoa.c b/contrib/ntp/tests/libntp/modetoa.c index 267b44e..03b384c 100644 --- a/contrib/ntp/tests/libntp/modetoa.c +++ b/contrib/ntp/tests/libntp/modetoa.c @@ -4,11 +4,21 @@ #include "unity.h" +void setUp(void); void test_KnownMode(void); void test_UnknownMode(void); void +setUp(void) +{ + init_lib(); + + return; +} + + +void test_KnownMode(void) { const int MODE = 3; // Should be "client" diff --git a/contrib/ntp/tests/libntp/msyslog.c b/contrib/ntp/tests/libntp/msyslog.c index dec8d85..987c814 100644 --- a/contrib/ntp/tests/libntp/msyslog.c +++ b/contrib/ntp/tests/libntp/msyslog.c @@ -10,6 +10,7 @@ void format_errmsg(char *, size_t, const char *, int); #endif +void setUp(void); void test_msnprintf(void); void test_msnprintfLiteralPercentm(void); void test_msnprintfBackslashLiteralPercentm(void); @@ -21,6 +22,15 @@ void test_msnprintfTruncate(void); void +setUp(void) +{ + init_lib(); + + return; +} + + +void test_msnprintf(void) { #define FMT_PREFIX "msyslog.cpp ENOENT: " char exp_buf[512]; diff --git a/contrib/ntp/tests/libntp/netof.c b/contrib/ntp/tests/libntp/netof.c index 2fde6cc..59dd709 100644 --- a/contrib/ntp/tests/libntp/netof.c +++ b/contrib/ntp/tests/libntp/netof.c @@ -8,14 +8,25 @@ #include "sockaddrtest.h" +void setUp(void); void test_ClassBAddress(void); void test_ClassCAddress(void); void test_ClassAAddress(void); void test_IPv6Address(void); +void +setUp(void) +{ + init_lib(); -void test_ClassBAddress(void) { + return; +} + + +void +test_ClassBAddress(void) +{ sockaddr_u input = CreateSockaddr4("172.16.2.1", NTP_PORT); sockaddr_u expected = CreateSockaddr4("172.16.0.0", NTP_PORT); @@ -23,9 +34,13 @@ void test_ClassBAddress(void) { TEST_ASSERT_TRUE(actual != NULL); TEST_ASSERT_TRUE(IsEqual(expected, *actual)); + + return; } -void test_ClassCAddress(void) { +void +test_ClassCAddress(void) +{ sockaddr_u input = CreateSockaddr4("192.0.2.255", NTP_PORT); sockaddr_u expected = CreateSockaddr4("192.0.2.0", NTP_PORT); @@ -33,9 +48,14 @@ void test_ClassCAddress(void) { TEST_ASSERT_TRUE(actual != NULL); TEST_ASSERT_TRUE(IsEqual(expected, *actual)); + + return; } -void test_ClassAAddress(void) { + +void +test_ClassAAddress(void) +{ /* Class A addresses are assumed to be classless, * thus the same address should be returned. */ @@ -46,24 +66,28 @@ void test_ClassAAddress(void) { TEST_ASSERT_TRUE(actual != NULL); TEST_ASSERT_TRUE(IsEqual(expected, *actual)); + + return; } -void test_IPv6Address(void) { +void +test_IPv6Address(void) +{ /* IPv6 addresses are assumed to have 64-bit host- and 64-bit network parts. */ - const struct in6_addr input_address = { + const struct in6_addr input_address = { { { 0x20, 0x01, 0x0d, 0xb8, - 0x85, 0xa3, 0x08, 0xd3, - 0x13, 0x19, 0x8a, 0x2e, - 0x03, 0x70, 0x73, 0x34 - }; // 2001:0db8:85a3:08d3:1319:8a2e:0370:7334 + 0x85, 0xa3, 0x08, 0xd3, + 0x13, 0x19, 0x8a, 0x2e, + 0x03, 0x70, 0x73, 0x34 + } } }; // 2001:0db8:85a3:08d3:1319:8a2e:0370:7334 - const struct in6_addr expected_address = { + const struct in6_addr expected_address = { { { 0x20, 0x01, 0x0d, 0xb8, - 0x85, 0xa3, 0x08, 0xd3, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 - }; // 2001:0db8:85a3:08d3:0000:0000:0000:0000 - + 0x85, 0xa3, 0x08, 0xd3, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 + } } }; // 2001:0db8:85a3:08d3:0000:0000:0000:0000 + sockaddr_u input; input.sa6.sin6_family = AF_INET6; input.sa6.sin6_addr = input_address; @@ -78,5 +102,6 @@ void test_IPv6Address(void) { TEST_ASSERT_TRUE(actual != NULL); TEST_ASSERT_TRUE(IsEqual(expected, *actual)); -} + return; +} diff --git a/contrib/ntp/tests/libntp/numtoa.c b/contrib/ntp/tests/libntp/numtoa.c index 5c7a663..42638b6 100644 --- a/contrib/ntp/tests/libntp/numtoa.c +++ b/contrib/ntp/tests/libntp/numtoa.c @@ -5,9 +5,20 @@ #include "unity.h" +void setUp(void); void test_Address(void); void test_Netmask(void); + +void +setUp(void) +{ + init_lib(); + + return; +} + + void test_Address(void) { const u_int32 input = htonl(3221225472UL + 512UL + 1UL); // 192.0.2.1 diff --git a/contrib/ntp/tests/libntp/numtohost.c b/contrib/ntp/tests/libntp/numtohost.c index cfce2d8..1c095eb 100644 --- a/contrib/ntp/tests/libntp/numtohost.c +++ b/contrib/ntp/tests/libntp/numtohost.c @@ -5,8 +5,19 @@ #include "unity.h" +void setUp(void); void test_LoopbackNetNonResolve(void); + +void +setUp(void) +{ + init_lib(); + + return; +} + + void test_LoopbackNetNonResolve(void) { /* A loopback address in 127.0.0.0/8 is chosen, and @@ -15,6 +26,6 @@ test_LoopbackNetNonResolve(void) { */ const u_int32 input = 127*256*256*256 + 1*256 + 1; // 127.0.1.1 - + TEST_ASSERT_EQUAL_STRING("127.0.1.1", numtohost(htonl(input))); } diff --git a/contrib/ntp/tests/libntp/octtoint.c b/contrib/ntp/tests/libntp/octtoint.c index 5c03d6d..83a1c99 100644 --- a/contrib/ntp/tests/libntp/octtoint.c +++ b/contrib/ntp/tests/libntp/octtoint.c @@ -14,61 +14,83 @@ void test_IllegalCharacter(void); void test_IllegalDigit(void); -void test_SingleDigit(void) { +void +test_SingleDigit(void) +{ const char* str = "5"; u_long actual; - TEST_ASSERT_TRUE(octtoint(str, &actual) ); + TEST_ASSERT_TRUE(octtoint(str, &actual)); TEST_ASSERT_EQUAL(5, actual); + + return; } -void test_MultipleDigits(void){ +void +test_MultipleDigits(void) +{ const char* str = "271"; u_long actual; - TEST_ASSERT_TRUE(octtoint(str, &actual) ); + TEST_ASSERT_TRUE(octtoint(str, &actual)); TEST_ASSERT_EQUAL(185, actual); + return; } -void test_Zero(void){ +void +test_Zero(void) +{ const char* str = "0"; u_long actual; - TEST_ASSERT_TRUE(octtoint(str, &actual) ); + TEST_ASSERT_TRUE(octtoint(str, &actual)); TEST_ASSERT_EQUAL(0, actual); + return; } -void test_MaximumUnsigned32bit(void){ +void +test_MaximumUnsigned32bit(void) +{ const char* str = "37777777777"; u_long actual; - TEST_ASSERT_TRUE(octtoint(str, &actual) ); + TEST_ASSERT_TRUE(octtoint(str, &actual)); TEST_ASSERT_EQUAL(4294967295UL, actual); + return; } -void test_Overflow(void){ +void +test_Overflow(void) +{ const char* str = "40000000000"; u_long actual; - TEST_ASSERT_FALSE(octtoint(str, &actual) ); + TEST_ASSERT_FALSE(octtoint(str, &actual)); + return; } -void test_IllegalCharacter(void){ +void +test_IllegalCharacter(void) +{ const char* str = "5ac2"; u_long actual; - TEST_ASSERT_FALSE(octtoint(str, &actual) ); + TEST_ASSERT_FALSE(octtoint(str, &actual)); + return; } -void test_IllegalDigit(void){ +void +test_IllegalDigit(void) +{ const char* str = "5283"; u_long actual; - TEST_ASSERT_FALSE(octtoint(str, &actual) ); + TEST_ASSERT_FALSE(octtoint(str, &actual)); + return; } diff --git a/contrib/ntp/tests/libntp/prettydate.c b/contrib/ntp/tests/libntp/prettydate.c index e1292bf..c940e2a 100644 --- a/contrib/ntp/tests/libntp/prettydate.c +++ b/contrib/ntp/tests/libntp/prettydate.c @@ -6,15 +6,26 @@ #include "unity.h" +void setUp(void); void test_ConstantDate(void); void +setUp(void) +{ + init_lib(); + + return; +} + + +void test_ConstantDate(void) { const u_int32 HALF = 2147483648UL; - l_fp time = {{3485080800UL}, HALF}; /* 2010-06-09 14:00:00.5 */ + l_fp e_time = {{3485080800UL}, HALF}; /* 2010-06-09 14:00:00.5 */ TEST_ASSERT_EQUAL_STRING("cfba1ce0.80000000 Wed, Jun 9 2010 14:00:00.500", - gmprettydate(&time)); + gmprettydate(&e_time)); + return; } diff --git a/contrib/ntp/tests/libntp/recvbuff.c b/contrib/ntp/tests/libntp/recvbuff.c index 6d6cf8e..6c089bb 100644 --- a/contrib/ntp/tests/libntp/recvbuff.c +++ b/contrib/ntp/tests/libntp/recvbuff.c @@ -13,6 +13,9 @@ void setUp(void) { init_recvbuff(RECV_INIT); + init_lib(); + + return; } void @@ -36,7 +39,7 @@ test_GetAndFree(void) { void test_GetAndFill(void) { - int initial = free_recvbuffs(); + // int initial = free_recvbuffs(); recvbuf_t* buf = get_free_recv_buffer(); add_full_recv_buffer(buf); diff --git a/contrib/ntp/tests/libntp/refidsmear.c b/contrib/ntp/tests/libntp/refidsmear.c index 04f396c..da1ebff 100644 --- a/contrib/ntp/tests/libntp/refidsmear.c +++ b/contrib/ntp/tests/libntp/refidsmear.c @@ -29,12 +29,21 @@ */ - +void setUp(void); void rtol(uint32_t r, char *es); void rtoltor(uint32_t er, char *es); void ltor(l_fp l, char *er); void test_refidsmear(void); + +void +setUp(void) +{ + init_lib(); + + return; +} + void rtol(uint32_t r, char *es) { @@ -48,7 +57,7 @@ rtol(uint32_t r, char *es) l = convertRefIDToLFP(htonl(r)); as = lfptoa(&l, 8); - + //printf("refid %#x, smear %s\n", r, as); TEST_ASSERT_NOT_NULL_MESSAGE(as, msg); @@ -58,8 +67,6 @@ rtol(uint32_t r, char *es) } - - void rtoltor(uint32_t er, char *es) { diff --git a/contrib/ntp/tests/libntp/refnumtoa.c b/contrib/ntp/tests/libntp/refnumtoa.c index 33ad3aa..9db5fb1 100644 --- a/contrib/ntp/tests/libntp/refnumtoa.c +++ b/contrib/ntp/tests/libntp/refnumtoa.c @@ -9,11 +9,21 @@ /* Might need to be updated if a new refclock gets this id. */ static const int UNUSED_REFCLOCK_ID = 250; +void setUp(void); void test_LocalClock(void); void test_UnknownId(void); void +setUp(void) +{ + init_lib(); + + return; +} + + +void test_LocalClock(void) { #ifdef REFCLOCK /* clockname() is useless otherwise */ /* We test with a refclock address of type LOCALCLOCK. @@ -26,7 +36,7 @@ test_LocalClock(void) { sockaddr_u address; address.sa4.sin_family = AF_INET; address.sa4.sin_addr.s_addr = htonl(addr); - + char stringStart[100]= ""; strcat(stringStart, clockname(REFCLK_LOCALCLOCK)); @@ -35,7 +45,7 @@ test_LocalClock(void) { char * expected = stringStart; TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address)); -#else +#else TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST"); #endif /* REFCLOCK */ } @@ -51,16 +61,16 @@ test_UnknownId(void) { sockaddr_u address; address.sa4.sin_family = AF_INET; address.sa4.sin_addr.s_addr = htonl(addr); - + char stringStart[100]= "REFCLK("; - char value[100] ; + char value[100] ; snprintf(value, sizeof(value), "%d", UNUSED_REFCLOCK_ID); strcat(stringStart,value); strcat(stringStart,",4)"); char * expected = stringStart; TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address)); -#else +#else TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST"); #endif /* REFCLOCK */ } diff --git a/contrib/ntp/tests/libntp/run-a_md5encrypt.c b/contrib/ntp/tests/libntp/run-a_md5encrypt.c index 122ed93..a4bfa36 100644 --- a/contrib/ntp/tests/libntp/run-a_md5encrypt.c +++ b/contrib/ntp/tests/libntp/run-a_md5encrypt.c @@ -52,11 +52,11 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("a_md5encrypt.c"); - RUN_TEST(test_Encrypt, 29); - RUN_TEST(test_DecryptValid, 30); - RUN_TEST(test_DecryptInvalid, 31); - RUN_TEST(test_IPv4AddressToRefId, 32); - RUN_TEST(test_IPv6AddressToRefId, 33); + RUN_TEST(test_Encrypt, 40); + RUN_TEST(test_DecryptValid, 41); + RUN_TEST(test_DecryptInvalid, 42); + RUN_TEST(test_IPv4AddressToRefId, 43); + RUN_TEST(test_IPv6AddressToRefId, 44); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-calendar.c b/contrib/ntp/tests/libntp/run-calendar.c index 50c5b20..555f3ba 100644 --- a/contrib/ntp/tests/libntp/run-calendar.c +++ b/contrib/ntp/tests/libntp/run-calendar.c @@ -63,21 +63,21 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("calendar.c"); - RUN_TEST(test_DaySplitMerge, 21); - RUN_TEST(test_SplitYearDays1, 22); - RUN_TEST(test_SplitYearDays2, 23); - RUN_TEST(test_RataDie1, 24); - RUN_TEST(test_LeapYears1, 25); - RUN_TEST(test_LeapYears2, 26); - RUN_TEST(test_RoundTripDate, 27); - RUN_TEST(test_RoundTripYearStart, 28); - RUN_TEST(test_RoundTripMonthStart, 29); - RUN_TEST(test_RoundTripWeekStart, 30); - RUN_TEST(test_RoundTripDayStart, 31); - RUN_TEST(test_IsoCalYearsToWeeks, 32); - RUN_TEST(test_IsoCalWeeksToYearStart, 33); - RUN_TEST(test_IsoCalWeeksToYearEnd, 34); - RUN_TEST(test_DaySecToDate, 35); + RUN_TEST(test_DaySplitMerge, 22); + RUN_TEST(test_SplitYearDays1, 23); + RUN_TEST(test_SplitYearDays2, 24); + RUN_TEST(test_RataDie1, 25); + RUN_TEST(test_LeapYears1, 26); + RUN_TEST(test_LeapYears2, 27); + RUN_TEST(test_RoundTripDate, 28); + RUN_TEST(test_RoundTripYearStart, 29); + RUN_TEST(test_RoundTripMonthStart, 30); + RUN_TEST(test_RoundTripWeekStart, 31); + RUN_TEST(test_RoundTripDayStart, 32); + RUN_TEST(test_IsoCalYearsToWeeks, 33); + RUN_TEST(test_IsoCalWeeksToYearStart, 34); + RUN_TEST(test_IsoCalWeeksToYearEnd, 35); + RUN_TEST(test_DaySecToDate, 36); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-decodenetnum.c b/contrib/ntp/tests/libntp/run-decodenetnum.c index 014151e..57b955c 100644 --- a/contrib/ntp/tests/libntp/run-decodenetnum.c +++ b/contrib/ntp/tests/libntp/run-decodenetnum.c @@ -53,12 +53,12 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("decodenetnum.c"); - RUN_TEST(test_IPv4AddressOnly, 7); - RUN_TEST(test_IPv4AddressWithPort, 8); - RUN_TEST(test_IPv6AddressOnly, 10); - RUN_TEST(test_IPv6AddressWithPort, 11); - RUN_TEST(test_IllegalAddress, 13); - RUN_TEST(test_IllegalCharInPort, 14); + RUN_TEST(test_IPv4AddressOnly, 8); + RUN_TEST(test_IPv4AddressWithPort, 9); + RUN_TEST(test_IPv6AddressOnly, 11); + RUN_TEST(test_IPv6AddressWithPort, 12); + RUN_TEST(test_IllegalAddress, 14); + RUN_TEST(test_IllegalCharInPort, 15); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-humandate.c b/contrib/ntp/tests/libntp/run-humandate.c index 1f2e717..690895f 100644 --- a/contrib/ntp/tests/libntp/run-humandate.c +++ b/contrib/ntp/tests/libntp/run-humandate.c @@ -49,8 +49,8 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("humandate.c"); - RUN_TEST(test_RegularTime, 8); - RUN_TEST(test_CurrentTime, 9); + RUN_TEST(test_RegularTime, 9); + RUN_TEST(test_CurrentTime, 10); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-lfpfunc.c b/contrib/ntp/tests/libntp/run-lfpfunc.c index ac6700f..83f9668 100644 --- a/contrib/ntp/tests/libntp/run-lfpfunc.c +++ b/contrib/ntp/tests/libntp/run-lfpfunc.c @@ -58,15 +58,15 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("lfpfunc.c"); - RUN_TEST(test_AdditionLR, 50); - RUN_TEST(test_AdditionRL, 51); - RUN_TEST(test_SubtractionLR, 52); - RUN_TEST(test_SubtractionRL, 53); - RUN_TEST(test_Negation, 54); - RUN_TEST(test_Absolute, 55); - RUN_TEST(test_FDF_RoundTrip, 56); - RUN_TEST(test_SignedRelOps, 57); - RUN_TEST(test_UnsignedRelOps, 58); + RUN_TEST(test_AdditionLR, 51); + RUN_TEST(test_AdditionRL, 52); + RUN_TEST(test_SubtractionLR, 53); + RUN_TEST(test_SubtractionRL, 54); + RUN_TEST(test_Negation, 55); + RUN_TEST(test_Absolute, 56); + RUN_TEST(test_FDF_RoundTrip, 57); + RUN_TEST(test_SignedRelOps, 58); + RUN_TEST(test_UnsignedRelOps, 59); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-lfptostr.c b/contrib/ntp/tests/libntp/run-lfptostr.c index bae0f85..fbdeb7a 100644 --- a/contrib/ntp/tests/libntp/run-lfptostr.c +++ b/contrib/ntp/tests/libntp/run-lfptostr.c @@ -58,17 +58,17 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("lfptostr.c"); - RUN_TEST(test_PositiveInteger, 23); - RUN_TEST(test_NegativeInteger, 24); - RUN_TEST(test_PositiveIntegerWithFraction, 25); - RUN_TEST(test_NegativeIntegerWithFraction, 26); - RUN_TEST(test_RoundingDownToInteger, 27); - RUN_TEST(test_RoundingMiddleToInteger, 28); - RUN_TEST(test_RoundingUpToInteger, 29); - RUN_TEST(test_SingleDecimal, 30); - RUN_TEST(test_MillisecondsRoundingUp, 31); - RUN_TEST(test_MillisecondsRoundingDown, 32); - RUN_TEST(test_UnsignedInteger, 33); + RUN_TEST(test_PositiveInteger, 24); + RUN_TEST(test_NegativeInteger, 25); + RUN_TEST(test_PositiveIntegerWithFraction, 26); + RUN_TEST(test_NegativeIntegerWithFraction, 27); + RUN_TEST(test_RoundingDownToInteger, 28); + RUN_TEST(test_RoundingMiddleToInteger, 29); + RUN_TEST(test_RoundingUpToInteger, 30); + RUN_TEST(test_SingleDecimal, 31); + RUN_TEST(test_MillisecondsRoundingUp, 32); + RUN_TEST(test_MillisecondsRoundingDown, 33); + RUN_TEST(test_UnsignedInteger, 34); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-modetoa.c b/contrib/ntp/tests/libntp/run-modetoa.c index 20e2d95..0c1558e 100644 --- a/contrib/ntp/tests/libntp/run-modetoa.c +++ b/contrib/ntp/tests/libntp/run-modetoa.c @@ -48,8 +48,8 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("modetoa.c"); - RUN_TEST(test_KnownMode, 7); - RUN_TEST(test_UnknownMode, 8); + RUN_TEST(test_KnownMode, 8); + RUN_TEST(test_UnknownMode, 9); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-msyslog.c b/contrib/ntp/tests/libntp/run-msyslog.c index 544fbc1..ff264f8 100644 --- a/contrib/ntp/tests/libntp/run-msyslog.c +++ b/contrib/ntp/tests/libntp/run-msyslog.c @@ -54,14 +54,14 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("msyslog.c"); - RUN_TEST(test_msnprintf, 13); - RUN_TEST(test_msnprintfLiteralPercentm, 14); - RUN_TEST(test_msnprintfBackslashLiteralPercentm, 15); - RUN_TEST(test_msnprintfBackslashPercent, 16); - RUN_TEST(test_msnprintfHangingPercent, 17); - RUN_TEST(test_format_errmsgHangingPercent, 18); - RUN_TEST(test_msnprintfNullTarget, 19); - RUN_TEST(test_msnprintfTruncate, 20); + RUN_TEST(test_msnprintf, 14); + RUN_TEST(test_msnprintfLiteralPercentm, 15); + RUN_TEST(test_msnprintfBackslashLiteralPercentm, 16); + RUN_TEST(test_msnprintfBackslashPercent, 17); + RUN_TEST(test_msnprintfHangingPercent, 18); + RUN_TEST(test_format_errmsgHangingPercent, 19); + RUN_TEST(test_msnprintfNullTarget, 20); + RUN_TEST(test_msnprintfTruncate, 21); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-netof.c b/contrib/ntp/tests/libntp/run-netof.c index 7a714f5..9301b84 100644 --- a/contrib/ntp/tests/libntp/run-netof.c +++ b/contrib/ntp/tests/libntp/run-netof.c @@ -52,10 +52,10 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("netof.c"); - RUN_TEST(test_ClassBAddress, 11); - RUN_TEST(test_ClassCAddress, 12); - RUN_TEST(test_ClassAAddress, 13); - RUN_TEST(test_IPv6Address, 14); + RUN_TEST(test_ClassBAddress, 12); + RUN_TEST(test_ClassCAddress, 13); + RUN_TEST(test_ClassAAddress, 14); + RUN_TEST(test_IPv6Address, 15); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-numtoa.c b/contrib/ntp/tests/libntp/run-numtoa.c index 640e61c..f3368a7 100644 --- a/contrib/ntp/tests/libntp/run-numtoa.c +++ b/contrib/ntp/tests/libntp/run-numtoa.c @@ -49,8 +49,8 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("numtoa.c"); - RUN_TEST(test_Address, 8); - RUN_TEST(test_Netmask, 9); + RUN_TEST(test_Address, 9); + RUN_TEST(test_Netmask, 10); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-numtohost.c b/contrib/ntp/tests/libntp/run-numtohost.c index 5ebe15b..49b5264 100644 --- a/contrib/ntp/tests/libntp/run-numtohost.c +++ b/contrib/ntp/tests/libntp/run-numtohost.c @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("numtohost.c"); - RUN_TEST(test_LoopbackNetNonResolve, 8); + RUN_TEST(test_LoopbackNetNonResolve, 9); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-prettydate.c b/contrib/ntp/tests/libntp/run-prettydate.c index e6c5ff3..e034cc2 100644 --- a/contrib/ntp/tests/libntp/run-prettydate.c +++ b/contrib/ntp/tests/libntp/run-prettydate.c @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("prettydate.c"); - RUN_TEST(test_ConstantDate, 9); + RUN_TEST(test_ConstantDate, 10); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-refnumtoa.c b/contrib/ntp/tests/libntp/run-refnumtoa.c index bb9fb60..d829580 100644 --- a/contrib/ntp/tests/libntp/run-refnumtoa.c +++ b/contrib/ntp/tests/libntp/run-refnumtoa.c @@ -49,8 +49,8 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("refnumtoa.c"); - RUN_TEST(test_LocalClock, 12); - RUN_TEST(test_UnknownId, 13); + RUN_TEST(test_LocalClock, 13); + RUN_TEST(test_UnknownId, 14); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-sfptostr.c b/contrib/ntp/tests/libntp/run-sfptostr.c index 1ebe43c..1dba912 100644 --- a/contrib/ntp/tests/libntp/run-sfptostr.c +++ b/contrib/ntp/tests/libntp/run-sfptostr.c @@ -24,6 +24,7 @@ #include <stdio.h> #include "config.h" #include "ntp_fp.h" +#include "ntp_stdlib.h" //=======External Functions This Runner Calls===== extern void setUp(void); @@ -54,14 +55,14 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("sfptostr.c"); - RUN_TEST(test_PositiveInteger, 11); - RUN_TEST(test_NegativeInteger, 12); - RUN_TEST(test_PositiveIntegerPositiveFraction, 13); - RUN_TEST(test_NegativeIntegerNegativeFraction, 14); - RUN_TEST(test_PositiveIntegerNegativeFraction, 15); - RUN_TEST(test_NegativeIntegerPositiveFraction, 16); - RUN_TEST(test_SingleDecimalInteger, 17); - RUN_TEST(test_SingleDecimalRounding, 18); + RUN_TEST(test_PositiveInteger, 13); + RUN_TEST(test_NegativeInteger, 14); + RUN_TEST(test_PositiveIntegerPositiveFraction, 15); + RUN_TEST(test_NegativeIntegerNegativeFraction, 16); + RUN_TEST(test_PositiveIntegerNegativeFraction, 17); + RUN_TEST(test_NegativeIntegerPositiveFraction, 18); + RUN_TEST(test_SingleDecimalInteger, 19); + RUN_TEST(test_SingleDecimalRounding, 20); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-socktoa.c b/contrib/ntp/tests/libntp/run-socktoa.c index a5066e3..df6ec9c 100644 --- a/contrib/ntp/tests/libntp/run-socktoa.c +++ b/contrib/ntp/tests/libntp/run-socktoa.c @@ -54,12 +54,12 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("socktoa.c"); - RUN_TEST(test_IPv4AddressWithPort, 10); - RUN_TEST(test_IPv6AddressWithPort, 12); - RUN_TEST(test_IgnoreIPv6Fields, 13); - RUN_TEST(test_ScopedIPv6AddressWithPort, 15); - RUN_TEST(test_HashEqual, 16); - RUN_TEST(test_HashNotEqual, 17); + RUN_TEST(test_IPv4AddressWithPort, 11); + RUN_TEST(test_IPv6AddressWithPort, 13); + RUN_TEST(test_IgnoreIPv6Fields, 14); + RUN_TEST(test_ScopedIPv6AddressWithPort, 16); + RUN_TEST(test_HashEqual, 17); + RUN_TEST(test_HashNotEqual, 18); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-statestr.c b/contrib/ntp/tests/libntp/run-statestr.c index 9cfe0bc..f0f9386 100644 --- a/contrib/ntp/tests/libntp/run-statestr.c +++ b/contrib/ntp/tests/libntp/run-statestr.c @@ -52,10 +52,10 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("statestr.c"); - RUN_TEST(test_PeerRestart, 9); - RUN_TEST(test_SysUnspecified, 10); - RUN_TEST(test_ClockCodeExists, 11); - RUN_TEST(test_ClockCodeUnknown, 12); + RUN_TEST(test_PeerRestart, 10); + RUN_TEST(test_SysUnspecified, 11); + RUN_TEST(test_ClockCodeExists, 12); + RUN_TEST(test_ClockCodeUnknown, 13); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-strtolfp.c b/contrib/ntp/tests/libntp/run-strtolfp.c index 7472319..404f57f 100644 --- a/contrib/ntp/tests/libntp/run-strtolfp.c +++ b/contrib/ntp/tests/libntp/run-strtolfp.c @@ -55,13 +55,13 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("strtolfp.c"); - RUN_TEST(test_PositiveInteger, 11); - RUN_TEST(test_NegativeInteger, 12); - RUN_TEST(test_PositiveFraction, 13); - RUN_TEST(test_NegativeFraction, 14); - RUN_TEST(test_PositiveMsFraction, 15); - RUN_TEST(test_NegativeMsFraction, 16); - RUN_TEST(test_InvalidChars, 17); + RUN_TEST(test_PositiveInteger, 12); + RUN_TEST(test_NegativeInteger, 13); + RUN_TEST(test_PositiveFraction, 14); + RUN_TEST(test_NegativeFraction, 15); + RUN_TEST(test_PositiveMsFraction, 16); + RUN_TEST(test_NegativeMsFraction, 17); + RUN_TEST(test_InvalidChars, 18); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-timespecops.c b/contrib/ntp/tests/libntp/run-timespecops.c index 6c26521..badc84a 100644 --- a/contrib/ntp/tests/libntp/run-timespecops.c +++ b/contrib/ntp/tests/libntp/run-timespecops.c @@ -78,34 +78,34 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("timespecops.c"); - RUN_TEST(test_Helpers1, 36); - RUN_TEST(test_Normalise, 37); - RUN_TEST(test_SignNoFrac, 38); - RUN_TEST(test_SignWithFrac, 39); - RUN_TEST(test_CmpFracEQ, 40); - RUN_TEST(test_CmpFracGT, 41); - RUN_TEST(test_CmpFracLT, 42); - RUN_TEST(test_AddFullNorm, 43); - RUN_TEST(test_AddFullOflow1, 44); - RUN_TEST(test_AddNsecNorm, 45); - RUN_TEST(test_AddNsecOflow1, 46); - RUN_TEST(test_SubFullNorm, 47); - RUN_TEST(test_SubFullOflow, 48); - RUN_TEST(test_SubNsecNorm, 49); - RUN_TEST(test_SubNsecOflow, 50); - RUN_TEST(test_Neg, 51); - RUN_TEST(test_AbsNoFrac, 52); - RUN_TEST(test_AbsWithFrac, 53); - RUN_TEST(test_Helpers2, 54); - RUN_TEST(test_ToLFPbittest, 55); - RUN_TEST(test_ToLFPrelPos, 56); - RUN_TEST(test_ToLFPrelNeg, 57); - RUN_TEST(test_ToLFPabs, 58); - RUN_TEST(test_FromLFPbittest, 59); - RUN_TEST(test_FromLFPrelPos, 60); - RUN_TEST(test_FromLFPrelNeg, 61); - RUN_TEST(test_LFProundtrip, 62); - RUN_TEST(test_ToString, 63); + RUN_TEST(test_Helpers1, 37); + RUN_TEST(test_Normalise, 38); + RUN_TEST(test_SignNoFrac, 39); + RUN_TEST(test_SignWithFrac, 40); + RUN_TEST(test_CmpFracEQ, 41); + RUN_TEST(test_CmpFracGT, 42); + RUN_TEST(test_CmpFracLT, 43); + RUN_TEST(test_AddFullNorm, 44); + RUN_TEST(test_AddFullOflow1, 45); + RUN_TEST(test_AddNsecNorm, 46); + RUN_TEST(test_AddNsecOflow1, 47); + RUN_TEST(test_SubFullNorm, 48); + RUN_TEST(test_SubFullOflow, 49); + RUN_TEST(test_SubNsecNorm, 50); + RUN_TEST(test_SubNsecOflow, 51); + RUN_TEST(test_Neg, 52); + RUN_TEST(test_AbsNoFrac, 53); + RUN_TEST(test_AbsWithFrac, 54); + RUN_TEST(test_Helpers2, 55); + RUN_TEST(test_ToLFPbittest, 56); + RUN_TEST(test_ToLFPrelPos, 57); + RUN_TEST(test_ToLFPrelNeg, 58); + RUN_TEST(test_ToLFPabs, 59); + RUN_TEST(test_FromLFPbittest, 60); + RUN_TEST(test_FromLFPrelPos, 61); + RUN_TEST(test_FromLFPrelNeg, 62); + RUN_TEST(test_LFProundtrip, 63); + RUN_TEST(test_ToString, 64); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-timevalops.c b/contrib/ntp/tests/libntp/run-timevalops.c index 4a9351c..df39ab9 100644 --- a/contrib/ntp/tests/libntp/run-timevalops.c +++ b/contrib/ntp/tests/libntp/run-timevalops.c @@ -77,34 +77,34 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("timevalops.c"); - RUN_TEST(test_Helpers1, 38); - RUN_TEST(test_Normalise, 39); - RUN_TEST(test_SignNoFrac, 40); - RUN_TEST(test_SignWithFrac, 41); - RUN_TEST(test_CmpFracEQ, 42); - RUN_TEST(test_CmpFracGT, 43); - RUN_TEST(test_CmpFracLT, 44); - RUN_TEST(test_AddFullNorm, 45); - RUN_TEST(test_AddFullOflow1, 46); - RUN_TEST(test_AddUsecNorm, 47); - RUN_TEST(test_AddUsecOflow1, 48); - RUN_TEST(test_SubFullNorm, 49); - RUN_TEST(test_SubFullOflow, 50); - RUN_TEST(test_SubUsecNorm, 51); - RUN_TEST(test_SubUsecOflow, 52); - RUN_TEST(test_Neg, 53); - RUN_TEST(test_AbsNoFrac, 54); - RUN_TEST(test_AbsWithFrac, 55); - RUN_TEST(test_Helpers2, 56); - RUN_TEST(test_ToLFPbittest, 57); - RUN_TEST(test_ToLFPrelPos, 58); - RUN_TEST(test_ToLFPrelNeg, 59); - RUN_TEST(test_ToLFPabs, 60); - RUN_TEST(test_FromLFPbittest, 61); - RUN_TEST(test_FromLFPrelPos, 62); - RUN_TEST(test_FromLFPrelNeg, 63); - RUN_TEST(test_LFProundtrip, 64); - RUN_TEST(test_ToString, 65); + RUN_TEST(test_Helpers1, 39); + RUN_TEST(test_Normalise, 40); + RUN_TEST(test_SignNoFrac, 41); + RUN_TEST(test_SignWithFrac, 42); + RUN_TEST(test_CmpFracEQ, 43); + RUN_TEST(test_CmpFracGT, 44); + RUN_TEST(test_CmpFracLT, 45); + RUN_TEST(test_AddFullNorm, 46); + RUN_TEST(test_AddFullOflow1, 47); + RUN_TEST(test_AddUsecNorm, 48); + RUN_TEST(test_AddUsecOflow1, 49); + RUN_TEST(test_SubFullNorm, 50); + RUN_TEST(test_SubFullOflow, 51); + RUN_TEST(test_SubUsecNorm, 52); + RUN_TEST(test_SubUsecOflow, 53); + RUN_TEST(test_Neg, 54); + RUN_TEST(test_AbsNoFrac, 55); + RUN_TEST(test_AbsWithFrac, 56); + RUN_TEST(test_Helpers2, 57); + RUN_TEST(test_ToLFPbittest, 58); + RUN_TEST(test_ToLFPrelPos, 59); + RUN_TEST(test_ToLFPrelNeg, 60); + RUN_TEST(test_ToLFPabs, 61); + RUN_TEST(test_FromLFPbittest, 62); + RUN_TEST(test_FromLFPrelPos, 63); + RUN_TEST(test_FromLFPrelNeg, 64); + RUN_TEST(test_LFProundtrip, 65); + RUN_TEST(test_ToString, 66); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/run-uglydate.c b/contrib/ntp/tests/libntp/run-uglydate.c index 6ec50f6..5667b70 100644 --- a/contrib/ntp/tests/libntp/run-uglydate.c +++ b/contrib/ntp/tests/libntp/run-uglydate.c @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("uglydate.c"); - RUN_TEST(test_ConstantDateTime, 8); + RUN_TEST(test_ConstantDateTime, 9); return (UnityEnd()); } diff --git a/contrib/ntp/tests/libntp/sfptostr.c b/contrib/ntp/tests/libntp/sfptostr.c index b115ae1..c7616c7 100644 --- a/contrib/ntp/tests/libntp/sfptostr.c +++ b/contrib/ntp/tests/libntp/sfptostr.c @@ -4,10 +4,12 @@ */ #include "config.h" #include "ntp_fp.h" +#include "ntp_stdlib.h" #include "unity.h" #define SFP_MAX_PRECISION 6 +void setUp(void); void test_PositiveInteger(void); void test_NegativeInteger(void); void test_PositiveIntegerPositiveFraction(void); @@ -18,6 +20,15 @@ void test_SingleDecimalInteger(void); void test_SingleDecimalRounding(void); +void +setUp(void) +{ + init_lib(); + + return; +} + + void test_PositiveInteger(void) { s_fp test = 300 << 16; // exact 300.000000 diff --git a/contrib/ntp/tests/libntp/socktoa.c b/contrib/ntp/tests/libntp/socktoa.c index 6661fa5..8423106 100644 --- a/contrib/ntp/tests/libntp/socktoa.c +++ b/contrib/ntp/tests/libntp/socktoa.c @@ -7,6 +7,7 @@ #include "sockaddrtest.h" +void setUp(void); void test_IPv4AddressWithPort(void); //#ifdef ISC_PLATFORM_HAVEIPV6 void test_IPv6AddressWithPort(void); @@ -16,6 +17,16 @@ void test_ScopedIPv6AddressWithPort(void); void test_HashEqual(void); void test_HashNotEqual(void); + +void +setUp(void) +{ + init_lib(); + + return; +} + + void test_IPv4AddressWithPort(void) { sockaddr_u input = CreateSockaddr4("192.0.2.10", 123); @@ -62,12 +73,12 @@ test_IPv6AddressWithPort(void) { void test_ScopedIPv6AddressWithPort(void) { #ifdef ISC_PLATFORM_HAVESCOPEID - const struct in6_addr address = { + const struct in6_addr address = { { { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x12, 0x3f, 0xff, 0xfe, 0x29, 0xff, 0xfa - }; + } } }; const char* expected = "fe80::212:3fff:fe29:fffa%5"; diff --git a/contrib/ntp/tests/libntp/statestr.c b/contrib/ntp/tests/libntp/statestr.c index 810ee6b..e7a1bd7 100644 --- a/contrib/ntp/tests/libntp/statestr.c +++ b/contrib/ntp/tests/libntp/statestr.c @@ -6,11 +6,22 @@ #include "unity.h" +void setUp(void); void test_PeerRestart(void); void test_SysUnspecified(void); void test_ClockCodeExists(void); void test_ClockCodeUnknown(void); + +void +setUp(void) +{ + init_lib(); + + return; +} + + // eventstr() void test_PeerRestart(void) { diff --git a/contrib/ntp/tests/libntp/strtolfp.c b/contrib/ntp/tests/libntp/strtolfp.c index f40ab50..6855d9b 100644 --- a/contrib/ntp/tests/libntp/strtolfp.c +++ b/contrib/ntp/tests/libntp/strtolfp.c @@ -8,6 +8,7 @@ /* This file tests both atolfp and mstolfp */ +void setUp(void); void test_PositiveInteger(void); void test_NegativeInteger(void); void test_PositiveFraction(void); @@ -17,6 +18,15 @@ void test_NegativeMsFraction(void); void test_InvalidChars(void); +void +setUp(void) +{ + init_lib(); + + return; +} + + void test_PositiveInteger(void) { const char *str = "500"; const char *str_ms = "500000"; diff --git a/contrib/ntp/tests/libntp/timespecops.c b/contrib/ntp/tests/libntp/timespecops.c index 86df7a1..68a472a 100644 --- a/contrib/ntp/tests/libntp/timespecops.c +++ b/contrib/ntp/tests/libntp/timespecops.c @@ -10,14 +10,14 @@ #include <string.h> -#define TEST_ASSERT_EQUAL_timespec(a, b) { \ - TEST_ASSERT_EQUAL_MESSAGE(a.tv_sec, b.tv_sec, "Field tv_sec"); \ +#define TEST_ASSERT_EQUAL_timespec(a, b) { \ + TEST_ASSERT_EQUAL_MESSAGE(a.tv_sec, b.tv_sec, "Field tv_sec"); \ TEST_ASSERT_EQUAL_MESSAGE(a.tv_nsec, b.tv_nsec, "Field tv_nsec"); \ } -#define TEST_ASSERT_EQUAL_l_fp(a, b) { \ - TEST_ASSERT_EQUAL_MESSAGE(a.l_i, b.l_i, "Field l_i"); \ +#define TEST_ASSERT_EQUAL_l_fp(a, b) { \ + TEST_ASSERT_EQUAL_MESSAGE(a.l_i, b.l_i, "Field l_i"); \ TEST_ASSERT_EQUAL_UINT_MESSAGE(a.l_uf, b.l_uf, "Field l_uf"); \ } @@ -33,6 +33,7 @@ struct lfpfracdata { }; +void setUp(void); void test_Helpers1(void); void test_Normalise(void); void test_SignNoFrac(void); @@ -64,35 +65,52 @@ void test_ToString(void); typedef int bool; -const bool timespec_isValid(struct timespec V); +const bool timespec_isValid(struct timespec V); struct timespec timespec_init(time_t hi, long lo); -l_fp l_fp_init(int32 i, u_int32 f); -bool AssertFpClose(const l_fp m, const l_fp n, const l_fp limit); -bool AssertTimespecClose(const struct timespec m, const struct timespec n, const struct timespec limit); +l_fp l_fp_init(int32 i, u_int32 f); +bool AssertFpClose(const l_fp m, const l_fp n, const l_fp limit); +bool AssertTimespecClose(const struct timespec m, + const struct timespec n, + const struct timespec limit); -//******************************************MY CUSTOM FUNCTIONS******************************* +//***************************MY CUSTOM FUNCTIONS*************************** +void +setUp(void) +{ + init_lib(); + + return; +} + const bool -timespec_isValid(struct timespec V) { +timespec_isValid(struct timespec V) +{ + return V.tv_nsec >= 0 && V.tv_nsec < 1000000000; } struct timespec -timespec_init(time_t hi, long lo) { - struct timespec V; +timespec_init(time_t hi, long lo) +{ + struct timespec V; + V.tv_sec = hi; V.tv_nsec = lo; + return V; } l_fp -l_fp_init(int32 i, u_int32 f) { +l_fp_init(int32 i, u_int32 f) +{ l_fp temp; + temp.l_i = i; temp.l_uf = f; @@ -101,7 +119,8 @@ l_fp_init(int32 i, u_int32 f) { bool -AssertFpClose(const l_fp m, const l_fp n, const l_fp limit) { +AssertFpClose(const l_fp m, const l_fp n, const l_fp limit) +{ l_fp diff; if (L_ISGEQ(&m, &n)) { @@ -111,7 +130,7 @@ AssertFpClose(const l_fp m, const l_fp n, const l_fp limit) { diff = n; L_SUB(&diff, &m); } - if (L_ISGEQ(&limit, &diff)){ + if (L_ISGEQ(&limit, &diff)) { return TRUE; } else { @@ -122,7 +141,9 @@ AssertFpClose(const l_fp m, const l_fp n, const l_fp limit) { bool -AssertTimespecClose(const struct timespec m, const struct timespec n, const struct timespec limit) { +AssertTimespecClose(const struct timespec m, const struct timespec n, + const struct timespec limit) +{ struct timespec diff; diff = abs_tspec(sub_tspec(m, n)); @@ -156,11 +177,13 @@ static const struct lfpfracdata fdata[] = { u_int32 -my_tick_to_tsf(u_int32 ticks) { +my_tick_to_tsf(u_int32 ticks) +{ // convert nanoseconds to l_fp fractional units, using double // precision float calculations or, if available, 64bit integer // arithmetic. This should give the precise fraction, rounded to // the nearest representation. + #ifdef HAVE_U_INT64 return (u_int32)((( ((u_int64)(ticks)) << 32) + 500000000) / 1000000000); #else @@ -172,7 +195,9 @@ my_tick_to_tsf(u_int32 ticks) { u_int32 -my_tsf_to_tick(u_int32 tsf) { +my_tsf_to_tick(u_int32 tsf) +{ + // Inverse operation: converts fraction to microseconds. #ifdef HAVE_U_INT64 return (u_int32)(( ((u_int64)(tsf)) * 1000000000 + 0x80000000) >> 32); @@ -189,7 +214,8 @@ my_tsf_to_tick(u_int32 tsf) { // --------------------------------------------------------------------- void -test_Helpers1(void) { +test_Helpers1(void) +{ struct timespec x; for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++) { @@ -202,6 +228,8 @@ test_Helpers1(void) { x.tv_nsec = 1000000000; TEST_ASSERT_FALSE(timespec_isValid(x)); } + + return; } @@ -210,14 +238,18 @@ test_Helpers1(void) { //---------------------------------------------------------------------- void -test_Normalise(void) { +test_Normalise(void) +{ long ns; + for ( ns = -2000000000; ns <= 2000000000; ns += 10000000) { struct timespec x = timespec_init(0, ns); x = normalize_tspec(x); TEST_ASSERT_TRUE(timespec_isValid(x)); } + + return; } //---------------------------------------------------------------------- @@ -225,9 +257,11 @@ test_Normalise(void) { //---------------------------------------------------------------------- void -test_SignNoFrac(void) { +test_SignNoFrac(void) +{ // sign test, no fraction int i; + for (i = -4; i <= 4; ++i) { struct timespec a = timespec_init(i, 0); int E = (i > 0) - (i < 0); @@ -235,26 +269,34 @@ test_SignNoFrac(void) { TEST_ASSERT_EQUAL(E, r); } + + return; } void -test_SignWithFrac(void) { +test_SignWithFrac(void) +{ // sign test, with fraction int i; + for (i = -4; i <= 4; ++i) { struct timespec a = timespec_init(i, 10); int E = (i >= 0) - (i < 0); int r = test_tspec(a); + TEST_ASSERT_EQUAL(E, r); } + + return; } //---------------------------------------------------------------------- // test compare //---------------------------------------------------------------------- void -test_CmpFracEQ(void) { +test_CmpFracEQ(void) +{ // fractions are equal int i, j; for (i = -4; i <= 4; ++i) @@ -263,38 +305,51 @@ test_CmpFracEQ(void) { struct timespec b = timespec_init( j , 200); int E = (i > j) - (i < j); int r = cmp_tspec_denorm(a, b); + TEST_ASSERT_EQUAL(E, r); } + + return; } void -test_CmpFracGT(void) { +test_CmpFracGT(void) +{ // fraction a bigger fraction b int i, j; + for (i = -4; i <= 4; ++i) for (j = -4; j <= 4; ++j) { struct timespec a = timespec_init(i, 999999800); struct timespec b = timespec_init(j, 200); int E = (i >= j) - (i < j); int r = cmp_tspec_denorm(a, b); + TEST_ASSERT_EQUAL(E, r); } + + return; } void -test_CmpFracLT(void) { +test_CmpFracLT(void) +{ // fraction a less fraction b int i, j; + for (i = -4; i <= 4; ++i) for (j = -4; j <= 4; ++j) { struct timespec a = timespec_init(i, 200); struct timespec b = timespec_init(j, 999999800); int E = (i > j) - (i <= j); int r = cmp_tspec_denorm(a, b); + TEST_ASSERT_EQUAL(E, r); } + + return; } //---------------------------------------------------------------------- @@ -302,8 +357,10 @@ test_CmpFracLT(void) { //---------------------------------------------------------------------- void -test_AddFullNorm(void) { +test_AddFullNorm(void) +{ int i, j; + for (i = -4; i <= 4; ++i) for (j = -4; j <= 4; ++j) { struct timespec a = timespec_init(i, 200); @@ -314,12 +371,16 @@ test_AddFullNorm(void) { c = add_tspec(a, b); TEST_ASSERT_EQUAL_timespec(E, c); } + + return; } void -test_AddFullOflow1(void) { +test_AddFullOflow1(void) +{ int i, j; + for (i = -4; i <= 4; ++i) for (j = -4; j <= 4; ++j) { struct timespec a = timespec_init(i, 200); @@ -330,12 +391,15 @@ test_AddFullOflow1(void) { c = add_tspec(a, b); TEST_ASSERT_EQUAL_timespec(E, c); } + + return; } void test_AddNsecNorm(void) { int i; + for (i = -4; i <= 4; ++i) { struct timespec a = timespec_init(i, 200); struct timespec E = timespec_init(i, 600); @@ -344,12 +408,16 @@ test_AddNsecNorm(void) { c = add_tspec_ns(a, 600 - 200); TEST_ASSERT_EQUAL_timespec(E, c); } + + return; } void -test_AddNsecOflow1(void) { +test_AddNsecOflow1(void) +{ int i; + for (i = -4; i <= 4; ++i) { struct timespec a = timespec_init(i, 200); struct timespec E = timespec_init(i + 1, 100); @@ -358,6 +426,8 @@ test_AddNsecOflow1(void) { c = add_tspec_ns(a, NANOSECONDS - 100); TEST_ASSERT_EQUAL_timespec(E, c); } + + return; } //---------------------------------------------------------------------- @@ -365,8 +435,10 @@ test_AddNsecOflow1(void) { //---------------------------------------------------------------------- void -test_SubFullNorm(void) { +test_SubFullNorm(void) +{ int i, j; + for (i = -4; i <= 4; ++i) for (j = -4; j <= 4; ++j) { struct timespec a = timespec_init( i , 600); @@ -377,12 +449,16 @@ test_SubFullNorm(void) { c = sub_tspec(a, b); TEST_ASSERT_EQUAL_timespec(E, c); } + + return; } void -test_SubFullOflow(void) { +test_SubFullOflow(void) +{ int i, j; + for (i = -4; i <= 4; ++i) for (j = -4; j <= 4; ++j) { struct timespec a = timespec_init(i, 100); @@ -393,12 +469,16 @@ test_SubFullOflow(void) { c = sub_tspec(a, b); TEST_ASSERT_EQUAL_timespec(E, c); } + + return; } void -test_SubNsecNorm(void) { +test_SubNsecNorm(void) +{ int i; + for (i = -4; i <= 4; ++i) { struct timespec a = timespec_init(i, 600); struct timespec E = timespec_init(i, 200); @@ -407,12 +487,16 @@ test_SubNsecNorm(void) { c = sub_tspec_ns(a, 600 - 200); TEST_ASSERT_EQUAL_timespec(E, c); } + + return; } void -test_SubNsecOflow(void) { +test_SubNsecOflow(void) +{ int i; + for (i = -4; i <= 4; ++i) { struct timespec a = timespec_init( i , 100); struct timespec E = timespec_init(i-1, 200); @@ -421,6 +505,8 @@ test_SubNsecOflow(void) { c = sub_tspec_ns(a, NANOSECONDS - 100); TEST_ASSERT_EQUAL_timespec(E, c); } + + return; } //---------------------------------------------------------------------- @@ -429,8 +515,10 @@ test_SubNsecOflow(void) { void -test_Neg(void) { +test_Neg(void) +{ int i; + for (i = -4; i <= 4; ++i) { struct timespec a = timespec_init(i, 100); struct timespec b; @@ -440,6 +528,8 @@ test_Neg(void) { c = add_tspec(a, b); TEST_ASSERT_EQUAL(0, test_tspec(c)); } + + return; } //---------------------------------------------------------------------- @@ -447,8 +537,10 @@ test_Neg(void) { //---------------------------------------------------------------------- void -test_AbsNoFrac(void) { +test_AbsNoFrac(void) +{ int i; + for (i = -4; i <= 4; ++i) { struct timespec a = timespec_init(i , 0); struct timespec b; @@ -456,12 +548,16 @@ test_AbsNoFrac(void) { b = abs_tspec(a); TEST_ASSERT_EQUAL((i != 0), test_tspec(b)); } + + return; } void -test_AbsWithFrac(void) { +test_AbsWithFrac(void) +{ int i; + for (i = -4; i <= 4; ++i) { struct timespec a = timespec_init(i, 100); struct timespec b; @@ -469,6 +565,8 @@ test_AbsWithFrac(void) { b = abs_tspec(a); TEST_ASSERT_EQUAL(1, test_tspec(b)); } + + return; } // --------------------------------------------------------------------- @@ -476,9 +574,9 @@ test_AbsWithFrac(void) { // --------------------------------------------------------------------- void -test_Helpers2(void) { +test_Helpers2(void) +{ struct timespec limit = timespec_init(0, 2); - struct timespec x, y; long i; @@ -489,7 +587,7 @@ test_Helpers2(void) { for (i = -4; i < 5; ++i) { y = x; y.tv_nsec += i; - if (i >= -2 && i <= 2){ + if (i >= -2 && i <= 2) { TEST_ASSERT_TRUE(AssertTimespecClose(x, y, limit)); } else @@ -498,6 +596,8 @@ test_Helpers2(void) { } } } + + return; } //---------------------------------------------------------------------- @@ -505,9 +605,11 @@ test_Helpers2(void) { //---------------------------------------------------------------------- void -test_ToLFPbittest(void) { +test_ToLFPbittest(void) +{ l_fp lfpClose = l_fp_init(0, 1); u_int32 i; + for (i = 0; i < 1000000000; i+=1000) { struct timespec a = timespec_init(1, i); l_fp E= l_fp_init(1, my_tick_to_tsf(i)); @@ -516,12 +618,16 @@ test_ToLFPbittest(void) { r = tspec_intv_to_lfp(a); TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose)); } + + return; } void -test_ToLFPrelPos(void) { +test_ToLFPrelPos(void) +{ int i; + for (i = 0; i < COUNTOF(fdata); ++i) { struct timespec a = timespec_init(1, fdata[i].nsec); l_fp E = l_fp_init(1, fdata[i].frac); @@ -530,12 +636,16 @@ test_ToLFPrelPos(void) { r = tspec_intv_to_lfp(a); TEST_ASSERT_EQUAL_l_fp(E, r); } + + return; } void -test_ToLFPrelNeg(void) { +test_ToLFPrelNeg(void) +{ int i; + for (i = 0; i < COUNTOF(fdata); ++i) { struct timespec a = timespec_init(-1, fdata[i].nsec); l_fp E = l_fp_init(~0, fdata[i].frac); @@ -544,12 +654,16 @@ test_ToLFPrelNeg(void) { r = tspec_intv_to_lfp(a); TEST_ASSERT_EQUAL_l_fp(E, r); } + + return; } void -test_ToLFPabs(void) { +test_ToLFPabs(void) +{ int i; + for (i = 0; i < COUNTOF(fdata); ++i) { struct timespec a = timespec_init(1, fdata[i].nsec); l_fp E = l_fp_init(1 + JAN_1970, fdata[i].frac); @@ -558,6 +672,8 @@ test_ToLFPabs(void) { r = tspec_stamp_to_lfp(a); TEST_ASSERT_EQUAL_l_fp(E, r); } + + return; } //---------------------------------------------------------------------- @@ -565,7 +681,8 @@ test_ToLFPabs(void) { //---------------------------------------------------------------------- void -test_FromLFPbittest(void) { +test_FromLFPbittest(void) +{ struct timespec limit = timespec_init(0, 2); // Not *exactly* a bittest, because 2**32 tests would take a @@ -582,13 +699,17 @@ test_FromLFPbittest(void) { // comparing to calculated value. TEST_ASSERT_TRUE(AssertTimespecClose(E, r, limit)); } + + return; } void -test_FromLFPrelPos(void) { +test_FromLFPrelPos(void) +{ struct timespec limit = timespec_init(0, 2); int i; + for (i = 0; i < COUNTOF(fdata); ++i) { l_fp a = l_fp_init(1, fdata[i].frac); struct timespec E = timespec_init(1, fdata[i].nsec); @@ -597,13 +718,17 @@ test_FromLFPrelPos(void) { r = lfp_intv_to_tspec(a); TEST_ASSERT_TRUE(AssertTimespecClose(E, r, limit)); } + + return; } void -test_FromLFPrelNeg(void) { +test_FromLFPrelNeg(void) +{ struct timespec limit = timespec_init(0, 2); int i; + for (i = 0; i < COUNTOF(fdata); ++i) { l_fp a = l_fp_init(~0, fdata[i].frac); struct timespec E = timespec_init(-1, fdata[i].nsec); @@ -612,14 +737,18 @@ test_FromLFPrelNeg(void) { r = lfp_intv_to_tspec(a); TEST_ASSERT_TRUE(AssertTimespecClose(E, r, limit)); } + + return; } // nsec -> frac -> nsec roundtrip, using a prime start and increment void -test_LFProundtrip(void) { +test_LFProundtrip(void) +{ int32_t t; u_int32 i; + for (t = -1; t < 2; ++t) for (i = 4999; i < 1000000000; i += 10007) { struct timespec E = timespec_init(t, i); @@ -630,6 +759,8 @@ test_LFProundtrip(void) { r = lfp_intv_to_tspec(a); TEST_ASSERT_EQUAL_timespec(E, r); } + + return; } //---------------------------------------------------------------------- @@ -637,7 +768,8 @@ test_LFProundtrip(void) { //---------------------------------------------------------------------- void -test_ToString(void) { +test_ToString(void) +{ static const struct { time_t sec; long nsec; @@ -653,12 +785,15 @@ test_ToString(void) { {-1,-1, "-1.000000001" }, }; int i; + for (i = 0; i < COUNTOF(data); ++i) { struct timespec a = timespec_init(data[i].sec, data[i].nsec); const char * E = data[i].repr; const char * r = tspectoa(a); TEST_ASSERT_EQUAL_STRING(E, r); } + + return; } // -*- EOF -*- diff --git a/contrib/ntp/tests/libntp/timevalops.c b/contrib/ntp/tests/libntp/timevalops.c index a2d9358..99a48eb 100644 --- a/contrib/ntp/tests/libntp/timevalops.c +++ b/contrib/ntp/tests/libntp/timevalops.c @@ -11,8 +11,8 @@ #include "unity.h" -#define TEST_ASSERT_EQUAL_timeval(a, b) { \ - TEST_ASSERT_EQUAL_MESSAGE(a.tv_sec, b.tv_sec, "Field tv_sec"); \ +#define TEST_ASSERT_EQUAL_timeval(a, b) { \ + TEST_ASSERT_EQUAL_MESSAGE(a.tv_sec, b.tv_sec, "Field tv_sec"); \ TEST_ASSERT_EQUAL_MESSAGE(a.tv_usec, b.tv_usec, "Field tv_usec"); \ } @@ -35,6 +35,7 @@ l_fp l_fp_init(int32 i, u_int32 f); bool AssertTimevalClose(const struct timeval m, const struct timeval n, const struct timeval limit); bool AssertFpClose(const l_fp m, const l_fp n, const l_fp limit); +void setUp(void); void test_Helpers1(void); void test_Normalise(void); void test_SignNoFrac(void); @@ -65,28 +66,43 @@ void test_LFProundtrip(void); void test_ToString(void); -//******************************************MY CUSTOM FUNCTIONS******************************* +//**********************************MY CUSTOM FUNCTIONS*********************** +void +setUp(void) +{ + init_lib(); + + return; +} + struct timeval -timeval_init( time_t hi, long lo){ +timeval_init(time_t hi, long lo) +{ struct timeval V; + V.tv_sec = hi; V.tv_usec = lo; + return V; } const bool -timeval_isValid(struct timeval V) { +timeval_isValid(struct timeval V) +{ + return V.tv_usec >= 0 && V.tv_usec < 1000000; } l_fp -l_fp_init(int32 i, u_int32 f) { +l_fp_init(int32 i, u_int32 f) +{ l_fp temp; + temp.l_i = i; temp.l_uf = f; @@ -95,25 +111,26 @@ l_fp_init(int32 i, u_int32 f) { bool -AssertTimevalClose(const struct timeval m, const struct timeval n, const struct timeval limit) { +AssertTimevalClose(const struct timeval m, const struct timeval n, const struct timeval limit) +{ struct timeval diff; diff = abs_tval(sub_tval(m, n)); if (cmp_tval(limit, diff) >= 0) return TRUE; - else { printf("m_expr which is %ld.%lu \nand\nn_expr which is %ld.%lu\nare not close; diff=%ld.%luusec\n", m.tv_sec, m.tv_usec, n.tv_sec, n.tv_usec, diff.tv_sec, diff.tv_usec); //I don't have variables m_expr and n_expr in unity, those are command line arguments which only getst has!!! - + return FALSE; } } bool -AssertFpClose(const l_fp m, const l_fp n, const l_fp limit) { +AssertFpClose(const l_fp m, const l_fp n, const l_fp limit) +{ l_fp diff; if (L_ISGEQ(&m, &n)) { @@ -123,7 +140,7 @@ AssertFpClose(const l_fp m, const l_fp n, const l_fp limit) { diff = n; L_SUB(&diff, &m); } - if (L_ISGEQ(&limit, &diff)){ + if (L_ISGEQ(&limit, &diff)) { return TRUE; } else { @@ -155,11 +172,13 @@ static const lfpfracdata fdata[] = { u_int32 -my_tick_to_tsf(u_int32 ticks) { +my_tick_to_tsf(u_int32 ticks) +{ // convert microseconds to l_fp fractional units, using double // precision float calculations or, if available, 64bit integer // arithmetic. This should give the precise fraction, rounded to // the nearest representation. + #ifdef HAVE_U_INT64 return (u_int32)((( ((u_int64)(ticks)) << 32) + 500000) / 1000000); //I put too much () when casting just to be safe #else @@ -171,7 +190,8 @@ my_tick_to_tsf(u_int32 ticks) { u_int32 -my_tsf_to_tick(u_int32 tsf) { +my_tsf_to_tick(u_int32 tsf) +{ // Inverse operation: converts fraction to microseconds. #ifdef HAVE_U_INT64 return (u_int32)( ((u_int64)(tsf) * 1000000 + 0x80000000) >> 32); //CHECK ME!!! @@ -182,7 +202,7 @@ my_tsf_to_tick(u_int32 tsf) { } -//***************************************END OF CUSTOM FUNCTIONS***************************** +//*******************************END OF CUSTOM FUNCTIONS********************* // --------------------------------------------------------------------- @@ -190,7 +210,8 @@ my_tsf_to_tick(u_int32 tsf) { // --------------------------------------------------------------------- void -test_Helpers1(void) { +test_Helpers1(void) +{ struct timeval x; for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++) { @@ -203,6 +224,8 @@ test_Helpers1(void) { x.tv_usec = 1000000; TEST_ASSERT_FALSE(timeval_isValid(x)); } + + return; } @@ -211,14 +234,18 @@ test_Helpers1(void) { //---------------------------------------------------------------------- void -test_Normalise(void) { +test_Normalise(void) +{ long ns; + for (ns = -2000000000; ns <= 2000000000; ns += 10000000) { struct timeval x = timeval_init(0, ns); - + x = normalize_tval(x); TEST_ASSERT_TRUE(timeval_isValid(x)); } + + return; } //---------------------------------------------------------------------- @@ -226,8 +253,10 @@ test_Normalise(void) { //---------------------------------------------------------------------- void -test_SignNoFrac(void) { +test_SignNoFrac(void) +{ int i; + // sign test, no fraction for (i = -4; i <= 4; ++i) { struct timeval a = timeval_init(i, 0); @@ -236,13 +265,17 @@ test_SignNoFrac(void) { TEST_ASSERT_EQUAL(E, r); } + + return; } void -test_SignWithFrac(void) { +test_SignWithFrac(void) +{ // sign test, with fraction int i; + for (i = -4; i <= 4; ++i) { struct timeval a = timeval_init(i, 10); int E = (i >= 0) - (i < 0); @@ -250,14 +283,18 @@ test_SignWithFrac(void) { TEST_ASSERT_EQUAL(E, r); } + + return; } //---------------------------------------------------------------------- // test compare //---------------------------------------------------------------------- void -test_CmpFracEQ(void) { +test_CmpFracEQ(void) +{ int i, j; + // fractions are equal for (i = -4; i <= 4; ++i) for (j = -4; j <= 4; ++j) { @@ -268,13 +305,17 @@ test_CmpFracEQ(void) { TEST_ASSERT_EQUAL(E, r); } + + return; } void -test_CmpFracGT(void) { +test_CmpFracGT(void) +{ // fraction a bigger fraction b int i, j; + for (i = -4; i <= 4; ++i) for (j = -4; j <= 4; ++j) { struct timeval a = timeval_init( i , 999800); @@ -284,13 +325,17 @@ test_CmpFracGT(void) { TEST_ASSERT_EQUAL(E, r); } + + return; } void -test_CmpFracLT(void) { +test_CmpFracLT(void) +{ // fraction a less fraction b int i, j; + for (i = -4; i <= 4; ++i) for (j = -4; j <= 4; ++j) { struct timeval a = timeval_init(i, 200); @@ -300,6 +345,8 @@ test_CmpFracLT(void) { TEST_ASSERT_EQUAL(E, r); } + + return; } //---------------------------------------------------------------------- @@ -307,8 +354,10 @@ test_CmpFracLT(void) { //---------------------------------------------------------------------- void -test_AddFullNorm(void) { +test_AddFullNorm(void) +{ int i, j; + for (i = -4; i <= 4; ++i) for (j = -4; j <= 4; ++j) { struct timeval a = timeval_init(i, 200); @@ -319,12 +368,16 @@ test_AddFullNorm(void) { c = add_tval(a, b); TEST_ASSERT_EQUAL_timeval(E, c); } + + return; } void -test_AddFullOflow1(void) { +test_AddFullOflow1(void) +{ int i, j; + for (i = -4; i <= 4; ++i) for (j = -4; j <= 4; ++j) { struct timeval a = timeval_init(i, 200); @@ -335,12 +388,16 @@ test_AddFullOflow1(void) { c = add_tval(a, b); TEST_ASSERT_EQUAL_timeval(E, c); } + + return; } void -test_AddUsecNorm(void) { +test_AddUsecNorm(void) +{ int i; + for (i = -4; i <= 4; ++i) { struct timeval a = timeval_init(i, 200); struct timeval E = timeval_init(i, 600); @@ -349,12 +406,16 @@ test_AddUsecNorm(void) { c = add_tval_us(a, 600 - 200); TEST_ASSERT_EQUAL_timeval(E, c); } + + return; } void -test_AddUsecOflow1(void) { +test_AddUsecOflow1(void) +{ int i; + for (i = -4; i <= 4; ++i) { struct timeval a = timeval_init(i, 200); struct timeval E = timeval_init(i + 1, 100); @@ -363,6 +424,8 @@ test_AddUsecOflow1(void) { c = add_tval_us(a, MICROSECONDS - 100); TEST_ASSERT_EQUAL_timeval(E, c); } + + return; } //---------------------------------------------------------------------- @@ -370,8 +433,10 @@ test_AddUsecOflow1(void) { //---------------------------------------------------------------------- void -test_SubFullNorm(void) { +test_SubFullNorm(void) +{ int i, j; + for (i = -4; i <= 4; ++i) for (j = -4; j <= 4; ++j) { struct timeval a = timeval_init(i, 600); @@ -382,12 +447,16 @@ test_SubFullNorm(void) { c = sub_tval(a, b); TEST_ASSERT_EQUAL_timeval(E, c); } + + return; } void -test_SubFullOflow(void) { +test_SubFullOflow(void) +{ int i, j; + for (i = -4; i <= 4; ++i) for (j = -4; j <= 4; ++j) { struct timeval a = timeval_init(i, 100); @@ -398,12 +467,16 @@ test_SubFullOflow(void) { c = sub_tval(a, b); TEST_ASSERT_EQUAL_timeval(E, c); } + + return; } void -test_SubUsecNorm(void) { +test_SubUsecNorm(void) +{ int i = -4; + for (i = -4; i <= 4; ++i) { struct timeval a = timeval_init(i, 600); struct timeval E = timeval_init(i, 200); @@ -412,12 +485,16 @@ test_SubUsecNorm(void) { c = sub_tval_us(a, 600 - 200); TEST_ASSERT_EQUAL_timeval(E, c); } + + return; } void -test_SubUsecOflow(void) { +test_SubUsecOflow(void) +{ int i = -4; + for (i = -4; i <= 4; ++i) { struct timeval a = timeval_init(i, 100); struct timeval E = timeval_init(i - 1, 200); @@ -426,6 +503,8 @@ test_SubUsecOflow(void) { c = sub_tval_us(a, MICROSECONDS - 100); TEST_ASSERT_EQUAL_timeval(E, c); } + + return; } //---------------------------------------------------------------------- @@ -433,8 +512,10 @@ test_SubUsecOflow(void) { //---------------------------------------------------------------------- void -test_Neg(void) { +test_Neg(void) +{ int i = -4; + for (i = -4; i <= 4; ++i) { struct timeval a = timeval_init(i, 100); struct timeval b; @@ -444,6 +525,8 @@ test_Neg(void) { c = add_tval(a, b); TEST_ASSERT_EQUAL(0, test_tval(c)); } + + return; } //---------------------------------------------------------------------- @@ -451,8 +534,10 @@ test_Neg(void) { //---------------------------------------------------------------------- void -test_AbsNoFrac(void) { +test_AbsNoFrac(void) +{ int i = -4; + for (i = -4; i <= 4; ++i) { struct timeval a = timeval_init(i, 0); struct timeval b; @@ -460,12 +545,16 @@ test_AbsNoFrac(void) { b = abs_tval(a); TEST_ASSERT_EQUAL((i != 0), test_tval(b)); } + + return; } void -test_AbsWithFrac(void) { +test_AbsWithFrac(void) +{ int i = -4; + for (i = -4; i <= 4; ++i) { struct timeval a = timeval_init(i, 100); struct timeval b; @@ -473,6 +562,8 @@ test_AbsWithFrac(void) { b = abs_tval(a); TEST_ASSERT_EQUAL(1, test_tval(b)); } + + return; } // --------------------------------------------------------------------- @@ -481,20 +572,20 @@ test_AbsWithFrac(void) { void -test_Helpers2(void) { - +test_Helpers2(void) +{ struct timeval limit = timeval_init(0, 2); struct timeval x, y; - long i; + long i; - for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++){ + for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++) { for (x.tv_usec = 1; x.tv_usec < 1000000; x.tv_usec += 499999) { for (i = -4; i < 5; ++i) { y = x; y.tv_usec += i; - if (i >= -2 && i <= 2){ + if (i >= -2 && i <= 2) { TEST_ASSERT_TRUE(AssertTimevalClose(x, y, limit));//ASSERT_PRED_FORMAT2(isClose, x, y); } else { @@ -503,6 +594,8 @@ test_Helpers2(void) { } } } + + return; } // and the global predicate instances we're using here @@ -515,8 +608,9 @@ test_Helpers2(void) { //---------------------------------------------------------------------- void -test_ToLFPbittest(void) { - l_fp lfpClose = l_fp_init(0, 1); +test_ToLFPbittest(void) +{ + l_fp lfpClose = l_fp_init(0, 1); u_int32 i = 0; for (i = 0; i < 1000000; ++i) { @@ -527,14 +621,17 @@ test_ToLFPbittest(void) { r = tval_intv_to_lfp(a); TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose)); //ASSERT_PRED_FORMAT2(FpClose, E, r); } + + return; } void -test_ToLFPrelPos(void) { +test_ToLFPrelPos(void) +{ l_fp lfpClose = l_fp_init(0, 1); - int i = 0; + for (i = 0; i < COUNTOF(fdata); ++i) { struct timeval a = timeval_init(1, fdata[i].usec); l_fp E = l_fp_init(1, fdata[i].frac); @@ -543,13 +640,17 @@ test_ToLFPrelPos(void) { r = tval_intv_to_lfp(a); TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose)); } + + return; } void -test_ToLFPrelNeg(void) { +test_ToLFPrelNeg(void) +{ l_fp lfpClose = l_fp_init(0, 1); int i = 0; + for (i = 0; i < COUNTOF(fdata); ++i) { struct timeval a = timeval_init(-1, fdata[i].usec); l_fp E = l_fp_init(~0, fdata[i].frac); @@ -558,14 +659,17 @@ test_ToLFPrelNeg(void) { r = tval_intv_to_lfp(a); TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose)); } + + return; } void -test_ToLFPabs(void) { +test_ToLFPabs(void) +{ l_fp lfpClose = l_fp_init(0, 1); - int i = 0; + for (i = 0; i < COUNTOF(fdata); ++i) { struct timeval a = timeval_init(1, fdata[i].usec); l_fp E = l_fp_init(1 + JAN_1970, fdata[i].frac); @@ -574,6 +678,8 @@ test_ToLFPabs(void) { r = tval_stamp_to_lfp(a); TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose)); } + + return; } //---------------------------------------------------------------------- @@ -581,12 +687,14 @@ test_ToLFPabs(void) { //---------------------------------------------------------------------- void -test_FromLFPbittest(void) { +test_FromLFPbittest(void) +{ struct timeval timevalClose = timeval_init(0, 1); // Not *exactly* a bittest, because 2**32 tests would take a // really long time even on very fast machines! So we do test // every 1000 fractional units. u_int32 tsf = 0; + for (tsf = 0; tsf < ~((u_int32)(1000)); tsf += 1000) { struct timeval E = timeval_init(1, my_tsf_to_tick(tsf)); l_fp a = l_fp_init(1, tsf); @@ -597,13 +705,17 @@ test_FromLFPbittest(void) { // comparing to calculated value. TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose)); } + + return; } void -test_FromLFPrelPos(void) { +test_FromLFPrelPos(void) +{ struct timeval timevalClose = timeval_init(0, 1); - int i = 0; + int i = 0; + for (i = 0; i < COUNTOF(fdata); ++i) { l_fp a = l_fp_init(1, fdata[i].frac); struct timeval E = timeval_init(1, fdata[i].usec); @@ -612,13 +724,17 @@ test_FromLFPrelPos(void) { r = lfp_intv_to_tval(a); TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose)); } + + return; } void -test_FromLFPrelNeg(void) { +test_FromLFPrelNeg(void) +{ struct timeval timevalClose = timeval_init(0, 1); int i = 0; + for (i = 0; i < COUNTOF(fdata); ++i) { l_fp a = l_fp_init(~0, fdata[i].frac); struct timeval E = timeval_init(-1, fdata[i].usec); @@ -627,14 +743,18 @@ test_FromLFPrelNeg(void) { r = lfp_intv_to_tval(a); TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose)); } + + return; } // usec -> frac -> usec roundtrip, using a prime start and increment void -test_LFProundtrip(void) { +test_LFProundtrip(void) +{ int32_t t = -1; u_int32 i = 5; + for (t = -1; t < 2; ++t) for (i = 5; i < 1000000; i += 11) { struct timeval E = timeval_init(t, i); @@ -645,6 +765,8 @@ test_LFProundtrip(void) { r = lfp_intv_to_tval(a); TEST_ASSERT_EQUAL_timeval(E, r); } + + return; } //---------------------------------------------------------------------- @@ -652,7 +774,8 @@ test_LFProundtrip(void) { //---------------------------------------------------------------------- void -test_ToString(void) { +test_ToString(void) +{ static const struct { time_t sec; long usec; @@ -668,6 +791,7 @@ test_ToString(void) { {-1,-1, "-1.000001" }, }; int i; + for (i = 0; i < COUNTOF(data); ++i) { struct timeval a = timeval_init(data[i].sec, data[i].usec); const char * E = data[i].repr; @@ -675,6 +799,8 @@ test_ToString(void) { TEST_ASSERT_EQUAL_STRING(E, r); } + + return; } // -*- EOF -*- diff --git a/contrib/ntp/tests/libntp/uglydate.c b/contrib/ntp/tests/libntp/uglydate.c index f47f3e4..3a5aa8a 100644 --- a/contrib/ntp/tests/libntp/uglydate.c +++ b/contrib/ntp/tests/libntp/uglydate.c @@ -5,14 +5,26 @@ #include "unity.h" +void setUp(void); void test_ConstantDateTime(void); + +void +setUp(void) +{ + init_lib(); + + return; +} + void -test_ConstantDateTime(void) { +test_ConstantDateTime(void) +{ const u_int32 HALF = 2147483648UL; - l_fp time = {{3485080800UL}, HALF}; /* 2010-06-09 14:00:00.5 */ + l_fp e_time = {{3485080800UL}, HALF}; /* 2010-06-09 14:00:00.5 */ TEST_ASSERT_EQUAL_STRING("3485080800.500000 10:159:14:00:00.500", - uglydate(&time)); + uglydate(&e_time)); + return; } diff --git a/contrib/ntp/tests/ntpd/leapsec.c b/contrib/ntp/tests/ntpd/leapsec.c index 37e4398..36ecd39 100644 --- a/contrib/ntp/tests/ntpd/leapsec.c +++ b/contrib/ntp/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/contrib/ntp/tests/ntpd/ntp_prio_q.c b/contrib/ntp/tests/ntpd/ntp_prio_q.c index c2d4f76..4b27157 100644 --- a/contrib/ntp/tests/ntpd/ntp_prio_q.c +++ b/contrib/ntp/tests/ntpd/ntp_prio_q.c @@ -251,6 +251,7 @@ test_AppendQueues(void) { free_node(e3_ptr); free_node(e4_ptr); free_node(e5_ptr); + free_node(e6_ptr); TEST_ASSERT_EQUAL(0, get_no_of_elements(q4)); diff --git a/contrib/ntp/tests/ntpd/ntp_restrict.c b/contrib/ntp/tests/ntpd/ntp_restrict.c index 98d6e83..08d236e 100644 --- a/contrib/ntp/tests/ntpd/ntp_restrict.c +++ b/contrib/ntp/tests/ntpd/ntp_restrict.c @@ -26,6 +26,7 @@ setUp(void) { } +void tearDown(void) { restrict_u *empty_restrict = malloc(sizeof(restrict_u)); memset(empty_restrict, 0, sizeof(restrict_u)); diff --git a/contrib/ntp/tests/ntpd/rc_cmdlength.c b/contrib/ntp/tests/ntpd/rc_cmdlength.c index e3d599f..dfe5316 100644 --- a/contrib/ntp/tests/ntpd/rc_cmdlength.c +++ b/contrib/ntp/tests/ntpd/rc_cmdlength.c @@ -3,6 +3,7 @@ #include "ntp.h" #include "ntp_calendar.h" #include "ntp_stdlib.h" +#include "rc_cmdlength.h" #include "unity.h" diff --git a/contrib/ntp/tests/ntpd/run-leapsec.c b/contrib/ntp/tests/ntpd/run-leapsec.c index c02cfa8..03b633e 100644 --- a/contrib/ntp/tests/ntpd/run-leapsec.c +++ b/contrib/ntp/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/contrib/ntp/tests/ntpd/run-ntp_restrict.c b/contrib/ntp/tests/ntpd/run-ntp_restrict.c index 0d945eb..d884462 100644 --- a/contrib/ntp/tests/ntpd/run-ntp_restrict.c +++ b/contrib/ntp/tests/ntpd/run-ntp_restrict.c @@ -55,14 +55,14 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("ntp_restrict.c"); - RUN_TEST(test_RestrictionsAreEmptyAfterInit, 59); - RUN_TEST(test_ReturnsCorrectDefaultRestrictions, 85); - RUN_TEST(test_HackingDefaultRestriction, 96); - RUN_TEST(test_CantRemoveDefaultEntry, 119); - RUN_TEST(test_AddingNewRestriction, 130); - RUN_TEST(test_TheMostFittingRestrictionIsMatched, 143); - RUN_TEST(test_DeletedRestrictionIsNotMatched, 165); - RUN_TEST(test_RestrictUnflagWorks, 189); + RUN_TEST(test_RestrictionsAreEmptyAfterInit, 60); + RUN_TEST(test_ReturnsCorrectDefaultRestrictions, 86); + RUN_TEST(test_HackingDefaultRestriction, 97); + RUN_TEST(test_CantRemoveDefaultEntry, 120); + RUN_TEST(test_AddingNewRestriction, 131); + RUN_TEST(test_TheMostFittingRestrictionIsMatched, 144); + RUN_TEST(test_DeletedRestrictionIsNotMatched, 166); + RUN_TEST(test_RestrictUnflagWorks, 190); return (UnityEnd()); } diff --git a/contrib/ntp/tests/ntpd/run-rc_cmdlength.c b/contrib/ntp/tests/ntpd/run-rc_cmdlength.c index c6fb7cc..927a45e 100644 --- a/contrib/ntp/tests/ntpd/run-rc_cmdlength.c +++ b/contrib/ntp/tests/ntpd/run-rc_cmdlength.c @@ -26,6 +26,7 @@ #include "ntp.h" #include "ntp_calendar.h" #include "ntp_stdlib.h" +#include "rc_cmdlength.h" #include "test-libntp.h" #include <string.h> @@ -51,7 +52,7 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("rc_cmdlength.c"); - RUN_TEST(test_EvaluateCommandLength, 15); + RUN_TEST(test_EvaluateCommandLength, 16); return (UnityEnd()); } diff --git a/contrib/ntp/tests/ntpd/run-t-ntp_signd.c b/contrib/ntp/tests/ntpd/run-t-ntp_signd.c index 662cada..5226f7f 100644 --- a/contrib/ntp/tests/ntpd/run-t-ntp_signd.c +++ b/contrib/ntp/tests/ntpd/run-t-ntp_signd.c @@ -36,7 +36,7 @@ extern void test_connect_correct_socket(void); extern void test_write_all(void); extern void test_send_packet(void); extern void test_recv_packet(void); -extern void test_send_via_ntp_signd(); +extern void test_send_via_ntp_signd(void); //=======Test Reset Option===== @@ -55,12 +55,12 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("t-ntp_signd.c"); - RUN_TEST(test_connect_incorrect_socket, 49); - RUN_TEST(test_connect_correct_socket, 54); - RUN_TEST(test_write_all, 74); - RUN_TEST(test_send_packet, 84); - RUN_TEST(test_recv_packet, 93); - RUN_TEST(test_send_via_ntp_signd, 104); + RUN_TEST(test_connect_incorrect_socket, 67); + RUN_TEST(test_connect_correct_socket, 68); + RUN_TEST(test_write_all, 69); + RUN_TEST(test_send_packet, 70); + RUN_TEST(test_recv_packet, 71); + RUN_TEST(test_send_via_ntp_signd, 72); return (UnityEnd()); } diff --git a/contrib/ntp/tests/ntpd/t-ntp_scanner.c b/contrib/ntp/tests/ntpd/t-ntp_scanner.c index 9bc77c4..862a2ee 100644 --- a/contrib/ntp/tests/ntpd/t-ntp_scanner.c +++ b/contrib/ntp/tests/ntpd/t-ntp_scanner.c @@ -26,13 +26,13 @@ void test_InitializeLexStack(void); void test_keywordIncorrectToken(void){ - char * temp = keyword(999); + const char * temp = keyword(999); //printf("%s\n",temp); TEST_ASSERT_EQUAL_STRING("(keyword not found)",temp); } void test_keywordServerToken(void){ - char * temp = keyword(401); + const char * temp = keyword(T_Server); //printf("%s",temp); //143 or 401 ? TEST_ASSERT_EQUAL_STRING("server",temp); } @@ -127,7 +127,7 @@ void test_EOC(void){ temp = is_EOC(';'); TEST_ASSERT_TRUE(temp); } - temp = is_EOC("A"); + temp = is_EOC('A'); TEST_ASSERT_FALSE(temp); temp = is_EOC('1'); TEST_ASSERT_FALSE(temp); diff --git a/contrib/ntp/tests/ntpd/t-ntp_signd.c b/contrib/ntp/tests/ntpd/t-ntp_signd.c index 45972fb..534c940 100644 --- a/contrib/ntp/tests/ntpd/t-ntp_signd.c +++ b/contrib/ntp/tests/ntpd/t-ntp_signd.c @@ -9,7 +9,6 @@ #include "test-libntp.h" - #define HAVE_NTP_SIGND #include "ntp_signd.c" @@ -20,41 +19,70 @@ extern int ux_socket_connect(const char *name); //MOCKED FUNCTIONS //this connect function overrides/mocks connect() from <sys/socket.h> -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;} - else return len; +/* +** Mocked read() and write() calls. +** +** These will only operate 4 bytes at a time. +** +** This is so write_all can be properly tested. +*/ + +static char rw_buf[4]; + +ssize_t +write(int fd, void const * buf, size_t len) +{ + REQUIRE(0 <= len); + if (len >= 4) len = 4; /* 4 bytes, max */ + (void)memcpy(rw_buf, buf, len); + + return len; } -ssize_t read(int fd, void * buf, size_t len){ - if(len >= 4){return 4;} - else return len; +ssize_t +read(int fd, void * buf, size_t len) +{ + REQUIRE(0 <= len); + if (len >= 4) len = 4; + (void)memcpy(buf, rw_buf, len); + return len; } //END OF MOCKED FUNCTIONS -int isGE(int a,int b){ - if(a >= b) {return 1;} +static int +isGE(int a,int b) +{ + if (a >= b) {return 1;} else {return 0;} } +extern void test_connect_incorrect_socket(void); +extern void test_connect_correct_socket(void); +extern void test_write_all(void); +extern void test_send_packet(void); +extern void test_recv_packet(void); +extern void test_send_via_ntp_signd(void); + void -test_connect_incorrect_socket(void){ +test_connect_incorrect_socket(void) +{ TEST_ASSERT_EQUAL(-1, ux_socket_connect(NULL)); + + return; } void -test_connect_correct_socket(void){ - - - +test_connect_correct_socket(void) +{ int temp = ux_socket_connect("/socket"); //risky, what if something is listening on :123, or localhost isnt 127.0.0.1? @@ -67,50 +95,87 @@ test_connect_correct_socket(void){ //char *socketName = "Random_Socket_Name"; //int length = strlen(socketName); + return; } void -test_write_all(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); + + (void)close(fd); + return; } void -test_send_packet(void){ +test_send_packet(void) +{ int fd = ux_socket_connect("/socket"); + + TEST_ASSERT_TRUE(isGE(fd, 0)); + char * str2 = "PACKET12345"; int temp = send_packet(fd, str2, strlen(str2)); + TEST_ASSERT_EQUAL(0,temp); + + (void)close(fd); + return; } +/* +** HMS: What's going on here? +** Looks like this needs more work. +*/ void -test_recv_packet(void){ +test_recv_packet(void) +{ int fd = ux_socket_connect("/socket"); - int size = 256; - char str[size]; + TEST_ASSERT_TRUE(isGE(fd, 0)); + + 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!) + + (void)close(fd); + return; } void -test_send_via_ntp_signd(){ - +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 + TEST_ASSERT_NOT_NULL(rbufp); + TEST_ASSERT_NOT_NULL(xpkt); + memset(xpkt, 0, sizeof(struct pkt)); + //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/contrib/ntp/tests/sandbox/run-uglydate.c b/contrib/ntp/tests/sandbox/run-uglydate.c index e65cd01..5a5a716 100644 --- a/contrib/ntp/tests/sandbox/run-uglydate.c +++ b/contrib/ntp/tests/sandbox/run-uglydate.c @@ -24,6 +24,7 @@ #include <stdio.h> #include "config.h" #include "ntp_fp.h" +#include "ntp_stdlib.h" //=======External Functions This Runner Calls===== extern void setUp(void); @@ -47,7 +48,7 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("uglydate.c"); - RUN_TEST(test_ConstantDateTime, 9); + RUN_TEST(test_ConstantDateTime, 10); return (UnityEnd()); } diff --git a/contrib/ntp/tests/sandbox/smeartest.c b/contrib/ntp/tests/sandbox/smeartest.c index a8ee210..cc4e503 100644 --- a/contrib/ntp/tests/sandbox/smeartest.c +++ b/contrib/ntp/tests/sandbox/smeartest.c @@ -2,6 +2,7 @@ #include <ntp.h> #include <ntp_fp.h> +#include <ntp_assert.h> /* * we want to test a refid format of: @@ -125,11 +126,14 @@ ltor(l_fp l) } +int main() { l_fp l; int rc; + init_lib(); + rtol(0xfe800000); rtol(0xfe800001); rtol(0xfe8ffffe); @@ -167,6 +171,8 @@ main() rtoltor(0xfe7fffff); rc = atolfp("-.932087", &l); + INSIST(1 == rc); + ltor(l); rtol(0xfec458b0); printf("%x -> %d.%d.%d.%d\n", diff --git a/contrib/ntp/tests/sandbox/uglydate.c b/contrib/ntp/tests/sandbox/uglydate.c index a7879c1..ba8377e 100644 --- a/contrib/ntp/tests/sandbox/uglydate.c +++ b/contrib/ntp/tests/sandbox/uglydate.c @@ -2,15 +2,30 @@ #include "ntp_fp.h" #include "unity.h" -//#include "ntp_stdlib.h" +#include "ntp_stdlib.h" + //#include "libntptest.h" +void setUp(void); +void test_ConstantDateTime(void); + + +void +setUp(void) +{ + init_lib(); + + return; +} + + void -test_ConstantDateTime(void) { +test_ConstantDateTime(void) +{ const u_int32 HALF = 2147483648UL; - l_fp time = {3485080800UL, HALF}; // 2010-06-09 14:00:00.5 + l_fp e_time = {{3485080800UL}, HALF}; // 2010-06-09 14:00:00.5 TEST_ASSERT_EQUAL_STRING("3485080800.500000 10:159:14:00:00.500", - uglydate(&time)); + uglydate(&e_time)); } diff --git a/contrib/ntp/tests/sec-2853/sec-2853.c b/contrib/ntp/tests/sec-2853/sec-2853.c index 49589d2..f9255b0 100644 --- a/contrib/ntp/tests/sec-2853/sec-2853.c +++ b/contrib/ntp/tests/sec-2853/sec-2853.c @@ -13,7 +13,7 @@ int embedded_nul( void ); int trailing_space( 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 +// static int exit_on_err = 0; // if not 0, exit if test failed void setUp(void) @@ -49,7 +49,6 @@ int basic_good( void ) { const char string[] = "good"; const char *EOstring; - char *cp; size_t len; int failed; @@ -60,9 +59,9 @@ int basic_good( void ) failed = ( 4 != len ); if ( failed || verbose ) - printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n", + printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n", string, - len, + (unsigned long long)len, 4, failed ? "NO <<" : "yes" ); @@ -74,7 +73,6 @@ int embedded_nul( void ) { const char string[] = "nul\0 there"; const char *EOstring; - char *cp; size_t len; int failed; @@ -85,9 +83,9 @@ int embedded_nul( void ) failed = ( 3 != len ); if ( failed || verbose ) - printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n", + printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n", string, - len, + (unsigned long long)len, 3, failed ? "NO <<" : "yes" ); @@ -99,7 +97,6 @@ int trailing_space( void ) { const char string[] = "trailing space "; const char *EOstring; - char *cp; size_t len; int failed; @@ -110,9 +107,9 @@ int trailing_space( void ) failed = ( 14 != len ); if ( failed || verbose ) - printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n", + printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n", string, - len, + (unsigned long long)len, 14, failed ? "NO <<" : "yes" ); |