SoW-2020-0002: Trace Hit Counters: trigger error reporting integration
[lttng-tools.git] / tests / unit / test_condition.c
1 /*
2 * test_condition.c
3 *
4 * Unit tests for the condition API.
5 *
6 * Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
7 *
8 * SPDX-License-Identifier: GPL-2.0-only
9 *
10 */
11
12 #include <assert.h>
13 #include <inttypes.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <unistd.h>
17
18 #include <tap/tap.h>
19
20 #include <lttng/event.h>
21 #include <lttng/event-rule/tracepoint.h>
22 #include <lttng/condition/condition-internal.h>
23 #include <lttng/condition/event-rule.h>
24 #include <lttng/domain.h>
25 #include <common/dynamic-buffer.h>
26 #include <common/buffer-view.h>
27
28 /* For error.h */
29 int lttng_opt_quiet = 1;
30 int lttng_opt_verbose;
31 int lttng_opt_mi;
32
33 #define NUM_TESTS 11
34
35 static
36 void test_condition_event_rule(void)
37 {
38 int ret, i;
39 struct lttng_event_rule *tracepoint = NULL;
40 const struct lttng_event_rule *tracepoint_tmp = NULL;
41 enum lttng_event_rule_status status;
42 struct lttng_condition *condition = NULL;
43 struct lttng_condition *condition_from_buffer = NULL;
44 enum lttng_condition_status condition_status;
45 const char *pattern="my_event_*";
46 const char *filter="msg_id == 23 && size >= 2048";
47 const char *exclusions[] = {"my_event_test1", "my_event_test2" ,"my_event_test3"};
48 struct lttng_payload buffer;
49
50 lttng_payload_init(&buffer);
51
52 tracepoint = lttng_event_rule_tracepoint_create(LTTNG_DOMAIN_UST);
53 ok(tracepoint, "tracepoint UST_DOMAIN");
54
55 status = lttng_event_rule_tracepoint_set_pattern(tracepoint, pattern);
56 ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern");
57
58 status = lttng_event_rule_tracepoint_set_filter(tracepoint, filter);
59 ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter");
60
61 status = lttng_event_rule_tracepoint_set_log_level_range_lower_bound(tracepoint, LTTNG_LOGLEVEL_WARNING);
62 ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting range loglevel");
63
64 for (i=0; i < 3; i++) {
65 status = lttng_event_rule_tracepoint_add_exclusion(tracepoint, exclusions[i]);
66 ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting exclusions");
67 }
68
69 condition = lttng_condition_event_rule_create(tracepoint);
70 ok(condition, "created condition");
71
72 condition_status = lttng_condition_event_rule_get_rule(condition, &tracepoint_tmp);
73 ok(condition_status == LTTNG_CONDITION_STATUS_OK, "getting event rule");
74 ok(tracepoint == tracepoint_tmp, "Ownership transfer is good");
75
76 ret = lttng_condition_serialize(condition, &buffer);
77 ok(ret == 0, "Condition serialized");
78
79 {
80 struct lttng_payload_view view = lttng_payload_view_from_payload(&buffer, 0, -1);
81 (void) lttng_condition_create_from_payload(&view, &condition_from_buffer);
82 }
83 ok(condition_from_buffer, "condition from buffer is non null");
84
85 ok(lttng_condition_is_equal(condition, condition_from_buffer), "serialized and from buffer are equal");
86
87 lttng_payload_reset(&buffer);
88 lttng_event_rule_destroy(tracepoint);
89 lttng_condition_destroy(condition);
90 lttng_condition_destroy(condition_from_buffer);
91 }
92
93 int main(int argc, const char *argv[])
94 {
95 plan_tests(NUM_TESTS);
96 test_condition_event_rule();
97 return exit_status();
98 }
This page took 0.044466 seconds and 5 git commands to generate.