4 * Unit tests for the notification API.
6 * Copyright (C) 2017 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
8 * SPDX-License-Identifier: MIT
20 #include <common/payload-view.h>
21 #include <common/payload.h>
22 #include <lttng/action/action-internal.h>
23 #include <lttng/action/action.h>
24 #include <lttng/action/firing-policy-internal.h>
25 #include <lttng/action/firing-policy.h>
26 #include <lttng/action/notify.h>
29 int lttng_opt_quiet
= 1;
30 int lttng_opt_verbose
;
35 static void test_action_notify(void)
38 enum lttng_action_status status
;
39 struct lttng_action
*notify_action
= NULL
,
40 *notify_action_from_buffer
= NULL
;
41 struct lttng_firing_policy
*policy
= NULL
, *default_policy
;
42 struct lttng_payload payload
;
44 lttng_payload_init(&payload
);
47 policy
= lttng_firing_policy_every_n_create(100);
49 default_policy
= lttng_firing_policy_every_n_create(1);
51 assert(policy
&& default_policy
);
53 notify_action
= lttng_action_notify_create();
54 ok(notify_action
, "Create notify action");
55 ok(lttng_action_get_type(notify_action
) == LTTNG_ACTION_TYPE_NOTIFY
,
56 "Action has type LTTNG_ACTION_TYPE_NOTIFY");
58 /* Validate the default policy for a notify action. */
60 const struct lttng_firing_policy
*cur_policy
= NULL
;
61 status
= lttng_action_notify_get_firing_policy(
62 notify_action
, &cur_policy
);
63 ok(status
== LTTNG_ACTION_STATUS_OK
&&
64 lttng_firing_policy_is_equal(
67 "Default policy is every n=1");
70 /* Set a custom policy. */
71 status
= lttng_action_notify_set_firing_policy(notify_action
, policy
);
72 ok(status
== LTTNG_ACTION_STATUS_OK
, "Set firing policy");
74 /* Validate the custom policy for a notify action. */
76 const struct lttng_firing_policy
*cur_policy
= NULL
;
77 status
= lttng_action_notify_get_firing_policy(
78 notify_action
, &cur_policy
);
79 ok(status
== LTTNG_ACTION_STATUS_OK
&&
80 lttng_firing_policy_is_equal(
83 "Notify action policy get");
86 ret
= lttng_action_serialize(notify_action
, &payload
);
87 ok(ret
== 0, "Action notify serialized");
90 struct lttng_payload_view view
=
91 lttng_payload_view_from_payload(
93 (void) lttng_action_create_from_payload(
94 &view
, ¬ify_action_from_buffer
);
96 ok(notify_action_from_buffer
,
97 "Notify action created from payload is non-null");
99 ok(lttng_action_is_equal(notify_action
, notify_action_from_buffer
),
100 "Serialized and de-serialized notify action are equal");
102 lttng_firing_policy_destroy(default_policy
);
103 lttng_firing_policy_destroy(policy
);
104 lttng_action_destroy(notify_action
);
105 lttng_action_destroy(notify_action_from_buffer
);
106 lttng_payload_reset(&payload
);
109 int main(int argc
, const char *argv
[])
111 plan_tests(NUM_TESTS
);
112 test_action_notify();
113 return exit_status();