• D
    selftests: do not macro-expand failed assertion expressions · 07bb43bb
    Dmitry V. Levin 提交于
    [ Upstream commit b708a3cc ]
    
    I've stumbled over the current macro-expand behaviour of the test
    harness:
    
    $ gcc -Wall -xc - <<'__EOF__'
    TEST(macro) {
    	int status = 0;
    	ASSERT_TRUE(WIFSIGNALED(status));
    }
    TEST_HARNESS_MAIN
    __EOF__
    $ ./a.out
    [==========] Running 1 tests from 1 test cases.
    [ RUN      ] global.macro
    <stdin>:4:global.macro:Expected 0 (0) != (((signed char) (((status) & 0x7f) + 1) >> 1) > 0) (0)
    global.macro: Test terminated by assertion
    [     FAIL ] global.macro
    [==========] 0 / 1 tests passed.
    [  FAILED  ]
    
    With this change the output of the same test looks much more
    comprehensible:
    
    [==========] Running 1 tests from 1 test cases.
    [ RUN      ] global.macro
    <stdin>:4:global.macro:Expected 0 (0) != WIFSIGNALED(status) (0)
    global.macro: Test terminated by assertion
    [     FAIL ] global.macro
    [==========] 0 / 1 tests passed.
    [  FAILED  ]
    
    The issue is very similar to the bug fixed in glibc assert(3)
    three years ago:
    https://sourceware.org/bugzilla/show_bug.cgi?id=18604
    
    Cc: Shuah Khan <shuah@kernel.org>
    Cc: Kees Cook <keescook@chromium.org>
    Cc: Andy Lutomirski <luto@amacapital.net>
    Cc: Will Drewry <wad@chromium.org>
    Cc: linux-kselftest@vger.kernel.org
    Signed-off-by: NDmitry V. Levin <ldv@altlinux.org>
    Acked-by: NKees Cook <keescook@chromium.org>
    Signed-off-by: NShuah Khan <shuah@kernel.org>
    Signed-off-by: NSasha Levin <sashal@kernel.org>
    Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
    07bb43bb
kselftest_harness.h 20.1 KB