Implement statedump unit test
[libside.git] / tests / unit / statedump.c
CommitLineData
8424ff79
MD
1#include <side/trace.h>
2
3static
4const char *mystr[] = {
5 "abc",
6 "def",
7 "ghi",
8};
9
10static
11int myint[] = {
12 0, 1, 2, 3, 4, 5,
13};
14
15side_static_event(my_provider_event_dump1, "myprovider", "myevent_dump1", SIDE_LOGLEVEL_DEBUG,
16 side_field_list(side_field_string("mystatestring"))
17);
18
19side_static_event(my_provider_event_dump2, "myprovider", "myevent_dump2", SIDE_LOGLEVEL_DEBUG,
20 side_field_list(side_field_s32("mystateint"))
21);
22
23side_static_event(my_provider_event, "myprovider", "myevent", SIDE_LOGLEVEL_DEBUG,
24 side_field_list(side_field_s32("myfield"))
25);
26
27static struct side_statedump_request_handle *statedump_request_handle;
28
29static
30void statedump_cb(void)
31{
32 size_t i;
33
34 printf("Executing application state dump callback\n");
35 side_event_cond(my_provider_event_dump1) {
36 for (i = 0; i < SIDE_ARRAY_SIZE(mystr); i++) {
37 side_statedump_event_call(my_provider_event_dump1,
38 side_arg_list(side_arg_string(mystr[i])));
39 }
40 }
41 side_event_cond(my_provider_event_dump2) {
42 for (i = 0; i < SIDE_ARRAY_SIZE(myint); i++) {
43 side_statedump_event_call(my_provider_event_dump2,
44 side_arg_list(side_arg_s32(myint[i])));
45 }
46 }
47}
48
49static void my_constructor(void)
50 __attribute((constructor));
51static void my_constructor(void)
52{
53 side_event_description_ptr_init();
54 statedump_request_handle = side_statedump_request_notification_register(statedump_cb);
55 if (!statedump_request_handle)
56 abort();
57}
58
59static void my_destructor(void)
60 __attribute((destructor));
61static void my_destructor(void)
62{
63 side_statedump_request_notification_unregister(statedump_request_handle);
64 side_event_description_ptr_exit();
65}
66
67int main()
68{
69 side_event(my_provider_event, side_arg_list(side_arg_s32(42)));
70 return 0;
71}
This page took 0.036713 seconds and 4 git commands to generate.