From a269c21fc3d52ab502aa5cf98e47aca6520e5a37 Mon Sep 17 00:00:00 2001 From: Arkadiusz Hiler Date: Wed, 8 May 2019 08:59:30 +0300 Subject: lib/tests/igt_subtest_group: Operate within defined behavior Quoting lib/igt_core.c: * - Code blocks with magic control flow are implemented with setjmp() and * longjmp(). This applies to #igt_fixture and #igt_subtest blocks and all the * three variants to finish test: igt_success(), igt_skip() and igt_fail(). * Mostly this is of no concern, except when such a control block changes * stack variables defined in the same function as the control block resides. * Any store/load behaviour after a longjmp() is ill-defined for these * variables. Avoid such code. * * Quoting the man page for longjmp(): * * "The values of automatic variables are unspecified after a call to * longjmp() if they meet all the following criteria:" * - "they are local to the function that made the corresponding setjmp() call; * - "their values are changed between the calls to setjmp() and longjmp(); and * - "they are not declared as volatile." igt_subtest_group test uses two local variables for tracking the state of execution, making sure that skips are working correctly. We can just make them volatile to be back on the defined grounds. v2: comment on the volatiles as suggested by Simon Ser Cc: Simon Ser Cc: Daniel Vetter Signed-off-by: Arkadiusz Hiler Reviewed-by: Petri Latvala Reviewed-by: Simon Ser --- lib/tests/igt_subtest_group.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/tests/igt_subtest_group.c b/lib/tests/igt_subtest_group.c index 7783d021..973a30e4 100644 --- a/lib/tests/igt_subtest_group.c +++ b/lib/tests/igt_subtest_group.c @@ -28,8 +28,13 @@ igt_main { - bool t1 = false; - int t2 = 0; + /* + * local variables have to be volatile here otherwise they end up being + * undefined when modified in igt_subtest, fixture, etc. because of + * longjmps + */ + volatile bool t1 = false; + volatile int t2 = 0; igt_subtest_group { igt_fixture { -- cgit v1.2.3