Implement statedump unit test
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 15 Dec 2023 21:44:47 +0000 (16:44 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 15 Dec 2023 21:52:59 +0000 (16:52 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
.gitignore
tests/Makefile.am
tests/unit/statedump.c [new file with mode: 0644]

index 71ee6c8be9e719286f07cadfcaa84f2829a8def6..06a13f80c471e6c79fdaadfbf236f5ade464dbed 100644 (file)
@@ -65,6 +65,7 @@ dkms.conf
 /tests/unit/.dirstamp
 /tests/unit/demo
 /tests/unit/test
+/tests/unit/statedump
 
 #automake
 /include/config.h
index e83a23900f7aef68f624322d3228a90b0332285d..e92b7f4217147eb415311f552a698981e42e1844 100644 (file)
@@ -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 (file)
index 0000000..c2541f0
--- /dev/null
@@ -0,0 +1,71 @@
+#include <side/trace.h>
+
+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;
+}
This page took 0.02631 seconds and 4 git commands to generate.