Introduce emission site for syscall event rule
[lttng-tools.git] / tests / unit / test_condition.c
CommitLineData
d17cfa5d
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>
e393070a 23#include <lttng/condition/on-event.h>
35a9ac41 24#include <lttng/condition/on-event-internal.h>
d17cfa5d 25#include <lttng/domain.h>
85b05318 26#include <lttng/log-level-rule.h>
d17cfa5d
JR
27#include <common/dynamic-buffer.h>
28#include <common/buffer-view.h>
29
30/* For error.h */
31int lttng_opt_quiet = 1;
32int lttng_opt_verbose;
33int lttng_opt_mi;
34
b006f85d 35#define NUM_TESTS 13
d17cfa5d
JR
36
37static
38void test_condition_event_rule(void)
39{
40 int ret, i;
41 struct lttng_event_rule *tracepoint = NULL;
42 const struct lttng_event_rule *tracepoint_tmp = NULL;
43 enum lttng_event_rule_status status;
44 struct lttng_condition *condition = NULL;
45 struct lttng_condition *condition_from_buffer = NULL;
46 enum lttng_condition_status condition_status;
47 const char *pattern="my_event_*";
48 const char *filter="msg_id == 23 && size >= 2048";
49 const char *exclusions[] = { "my_event_test1", "my_event_test2", "my_event_test3" };
85b05318 50 struct lttng_log_level_rule *log_level_rule_at_least_as_severe = NULL;
d17cfa5d
JR
51 struct lttng_payload buffer;
52
53 lttng_payload_init(&buffer);
54
85b05318
JR
55 /* Create log level rule. */
56 log_level_rule_at_least_as_severe =
57 lttng_log_level_rule_at_least_as_severe_as_create(
58 LTTNG_LOGLEVEL_WARNING);
59 assert(log_level_rule_at_least_as_severe);
60
d17cfa5d
JR
61 tracepoint = lttng_event_rule_tracepoint_create(LTTNG_DOMAIN_UST);
62 ok(tracepoint, "tracepoint UST_DOMAIN");
63
64 status = lttng_event_rule_tracepoint_set_pattern(tracepoint, pattern);
65 ok(status == LTTNG_EVENT_RULE_STATUS_OK, "Setting pattern");
66
67 status = lttng_event_rule_tracepoint_set_filter(tracepoint, filter);
68 ok(status == LTTNG_EVENT_RULE_STATUS_OK, "Setting filter");
69
85b05318
JR
70 status = lttng_event_rule_tracepoint_set_log_level_rule(
71 tracepoint, log_level_rule_at_least_as_severe);
d17cfa5d
JR
72 ok(status == LTTNG_EVENT_RULE_STATUS_OK, "Setting log level range");
73
74 for (i = 0; i < 3; i++) {
75 status = lttng_event_rule_tracepoint_add_exclusion(
76 tracepoint, exclusions[i]);
77 ok(status == LTTNG_EVENT_RULE_STATUS_OK,
78 "Setting exclusion pattern");
79 }
80
d602bd6a 81 condition = lttng_condition_on_event_create(tracepoint);
d17cfa5d
JR
82 ok(condition, "Created condition");
83
d602bd6a 84 condition_status = lttng_condition_on_event_get_rule(
d17cfa5d
JR
85 condition, &tracepoint_tmp);
86 ok(condition_status == LTTNG_CONDITION_STATUS_OK,
87 "Getting event rule from event rule condition");
88 ok(tracepoint == tracepoint_tmp, "lttng_condition_event_rule_get_rule provides a reference to the original rule");
89
90 ret = lttng_condition_serialize(condition, &buffer);
91 ok(ret == 0, "Condition serialized");
92
93 {
94 struct lttng_payload_view view =
95 lttng_payload_view_from_payload(&buffer, 0, -1);
96
97 (void) lttng_condition_create_from_payload(
98 &view, &condition_from_buffer);
99 }
100
101 ok(condition_from_buffer, "Condition created from payload is non-null");
102
103 ok(lttng_condition_is_equal(condition, condition_from_buffer),
104 "Serialized and de-serialized conditions are equal");
105
106 lttng_payload_reset(&buffer);
107 lttng_event_rule_destroy(tracepoint);
108 lttng_condition_destroy(condition);
109 lttng_condition_destroy(condition_from_buffer);
85b05318 110 lttng_log_level_rule_destroy(log_level_rule_at_least_as_severe);
d17cfa5d
JR
111}
112
113int main(int argc, const char *argv[])
114{
115 plan_tests(NUM_TESTS);
116 test_condition_event_rule();
117 return exit_status();
118}
This page took 0.027909 seconds and 4 git commands to generate.