From 8424ff797105f9119d8c8e1464670d9c468a1dd8 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 15 Dec 2023 16:44:47 -0500 Subject: [PATCH] Implement statedump unit test Signed-off-by: Mathieu Desnoyers --- .gitignore | 1 + tests/Makefile.am | 9 +++++- tests/unit/statedump.c | 71 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tests/unit/statedump.c diff --git a/.gitignore b/.gitignore index 71ee6c8..06a13f8 100644 --- a/.gitignore +++ b/.gitignore @@ -65,6 +65,7 @@ dkms.conf /tests/unit/.dirstamp /tests/unit/demo /tests/unit/test +/tests/unit/statedump #automake /include/config.h diff --git a/tests/Makefile.am b/tests/Makefile.am index e83a239..e92b7f4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -15,7 +15,8 @@ TAP_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' \ noinst_PROGRAMS = \ regression/side-rcu-test \ unit/test \ - unit/demo + unit/demo \ + unit/statedump regression_side_rcu_test_SOURCES = regression/side-rcu-test.c regression_side_rcu_test_LDADD = \ @@ -36,5 +37,11 @@ unit_demo_LDADD = \ $(top_builddir)/tests/utils/libtap.la \ $(RSEQ_LIBS) +unit_statedump_SOURCES = unit/statedump.c +unit_statedump_LDADD = \ + $(top_builddir)/src/libside.la \ + $(top_builddir)/tests/utils/libtap.la \ + $(RSEQ_LIBS) + # Currently no tap tests to run TESTS = diff --git a/tests/unit/statedump.c b/tests/unit/statedump.c new file mode 100644 index 0000000..c2541f0 --- /dev/null +++ b/tests/unit/statedump.c @@ -0,0 +1,71 @@ +#include + +static +const char *mystr[] = { + "abc", + "def", + "ghi", +}; + +static +int myint[] = { + 0, 1, 2, 3, 4, 5, +}; + +side_static_event(my_provider_event_dump1, "myprovider", "myevent_dump1", SIDE_LOGLEVEL_DEBUG, + side_field_list(side_field_string("mystatestring")) +); + +side_static_event(my_provider_event_dump2, "myprovider", "myevent_dump2", SIDE_LOGLEVEL_DEBUG, + side_field_list(side_field_s32("mystateint")) +); + +side_static_event(my_provider_event, "myprovider", "myevent", SIDE_LOGLEVEL_DEBUG, + side_field_list(side_field_s32("myfield")) +); + +static struct side_statedump_request_handle *statedump_request_handle; + +static +void statedump_cb(void) +{ + size_t i; + + printf("Executing application state dump callback\n"); + side_event_cond(my_provider_event_dump1) { + for (i = 0; i < SIDE_ARRAY_SIZE(mystr); i++) { + side_statedump_event_call(my_provider_event_dump1, + side_arg_list(side_arg_string(mystr[i]))); + } + } + side_event_cond(my_provider_event_dump2) { + for (i = 0; i < SIDE_ARRAY_SIZE(myint); i++) { + side_statedump_event_call(my_provider_event_dump2, + side_arg_list(side_arg_s32(myint[i]))); + } + } +} + +static void my_constructor(void) + __attribute((constructor)); +static void my_constructor(void) +{ + side_event_description_ptr_init(); + statedump_request_handle = side_statedump_request_notification_register(statedump_cb); + if (!statedump_request_handle) + abort(); +} + +static void my_destructor(void) + __attribute((destructor)); +static void my_destructor(void) +{ + side_statedump_request_notification_unregister(statedump_request_handle); + side_event_description_ptr_exit(); +} + +int main() +{ + side_event(my_provider_event, side_arg_list(side_arg_s32(42))); + return 0; +} -- 2.34.1