tests: units: action: stop session
[lttng-tools.git] / tests / unit / test_action.c
index 30fe06e70f4584261934266a4454ead0ea598d2b..1b4a9f9aeed63d35006f1601c7ba5a68bfc65e4e 100644 (file)
 #include <lttng/action/firing-policy.h>
 #include <lttng/action/notify.h>
 #include <lttng/action/rotate-session.h>
+#include <lttng/action/start-session.h>
+#include <lttng/action/stop-session.h>
 
 /* For error.h */
 int lttng_opt_quiet = 1;
 int lttng_opt_verbose;
 int lttng_opt_mi;
 
-#define NUM_TESTS 21
+#define NUM_TESTS 47
 
 static void test_action_notify(void)
 {
@@ -212,10 +214,221 @@ static void test_action_rotate_session(void)
        lttng_payload_reset(&payload);
 }
 
+static void test_action_start_session(void)
+{
+       int ret;
+       enum lttng_action_status status;
+       struct lttng_action *start_session_action = NULL,
+                           *start_session_action_from_buffer = NULL;
+       struct lttng_firing_policy *policy = NULL, *default_policy;
+       struct lttng_payload payload;
+       const char *session_name = "my_session_name";
+       const char *get_session_name;
+
+       lttng_payload_init(&payload);
+
+       /* To set. */
+       policy = lttng_firing_policy_every_n_create(100);
+       /* For comparison. */
+       default_policy = lttng_firing_policy_every_n_create(1);
+
+       assert(policy && default_policy);
+
+       start_session_action = lttng_action_start_session_create();
+       ok(start_session_action, "Create start_session action");
+       ok(lttng_action_get_type(start_session_action) ==
+                                       LTTNG_ACTION_TYPE_START_SESSION,
+                       "Action has type LTTNG_ACTION_TYPE_START_SESSION");
+
+       /* Session name setter. */
+       status = lttng_action_start_session_set_session_name(NULL, NULL);
+       ok(status == LTTNG_ACTION_STATUS_INVALID,
+                       "Set session name (NULL,NULL) expect invalid");
+       status = lttng_action_start_session_set_session_name(
+                       start_session_action, NULL);
+       ok(status == LTTNG_ACTION_STATUS_INVALID,
+                       "Set session name (object,NULL) expect invalid");
+       status = lttng_action_start_session_set_session_name(
+                       NULL, session_name);
+       ok(status == LTTNG_ACTION_STATUS_INVALID,
+                       "Set session name (NULL,object) expect invalid");
+
+       /* Set the session name */
+       status = lttng_action_start_session_set_session_name(
+                       start_session_action, session_name);
+       ok(status == LTTNG_ACTION_STATUS_OK, "Set session name");
+
+       status = lttng_action_start_session_get_session_name(
+                       start_session_action, &get_session_name);
+       ok(status == LTTNG_ACTION_STATUS_OK &&
+                                       !strcmp(session_name, get_session_name),
+                       "Get session name, expected `%s` got `%s`",
+                       session_name, get_session_name);
+
+       /* Validate the default policy for a start_session action. */
+       {
+               const struct lttng_firing_policy *cur_policy = NULL;
+               status = lttng_action_start_session_get_firing_policy(
+                               start_session_action, &cur_policy);
+               ok(status == LTTNG_ACTION_STATUS_OK &&
+                                               lttng_firing_policy_is_equal(
+                                                               default_policy,
+                                                               cur_policy),
+                               "Default policy is every n=1");
+       }
+
+       /* Set a custom policy. */
+       status = lttng_action_start_session_set_firing_policy(
+                       start_session_action, policy);
+       ok(status == LTTNG_ACTION_STATUS_OK, "Set firing policy");
+
+       /* Validate the custom policy for a start_session action. */
+       {
+               const struct lttng_firing_policy *cur_policy = NULL;
+               status = lttng_action_start_session_get_firing_policy(
+                               start_session_action, &cur_policy);
+               ok(status == LTTNG_ACTION_STATUS_OK &&
+                                               lttng_firing_policy_is_equal(
+                                                               policy,
+                                                               cur_policy),
+                               "start_session action policy get");
+       }
+
+       /* Ser/des tests. */
+       ret = lttng_action_serialize(start_session_action, &payload);
+       ok(ret == 0, "Action start_session serialized");
+
+       {
+               struct lttng_payload_view view =
+                               lttng_payload_view_from_payload(
+                                               &payload, 0, -1);
+               (void) lttng_action_create_from_payload(
+                               &view, &start_session_action_from_buffer);
+       }
+       ok(start_session_action_from_buffer,
+                       "start_session action created from payload is non-null");
+
+       ok(lttng_action_is_equal(start_session_action,
+                          start_session_action_from_buffer),
+                       "Serialized and de-serialized start_session action are equal");
+
+       lttng_firing_policy_destroy(default_policy);
+       lttng_firing_policy_destroy(policy);
+       lttng_action_destroy(start_session_action);
+       lttng_action_destroy(start_session_action_from_buffer);
+       lttng_payload_reset(&payload);
+}
+
+static void test_action_stop_session(void)
+{
+       int ret;
+       enum lttng_action_status status;
+       struct lttng_action *stop_session_action = NULL,
+                           *stop_session_action_from_buffer = NULL;
+       struct lttng_firing_policy *policy = NULL, *default_policy;
+       struct lttng_payload payload;
+       const char *session_name = "my_session_name";
+       const char *get_session_name;
+
+       lttng_payload_init(&payload);
+
+       /* To set. */
+       policy = lttng_firing_policy_every_n_create(100);
+       /* For comparison. */
+       default_policy = lttng_firing_policy_every_n_create(1);
+
+       assert(policy && default_policy);
+
+       stop_session_action = lttng_action_stop_session_create();
+       ok(stop_session_action, "Create stop_session action");
+       ok(lttng_action_get_type(stop_session_action) ==
+                                       LTTNG_ACTION_TYPE_STOP_SESSION,
+                       "Action has type LTTNG_ACTION_TYPE_STOP_SESSION");
+
+       /* Session name setter. */
+       status = lttng_action_stop_session_set_session_name(NULL, NULL);
+       ok(status == LTTNG_ACTION_STATUS_INVALID,
+                       "Set session name (NULL,NULL) expect invalid");
+       status = lttng_action_stop_session_set_session_name(
+                       stop_session_action, NULL);
+       ok(status == LTTNG_ACTION_STATUS_INVALID,
+                       "Set session name (object,NULL) expect invalid");
+       status = lttng_action_stop_session_set_session_name(NULL, session_name);
+       ok(status == LTTNG_ACTION_STATUS_INVALID,
+                       "Set session name (NULL,object) expect invalid");
+
+       /* Set the session name */
+       status = lttng_action_stop_session_set_session_name(
+                       stop_session_action, session_name);
+       ok(status == LTTNG_ACTION_STATUS_OK, "Set session name");
+
+       status = lttng_action_stop_session_get_session_name(
+                       stop_session_action, &get_session_name);
+       ok(status == LTTNG_ACTION_STATUS_OK &&
+                                       !strcmp(session_name, get_session_name),
+                       "Get session name, expected `%s` got `%s`",
+                       session_name, get_session_name);
+
+       /* Validate the default policy for a stop_session action. */
+       {
+               const struct lttng_firing_policy *cur_policy = NULL;
+               status = lttng_action_stop_session_get_firing_policy(
+                               stop_session_action, &cur_policy);
+               ok(status == LTTNG_ACTION_STATUS_OK &&
+                                               lttng_firing_policy_is_equal(
+                                                               default_policy,
+                                                               cur_policy),
+                               "Default policy is every n=1");
+       }
+
+       /* Set a custom policy. */
+       status = lttng_action_stop_session_set_firing_policy(
+                       stop_session_action, policy);
+       ok(status == LTTNG_ACTION_STATUS_OK, "Set firing policy");
+
+       /* Validate the custom policy for a stop_session action. */
+       {
+               const struct lttng_firing_policy *cur_policy = NULL;
+               status = lttng_action_stop_session_get_firing_policy(
+                               stop_session_action, &cur_policy);
+               ok(status == LTTNG_ACTION_STATUS_OK &&
+                                               lttng_firing_policy_is_equal(
+                                                               policy,
+                                                               cur_policy),
+                               "stop_session action policy get");
+       }
+
+       /* Ser/des tests. */
+       ret = lttng_action_serialize(stop_session_action, &payload);
+       ok(ret == 0, "Action stop_session serialized");
+
+       {
+               struct lttng_payload_view view =
+                               lttng_payload_view_from_payload(
+                                               &payload, 0, -1);
+               (void) lttng_action_create_from_payload(
+                               &view, &stop_session_action_from_buffer);
+       }
+       ok(stop_session_action_from_buffer,
+                       "stop_session action created from payload is non-null");
+
+       ok(lttng_action_is_equal(stop_session_action,
+                          stop_session_action_from_buffer),
+                       "Serialized and de-serialized stop_session action are equal");
+
+       lttng_firing_policy_destroy(default_policy);
+       lttng_firing_policy_destroy(policy);
+       lttng_action_destroy(stop_session_action);
+       lttng_action_destroy(stop_session_action_from_buffer);
+       lttng_payload_reset(&payload);
+}
+
 int main(int argc, const char *argv[])
 {
        plan_tests(NUM_TESTS);
        test_action_notify();
        test_action_rotate_session();
+       test_action_start_session();
+       test_action_stop_session();
        return exit_status();
 }
This page took 0.025038 seconds and 4 git commands to generate.