From 95beb170ea84220fbcf159582ce08a0819470b5a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 2 Jul 2020 16:28:37 +0200 Subject: [PATCH 1/4] ndisc/tests: make assertion checks a macro and not a function in test-ndisc-fake By having it a function, the assertion failure does not show the line number of the origin. Make them a macro, so that we see where exactly it failed. (cherry picked from commit 3b896cc64237262055cc44abb7e914c905e33ecf) (cherry picked from commit b1a7eda71d73de410736b23ca82a70b7eeba239b) (cherry picked from commit 8316943338bab1f5682e0e1f222e570a394a5410) (cherry picked from commit 017bfbf4d72b5bc926e62ebb6de832e6385964aa) --- src/ndisc/tests/test-ndisc-fake.c | 75 ++++++++++++++++--------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/src/ndisc/tests/test-ndisc-fake.c b/src/ndisc/tests/test-ndisc-fake.c index f752376d9a..9cd6f64637 100644 --- a/src/ndisc/tests/test-ndisc-fake.c +++ b/src/ndisc/tests/test-ndisc-fake.c @@ -61,44 +61,45 @@ match_gateway (const NMNDiscData *rdata, guint idx, const char *addr, guint32 ts g_assert_cmpint (gw->preference, ==, pref); } -static void -match_address (const NMNDiscData *rdata, guint idx, const char *addr, guint32 ts, guint32 lt, guint32 preferred) -{ - const NMNDiscAddress *a; - char buf[INET6_ADDRSTRLEN]; +#define match_address(rdata, idx, addr, ts, lt, pref) \ + G_STMT_START { \ + const NMNDiscData *_rdata = (rdata); \ + guint _idx = (idx); \ + const NMNDiscAddress *_a; \ + \ + g_assert (_rdata); \ + g_assert_cmpint (_idx, <, _rdata->addresses_n); \ + g_assert (_rdata->addresses); \ + \ + _a = &_rdata->addresses[_idx]; \ + \ + nmtst_assert_ip6_address (&_a->address, (addr)); \ + g_assert_cmpint (_a->timestamp, ==, (ts)); \ + g_assert_cmpint (_a->lifetime, ==, (lt)); \ + g_assert_cmpint (_a->preferred, ==, (pref)); \ + } G_STMT_END - g_assert (rdata); - g_assert_cmpint (idx, <, rdata->addresses_n); - g_assert (rdata->addresses); - - a = &rdata->addresses[idx]; - - g_assert_cmpstr (inet_ntop (AF_INET6, &a->address, buf, sizeof (buf)), ==, addr); - g_assert_cmpint (a->timestamp, ==, ts); - g_assert_cmpint (a->lifetime, ==, lt); - g_assert_cmpint (a->preferred, ==, preferred); -} - -static void -match_route (const NMNDiscData *rdata, guint idx, const char *nw, int plen, const char *gw, guint32 ts, guint32 lt, NMIcmpv6RouterPref pref) -{ - const NMNDiscRoute *route; - char buf[INET6_ADDRSTRLEN]; - - g_assert (rdata); - g_assert_cmpint (idx, <, rdata->routes_n); - g_assert (rdata->routes); - g_assert (plen > 0 && plen <= 128); - - route = &rdata->routes[idx]; - - g_assert_cmpstr (inet_ntop (AF_INET6, &route->network, buf, sizeof (buf)), ==, nw); - g_assert_cmpint ((int) route->plen, ==, plen); - g_assert_cmpstr (inet_ntop (AF_INET6, &route->gateway, buf, sizeof (buf)), ==, gw); - g_assert_cmpint (route->timestamp, ==, ts); - g_assert_cmpint (route->lifetime, ==, lt); - g_assert_cmpint (route->preference, ==, pref); -} +#define match_route(rdata, idx, nw, pl, gw, ts, lt, pref) \ + G_STMT_START { \ + const NMNDiscData *_rdata = (rdata); \ + guint _idx = (idx); \ + const NMNDiscRoute *_r; \ + int _plen = (pl); \ + \ + g_assert (_rdata); \ + g_assert_cmpint (_idx, <, _rdata->routes_n); \ + g_assert (_rdata->routes); \ + g_assert (_plen > 0 && _plen <= 128); \ + \ + _r = &_rdata->routes[idx]; \ + \ + nmtst_assert_ip6_address (&_r->network, (nw)); \ + g_assert_cmpint ((int) _r->plen, ==, _plen); \ + nmtst_assert_ip6_address (&_r->gateway, (gw)); \ + g_assert_cmpint (_r->timestamp, ==, (ts)); \ + g_assert_cmpint (_r->lifetime, ==, (lt)); \ + g_assert_cmpint (_r->preference, ==, (pref)); \ + } G_STMT_END static void match_dns_server (const NMNDiscData *rdata, guint idx, const char *addr, guint32 ts, guint32 lt) From 348e3addc8cecd7da9aed8a98c75d3acac1ea1a2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 2 Jul 2020 23:14:01 +0200 Subject: [PATCH 2/4] ndisc/tests: relax the assertion in "test-ndisc-fake.c" test:ERROR:../src/ndisc/tests/test-ndisc-fake.c:373:test_preference_changed_cb: assertion failed (_a->timestamp == (data->timestamp1 + 3)): (9 == 10) (cherry picked from commit 8209095ee1c462c69d5203cdef11c61bfb0aa546) (cherry picked from commit 75177f69675557c3ff2508eb75285396849d625e) (cherry picked from commit c32f993486395bb1a0050c09d290c290da44bb1b) (cherry picked from commit 712194ac8ca3bfbc4da0fbdb2ca4118f10b6f759) --- src/ndisc/tests/test-ndisc-fake.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ndisc/tests/test-ndisc-fake.c b/src/ndisc/tests/test-ndisc-fake.c index 9cd6f64637..da3c5e5698 100644 --- a/src/ndisc/tests/test-ndisc-fake.c +++ b/src/ndisc/tests/test-ndisc-fake.c @@ -66,6 +66,7 @@ match_gateway (const NMNDiscData *rdata, guint idx, const char *addr, guint32 ts const NMNDiscData *_rdata = (rdata); \ guint _idx = (idx); \ const NMNDiscAddress *_a; \ + guint _ts = (ts); \ \ g_assert (_rdata); \ g_assert_cmpint (_idx, <, _rdata->addresses_n); \ @@ -74,7 +75,8 @@ match_gateway (const NMNDiscData *rdata, guint idx, const char *addr, guint32 ts _a = &_rdata->addresses[_idx]; \ \ nmtst_assert_ip6_address (&_a->address, (addr)); \ - g_assert_cmpint (_a->timestamp, ==, (ts)); \ + g_assert_cmpint (_a->timestamp, >=, _ts); \ + g_assert_cmpint (_a->timestamp, <=, _ts + 1); \ g_assert_cmpint (_a->lifetime, ==, (lt)); \ g_assert_cmpint (_a->preferred, ==, (pref)); \ } G_STMT_END @@ -384,7 +386,7 @@ test_preference_changed_cb (NMNDisc *ndisc, const NMNDiscData *rdata, guint chan match_gateway (rdata, 0, "fe80::1", data->timestamp1 + 2, 10, NM_ICMPV6_ROUTER_PREF_HIGH); match_gateway (rdata, 1, "fe80::2", data->timestamp1 + 1, 10, NM_ICMPV6_ROUTER_PREF_MEDIUM); g_assert_cmpint (rdata->addresses_n, ==, 2); - match_address (rdata, 0, "2001:db8:a:a::1", data->timestamp1 + 3, 9, 9); + match_address (rdata, 0, "2001:db8:a:a::1", data->timestamp1 + 2, 9, 9); match_address (rdata, 1, "2001:db8:a:b::1", data->timestamp1 + 1, 10, 10); g_assert_cmpint (rdata->routes_n, ==, 2); match_route (rdata, 0, "2001:db8:a:a::", 64, "fe80::1", data->timestamp1 + 2, 10, 15); From 781849c029b0585bc435cd5ca72bc55c9aeddd5c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 3 Jul 2020 19:27:13 +0200 Subject: [PATCH 3/4] ndisc/tests: fix assertion in "test-ndisc-fake.c" First I wanted to fix test:ERROR:../src/ndisc/tests/test-ndisc-fake.c:373:test_preference_changed_cb: assertion failed (_a->timestamp == (data->timestamp1 + 3)): (9 == 10) but that leads to a different failure: test:ERROR:../src/ndisc/tests/test-ndisc-fake.c:375:test_preference_changed_cb: assertion failed (_a->lifetime == (9)): (10 == 9) Instead, the start and end times must match exact (in their duration), we only allow them to be shifted by up to one second. Fixes: 8209095ee1c4 ('ndisc/tests: relax the assertion in "test-ndisc-fake.c"') (cherry picked from commit b2f03544a7947c3157f987f630e6c473cacbb53a) (cherry picked from commit 838777a891f6999daee3b14cbad74a5e0bd06203) (cherry picked from commit 1470212f4cf3d1f078ac5ca3be1dae28b4e53a1f) (cherry picked from commit 6f2731b6cbf8aa4784d3cd5c9a03c92493fa3846) --- src/ndisc/tests/test-ndisc-fake.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ndisc/tests/test-ndisc-fake.c b/src/ndisc/tests/test-ndisc-fake.c index da3c5e5698..af623e508e 100644 --- a/src/ndisc/tests/test-ndisc-fake.c +++ b/src/ndisc/tests/test-ndisc-fake.c @@ -77,8 +77,8 @@ match_gateway (const NMNDiscData *rdata, guint idx, const char *addr, guint32 ts nmtst_assert_ip6_address (&_a->address, (addr)); \ g_assert_cmpint (_a->timestamp, >=, _ts); \ g_assert_cmpint (_a->timestamp, <=, _ts + 1); \ - g_assert_cmpint (_a->lifetime, ==, (lt)); \ - g_assert_cmpint (_a->preferred, ==, (pref)); \ + g_assert_cmpint (_a->timestamp + _a->lifetime, ==, _ts + (lt)); \ + g_assert_cmpint (_a->timestamp + _a->preferred, ==, _ts + (pref)); \ } G_STMT_END #define match_route(rdata, idx, nw, pl, gw, ts, lt, pref) \ @@ -386,7 +386,7 @@ test_preference_changed_cb (NMNDisc *ndisc, const NMNDiscData *rdata, guint chan match_gateway (rdata, 0, "fe80::1", data->timestamp1 + 2, 10, NM_ICMPV6_ROUTER_PREF_HIGH); match_gateway (rdata, 1, "fe80::2", data->timestamp1 + 1, 10, NM_ICMPV6_ROUTER_PREF_MEDIUM); g_assert_cmpint (rdata->addresses_n, ==, 2); - match_address (rdata, 0, "2001:db8:a:a::1", data->timestamp1 + 2, 9, 9); + match_address (rdata, 0, "2001:db8:a:a::1", data->timestamp1 + 3, 9, 9); match_address (rdata, 1, "2001:db8:a:b::1", data->timestamp1 + 1, 10, 10); g_assert_cmpint (rdata->routes_n, ==, 2); match_route (rdata, 0, "2001:db8:a:a::", 64, "fe80::1", data->timestamp1 + 2, 10, 15); From b00b4dadfb75984a30ded8fedaff2e67c609c0f8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 7 Jul 2020 22:28:44 +0200 Subject: [PATCH 4/4] ndisc/tests: relax assertion in "test-ndisc-fake.c" Still assertion failures: ERROR:../src/ndisc/tests/test-ndisc-fake.c:375:test_preference_changed_cb: assertion failed (_a->timestamp >= _ts): (9 >= 10) (cherry picked from commit a5133e708e85e02b9cbf199c0840e00f118b59c7) (cherry picked from commit 75e8f4c36f640362841d232ad2aa1b591f35bb8e) (cherry picked from commit 80dbc0f17bb4d1142ab103ed8bb2965df7929e52) (cherry picked from commit e6f235d9710c67e869d381604aaa58e4e6bc1447) --- src/ndisc/tests/test-ndisc-fake.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ndisc/tests/test-ndisc-fake.c b/src/ndisc/tests/test-ndisc-fake.c index af623e508e..3930d4acc4 100644 --- a/src/ndisc/tests/test-ndisc-fake.c +++ b/src/ndisc/tests/test-ndisc-fake.c @@ -75,8 +75,8 @@ match_gateway (const NMNDiscData *rdata, guint idx, const char *addr, guint32 ts _a = &_rdata->addresses[_idx]; \ \ nmtst_assert_ip6_address (&_a->address, (addr)); \ - g_assert_cmpint (_a->timestamp, >=, _ts); \ g_assert_cmpint (_a->timestamp, <=, _ts + 1); \ + g_assert_cmpint ((int) _a->timestamp, >=, (int) _ts - 1); \ g_assert_cmpint (_a->timestamp + _a->lifetime, ==, _ts + (lt)); \ g_assert_cmpint (_a->timestamp + _a->preferred, ==, _ts + (pref)); \ } G_STMT_END