Run clang-format on the whole tree
[lttng-tools.git] / tests / unit / test_rate_policy.cpp
index 755bfca029e4e95f3b90ddb13e06e08740c86df5..1c2c46961d5fe595d5552a8470f9c5fd87525a02 100644 (file)
@@ -7,18 +7,18 @@
  *
  */
 
-#include <inttypes.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <tap/tap.h>
-
 #include <common/payload-view.hpp>
 #include <common/payload.hpp>
+
 #include <lttng/action/rate-policy-internal.hpp>
 #include <lttng/action/rate-policy.h>
 
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <tap/tap.h>
+#include <unistd.h>
+
 /* For error.h. */
 int lttng_opt_quiet = 1;
 int lttng_opt_verbose;
@@ -43,90 +43,65 @@ static void test_rate_policy_every_n(void)
        policy_a = lttng_rate_policy_every_n_create(interval_a_b);
        policy_b = lttng_rate_policy_every_n_create(interval_a_b);
        policy_c = lttng_rate_policy_every_n_create(interval_c);
-       ok(policy_a != NULL,
-                       "Rate policy every n A created: interval: %" PRIu64,
-                       interval_a_b);
-       ok(policy_b != NULL,
-                       "Rate policy every n B created: interval: %" PRIu64,
-                       interval_a_b);
-       ok(policy_c != NULL,
-                       "Rate policy every n C created: interval: %" PRIu64,
-                       interval_c);
-
-       ok(LTTNG_RATE_POLICY_TYPE_EVERY_N ==
-                                       lttng_rate_policy_get_type(policy_a),
-                       "Type is LTTNG_RATE_POLICY_TYPE_EVERY_N");
+       ok(policy_a != NULL, "Rate policy every n A created: interval: %" PRIu64, interval_a_b);
+       ok(policy_b != NULL, "Rate policy every n B created: interval: %" PRIu64, interval_a_b);
+       ok(policy_c != NULL, "Rate policy every n C created: interval: %" PRIu64, interval_c);
+
+       ok(LTTNG_RATE_POLICY_TYPE_EVERY_N == lttng_rate_policy_get_type(policy_a),
+          "Type is LTTNG_RATE_POLICY_TYPE_EVERY_N");
 
        /* Getter tests */
        status = lttng_rate_policy_every_n_get_interval(NULL, NULL);
-       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID,
-                       "Get interval returns INVALID");
+       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID, "Get interval returns INVALID");
 
        status = lttng_rate_policy_every_n_get_interval(NULL, &interval_query);
-       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID,
-                       "Get interval returns INVALID");
+       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID, "Get interval returns INVALID");
 
        status = lttng_rate_policy_every_n_get_interval(policy_a, NULL);
-       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID,
-                       "Get interval returns INVALID");
-
-       status = lttng_rate_policy_every_n_get_interval(
-                       policy_a, &interval_query);
-       ok(status == LTTNG_RATE_POLICY_STATUS_OK &&
-                                       interval_query == interval_a_b,
-                       " Getting interval A");
-
-       status = lttng_rate_policy_every_n_get_interval(
-                       policy_b, &interval_query);
-       ok(status == LTTNG_RATE_POLICY_STATUS_OK &&
-                                       interval_query == interval_a_b,
-                       " Getting interval B");
-
-       status = lttng_rate_policy_every_n_get_interval(
-                       policy_c, &interval_query);
-       ok(status == LTTNG_RATE_POLICY_STATUS_OK &&
-                                       interval_query == interval_c,
-                       " Getting interval C");
+       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID, "Get interval returns INVALID");
+
+       status = lttng_rate_policy_every_n_get_interval(policy_a, &interval_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_OK && interval_query == interval_a_b,
+          " Getting interval A");
+
+       status = lttng_rate_policy_every_n_get_interval(policy_b, &interval_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_OK && interval_query == interval_a_b,
+          " Getting interval B");
+
+       status = lttng_rate_policy_every_n_get_interval(policy_c, &interval_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_OK && interval_query == interval_c,
+          " Getting interval C");
 
        /* is_equal tests */
        /* TODO: this is the behaviour introduced by the
         * lttng_condition_is_equal back in 2017 do we want to fix this and
         * return true if both are NULL?
         */
