4 * Unit tests for the action API.
6 * Copyright (C) 2021 Francis Deslauriers <francis.deslauriers@efficios.com>
8 * SPDX-License-Identifier: GPL-2.0-only
20 #include <lttng/action/action.h>
21 #include <lttng/action/action-internal.h>
22 #include <lttng/action/incr-value.h>
23 #include <lttng/action/incr-value-internal.h>
25 #include <lttng/map-key-internal.h>
27 #include <common/dynamic-buffer.h>
28 #include <common/buffer-view.h>
29 #include <common/payload.h>
32 int lttng_opt_quiet
= 1;
33 int lttng_opt_verbose
;
39 void test_action_incr_value(void)
42 struct lttng_action
*action
= NULL
;
43 struct lttng_action
*action_from_buffer
= NULL
;
44 const char *map_name
= "my_map_name";
45 const char *session_name
= "my_session_name";
46 const char *first_part_key
= "first_part_🥇_";
47 const char *second_part_key
= "_🥈_second_part";
48 struct lttng_map_key
*key
= NULL
;
49 enum lttng_action_status action_status
;
50 enum lttng_map_key_status key_status
;
51 struct lttng_payload buffer
;
52 const struct lttng_map_key
*key_from_buffer
;
53 const struct lttng_map_key_token
*token
;
55 lttng_payload_init(&buffer
);
57 /* Test key creation */
58 key
= lttng_map_key_create();
59 ok(key
, "Key created");
61 key_status
= lttng_map_key_append_token_string(key
, first_part_key
);
62 ok(key_status
== LTTNG_MAP_KEY_STATUS_OK
, "Key append first string");
64 key_status
= lttng_map_key_append_token_variable(key
, LTTNG_MAP_KEY_TOKEN_VARIABLE_TYPE_EVENT_NAME
);
65 ok(key_status
== LTTNG_MAP_KEY_STATUS_OK
, "Key append event name variable");
67 key_status
= lttng_map_key_append_token_string(key
, second_part_key
);
68 ok(key_status
== LTTNG_MAP_KEY_STATUS_OK
, "Key append second string");
70 /*Test incr value action creation */
71 action
= lttng_action_incr_value_create();
72 ok(action
, "Incr-value action created");
74 action_status
= lttng_action_incr_value_set_session_name(action
, session_name
);
75 ok(action_status
== LTTNG_ACTION_STATUS_OK
, "incr-value set session name");
77 action_status
= lttng_action_incr_value_set_map_name(action
, map_name
);
78 ok(action_status
== LTTNG_ACTION_STATUS_OK
, "incr-value set map name");
80 action_status
= lttng_action_incr_value_set_key(action
, key
);
81 ok(action_status
== LTTNG_ACTION_STATUS_OK
, "incr-value set key");
83 /* Test incr value action serialization */
84 ret
= lttng_action_serialize(action
, &buffer
);
85 ok(ret
== 0, "Incr value action serialized");
88 struct lttng_payload_view view
=
89 lttng_payload_view_from_payload(&buffer
, 0, -1);
91 (void) lttng_action_create_from_payload(
92 &view
, &action_from_buffer
);
94 ok(action_from_buffer
, "Incr value action created from payload is non-null");
96 action_status
= lttng_action_incr_value_get_key(action
, &key_from_buffer
);
97 ok(key_from_buffer
, "Retrived key from incr value action");
99 token
= lttng_map_key_get_token_at_index(key_from_buffer
, 0);
100 ok(token
->type
== LTTNG_MAP_KEY_TOKEN_TYPE_STRING
, "First key token is a string");
102 token
= lttng_map_key_get_token_at_index(key_from_buffer
, 1);
103 ok(token
->type
== LTTNG_MAP_KEY_TOKEN_TYPE_VARIABLE
, "Second key token is a variable");
105 token
= lttng_map_key_get_token_at_index(key_from_buffer
, 2);
106 ok(token
->type
== LTTNG_MAP_KEY_TOKEN_TYPE_STRING
, "Third key token is a string");
108 lttng_payload_reset(&buffer
);
110 lttng_action_destroy(action
);
111 lttng_action_destroy(action_from_buffer
);
112 lttng_map_key_destroy(key
);
115 int main(int argc
, const char *argv
[])
117 plan_tests(NUM_TESTS
);
118 test_action_incr_value();
119 return exit_status();