lkml.org 
[lkml]   [2018]   [May]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Subject[PATCH 02/13] x86/pkeys/selftests: Stop using assert()
    From
    Date

    From: Dave Hansen <dave.hansen@linux.intel.com>

    If we use assert(), the program "crashes". That can be scary to users,
    so stop doing it. Just exit with a >0 exit code instead.

    Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
    Cc: Ram Pai <linuxram@us.ibm.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Dave Hansen <dave.hansen@intel.com>
    Cc: Michael Ellermen <mpe@ellerman.id.au>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Shuah Khan <shuah@kernel.org>
    ---

    b/tools/testing/selftests/x86/protection_keys.c | 12 ++++++++----
    1 file changed, 8 insertions(+), 4 deletions(-)

    diff -puN tools/testing/selftests/x86/protection_keys.c~pkeys-selftests-do-not-assert tools/testing/selftests/x86/protection_keys.c
    --- a/tools/testing/selftests/x86/protection_keys.c~pkeys-selftests-do-not-assert 2018-05-09 09:20:18.717698407 -0700
    +++ b/tools/testing/selftests/x86/protection_keys.c 2018-05-09 09:20:18.720698407 -0700
    @@ -72,10 +72,9 @@ extern void abort_hooks(void);
    test_nr, iteration_nr); \
    dprintf0("errno at assert: %d", errno); \
    abort_hooks(); \
    - assert(condition); \
    + exit(__LINE__); \
    } \
    } while (0)
    -#define raw_assert(cond) assert(cond)

    void cat_into_file(char *str, char *file)
    {
    @@ -87,12 +86,17 @@ void cat_into_file(char *str, char *file
    * these need to be raw because they are called under
    * pkey_assert()
    */
    - raw_assert(fd >= 0);
    + if (fd < 0) {
    + fprintf(stderr, "error opening '%s'\n", str);
    + perror("error: ");
    + exit(__LINE__);
    + }
    +
    ret = write(fd, str, strlen(str));
    if (ret != strlen(str)) {
    perror("write to file failed");
    fprintf(stderr, "filename: '%s' str: '%s'\n", file, str);
    - raw_assert(0);
    + exit(__LINE__);
    }
    close(fd);
    }
    _
    \
     
     \ /
      Last update: 2018-05-09 19:21    [W:4.056 / U:0.756 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site