-       ok(false == lttng_rate_policy_is_equal(NULL, NULL),
-                       "is equal (NULL,NULL)");
-       ok(false == lttng_rate_policy_is_equal(policy_a, NULL),
-                       "is equal (object, NULL)");
-       ok(false == lttng_rate_policy_is_equal(NULL, policy_a),
-                       " is equal (NULL, object)");
-       ok(true == lttng_rate_policy_is_equal(policy_a, policy_a),
-                       "is equal (object A, object A)");
-
-       ok(true == lttng_rate_policy_is_equal(policy_a, policy_b),
-                       "is equal (object A, object B");
-       ok(true == lttng_rate_policy_is_equal(policy_b, policy_a),
-                       "is equal (object B, object A");
+       ok(false == lttng_rate_policy_is_equal(NULL, NULL), "is equal (NULL,NULL)");
+       ok(false == lttng_rate_policy_is_equal(policy_a, NULL), "is equal (object, NULL)");
+       ok(false == lttng_rate_policy_is_equal(NULL, policy_a), " is equal (NULL, object)");
+       ok(true == lttng_rate_policy_is_equal(policy_a, policy_a), "is equal (object A, object A)");
+
+       ok(true == lttng_rate_policy_is_equal(policy_a, policy_b), "is equal (object A, object B");
+       ok(true == lttng_rate_policy_is_equal(policy_b, policy_a), "is equal (object B, object A");
 
        ok(false == lttng_rate_policy_is_equal(policy_a, policy_c),
-                       "is equal (object A, object C)");
+          "is equal (object A, object C)");
        ok(false == lttng_rate_policy_is_equal(policy_c, policy_a),
-                       "is equal (object C, object A)");
+          "is equal (object C, object A)");
 
        /* Serialization and create_from buffer. */
        ok(lttng_rate_policy_serialize(policy_a, &payload) == 0, "Serializing");
        {
-               struct lttng_payload_view view =
-                               lttng_payload_view_from_payload(
-                                               &payload, 0, -1);
-
-               ok(lttng_rate_policy_create_from_payload(
-                                  &view, &policy_from_buffer) > 0 &&
-                                               policy_from_buffer != NULL,
-                               "Deserializing");
+               struct lttng_payload_view view = lttng_payload_view_from_payload(&payload, 0, -1);
+
+               ok(lttng_rate_policy_create_from_payload(&view, &policy_from_buffer) > 0 &&
+                          policy_from_buffer != NULL,
+                  "Deserializing");
        }
 
        ok(lttng_rate_policy_is_equal(policy_a, policy_from_buffer),
-                       "serialized and from buffer are equal");
+          "serialized and from buffer are equal");
 
        lttng_rate_policy_destroy(policy_a);
        lttng_rate_policy_destroy(policy_b);
@@ -152,87 +127,61 @@ static void test_rate_policy_once_after_n(void)
        policy_a = lttng_rate_policy_once_after_n_create(threshold_a_b);
        policy_b = lttng_rate_policy_once_after_n_create(threshold_a_b);
        policy_c = lttng_rate_policy_once_after_n_create(threshold_c);
-       ok(policy_a != NULL,
-                       "Rate policy every n A created: threshold: %" PRIu64,
-                       threshold_a_b);
-       ok(policy_b != NULL,
-                       "Rate policy every n B created: threshold: %" PRIu64,
-                       threshold_a_b);
-       ok(policy_c != NULL,
-                       "Rate policy every n C created: threshold: %" PRIu64,
-                       threshold_c);
-
-       ok(LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N ==
-                                       lttng_rate_policy_get_type(policy_a),
-                       "Type is LTTNG_RATE_POLICY_TYPE_once_after_n");
+       ok(policy_a != NULL, "Rate policy every n A created: threshold: %" PRIu64, threshold_a_b);
+       ok(policy_b != NULL, "Rate policy every n B created: threshold: %" PRIu64, threshold_a_b);
+       ok(policy_c != NULL, "Rate policy every n C created: threshold: %" PRIu64, threshold_c);
+
+       ok(LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N == lttng_rate_policy_get_type(policy_a),
+          "Type is LTTNG_RATE_POLICY_TYPE_once_after_n");
 
        /* Getter tests */
        status = lttng_rate_policy_once_after_n_get_threshold(NULL, NULL);
-       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID,
-                       "Get threshold returns INVALID");
+       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID, "Get threshold returns INVALID");
 
-       status = lttng_rate_policy_once_after_n_get_threshold(
-                       NULL, &threshold_query);
-       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID,
-                       "Get threshold returns INVALID");
+       status = lttng_rate_policy_once_after_n_get_threshold(NULL, &threshold_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID, "Get threshold returns INVALID");
 
        status = lttng_rate_policy_once_after_n_get_threshold(policy_a, NULL);
