SoW-2020-0002: Trace Hit Counters
[lttng-tools.git] / tests / unit / test_condition.c
index 3b0144a0aae9994c4e212758b75290f7b04afbcf..539e0b0b663300737a617c577470fc179c446c37 100644 (file)
 #include <lttng/event.h>
 #include <lttng/event-rule/tracepoint.h>
 #include <lttng/condition/condition-internal.h>
-#include <lttng/condition/event-rule.h>
+#include <lttng/condition/on-event.h>
+#include <lttng/condition/on-event-internal.h>
 #include <lttng/domain.h>
+#include <lttng/log-level-rule.h>
 #include <common/dynamic-buffer.h>
 #include <common/buffer-view.h>
 
@@ -30,7 +32,7 @@ int lttng_opt_quiet = 1;
 int lttng_opt_verbose;
 int lttng_opt_mi;
 
-#define NUM_TESTS 13
+#define NUM_TESTS 15
 
 static
 void test_condition_event_rule(void)
@@ -45,10 +47,16 @@ void test_condition_event_rule(void)
        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" };
+       uint64_t _error_count = 420, _error_counter_index = 9999, error_count, error_counter_index;
+       struct lttng_log_level_rule *log_level_rule_at_least_as_severe = NULL;
        struct lttng_payload buffer;
 
        lttng_payload_init(&buffer);
 
+       /* Create log level rule */
+       log_level_rule_at_least_as_severe = lttng_log_level_rule_at_least_as_severe_as_create(LTTNG_LOGLEVEL_WARNING);
+       assert(log_level_rule_at_least_as_severe);
+
        tracepoint = lttng_event_rule_tracepoint_create(LTTNG_DOMAIN_UST);
        ok(tracepoint, "tracepoint UST_DOMAIN");
 
@@ -58,8 +66,7 @@ void test_condition_event_rule(void)
        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);
+       status = lttng_event_rule_tracepoint_set_log_level_rule(tracepoint, log_level_rule_at_least_as_severe);
        ok(status == LTTNG_EVENT_RULE_STATUS_OK, "Setting log level range");
 
        for (i = 0; i < 3; i++) {
@@ -69,10 +76,14 @@ void test_condition_event_rule(void)
                                "Setting exclusion pattern");
        }
 
-       condition = lttng_condition_event_rule_create(tracepoint);
+       condition = lttng_condition_on_event_create(tracepoint);
        ok(condition, "Created condition");
 
-       condition_status = lttng_condition_event_rule_get_rule(
+       /* Set the error count information */
+       lttng_condition_on_event_set_error_count(condition, _error_count);
+       lttng_condition_on_event_set_error_counter_index(condition, _error_counter_index);
+
+       condition_status = lttng_condition_on_event_get_rule(
                        condition, &tracepoint_tmp);
        ok(condition_status == LTTNG_CONDITION_STATUS_OK,
                        "Getting event rule from event rule condition");
@@ -94,10 +105,17 @@ void test_condition_event_rule(void)
        ok(lttng_condition_is_equal(condition, condition_from_buffer),
                        "Serialized and de-serialized conditions are equal");
 
+       /* Error count info is not considered in is_equal so test it separately */
+       error_count = lttng_condition_on_event_get_error_count(condition_from_buffer);
+       error_counter_index = lttng_condition_on_event_get_error_counter_index(condition_from_buffer);
+       ok(error_count == _error_count, "Error count is the same. Got %" PRIu64 " Expected %" PRIu64, error_count, _error_count);
+       ok(error_counter_index == _error_counter_index, "Error count index is the same. Got %" PRIu64 " Expected %" PRIu64, error_count, _error_count);
+
        lttng_payload_reset(&buffer);
        lttng_event_rule_destroy(tracepoint);
        lttng_condition_destroy(condition);
        lttng_condition_destroy(condition_from_buffer);
+       lttng_log_level_rule_destroy(log_level_rule_at_least_as_severe);
 }
 
 int main(int argc, const char *argv[])
This page took 0.025385 seconds and 5 git commands to generate.