From: Jérémie Galarneau Date: Wed, 3 May 2023 18:55:09 +0000 (-0400) Subject: Tests: environment: base WaitTraceTestApplication on gen-ust-events X-Git-Url: https://git.liburcu.org/?p=lttng-tools.git;a=commitdiff_plain;h=ef07b7aee748b531763ee6a62a900cbcde4978cc Tests: environment: base WaitTraceTestApplication on gen-ust-events WaitTraceTestApplication wraps gen-ust-nevents, but that test app offers few synchronization points compared to gen-ust-events. The synchronization points to determine that the application has reached its `main()` and just before emiting its first event are added to gen-ust-events. WaitTraceTestApplication is adapted to use those new options. Signed-off-by: Jérémie Galarneau Change-Id: Idf717fbaa9108d48a3f7d2b26946a4e5c5dfffd5 --- diff --git a/tests/utils/lttngtest/environment.py b/tests/utils/lttngtest/environment.py index 2710a7efb..c3d6e8262 100644 --- a/tests/utils/lttngtest/environment.py +++ b/tests/utils/lttngtest/environment.py @@ -92,10 +92,7 @@ class WaitTraceTestApplication: wait_time_between_events_us=0, # type: int ): self._environment = environment # type: Environment - if event_count % 5: - # The test application currently produces 5 different events per iteration. - raise ValueError("event count must be a multiple of 5") - self._iteration_count = int(event_count / 5) # type: int + self._iteration_count = event_count # File that the application will wait to see before tracing its events. self._app_start_tracing_file_path = pathlib.Path( tempfile.mktemp( @@ -122,7 +119,7 @@ class WaitTraceTestApplication: test_app_args = [str(binary_path)] test_app_args.extend( shlex.split( - "--iter {iteration_count} --create-in-main {app_ready_file_path} --wait-before-first-event {app_start_tracing_file_path} --wait {wait_time_between_events_us}".format( + "--iter {iteration_count} --sync-application-in-main-touch {app_ready_file_path} --sync-before-first-event {app_start_tracing_file_path} --wait {wait_time_between_events_us}".format( iteration_count=self._iteration_count, app_ready_file_path=app_ready_file_path, app_start_tracing_file_path=self._app_start_tracing_file_path, @@ -420,8 +417,8 @@ class _Environment(logger._Logger): / "tests" / "utils" / "testapp" - / "gen-ust-nevents" - / "gen-ust-nevents", + / "gen-ust-events" + / "gen-ust-events", event_count, self, ) diff --git a/tests/utils/testapp/gen-ust-events/gen-ust-events.cpp b/tests/utils/testapp/gen-ust-events/gen-ust-events.cpp index d64d55421..74ba9cf04 100644 --- a/tests/utils/testapp/gen-ust-events/gen-ust-events.cpp +++ b/tests/utils/testapp/gen-ust-events/gen-ust-events.cpp @@ -32,12 +32,14 @@ static struct option long_options[] = { /* These options set a flag. */ { "iter", required_argument, nullptr, 'i' }, { "wait", required_argument, nullptr, 'w' }, - { "sync-after-first-event", required_argument, nullptr, 'a' }, - { "sync-before-last-event", required_argument, nullptr, 'b' }, - { "sync-before-last-event-touch", required_argument, nullptr, 'c' }, - { "sync-before-exit", required_argument, nullptr, 'd' }, - { "sync-before-exit-touch", required_argument, nullptr, 'e' }, - { "emit-end-event", no_argument, nullptr, 'f' }, + { "sync-application-in-main-touch", required_argument, nullptr, 'a' }, + { "sync-before-first-event", required_argument, nullptr, 'b' }, + { "sync-after-first-event", required_argument, nullptr, 'c' }, + { "sync-before-last-event", required_argument, nullptr, 'd' }, + { "sync-before-last-event-touch", required_argument, nullptr, 'e' }, + { "sync-before-exit", required_argument, nullptr, 'f' }, + { "sync-before-exit-touch", required_argument, nullptr, 'g' }, + { "emit-end-event", no_argument, nullptr, 'h' }, { nullptr, 0, nullptr, 0 } }; @@ -54,6 +56,8 @@ int main(int argc, char **argv) uint32_t net_values[] = { 1, 2, 3 }; int nr_iter = 100, ret = 0, first_event_file_created = 0; useconds_t nr_usec = 0; + char *application_in_main_file_path = nullptr; + char *before_first_event_file_path = nullptr; char *after_first_event_file_path = nullptr; char *before_last_event_file_path = nullptr; /* @@ -72,25 +76,31 @@ int main(int argc, char **argv) net_values[i] = htonl(net_values[i]); } - while ((option = getopt_long(argc, argv, "i:w:a:b:c:d:e:f", long_options, &option_index)) != + while ((option = getopt_long(argc, argv, "i:w:a:b:c:d:e:f:g:h", long_options, &option_index)) != -1) { switch (option) { case 'a': - after_first_event_file_path = strdup(optarg); + application_in_main_file_path = strdup(optarg); break; case 'b': - before_last_event_file_path = strdup(optarg); + before_first_event_file_path = strdup(optarg); break; case 'c': - before_last_event_file_path_touch = strdup(optarg); + after_first_event_file_path = strdup(optarg); break; case 'd': - before_exit_file_path = strdup(optarg); + before_last_event_file_path = strdup(optarg); break; case 'e': - before_exit_file_path_touch = strdup(optarg); + before_last_event_file_path_touch = strdup(optarg); break; case 'f': + before_exit_file_path = strdup(optarg); + break; + case 'g': + before_exit_file_path_touch = strdup(optarg); + break; + case 'h': emit_end_event = true; break; case 'i': @@ -129,6 +139,14 @@ int main(int argc, char **argv) goto end; } + if (application_in_main_file_path) { + create_file(application_in_main_file_path); + } + + if (before_first_event_file_path) { + wait_on_file(before_first_event_file_path); + } + for (i = 0; nr_iter < 0 || i < nr_iter; i++) { if (nr_iter >= 0 && i == nr_iter - 1) { if (before_last_event_file_path_touch) { @@ -204,6 +222,8 @@ int main(int argc, char **argv) } } end: + free(application_in_main_file_path); + free(before_first_event_file_path); free(after_first_event_file_path); free(before_last_event_file_path); free(before_last_event_file_path_touch);