Commit | Line | Data |
---|---|---|
5024c2ac JR |
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 3 | |
34 | ||
35 | static | |
36 | void test_condition_event_rule(void) | |
37 | { | |
38 | int ret; | |
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_dynamic_buffer buffer; | |
49 | struct lttng_buffer_view view; | |
50 | ||
51 | lttng_dynamic_buffer_init(&buffer); | |
52 | ||
53 | tracepoint = lttng_event_rule_tracepoint_create(LTTNG_DOMAIN_UST); | |
54 | ok(tracepoint, "tracepoint UST_DOMAIN"); | |
55 | ||
56 | status = lttng_event_rule_tracepoint_set_pattern(tracepoint, pattern); | |
57 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting pattern"); | |
58 | ||
59 | status = lttng_event_rule_tracepoint_set_filter(tracepoint, filter); | |
60 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting filter"); | |
61 | ||
62 | status = lttng_event_rule_tracepoint_set_loglevel_range(tracepoint, LTTNG_LOGLEVEL_WARNING); | |
63 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting range loglevel"); | |
64 | ||
65 | status = lttng_event_rule_tracepoint_set_exclusions(tracepoint, 3, exclusions); | |
66 | ok(status == LTTNG_EVENT_RULE_STATUS_OK, "setting exclusions"); | |
67 | ||
68 | condition = lttng_condition_event_rule_create(tracepoint); | |
69 | ok(condition, "created condition"); | |
70 | ||
71 | condition_status = lttng_condition_event_rule_get_rule(condition, &tracepoint_tmp); | |
72 | ok(condition_status == LTTNG_CONDITION_STATUS_OK, "getting event rule"); | |
73 | ok(tracepoint == tracepoint_tmp, "Ownership transfer is good"); | |
74 | ||
75 | ret = lttng_condition_serialize(condition, &buffer, NULL); | |
76 | ok(ret == 0, "Condition serialized"); | |
77 | ||
78 | view = lttng_buffer_view_from_dynamic_buffer(&buffer, 0, -1); | |
79 | (void) lttng_condition_create_from_buffer(&view, &condition_from_buffer); | |
80 | ok(condition_from_buffer, "condition from buffer is non null"); | |
81 | ||
82 | ok(lttng_condition_is_equal(condition, condition_from_buffer), "serialized and from buffer are equal"); | |
83 | ||
84 | lttng_dynamic_buffer_reset(&buffer); | |
85 | lttng_condition_destroy(condition); | |
86 | lttng_condition_destroy(condition_from_buffer); | |
87 | } | |
88 | ||
89 | int main(int argc, const char *argv[]) | |
90 | { | |
91 | plan_tests(NUM_TESTS); | |
92 | test_condition_event_rule(); | |
93 | return exit_status(); | |
94 | } |