Tests: unit: lttng_condition_event_rule
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Wed, 4 Dec 2019 19:30:38 +0000 (14:30 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 24 Nov 2020 20:03:14 +0000 (15:03 -0500)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I281df3b2267d6ddf3b0591d181b7f276802d8963

.gitignore
tests/unit/Makefile.am
tests/unit/test_condition.c [new file with mode: 0644]

index 2032177eabfb1c0e25110a641ba22ac9a416ba9d..6313f131ceaa3573c82fda4ccca975bbd0ffae52 100644 (file)
@@ -91,6 +91,7 @@ compile_commands.json
 /tests/unit/test_fd_tracker
 /tests/unit/test_payload
 /tests/unit/test_event_rule
+/tests/unit/test_condition
 /tests/unit/test_unix_socket
 kernel_all_events_basic
 kernel_event_basic
index 8e2703726e9d8e64bf88e9c8377abb25314585dd..8ce735890241c65574c4a14ed1cf75416951bcda 100644 (file)
@@ -50,6 +50,7 @@ noinst_PROGRAMS = test_uri test_session test_kernel_data \
                   test_payload \
                   test_unix_socket \
                   test_kernel_probe \
+                  test_condition \
                   test_event_rule 
 
 if HAVE_LIBLTTNG_UST_CTL
@@ -204,6 +205,10 @@ test_notification_LDADD = $(LIBTAP) $(LIBLTTNG_CTL) $(DL_LIBS)
 test_event_rule_SOURCES = test_event_rule.c
 test_event_rule_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBLTTNG_CTL) $(DL_LIBS)
 
+# Condition api
+test_condition_SOURCES = test_condition.c
+test_condition_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBLTTNG_CTL) $(DL_LIBS)
+
 # relayd backward compat for groou-by-session utilities
 test_relayd_backward_compat_group_by_session_SOURCES = test_relayd_backward_compat_group_by_session.c
 test_relayd_backward_compat_group_by_session_LDADD = $(LIBTAP) $(LIBCOMMON) $(RELAYD_OBJS)
diff --git a/tests/unit/test_condition.c b/tests/unit/test_condition.c
new file mode 100644 (file)
index 0000000..3b0144a
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * test_condition.c
+ *
+ * Unit tests for the condition API.
+ *
+ * Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-only
+ *
+ */
+
+#include <assert.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <tap/tap.h>
+
+#include <lttng/event.h>
+#include <lttng/event-rule/tracepoint.h>
+#include <lttng/condition/condition-internal.h>
+#include <lttng/condition/event-rule.h>
+#include <lttng/domain.h>
+#include <common/dynamic-buffer.h>
+#include <common/buffer-view.h>
+
+/* For error.h */
+int lttng_opt_quiet = 1;
+int lttng_opt_verbose;
+int lttng_opt_mi;
+
+#define NUM_TESTS 13
+
+static
+void test_condition_event_rule(void)
+{
+       int ret, i;
+       struct lttng_event_rule *tracepoint = NULL;
+       const struct lttng_event_rule *tracepoint_tmp = NULL;
+       enum lttng_event_rule_status status;
+       struct lttng_condition *condition = NULL;
+       struct lttng_condition *condition_from_buffer = NULL;
+       enum lttng_condition_status condition_status;
+       const char *pattern="my_event_*";
+       const char *filter="msg_id == 23 && size >= 2048";
+       const char *exclusions[] = { "my_event_test1", "my_event_test2", "my_event_test3" };
+       struct lttng_payload buffer;
+
+       lttng_payload_init(&buffer);
+
+       tracepoint = lttng_event_rule_tracepoint_create(LTTNG_DOMAIN_UST);
+       ok(tracepoint, "tracepoint UST_DOMAIN");
+
+       status = lttng_event_rule_tracepoint_set_pattern(tracepoint, pattern);
+       ok(status == LTTNG_EVENT_RULE_STATUS_OK, "Setting pattern");
+
+       status = lttng_event_rule_tracepoint_set_filter(tracepoint, filter);
+       ok(status == LTTNG_EVENT_RULE_STATUS_OK, "Setting filter");
+
+       status = lttng_event_rule_tracepoint_set_log_level_range_lower_bound(
+                       tracepoint, LTTNG_LOGLEVEL_WARNING);
+       ok(status == LTTNG_EVENT_RULE_STATUS_OK, "Setting log level range");
+
+       for (i = 0; i < 3; i++) {
+               status = lttng_event_rule_tracepoint_add_exclusion(
+                               tracepoint, exclusions[i]);
+               ok(status == LTTNG_EVENT_RULE_STATUS_OK,
+                               "Setting exclusion pattern");
+       }
+
+       condition = lttng_condition_event_rule_create(tracepoint);
+       ok(condition, "Created condition");
+
+       condition_status = lttng_condition_event_rule_get_rule(
+                       condition, &tracepoint_tmp);
+       ok(condition_status == LTTNG_CONDITION_STATUS_OK,
+                       "Getting event rule from event rule condition");
+       ok(tracepoint == tracepoint_tmp, "lttng_condition_event_rule_get_rule provides a reference to the original rule");
+
+       ret = lttng_condition_serialize(condition, &buffer);
+       ok(ret == 0, "Condition serialized");
+
+       {
+               struct lttng_payload_view view =
+                               lttng_payload_view_from_payload(&buffer, 0, -1);
+
+               (void) lttng_condition_create_from_payload(
+                               &view, &condition_from_buffer);
+       }
+
+       ok(condition_from_buffer, "Condition created from payload is non-null");
+
+       ok(lttng_condition_is_equal(condition, condition_from_buffer),
+                       "Serialized and de-serialized conditions are equal");
+
+       lttng_payload_reset(&buffer);
+       lttng_event_rule_destroy(tracepoint);
+       lttng_condition_destroy(condition);
+       lttng_condition_destroy(condition_from_buffer);
+}
+
+int main(int argc, const char *argv[])
+{
+       plan_tests(NUM_TESTS);
+       test_condition_event_rule();
+       return exit_status();
+}
This page took 0.027469 seconds and 4 git commands to generate.