X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=tests%2Fregression%2Ftools%2Fnotification%2Frotation.c;h=1007de44ee18e5d7ce987c8b14714a512b97c145;hb=HEAD;hp=f32a0d7737efb95b3b778c3e14784ec19dc40395;hpb=a5c2d2a71919b8d1542b62f6d32579125cc2c8f8;p=lttng-tools.git diff --git a/tests/regression/tools/notification/rotation.c b/tests/regression/tools/notification/rotation.c index f32a0d773..1007de44e 100644 --- a/tests/regression/tools/notification/rotation.c +++ b/tests/regression/tools/notification/rotation.c @@ -9,13 +9,13 @@ * */ -#include -#include -#include -#include +#include + #include +#include #include -#include +#include +#include #define TEST_COUNT 36 @@ -26,41 +26,35 @@ struct session { uint64_t expected_rotation_id = UINT64_MAX; -static -int test_condition(struct lttng_condition *condition, const char *type_name) +static int test_condition(struct lttng_condition *condition, const char *type_name) { int ret = 0; const char *out_session_name; - const char * const session_name = "test session name"; + const char *const session_name = "test session name"; enum lttng_condition_status status; - status = lttng_condition_session_rotation_get_session_name(condition, - &out_session_name); + status = lttng_condition_session_rotation_get_session_name(condition, &out_session_name); ok(status == LTTNG_CONDITION_STATUS_UNSET, - "Getting unset name of %s condition fails with LTTNG_CONDITION_STATUS_UNSET", - type_name); + "Getting unset name of %s condition fails with LTTNG_CONDITION_STATUS_UNSET", + type_name); - status = lttng_condition_session_rotation_set_session_name(condition, - session_name); + status = lttng_condition_session_rotation_set_session_name(condition, session_name); ok(status == LTTNG_CONDITION_STATUS_OK, - "Setting session name \"%s\" of %s condition succeeds", - session_name, type_name); + "Setting session name \"%s\" of %s condition succeeds", + session_name, + type_name); - status = lttng_condition_session_rotation_get_session_name(condition, - &out_session_name); - ok(status == LTTNG_CONDITION_STATUS_OK, - "Getting name of %s condition succeeds", - type_name); + status = lttng_condition_session_rotation_get_session_name(condition, &out_session_name); + ok(status == LTTNG_CONDITION_STATUS_OK, "Getting name of %s condition succeeds", type_name); ok(out_session_name && !strcmp(session_name, out_session_name), - "Session name returned by %s condition matches the expected name", - type_name); + "Session name returned by %s condition matches the expected name", + type_name); return ret; } -static -int setup_rotation_trigger(const struct session *session, - struct lttng_notification_channel *notification_channel) +static int setup_rotation_trigger(const struct session *session, + struct lttng_notification_channel *notification_channel) { int ret; struct lttng_condition *rotation_ongoing_condition = NULL; @@ -79,8 +73,7 @@ int setup_rotation_trigger(const struct session *session, } /* Create rotation ongoing and completed conditions. */ - rotation_ongoing_condition = - lttng_condition_session_rotation_ongoing_create(); + rotation_ongoing_condition = lttng_condition_session_rotation_ongoing_create(); ok(rotation_ongoing_condition, "Create session rotation ongoing condition"); if (!rotation_ongoing_condition) { ret = -1; @@ -91,15 +84,14 @@ int setup_rotation_trigger(const struct session *session, goto end; } condition_status = lttng_condition_session_rotation_set_session_name( - rotation_ongoing_condition, session->name); + rotation_ongoing_condition, session->name); if (condition_status != LTTNG_CONDITION_STATUS_OK) { ret = -1; diag("Failed to set session name on session rotation ongoing condition"); goto end; } - rotation_completed_condition = - lttng_condition_session_rotation_completed_create(); + rotation_completed_condition = lttng_condition_session_rotation_completed_create(); ok(rotation_completed_condition, "Create session rotation completed condition"); if (!rotation_completed_condition) { ret = -1; @@ -111,42 +103,38 @@ int setup_rotation_trigger(const struct session *session, goto end; } condition_status = lttng_condition_session_rotation_set_session_name( - rotation_completed_condition, session->name); + rotation_completed_condition, session->name); if (condition_status != LTTNG_CONDITION_STATUS_OK) { ret = -1; goto end; } notification_channel_status = lttng_notification_channel_subscribe( - notification_channel, rotation_ongoing_condition); + notification_channel, rotation_ongoing_condition); ok(notification_channel_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, - "Subscribe to session rotation ongoing notifications"); - if (notification_channel_status != - LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) { + "Subscribe to session rotation ongoing notifications"); + if (notification_channel_status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) { ret = -1; goto end; } notification_channel_status = lttng_notification_channel_subscribe( - notification_channel, rotation_completed_condition); + notification_channel, rotation_completed_condition); ok(notification_channel_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, - "Subscribe to session rotation completed notifications"); - if (notification_channel_status != - LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) { + "Subscribe to session rotation completed notifications"); + if (notification_channel_status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) { ret = -1; goto end; } /* Create rotation ongoing and completed triggers. */ - rotation_ongoing_trigger = lttng_trigger_create( - rotation_ongoing_condition, notify); + rotation_ongoing_trigger = lttng_trigger_create(rotation_ongoing_condition, notify); ok(rotation_ongoing_trigger, "Create a rotation ongoing notification trigger"); if (!rotation_ongoing_trigger) { ret = -1; goto end; } - rotation_completed_trigger = lttng_trigger_create( - rotation_completed_condition, notify); + rotation_completed_trigger = lttng_trigger_create(rotation_completed_condition, notify); ok(rotation_completed_trigger, "Create a rotation completed notification trigger"); if (!rotation_completed_trigger) { ret = -1; @@ -154,18 +142,15 @@ int setup_rotation_trigger(const struct session *session, } /* Register rotation ongoing and completed triggers. */ - ret_code = lttng_register_trigger_with_automatic_name( - rotation_ongoing_trigger); + ret_code = lttng_register_trigger_with_automatic_name(rotation_ongoing_trigger); ok(ret_code == LTTNG_OK, "Registered session rotation ongoing trigger"); if (ret_code != LTTNG_OK) { ret = -ret_code; goto end; } - ret_code = lttng_register_trigger_with_automatic_name( - rotation_completed_trigger); - ok(ret_code == LTTNG_OK, - "Registered session rotation completed trigger"); + ret_code = lttng_register_trigger_with_automatic_name(rotation_completed_trigger); + ok(ret_code == LTTNG_OK, "Registered session rotation completed trigger"); if (ret_code != LTTNG_OK) { ret = -ret_code; goto end; @@ -180,12 +165,10 @@ end: return ret; } -static -int test_notification( - struct lttng_notification_channel *notification_channel, - const struct session *session, - const char *expected_notification_type_name, - enum lttng_condition_type expected_condition_type) +static int test_notification(struct lttng_notification_channel *notification_channel, + const struct session *session, + const char *expected_notification_type_name, + enum lttng_condition_type expected_condition_type) { int ret = 0; bool notification_pending; @@ -203,28 +186,28 @@ int test_notification( const char *chunk_path = NULL; notification_channel_status = lttng_notification_channel_has_pending_notification( - notification_channel, ¬ification_pending); + notification_channel, ¬ification_pending); ok(notification_channel_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK, - "Check for %s notification pending on notification channel", - expected_notification_type_name); + "Check for %s notification pending on notification channel", + expected_notification_type_name); if (notification_channel_status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) { ret = -1; goto end; } ok(notification_pending, - "Session %s notification is pending on notification channel", - expected_notification_type_name); + "Session %s notification is pending on notification channel", + expected_notification_type_name); if (!notification_pending) { ret = -1; goto end; } notification_channel_status = lttng_notification_channel_get_next_notification( - notification_channel, ¬ification); + notification_channel, ¬ification); ok(notification_channel_status == LTTNG_NOTIFICATION_CHANNEL_STATUS_OK && notification, - "Get %s notification from notification channel", - expected_notification_type_name); + "Get %s notification from notification channel", + expected_notification_type_name); if (notification_channel_status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK || !notification) { ret = -1; goto end; @@ -239,18 +222,18 @@ int test_notification( condition_type = lttng_condition_get_type(condition); ok(condition_type == expected_condition_type, - "Notification condition obtained from notification channel is of type \"%s\"", - expected_notification_type_name); + "Notification condition obtained from notification channel is of type \"%s\"", + expected_notification_type_name); if (condition_type != expected_condition_type) { ret = -1; goto end; } - condition_status = lttng_condition_session_rotation_get_session_name( - condition, &session_name); + condition_status = + lttng_condition_session_rotation_get_session_name(condition, &session_name); ok(condition_status == LTTNG_CONDITION_STATUS_OK && session_name && - !strcmp(session_name, session->name), - "Condition obtained from notification has the correct session name assigned"); + !strcmp(session_name, session->name), + "Condition obtained from notification has the correct session name assigned"); if (condition_status != LTTNG_CONDITION_STATUS_OK || !session_name) { ret = -1; goto end; @@ -264,18 +247,17 @@ int test_notification( } condition_type = lttng_evaluation_get_type(evaluation); ok(condition_type == expected_condition_type, - "Condition evaluation obtained from notification channel is of type \"%s\"", - expected_notification_type_name); + "Condition evaluation obtained from notification channel is of type \"%s\"", + expected_notification_type_name); if (condition_type != expected_condition_type) { ret = -1; goto end; } - evaluation_status = lttng_evaluation_session_rotation_get_id(evaluation, - &rotation_id); + evaluation_status = lttng_evaluation_session_rotation_get_id(evaluation, &rotation_id); ok(evaluation_status == LTTNG_EVALUATION_STATUS_OK, - "Get %s id from notification evaluation", - expected_notification_type_name); + "Get %s id from notification evaluation", + expected_notification_type_name); if (evaluation_status != LTTNG_EVALUATION_STATUS_OK) { ret = -1; goto end; @@ -289,51 +271,52 @@ int test_notification( goto end; } - evaluation_status = lttng_evaluation_session_rotation_completed_get_location( - evaluation, &location); + evaluation_status = + lttng_evaluation_session_rotation_completed_get_location(evaluation, &location); ok(evaluation_status == LTTNG_EVALUATION_STATUS_OK && location, - "Get session %s chunk location from evaluation", - expected_notification_type_name); + "Get session %s chunk location from evaluation", + expected_notification_type_name); if (evaluation_status != LTTNG_EVALUATION_STATUS_OK || !location) { ret = -1; goto end; } - ok(lttng_trace_archive_location_get_type(location) == LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL, - "Location returned from the session rotation completed notification is of type 'local'"); + ok(lttng_trace_archive_location_get_type(location) == + LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL, + "Location returned from the session rotation completed notification is of type 'local'"); - location_status = lttng_trace_archive_location_local_get_absolute_path( - location, &chunk_path); + location_status = + lttng_trace_archive_location_local_get_absolute_path(location, &chunk_path); ok(location_status == LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK && chunk_path, - "Retrieved path from location returned by the session rotation completed notification"); + "Retrieved path from location returned by the session rotation completed notification"); diag("Chunk available at %s", chunk_path ? chunk_path : "NULL"); ok(chunk_path && !strncmp(session->output_path, chunk_path, strlen(session->output_path)), - "Returned path from location starts with the output path"); + "Returned path from location starts with the output path"); end: lttng_notification_destroy(notification); return ret; } -static -int test_rotation_ongoing_notification( - struct lttng_notification_channel *notification_channel, - struct session *session) +static int +test_rotation_ongoing_notification(struct lttng_notification_channel *notification_channel, + struct session *session) { - return test_notification(notification_channel, session, - "rotation ongoing", - LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING); + return test_notification(notification_channel, + session, + "rotation ongoing", + LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING); } -static -int test_rotation_completed_notification( - struct lttng_notification_channel *notification_channel, - struct session *session) +static int +test_rotation_completed_notification(struct lttng_notification_channel *notification_channel, + struct session *session) { - return test_notification(notification_channel, session, - "rotation completed", - LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED); + return test_notification(notification_channel, + session, + "rotation completed", + LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED); } int main(int argc, const char *argv[]) @@ -343,8 +326,7 @@ int main(int argc, const char *argv[]) struct lttng_notification_channel *notification_channel = NULL; struct lttng_rotation_handle *rotation_handle = NULL; enum lttng_rotation_status rotation_status; - enum lttng_rotation_state rotation_state = - LTTNG_ROTATION_STATE_NO_ROTATION; + enum lttng_rotation_state rotation_state = LTTNG_ROTATION_STATE_NO_ROTATION; if (argc != 3) { puts("Usage: rotation SESSION_NAME SESSION_OUTPUT_PATH"); @@ -357,8 +339,8 @@ int main(int argc, const char *argv[]) plan_tests(TEST_COUNT); - notification_channel = lttng_notification_channel_create( - lttng_session_daemon_notification_endpoint); + notification_channel = + lttng_notification_channel_create(lttng_session_daemon_notification_endpoint); if (!notification_channel) { diag("Failed to create notification channel"); ret = -1; @@ -372,20 +354,19 @@ int main(int argc, const char *argv[]) /* Start rotation and wait for its completion. */ ret = lttng_rotate_session(session.name, NULL, &rotation_handle); - ok(ret >= 0 && rotation_handle, "Start rotation of session \"%s\"", - session.name); + ok(ret >= 0 && rotation_handle, "Start rotation of session \"%s\"", session.name); if (ret < 0 || !rotation_handle) { goto error; } do { - rotation_status = lttng_rotation_handle_get_state( - rotation_handle, &rotation_state); + rotation_status = lttng_rotation_handle_get_state(rotation_handle, &rotation_state); } while (rotation_state == LTTNG_ROTATION_STATE_ONGOING && - rotation_status == LTTNG_ROTATION_STATUS_OK); + rotation_status == LTTNG_ROTATION_STATUS_OK); ok(rotation_status == LTTNG_ROTATION_STATUS_OK && - rotation_state == LTTNG_ROTATION_STATE_COMPLETED, - "Complete rotation of session \"%s\"", session.name); + rotation_state == LTTNG_ROTATION_STATE_COMPLETED, + "Complete rotation of session \"%s\"", + session.name); /* * After a rotation has completed, we can expect two notifications to @@ -393,14 +374,12 @@ int main(int argc, const char *argv[]) * - Session rotation ongoing * - Session rotation completed */ - ret = test_rotation_ongoing_notification(notification_channel, - &session); + ret = test_rotation_ongoing_notification(notification_channel, &session); if (ret) { goto error; } - ret = test_rotation_completed_notification(notification_channel, - &session); + ret = test_rotation_completed_notification(notification_channel, &session); if (ret) { goto error; }