kselftest/arm64: Print ASCII version of unknown signal frame magic values
authorMark Brown <broonie@kernel.org>
Wed, 2 Nov 2022 14:05:43 +0000 (14:05 +0000)
committerWill Deacon <will@kernel.org>
Tue, 8 Nov 2022 16:04:51 +0000 (16:04 +0000)
The signal magic values are supposed to be allocated as somewhat meaningful
ASCII so if we encounter a bad magic value print the any alphanumeric
characters we find in it as well as the hex value to aid debuggability.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20221102140543.98193-1-broonie@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
tools/testing/selftests/arm64/signal/testcases/testcases.c

index e1c625b20ac4cb818f01f049b70e9dd417da5a08..d2eda7b5de26cdb74d1cf2ad6623d02534d9f057 100644 (file)
@@ -1,5 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (C) 2019 ARM Limited */
+
+#include <ctype.h>
+#include <string.h>
+
 #include "testcases.h"
 
 struct _aarch64_ctx *get_header(struct _aarch64_ctx *head, uint32_t magic,
@@ -109,7 +113,7 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
        bool terminated = false;
        size_t offs = 0;
        int flags = 0;
-       int new_flags;
+       int new_flags, i;
        struct extra_context *extra = NULL;
        struct sve_context *sve = NULL;
        struct za_context *za = NULL;
@@ -117,6 +121,7 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
                (struct _aarch64_ctx *)uc->uc_mcontext.__reserved;
        void *extra_data = NULL;
        size_t extra_sz = 0;
+       char magic[4];
 
        if (!err)
                return false;
@@ -194,11 +199,19 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
                        /*
                         * A still unknown Magic: potentially freshly added
                         * to the Kernel code and still unknown to the
-                        * tests.
+                        * tests.  Magic numbers are supposed to be allocated
+                        * as somewhat meaningful ASCII strings so try to
+                        * print as such as well as the raw number.
                         */
+                       memcpy(magic, &head->magic, sizeof(magic));
+                       for (i = 0; i < sizeof(magic); i++)
+                               if (!isalnum(magic[i]))
+                                       magic[i] = '?';
+
                        fprintf(stdout,
-                               "SKIP Unknown MAGIC: 0x%X - Is KSFT arm64/signal up to date ?\n",
-                               head->magic);
+                               "SKIP Unknown MAGIC: 0x%X (%c%c%c%c) - Is KSFT arm64/signal up to date ?\n",
+                               head->magic,
+                               magic[3], magic[2], magic[1], magic[0]);
                        break;
                }