Commit | Line | Data |
---|---|---|
1831ae68 FD |
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 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
9 | * of this software and associated documentation files (the "Software"), to deal | |
10 | * in the Software without restriction, including without limitation the rights | |
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
12 | * copies of the Software, and to permit persons to whom the Software is | |
13 | * furnished to do so, subject to the following conditions: | |
14 | * | |
15 | * The above copyright notice and this permission notice shall be included in | |
16 | * all copies or substantial portions of the Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
24 | * SOFTWARE. | |
25 | */ | |
26 | ||
27 | #include <assert.h> | |
28 | #include <inttypes.h> | |
29 | #include <stdio.h> | |
30 | #include <string.h> | |
31 | #include <unistd.h> | |
32 | ||
33 | #include <tap/tap.h> | |
34 | ||
35 | #include <lttng/event.h> | |
36 | #include <lttng/event-rule/tracepoint.h> | |
37 | #include <lttng/condition/condition-internal.h> | |
38 | #include <lttng/condition/event-rule.h> | |
39 | #include <lttng/domain.h> | |
40 | #include <common/dynamic-buffer.h> | |
41 | #include <common/buffer-view.h> | |
42 | ||
43 | /* For error.h */ | |
44 | int lttng_opt_quiet = 1; | |
45 | int lttng_opt_verbose; | |
46 | int lttng_opt_mi; | |
47 | ||
48 | #define NUM_TESTS 3 | |
49 | ||
50 | void test_condition_event_rule(void) | |
51 | { | |
52 | int ret; | |
53 | struct lttng_event_rule *tracepoint = NULL; | |
54 | const struct lttng_event_rule *tracepoint_tmp = NULL; | |
55 | enum lttng_event_rule_status status; | |
56 | struct lttng_condition *condition = NULL; | |
57 | struct lttng_condition *condition_from_buffer = NULL; | |
58 | enum lttng_condition_status condition_status; | |
59 | const char *pattern="my_event_*"; | |
60 | const char *filter="msg_id == 23 && size >= 2048"; | |
61 | const char *exclusions[] = {"my_event_test1", "my_event_test2" ,"my_event_test3"}; | |
62 | struct lttng_dynamic_buffer buffer; | |
63 | struct lttng_buffer_view view; | |
64 | ||
65 | lttng_dynamic_buffer_init(&buffer); | |
66 | ||
67 | tracepoint = lttng_event_rule_tracepoint_create(LTTNG_DOMAIN_UST); | |
68 | ok(tracepoint, "tracepoint UST_DOMAIN"); | |
69 | ||
70 | status = lttng_event_rule_tracepoint_set_pattern(tracepoint, pattern); | |
71 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern"); | |
72 | ||
73 | status = lttng_event_rule_tracepoint_set_filter(tracepoint, filter); | |
74 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter"); | |
75 | ||
76 | status = lttng_event_rule_tracepoint_set_loglevel_range(tracepoint, LTTNG_LOGLEVEL_WARNING); | |
77 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting range loglevel"); | |
78 | ||
79 | status = lttng_event_rule_tracepoint_set_exclusions(tracepoint, 3, exclusions); | |
80 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting exclusions"); | |
81 | ||
82 | condition = lttng_condition_event_rule_create(tracepoint); | |
83 | ok(condition, "created condition"); | |
84 | ||
85 | condition_status = lttng_condition_event_rule_get_rule(condition, &tracepoint_tmp); | |
86 | ok(condition_status == LTTNG_CONDITION_STATUS_OK, "getting event rule"); | |
87 | ok(tracepoint == tracepoint_tmp, "Ownership transfer is good"); | |
88 | ||
89 | ret = lttng_condition_serialize(condition, &buffer, NULL); | |
90 | ok(ret == 0, "Condition serialized"); | |
91 | ||
92 | view = lttng_buffer_view_from_dynamic_buffer(&buffer, 0, -1); | |
93 | (void) lttng_condition_create_from_buffer(&view, &condition_from_buffer); | |
94 | ok(condition_from_buffer, "condition from buffer is non null"); | |
95 | ||
96 | ok(lttng_condition_is_equal(condition, condition_from_buffer), "serialized and from buffer are equal"); | |
97 | ||
98 | lttng_dynamic_buffer_reset(&buffer); | |
99 | lttng_condition_destroy(condition); | |
100 | lttng_condition_destroy(condition_from_buffer); | |
101 | } | |
102 | ||
103 | int main(int argc, const char *argv[]) | |
104 | { | |
105 | plan_tests(NUM_TESTS); | |
106 | test_condition_event_rule(); | |
107 | return exit_status(); | |
108 | } |