Skip to contentSkip to conversation

Fix kselftest_harness regression

PATCH In review Mickaël Salaün 3 participants 5 messages Jun 11, 2017 – Jun 12, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Fix kselftest_harness regression

In the linux-next tree, commit f3380b7b8a72 ("selftests: kselftest_harness: fix compile warnings") changes the test behavior when a test goes wrong. Instead, the error handler is called when a test succeed.

Mickaël Salaün (2):
Revert "selftests: kselftest_harness: fix compile warnings"
selftests: kselftest_harness: Fix compile warning

 tools/testing/selftests/kselftest_harness.h   | 3 +--
 tools/testing/selftests/seccomp/seccomp_bpf.c | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/2 Revert "selftests: kselftest_harness: fix compile warnings"

This reverts commit f3380b7b8a72f435daceb49f7f7513f3ea2ce5ea.

The OPTIONAL_HANDLER macro, called by all ASSERT_* and EXPECT_* macros, must support an optional error handler. This is done with an optional block after the "for" loop.

This enable to pass 52/52 seccomp-bpf tests instead of 42/52.

Cc Andy Lutomirski <[email protected]>
Cc Kees Cook <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Will Drewry <[email protected]>
---
 tools/testing/selftests/kselftest_harness.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/selftests/kselftest_harness.h +1 -2
index 432245faeab3..c56f72e07cd7 100644
@@ -555,8 +555,7 @@
  * return while still providing an optional block to the API consumer.
  */
 #define OPTIONAL_HANDLER(_assert) \
-	for (; _metadata->trigger;  _metadata->trigger = __bail(_assert)) \
-		;
+	for (; _metadata->trigger;  _metadata->trigger = __bail(_assert))
 
 #define __EXPECT(_expected, _seen, _t, _assert) do { \
 	/* Avoid multiple evaluation of the cases */ \
Signature · 1 line
2.11.0
#2 lore raw

PATCH 2/2 selftests: kselftest_harness: Fix compile warning

In reply to Mickaël Salaün

Do not confuse the compiler with a semicolon preceding a block. Replace the semicolon with an empty block to avoid a warning:

gcc -Wl,-no-as-needed -Wall -lpthread seccomp_bpf.c -o /.../linux/tools/testing/selftests/seccomp/seccomp_bpf In file included from seccomp_bpf.c:40:0:
seccomp_bpf.c: In function ‘change_syscall’:
../kselftest_harness.h:558:2: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]

    for (; _metadata->trigger;  _metadata->trigger = __bail(_assert))
    ^
  ../kselftest_harness.h:574:14: note: in expansion of macro ‘OPTIONAL_HANDLER’
   } while (0); OPTIONAL_HANDLER(_assert)
                ^~~~~~~~~~~~~~~~
  ../kselftest_harness.h:440:2: note: in expansion of macro ‘__EXPECT’
    __EXPECT(expected, seen, ==, 0)
    ^~~~~~~~
  seccomp_bpf.c:1313:2: note: in expansion of macro ‘EXPECT_EQ’
    EXPECT_EQ(0, ret);
    ^~~~~~~~~
  seccomp_bpf.c:1317:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘for’
    {
    ^
Cc Andy Lutomirski <[email protected]>
Cc Kees Cook <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Will Drewry <[email protected]>
---
 tools/testing/selftests/seccomp/seccomp_bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/seccomp/seccomp_bpf.c +1 -1
index 7ba94efb24fd..18dad07ae16b 100644
@@ -1310,7 +1310,7 @@ void change_syscall(struct __test_metadata *_metadata,
 	iov.iov_len = sizeof(regs);
 	ret = ptrace(PTRACE_GETREGSET, tracee, NT_PRSTATUS, &iov);
 #endif
-	EXPECT_EQ(0, ret);
+	EXPECT_EQ(0, ret) {}
 
 #if defined(__x86_64__) || defined(__i386__) || defined(__powerpc__) || \
     defined(__s390__) || defined(__hppa__)
Signature · 1 line
2.11.0
Acked-by on v1 2/2
#3 lore raw

Re: [PATCH v1 2/2] selftests: kselftest_harness: Fix compile warning

Quoted 22 lines · Mickaël Salaün

Do not confuse the compiler with a semicolon preceding a block. Replace the semicolon with an empty block to avoid a warning:

gcc -Wl,-no-as-needed -Wall -lpthread seccomp_bpf.c -o /.../linux/tools/testing/selftests/seccomp/seccomp_bpf In file included from seccomp_bpf.c:40:0:
seccomp_bpf.c: In function ‘change_syscall’:
../kselftest_harness.h:558:2: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]

    for (; _metadata->trigger;  _metadata->trigger = __bail(_assert))
    ^
  ../kselftest_harness.h:574:14: note: in expansion of macro ‘OPTIONAL_HANDLER’
   } while (0); OPTIONAL_HANDLER(_assert)
                ^~~~~~~~~~~~~~~~
  ../kselftest_harness.h:440:2: note: in expansion of macro ‘__EXPECT’
    __EXPECT(expected, seen, ==, 0)
    ^~~~~~~~
  seccomp_bpf.c:1313:2: note: in expansion of macro ‘EXPECT_EQ’
    EXPECT_EQ(0, ret);
    ^~~~~~~~~
  seccomp_bpf.c:1317:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘for’
    {
    ^
Quoted 5 lines
Cc Andy Lutomirski <[email protected]>
Cc Kees Cook <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Will Drewry <[email protected]>

Eek, thanks for catching that. :)

