diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 04:24:34 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 04:24:34 +0000 |
commit | 137ce8dd46d313f15ee93ddbb5428d702aa61ed8 (patch) | |
tree | a49f76849019651842962dff2197b705e33831e7 /tests/lib | |
parent | Releasing progress-linux version 9.1-0.1~progress7.99u1. (diff) | |
download | frr-137ce8dd46d313f15ee93ddbb5428d702aa61ed8.tar.xz frr-137ce8dd46d313f15ee93ddbb5428d702aa61ed8.zip |
Merging upstream version 10.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/cli/common_cli.c | 1 | ||||
-rw-r--r-- | tests/lib/northbound/test_oper_data.c | 28 | ||||
-rw-r--r-- | tests/lib/northbound/test_oper_data.refout | 4 | ||||
-rw-r--r-- | tests/lib/subdir.am | 3 | ||||
-rw-r--r-- | tests/lib/test_darr.c | 145 | ||||
-rw-r--r-- | tests/lib/test_darr.py | 8 | ||||
-rw-r--r-- | tests/lib/test_frrlua.c | 12 | ||||
-rw-r--r-- | tests/lib/test_frrscript.c | 4 | ||||
-rw-r--r-- | tests/lib/test_grpc.cpp | 6 | ||||
-rw-r--r-- | tests/lib/test_heavy_wq.c | 6 | ||||
-rw-r--r-- | tests/lib/test_privs.c | 1 |
11 files changed, 204 insertions, 14 deletions
diff --git a/tests/lib/cli/common_cli.c b/tests/lib/cli/common_cli.c index e0981b9..f9f584f 100644 --- a/tests/lib/cli/common_cli.c +++ b/tests/lib/cli/common_cli.c @@ -7,6 +7,7 @@ */ #include <zebra.h> +#include <sys/stat.h> #include "frrevent.h" #include "vty.h" diff --git a/tests/lib/northbound/test_oper_data.c b/tests/lib/northbound/test_oper_data.c index f82eddd..8f7e7c5 100644 --- a/tests/lib/northbound/test_oper_data.c +++ b/tests/lib/northbound/test_oper_data.c @@ -5,6 +5,7 @@ */ #include <zebra.h> +#include <sys/stat.h> #include "frrevent.h" #include "vty.h" @@ -199,6 +200,25 @@ static struct yang_data *frr_test_module_vrfs_vrf_routes_route_active_get_elem( return NULL; } + +/* + * XPath: /frr-test-module:frr-test-module/c1value + */ +static struct yang_data * +frr_test_module_c1value_get_elem(struct nb_cb_get_elem_args *args) +{ + return yang_data_new_uint8(args->xpath, 21); +} + +/* + * XPath: /frr-test-module:frr-test-module/c2cont/c2value + */ +static struct yang_data * +frr_test_module_c2cont_c2value_get_elem(struct nb_cb_get_elem_args *args) +{ + return yang_data_new_uint32(args->xpath, 0xAB010203); +} + /* clang-format off */ const struct frr_yang_module_info frr_test_module_info = { .name = "frr-test-module", @@ -243,6 +263,14 @@ const struct frr_yang_module_info frr_test_module_info = { .cbs.get_elem = frr_test_module_vrfs_vrf_routes_route_active_get_elem, }, { + .xpath = "/frr-test-module:frr-test-module/c1value", + .cbs.get_elem = frr_test_module_c1value_get_elem, + }, + { + .xpath = "/frr-test-module:frr-test-module/c2cont/c2value", + .cbs.get_elem = frr_test_module_c2cont_c2value_get_elem, + }, + { .xpath = NULL, }, } diff --git a/tests/lib/northbound/test_oper_data.refout b/tests/lib/northbound/test_oper_data.refout index 57ecd2f..aa930fe 100644 --- a/tests/lib/northbound/test_oper_data.refout +++ b/tests/lib/northbound/test_oper_data.refout @@ -112,6 +112,10 @@ test# show yang operational-data /frr-test-module:frr-test-module }
}
]
+ },
+ "c1value": 21,
+ "c2cont": {
+ "c2value": 2868969987
}
}
}
diff --git a/tests/lib/subdir.am b/tests/lib/subdir.am index 6c1be50..94df362 100644 --- a/tests/lib/subdir.am +++ b/tests/lib/subdir.am @@ -25,7 +25,7 @@ copy_script: tests/lib/script1.lua $(INSTALL_SCRIPT) $< tests/lib/script1.lua ############################################################################## -GRPC_TESTS_LDADD = staticd/libstatic.a grpc/libfrrgrpc_pb.la -lgrpc++ -lprotobuf $(ALL_TESTS_LDADD) $(LIBYANG_LIBS) -lm +GRPC_TESTS_LDADD = mgmtd/libmgmt_be_nb.la staticd/libstatic.a grpc/libfrrgrpc_pb.la $(GRPC_LIBS) $(ALL_TESTS_LDADD) $(LIBYANG_LIBS) -lm if GRPC check_PROGRAMS += tests/lib/test_grpc @@ -162,6 +162,7 @@ tests_lib_test_darr_CFLAGS = $(TESTS_CFLAGS) tests_lib_test_darr_CPPFLAGS = $(TESTS_CPPFLAGS) tests_lib_test_darr_LDADD = $(ALL_TESTS_LDADD) tests_lib_test_darr_SOURCES = tests/lib/test_darr.c +EXTRA_DIST += tests/lib/test_darr.py check_PROGRAMS += tests/lib/test_graph diff --git a/tests/lib/test_darr.c b/tests/lib/test_darr.c index 9150aed..74aedac 100644 --- a/tests/lib/test_darr.c +++ b/tests/lib/test_darr.c @@ -14,7 +14,8 @@ * [x] - darr_append_n * [x] - darr_append_nz * [x] - darr_cap - * [-] - darr_ensure_cap + * [x] - darr_ensure_avail + * [x] - darr_ensure_cap * [x] - darr_ensure_i * [x] - darr_foreach_i * [x] - darr_foreach_p @@ -23,6 +24,15 @@ * [ ] - darr_insertz * [x] - darr_insert_n * [x] - darr_insert_nz + * [x] - darr_in_sprintf + * [x] - darr_in_strcat + * [x] - darr_in_strcat_tail + * [ ] - darr_in_strcatf + * [ ] - darr_in_vstrcatf + * [x] - darr_in_strdup + * [x] - darr_in_strdup_cap + * [-] - darr_in_vsprintf + * [x] - darr_lasti * [x] - darr_maxi * [x] - darr_pop * [x] - darr_push @@ -31,6 +41,13 @@ * [x] - darr_remove_n * [x] - darr_reset * [x] - darr_setlen + * [x] - darr_set_strlen + * [x] - darr_sprintf + * [x] - darr_strdup + * [x] - darr_strdup_cap + * [x] - darr_strlen + * [x] - darr_strnul + * [ ] - darr_vsprintf */ static void test_int(void) @@ -43,6 +60,11 @@ static void test_int(void) int *dap; uint i; + assert(darr_len(da1) == 0); + assert(darr_lasti(da1) == -1); + assert(darr_last(da1) == NULL); + assert(darr_end(da1) == NULL); + darr_ensure_i(da1, 0); da1[0] = 0; assert(darr_len(da1) == 1); @@ -57,9 +79,11 @@ static void test_int(void) da1[i] = i; assert(darr_len(da1) == 5); + assert(darr_lasti(da1) == 4); /* minimum non-pow2 array size for long long and smaller */ assert(darr_cap(da1) == 8); assert(!memcmp(da1, a1, sizeof(a1))); + assert(&da1[darr_lasti(da1)] == darr_last(da1)); /* reverse the numbers */ darr_foreach_p (da1, dap) @@ -185,6 +209,20 @@ static void test_struct(void) assert(darr_cap(da1) == 8); assert(!memcmp(da1, a1, sizeof(a1))); + assert(darr_cap(da1) - darr_len(da1) == 3); + darr_ensure_avail(da1, 2); + assert(darr_cap(da1) == 8); + darr_ensure_avail(da1, 3); + assert(darr_cap(da1) == 8); + darr_ensure_avail(da1, 4); + assert(darr_cap(da1) == 16); + + darr_ensure_cap(da1, 16); + assert(darr_cap(da1) == 16); + + darr_ensure_cap(da1, 20); + assert(darr_cap(da1) == 32); + darr_append_n(da1, 100); assert(darr_len(da1) == 105); @@ -272,8 +310,113 @@ static void test_struct(void) darr_free(da2); } +static void test_string(void) +{ + const char *src = "ABCDE"; + const char *add = "FGHIJ"; + uint srclen = strlen(src); + uint addlen = strlen(add); + char *da1 = NULL; + char *da2 = NULL; + + assert(darr_strlen(da1) == 0); + + da1 = darr_strdup(src); + assert(darr_strlen(da1) == strlen(da1)); + assert(darr_strlen(da1) == srclen); + assert(darr_len(da1) == srclen + 1); + assert(darr_ilen(da1) == (int)srclen + 1); + assert(darr_cap(da1) >= 8); + assert(darr_last(da1) == darr_strnul(da1)); + assert(darr_strnul(da1) == da1 + darr_strlen(da1)); + + da2 = da1; + darr_in_strdup(da1, src); + assert(da1 == da2); + assert(darr_strlen(da1) == strlen(da1)); + assert(darr_strlen(da1) == srclen); + assert(darr_len(da1) == srclen + 1); + darr_free(da1); + assert(da1 == NULL); + + da1 = darr_strdup_cap(src, 128); + assert(darr_strlen(da1) == srclen); + assert(darr_cap(da1) >= 128); + + darr_in_strdup_cap(da1, src, 256); + assert(darr_strlen(da1) == srclen); + assert(darr_cap(da1) >= 256); + darr_free(da1); + + da1 = darr_strdup_cap(add, 2); + assert(darr_strlen(da1) == addlen); + assert(darr_cap(da1) >= 8); + + darr_in_strdup(da1, "ab"); + darr_in_strcat(da1, "/"); + darr_in_strcat(da1, "foo"); + assert(!strcmp("ab/foo", da1)); + darr_free(da1); + + da1 = darr_in_strcat(da1, "ab"); + darr_in_strcat(da1, "/"); + darr_in_strcat(da1, "foo"); + assert(!strcmp("ab/foo", da1)); + + darr_set_strlen(da1, 5); + assert(!strcmp("ab/fo", da1)); + darr_set_strlen(da1, 1); + assert(!strcmp("a", da1)); + + darr_in_strdup(da1, "ab"); + da2 = darr_strdup(add); + darr_in_strcat_tail(da1, da2); + assert(!strcmp("abHIJ", da1)); + assert(darr_strlen(da1) == 5); + assert(darr_len(da1) == 6); + darr_free(da1); + darr_free(da2); + + da1 = darr_strdup("abcde"); + da2 = darr_strdup(add); + darr_in_strcat_tail(da1, da2); + assert(!strcmp("abcde", da1)); + assert(darr_strlen(da1) == 5); + assert(darr_len(da1) == 6); + darr_free(da1); + darr_free(da2); + + da1 = darr_sprintf("0123456789: %08X", 0xDEADBEEF); + assert(!strcmp(da1, "0123456789: DEADBEEF")); + assert(darr_strlen(da1) == 20); + assert(darr_cap(da1) == 128); + da2 = da1; + darr_in_sprintf(da1, "9876543210: %08x", 0x0BADF00D); + assert(da1 == da2); + assert(!strcmp("9876543210: 0badf00d", da2)); + darr_free(da1); + da2 = NULL; + + da1 = NULL; + darr_in_sprintf(da1, "0123456789: %08X", 0xDEADBEEF); + assert(!strcmp(da1, "0123456789: DEADBEEF")); + assert(darr_strlen(da1) == 20); + assert(darr_cap(da1) == 128); + darr_free(da1); + + da1 = darr_sprintf("0123456789: %08x", 0xDEADBEEF); + darr_in_strcatf(da1, " 9876543210: %08x", 0x0BADF00D); + assert(!strcmp("0123456789: deadbeef 9876543210: 0badf00d", da1)); + darr_free(da1); + + da1 = darr_in_strcatf(da1, "0123456789: %08x", 0xDEADBEEF); + assert(!strcmp("0123456789: deadbeef", da1)); + darr_free(da1); +} + int main(int argc, char **argv) { test_int(); test_struct(); + test_string(); } diff --git a/tests/lib/test_darr.py b/tests/lib/test_darr.py new file mode 100644 index 0000000..dea3bdf --- /dev/null +++ b/tests/lib/test_darr.py @@ -0,0 +1,8 @@ +import frrtest + + +class TestDarr(frrtest.TestMultiOut): + program = "./test_darr" + + +TestDarr.exit_cleanly() diff --git a/tests/lib/test_frrlua.c b/tests/lib/test_frrlua.c index 701e171..2760a27 100644 --- a/tests/lib/test_frrlua.c +++ b/tests/lib/test_frrlua.c @@ -13,14 +13,22 @@ static void test_encode_decode(void) { lua_State *L = luaL_newstate(); - long long a = 123; - long long b = a; + int a = 123; + int b = a; lua_pushintegerp(L, &a); lua_decode_integerp(L, -1, &a); assert(a == b); assert(lua_gettop(L) == 0); + long long ll_a = 123L; + long long ll_b = a; + + lua_pushlonglongp(L, &ll_a); + lua_decode_longlongp(L, -1, &ll_a); + assert(ll_a == ll_b); + assert(lua_gettop(L) == 0); + time_t time_a = 100; time_t time_b; diff --git a/tests/lib/test_frrscript.c b/tests/lib/test_frrscript.c index 7d4746c..9698aea 100644 --- a/tests/lib/test_frrscript.c +++ b/tests/lib/test_frrscript.c @@ -32,7 +32,7 @@ int main(int argc, char **argv) assert(result == 0); result = frrscript_call(fs, "bar", ("a", &a), ("b", &b)); assert(result == 0); - long long *cptr = frrscript_get_result(fs, "bar", "c", lua_tointegerp); + long long *cptr = frrscript_get_result(fs, "bar", "c", lua_tolonglongp); /* a should not occur in the returned table in script */ assert(a == 100); @@ -47,7 +47,7 @@ int main(int argc, char **argv) result = frrscript_call(fs, "fact", ("n", &n)); assert(result == 0); long long *ansptr = - frrscript_get_result(fs, "fact", "ans", lua_tointegerp); + frrscript_get_result(fs, "fact", "ans", lua_tolonglongp); assert(*ansptr == 120); /* check consecutive call + get_result without re-loading */ diff --git a/tests/lib/test_grpc.cpp b/tests/lib/test_grpc.cpp index 957ffde..2023136 100644 --- a/tests/lib/test_grpc.cpp +++ b/tests/lib/test_grpc.cpp @@ -119,8 +119,10 @@ static void static_startup(void) hook_register(routing_conf_event, routing_control_plane_protocols_name_validate); - - routing_control_plane_protocols_register_vrf_dependency(); + hook_register(routing_create, + routing_control_plane_protocols_staticd_create); + hook_register(routing_destroy, + routing_control_plane_protocols_staticd_destroy); // Add a route vty = vty_new(); diff --git a/tests/lib/test_heavy_wq.c b/tests/lib/test_heavy_wq.c index 225573a..8c2765c 100644 --- a/tests/lib/test_heavy_wq.c +++ b/tests/lib/test_heavy_wq.c @@ -76,12 +76,6 @@ static wq_item_status slow_func(struct work_queue *wq, void *data) for (j = 0; j < 300; j++) x += sin(x) * j; - if ((hn->i % ITERS_LATER) == 0) - return WQ_RETRY_LATER; - - if ((hn->i % ITERS_ERR) == 0) - return WQ_RETRY_NOW; - if ((hn->i % ITERS_PRINT) == 0) printf("%s did %d, x = %g\n", hn->str, hn->i, x); diff --git a/tests/lib/test_privs.c b/tests/lib/test_privs.c index e267548..caf55c7 100644 --- a/tests/lib/test_privs.c +++ b/tests/lib/test_privs.c @@ -3,6 +3,7 @@ */ #include <zebra.h> +#include <sys/stat.h> #include <lib/version.h> #include "getopt.h" |