summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-05 09:56:23 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-05 09:56:23 +0000
commitc15d6efd40655f717841d00839a43df1ead5cb26 (patch)
tree35d579f9a19170e2b39085669ca92533c2d161b4 /tests/lib
parentAdding upstream version 10.0.1. (diff)
downloadfrr-c15d6efd40655f717841d00839a43df1ead5cb26.tar.xz
frr-c15d6efd40655f717841d00839a43df1ead5cb26.zip
Adding upstream version 10.1.upstream/10.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/northbound/test_oper_data.c47
-rw-r--r--tests/lib/northbound/test_oper_data.in1
-rw-r--r--tests/lib/northbound/test_oper_data.refout2
-rw-r--r--tests/lib/subdir.am4
-rw-r--r--tests/lib/test_printfrr.c24
5 files changed, 75 insertions, 3 deletions
diff --git a/tests/lib/northbound/test_oper_data.c b/tests/lib/northbound/test_oper_data.c
index 8f7e7c5..321f158 100644
--- a/tests/lib/northbound/test_oper_data.c
+++ b/tests/lib/northbound/test_oper_data.c
@@ -14,6 +14,7 @@
#include "lib_vty.h"
#include "log.h"
#include "northbound.h"
+#include "northbound_cli.h"
static struct event_loop *master;
@@ -200,6 +201,19 @@ static struct yang_data *frr_test_module_vrfs_vrf_routes_route_active_get_elem(
return NULL;
}
+/*
+ * XPath: /frr-test-module:frr-test-module/vrfs/vrf/ping
+ */
+static int frr_test_module_vrfs_vrf_ping(struct nb_cb_rpc_args *args)
+{
+ const char *vrf = yang_dnode_get_string(args->input, "../name");
+ const char *data = yang_dnode_get_string(args->input, "data");
+
+ yang_dnode_rpc_output_add(args->output, "vrf", vrf);
+ yang_dnode_rpc_output_add(args->output, "data-out", data);
+
+ return NB_OK;
+}
/*
* XPath: /frr-test-module:frr-test-module/c1value
@@ -263,6 +277,10 @@ 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/vrfs/vrf/ping",
+ .cbs.rpc = frr_test_module_vrfs_vrf_ping,
+ },
+ {
.xpath = "/frr-test-module:frr-test-module/c1value",
.cbs.get_elem = frr_test_module_c1value_get_elem,
},
@@ -277,6 +295,33 @@ const struct frr_yang_module_info frr_test_module_info = {
};
/* clang-format on */
+DEFUN(test_rpc, test_rpc_cmd, "test rpc",
+ "Test\n"
+ "RPC\n")
+{
+ struct lyd_node *output = NULL;
+ char xpath[XPATH_MAXLEN];
+ int ret;
+
+ snprintf(xpath, sizeof(xpath),
+ "/frr-test-module:frr-test-module/vrfs/vrf[name='testname']/ping");
+
+ nb_cli_rpc_enqueue(vty, "data", "testdata");
+
+ ret = nb_cli_rpc(vty, xpath, &output);
+ if (ret != CMD_SUCCESS) {
+ vty_out(vty, "RPC failed\n");
+ return ret;
+ }
+
+ vty_out(vty, "vrf %s data %s\n", yang_dnode_get_string(output, "vrf"),
+ yang_dnode_get_string(output, "data-out"));
+
+ yang_dnode_free(output);
+
+ return CMD_SUCCESS;
+}
+
static const struct frr_yang_module_info *const modules[] = {
&frr_test_module_info,
};
@@ -416,6 +461,8 @@ int main(int argc, char **argv)
lib_cmd_init();
nb_init(master, modules, array_size(modules), false);
+ install_element(ENABLE_NODE, &test_rpc_cmd);
+
/* Create artificial data. */
create_data(num_vrfs, num_interfaces, num_routes);
diff --git a/tests/lib/northbound/test_oper_data.in b/tests/lib/northbound/test_oper_data.in
index a6c4f87..f7c44ca 100644
--- a/tests/lib/northbound/test_oper_data.in
+++ b/tests/lib/northbound/test_oper_data.in
@@ -1 +1,2 @@
show yang operational-data /frr-test-module:frr-test-module
+test rpc
diff --git a/tests/lib/northbound/test_oper_data.refout b/tests/lib/northbound/test_oper_data.refout
index aa930fe..7c56564 100644
--- a/tests/lib/northbound/test_oper_data.refout
+++ b/tests/lib/northbound/test_oper_data.refout
@@ -119,5 +119,7 @@ test# show yang operational-data /frr-test-module:frr-test-module
}
}
}
+test# test rpc
+vrf testname data testdata
test#
end.
diff --git a/tests/lib/subdir.am b/tests/lib/subdir.am
index 94df362..185b895 100644
--- a/tests/lib/subdir.am
+++ b/tests/lib/subdir.am
@@ -34,6 +34,10 @@ tests_lib_test_grpc_CXXFLAGS = $(WERROR) $(TESTS_CXXFLAGS)
tests_lib_test_grpc_CPPFLAGS = $(TESTS_CPPFLAGS)
tests_lib_test_grpc_LDADD = $(GRPC_TESTS_LDADD)
tests_lib_test_grpc_SOURCES = tests/lib/test_grpc.cpp
+nodist_tests_lib_test_grpc_SOURCES = \
+ yang/frr-bfdd.yang.c \
+ yang/frr-staticd.yang.c \
+ # end
##############################################################################
diff --git a/tests/lib/test_printfrr.c b/tests/lib/test_printfrr.c
index 66699ec..a81ebcd 100644
--- a/tests/lib/test_printfrr.c
+++ b/tests/lib/test_printfrr.c
@@ -143,6 +143,8 @@ int main(int argc, char **argv)
NAN,
};
uint64_t ui64 = 0xfeed1278cafef00d;
+ uint16_t i16 = -23456;
+ int_fast8_t if8 = 123;
struct in_addr ip;
char *p;
char buf[256];
@@ -169,6 +171,16 @@ int main(int argc, char **argv)
FMT_NSTD(printchk("11110000000011111010010111000011", "%b", 0xf00fa5c3));
FMT_NSTD(printchk("0b01011010", "%#010b", 0x5a));
+/* FMT_NSTD is conditional on the frr-format plugin being NOT enabled.
+ * However, the frr-format plugin does not support %wd/%wfd yet, so this needs
+ * to be unconditional.
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat"
+ printchk("123 -23456 feed1278cafef00d 9876", "%wf8d %w16d %w64x %d",
+ if8, i16, ui64, 9876);
+#pragma GCC diagnostic pop
+
inet_aton("192.168.1.2", &ip);
printchk("192.168.1.2", "%pI4", &ip);
printchk(" 192.168.1.2", "%20pI4", &ip);
@@ -218,19 +230,25 @@ int main(int argc, char **argv)
printchk("02:ca:fe:f0:0d:1e", "%pFXh", &pfx);
struct prefix_sg sg;
- sg.src.s_addr = INADDR_ANY;
+ SET_IPADDR_V4(&sg.src);
+ sg.src.ipaddr_v4.s_addr = INADDR_ANY;
sg.grp.s_addr = INADDR_ANY;
printchk("(*,*)", "%pPSG4", &sg);
- inet_aton("192.168.1.2", &sg.src);
+ inet_aton("192.168.1.2", &sg.src.ipaddr_v4);
printchk("(192.168.1.2,*)", "%pPSG4", &sg);
inet_aton("224.1.2.3", &sg.grp);
printchk("(192.168.1.2,224.1.2.3)", "%pPSG4", &sg);
- sg.src.s_addr = INADDR_ANY;
+ SET_IPADDR_NONE(&sg.src);
+ sg.src.ipaddr_v4.s_addr = INADDR_ANY;
printchk("(*,224.1.2.3)", "%pPSG4", &sg);
+ SET_IPADDR_V6(&sg.src);
+ inet_pton(AF_INET6, "1:2:3:4::5", &sg.src.ipaddr_v6);
+ printchk("(1:2:3:4::5,224.1.2.3)", "%pPSG4", &sg);
+
uint8_t randhex[] = { 0x12, 0x34, 0x00, 0xca, 0xfe, 0x00, 0xaa, 0x55 };
FMT_NSTD(printchk("12 34 00 ca fe 00 aa 55", "%.8pHX", randhex));