diff --git a/test/unit/sources.c b/test/unit/sources.c index 606fcab..fdc70c0 100644 --- a/test/unit/sources.c +++ b/test/unit/sources.c @@ -22,14 +22,12 @@ #include "test.h" static SRC_Instance -create_source(SRC_Type type, int authenticated, int sel_options) +create_source(SRC_Type type, IPAddr *addr, int authenticated, int sel_options) { - static IPAddr addr; + TST_GetRandomAddress(addr, IPADDR_UNSPEC, -1); - TST_GetRandomAddress(&addr, IPADDR_UNSPEC, -1); - - return SRC_CreateNewInstance(UTI_IPToRefid(&addr), type, authenticated, sel_options, - type == SRC_NTP ? &addr : NULL, + return SRC_CreateNewInstance(UTI_IPToRefid(addr), type, authenticated, sel_options, + type == SRC_NTP ? addr : NULL, SRC_DEFAULT_MINSAMPLES, SRC_DEFAULT_MAXSAMPLES, 0.0, 1.0); } @@ -38,6 +36,7 @@ test_unit(void) { SRC_AuthSelectMode sel_mode; SRC_Instance srcs[16]; + IPAddr addrs[16]; RPT_SourceReport report; NTP_Sample sample; int i, j, k, l, n1, n2, n3, n4, samples, sel_options; @@ -63,7 +62,7 @@ test_unit(void) SRC_SELECT_TRUST | SRC_SELECT_REQUIRE); DEBUG_LOG("added source %d options %d", j, sel_options); - srcs[j] = create_source(SRC_NTP, 0, sel_options); + srcs[j] = create_source(SRC_NTP, &addrs[j], 0, sel_options); SRC_UpdateReachability(srcs[j], 1); samples = (i + j) % 5 + 3; @@ -127,7 +126,7 @@ test_unit(void) } } - DEBUG_LOG("sources %d passed %d trusted %d/%d required %d/%d", j, passed, + DEBUG_LOG("sources %d passed %d trusted %d/%d required %d/%d", j + 1, passed, trusted_passed, trusted, required_passed, required); TEST_CHECK(!trusted || !passed || (passed_lo >= trusted_lo && passed_hi <= trusted_hi)); @@ -178,13 +177,13 @@ test_unit(void) assert(n1 + n2 + n3 < sizeof (srcs) / sizeof (srcs[0])); for (j = 0; j < n1; j++) - srcs[j] = create_source(SRC_REFCLOCK, random() % 2, sel_options); + srcs[j] = create_source(SRC_REFCLOCK, &addrs[j], random() % 2, sel_options); for (; j < n1 + n2; j++) - srcs[j] = create_source(SRC_NTP, 1, sel_options); + srcs[j] = create_source(SRC_NTP, &addrs[j], 1, sel_options); for (; j < n1 + n2 + n3; j++) - srcs[j] = create_source(SRC_NTP, 0, sel_options); + srcs[j] = create_source(SRC_NTP, &addrs[j], 0, sel_options); for (; j < n1 + n2 + n3 + n4; j++) - srcs[j] = create_source(random() % 2 ? SRC_REFCLOCK : SRC_NTP, + srcs[j] = create_source(random() % 2 ? SRC_REFCLOCK : SRC_NTP, &addrs[j], random() % 2, sel_options | SRC_SELECT_NOSELECT); switch (sel_mode) { @@ -218,7 +217,7 @@ test_unit(void) for (j = n1 + n2 + n3; j < n1 + n2 + n3 + n4; j++) TEST_CHECK(srcs[j]->sel_options == (sel_options | SRC_SELECT_NOSELECT)); - for (j = n1 + n2 + n3 - 1; j >= 0; j--) { + for (j = n1 + n2 + n3 + n4 - 1; j >= 0; j--) { if (j < n1 + n2) TEST_CHECK(srcs[j]->sel_options == sel_options); SRC_DestroyInstance(srcs[j]);