-       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID,
-                       "Get threshold returns INVALID");
-
-       status = lttng_rate_policy_once_after_n_get_threshold(
-                       policy_a, &threshold_query);
-       ok(status == LTTNG_RATE_POLICY_STATUS_OK &&
-                                       threshold_query == threshold_a_b,
-                       " Getting threshold A");
-
-       status = lttng_rate_policy_once_after_n_get_threshold(
-                       policy_b, &threshold_query);
-       ok(status == LTTNG_RATE_POLICY_STATUS_OK &&
-                                       threshold_query == threshold_a_b,
-                       " Getting threshold B");
-
-       status = lttng_rate_policy_once_after_n_get_threshold(
-                       policy_c, &threshold_query);
-       ok(status == LTTNG_RATE_POLICY_STATUS_OK &&
-                                       threshold_query == threshold_c,
-                       " Getting threshold C");
+       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID, "Get threshold returns INVALID");
+
+       status = lttng_rate_policy_once_after_n_get_threshold(policy_a, &threshold_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_OK && threshold_query == threshold_a_b,
+          " Getting threshold A");
+
+       status = lttng_rate_policy_once_after_n_get_threshold(policy_b, &threshold_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_OK && threshold_query == threshold_a_b,
+          " Getting threshold B");
+
+       status = lttng_rate_policy_once_after_n_get_threshold(policy_c, &threshold_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_OK && threshold_query == threshold_c,
+          " Getting threshold C");
 
        /* is_equal tests */
-       ok(false == lttng_rate_policy_is_equal(NULL, NULL),
-                       "is equal (NULL,NULL)");
-       ok(false == lttng_rate_policy_is_equal(policy_a, NULL),
-                       "is equal (object, NULL)");
-       ok(false == lttng_rate_policy_is_equal(NULL, policy_a),
-                       " is equal (NULL, object)");
-       ok(true == lttng_rate_policy_is_equal(policy_a, policy_a),
-                       "is equal (object A, object A)");
-
-       ok(true == lttng_rate_policy_is_equal(policy_a, policy_b),
-                       "is equal (object A, object B");
-       ok(true == lttng_rate_policy_is_equal(policy_b, policy_a),
-                       "is equal (object B, object A");
+       ok(false == lttng_rate_policy_is_equal(NULL, NULL), "is equal (NULL,NULL)");
+       ok(false == lttng_rate_policy_is_equal(policy_a, NULL), "is equal (object, NULL)");
+       ok(false == lttng_rate_policy_is_equal(NULL, policy_a), " is equal (NULL, object)");
+       ok(true == lttng_rate_policy_is_equal(policy_a, policy_a), "is equal (object A, object A)");
+
+       ok(true == lttng_rate_policy_is_equal(policy_a, policy_b), "is equal (object A, object B");
+       ok(true == lttng_rate_policy_is_equal(policy_b, policy_a), "is equal (object B, object A");
 
        ok(false == lttng_rate_policy_is_equal(policy_a, policy_c),
-                       "is equal (object A, object C)");
+          "is equal (object A, object C)");
        ok(false == lttng_rate_policy_is_equal(policy_c, policy_a),
-                       "is equal (object C, object A)");
+          "is equal (object C, object A)");
 
        /* Serialization and create_from buffer. */
        ok(lttng_rate_policy_serialize(policy_a, &payload) == 0, "Serializing");
        {
-               struct lttng_payload_view view =
-                               lttng_payload_view_from_payload(
-                                               &payload, 0, -1);
-
-               ok(lttng_rate_policy_create_from_payload(
-                                  &view, &policy_from_buffer) > 0 &&
-                                               policy_from_buffer != NULL,
-                               "Deserializing");
+               struct lttng_payload_view view = lttng_payload_view_from_payload(&payload, 0, -1);
+
+               ok(lttng_rate_policy_create_from_payload(&view, &policy_from_buffer) > 0 &&
+                          policy_from_buffer != NULL,
+                  "Deserializing");
        }
 
        ok(lttng_rate_policy_is_equal(policy_a, policy_from_buffer),
-                       "serialized and from buffer are equal");
+          "serialized and from buffer are equal");
 
        lttng_rate_policy_destroy(policy_a);
        lttng_rate_policy_destroy(policy_b);
This page took 0.025767 seconds and 4 git commands to generate.