From: Jonathan Rajotte Date: Wed, 4 Dec 2019 19:30:38 +0000 (-0500) Subject: Tests: unit: lttng_condition_event_rule X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=d17cfa5dfb6045cffbc7a726954eef2220f2806e;p=lttng-tools.git Tests: unit: lttng_condition_event_rule Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: I281df3b2267d6ddf3b0591d181b7f276802d8963 --- diff --git a/.gitignore b/.gitignore index 2032177ea..6313f131c 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 8e2703726..8ce735890 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -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 index 000000000..3b0144a0a --- /dev/null +++ b/tests/unit/test_condition.c @@ -0,0 +1,108 @@ +/* + * test_condition.c + * + * Unit tests for the condition API. + * + * Copyright (C) 2019 Jonathan Rajotte + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +/* 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(); +}