Re: [PATCH v2 04/18] perf test cs-etm: Test process attribution

From: James Clark

Date: Wed Jun 03 2026 - 07:23:21 EST




On 03/06/2026 12:10 pm, Leo Yan wrote:
On Tue, Jun 02, 2026 at 03:26:46PM +0100, James Clark wrote:

[...]

+check_samples() {
+ owner_samples=$(grep -c "proc1.*context_switch_loop_proc1" "$tmpdir/script" || true)
+ next_samples=$(grep -c "proc2.*context_switch_loop_proc2" "$tmpdir/script" || true)
+
+ if [ "$owner_samples" -eq 0 ] || [ "$next_samples" -eq 0 ]; then
+ echo "No samples found"
+ cleanup

We don't need cleanup explictly here, as trap covers exit case?


We need it whenever we call exit because it removes the trap which would trap and return with its own (potentially different) exit value.

The alternative is a global $err which you set and then call exit without a value and let cleanup() do exit $err. But from searching the existing shell tests calling cleanup before exit seemed to be more common so I did it that way.

+ exit 1
+ fi
+
+ if grep "proc2.*context_switch_loop_proc1" "$tmpdir/script"; then
+ echo "Thread1 symbol was attributed to proc2"
+ cleanup

Ditto.

+ exit 1
+ fi
+
+ if grep "proc1.*context_switch_loop_proc2" "$tmpdir/script"; then
+ echo "Thread2 symbol was attributed to proc1"
+ cleanup

Ditto.

Otherwise:

Reviewed-by: Leo Yan <leo.yan@xxxxxxx>