From 849019151cf07f376a4a68ce1669e357f4775657 Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Fri, 10 May 2024 14:41:11 -0400 Subject: [PATCH] tests: Correct use of taskset in snapshot tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Observed issue ============== While investigating potential changes to how buffers are flushed during snapshots, I discovered that the changes made the small overwrite test flaky. After investigation, the issue appears to be a problem with the test that was exposed by the other changes. Cause ===== `taskset` handles its arguments more strictly than many other CLI programs, and the argument order used is not valid. As the return of the taskset invocation in the test isn't validated, there was little indication of the issue save a warning that is easily lost in the text. The following example demonstrates the situation: ``` $ bash -x test.sh + taskset -p 910843 pid 910843's current affinity mask: f + echo 0 0 + ./tests/utils/testapp/gen-ust-events/gen-ust-events Process 910845 has 4 cpus in its affinity set CPU 0 is set? 1 CPU 1 is set? 1 CPU 2 is set? 1 CPU 3 is set? 1 + taskset -c 0 -p 910843 taskset: failed to execute -p: No such file or directory + echo 127 127 + ./tests/utils/testapp/gen-ust-events/gen-ust-events Process 910849 has 4 cpus in its affinity set CPU 0 is set? 1 CPU 1 is set? 1 CPU 2 is set? 1 CPU 3 is set? 1 + taskset -pc 0 910843 pid 910843's current affinity list: 0-3 pid 910843's new affinity list: 0 + echo 0 0 + ./tests/utils/testapp/gen-ust-events/gen-ust-events Process 910853 has 1 cpus in its affinity set CPU 0 is set? 1 ``` Solution ======== Correct the invocation of taskset and add a check on its return code when used to set the cpu affinity of the current process. Known drawbacks =============== None. Change-Id: Ia629121624532746431875b2031dd65df207666d Signed-off-by: Kienan Stewart Signed-off-by: Jérémie Galarneau --- tests/regression/tools/snapshots/ust_test | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/regression/tools/snapshots/ust_test b/tests/regression/tools/snapshots/ust_test index 5188c2b5b..e49549804 100755 --- a/tests/regression/tools/snapshots/ust_test +++ b/tests/regression/tools/snapshots/ust_test @@ -16,7 +16,7 @@ TESTAPP_NAME="gen-ust-events" TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" APPS_PID=() -NUM_TESTS=104 +NUM_TESTS=106 TRACE_PATH=$(mktemp -d -t tmp.test_snapshots_ust_trace_path.XXXXXX) @@ -209,7 +209,8 @@ function test_ust_local_snapshot_small_discard_buffers () OLDCPUSET=$(taskset -p $$) diag "Test local UST snapshots with small discard buffers" - taskset -c "$(get_any_available_cpu)" -p $$ 1>/dev/null 2>&1 + taskset -cp "$(get_any_available_cpu)" $$ 1>/dev/null 2>&1 + ok $? "Set current process CPU affinity" create_lttng_session_no_output "$SESSION_NAME" enable_mmap_small_discard_ust_channel "$SESSION_NAME" $CHANNEL_NAME enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME @@ -254,7 +255,8 @@ function test_ust_local_snapshot_small_overwrite_buffers () OLDCPUSET=$(taskset -p $$) diag "Test local UST snapshots with small overwrite buffers" - taskset -p "$(get_any_available_cpu)" $$ 1>/dev/null 2>&1 + taskset -cp "$(get_any_available_cpu)" $$ 1>/dev/null 2>&1 + ok $? "Set current process CPU affinity" create_lttng_session_no_output "$SESSION_NAME" enable_mmap_small_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME -- 2.34.1