-Kees

Quoted 20 lines
---
 tools/testing/selftests/seccomp/seccomp_bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/seccomp/seccomp_bpf.c +1 -2
index 7ba94efb24fd..18dad07ae16b 100644
@@ -1310,7 +1310,7 @@ void change_syscall(struct __test_metadata *_metadata,
        iov.iov_len = sizeof(regs);
        ret = ptrace(PTRACE_GETREGSET, tracee, NT_PRSTATUS, &iov);
 #endif
-       EXPECT_EQ(0, ret);
+       EXPECT_EQ(0, ret) {}
 
 #if defined(__x86_64__) || defined(__i386__) || defined(__powerpc__) || \
     defined(__s390__) || defined(__hppa__)
--

2.11.0

Signature · 2 lines
Kees Cook
Pixel Security
maintainer
#4 lore raw

Re: [PATCH v1 2/2] selftests: kselftest_harness: Fix compile warning

Quoted 29 lines · Kees Cook
Quoted 22 lines · Mickaël Salaün

Do not confuse the compiler with a semicolon preceding a block. Replace the semicolon with an empty block to avoid a warning:

gcc -Wl,-no-as-needed -Wall -lpthread seccomp_bpf.c -o /.../linux/tools/testing/selftests/seccomp/seccomp_bpf In file included from seccomp_bpf.c:40:0:
seccomp_bpf.c: In function ‘change_syscall’:
../kselftest_harness.h:558:2: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]

    for (; _metadata->trigger;  _metadata->trigger = __bail(_assert))
    ^
  ../kselftest_harness.h:574:14: note: in expansion of macro ‘OPTIONAL_HANDLER’
   } while (0); OPTIONAL_HANDLER(_assert)
                ^~~~~~~~~~~~~~~~
  ../kselftest_harness.h:440:2: note: in expansion of macro ‘__EXPECT’
    __EXPECT(expected, seen, ==, 0)
    ^~~~~~~~
  seccomp_bpf.c:1313:2: note: in expansion of macro ‘EXPECT_EQ’
    EXPECT_EQ(0, ret);
    ^~~~~~~~~
  seccomp_bpf.c:1317:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘for’
    {
    ^
Quoted 5 lines
Cc Andy Lutomirski <[email protected]>
Cc Kees Cook <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Will Drewry <[email protected]>
Quoted 5 lines

Eek, thanks for catching that. :)

-Kees

Thanks. Ths fix is now in linux-kselftest next.

-- Shuah