From: "H. Peter Anvin" <hpa@zytor.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Andy Lutomirski <luto@kernel.org>,
Borislav Petkov <bp@alien8.de>, "H. Peter Anvin" <hpa@zytor.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH v4 2/6] x86/syscall: simplify message reporting in syscall_numbering.c
Date: Tue, 18 May 2021 12:12:59 -0700 [thread overview]
Message-ID: <20210518191303.4135296-3-hpa@zytor.com> (raw)
In-Reply-To: <20210518191303.4135296-1-hpa@zytor.com>
From: "H. Peter Anvin (Intel)" <hpa@zytor.com>
Reduce some boiler plate in printing and indenting messages in
syscall_numbering.c. This makes it easier to produce clean status
output.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
---
.../testing/selftests/x86/syscall_numbering.c | 102 ++++++++++++------
1 file changed, 71 insertions(+), 31 deletions(-)
diff --git a/tools/testing/selftests/x86/syscall_numbering.c b/tools/testing/selftests/x86/syscall_numbering.c
index 7dd86bcbee25..03915cd48cfc 100644
--- a/tools/testing/selftests/x86/syscall_numbering.c
+++ b/tools/testing/selftests/x86/syscall_numbering.c
@@ -34,6 +34,33 @@
static unsigned int nerr = 0; /* Cumulative error count */
static int nullfd = -1; /* File descriptor for /dev/null */
+static int indent = 0;
+
+static inline unsigned int offset(void)
+{
+ return 8+indent*4;
+}
+
+#define msg(lvl, fmt, ...) printf("%-*s" fmt, offset(), "[" #lvl "]", \
+ ## __VA_ARGS__)
+
+#define run(fmt, ...) msg(RUN, fmt, ## __VA_ARGS__)
+#define info(fmt, ...) msg(INFO, fmt, ## __VA_ARGS__)
+#define ok(fmt, ...) msg(OK, fmt, ## __VA_ARGS__)
+
+#define fail(fmt, ...) \
+ do { \
+ msg(FAIL, fmt, ## __VA_ARGS__); \
+ nerr++; \
+ } while (0)
+
+#define crit(fmt, ...) \
+ do { \
+ indent = 0; \
+ msg(FAIL, fmt, ## __VA_ARGS__); \
+ msg(SKIP, "Unable to run test\n"); \
+ exit(71); /* EX_OSERR */ \
+ } while (0)
/*
* Directly invokes the given syscall with nullfd as the first argument
@@ -91,28 +118,37 @@ static unsigned int _check_for(int msb, int start, int end, long long expect,
{
unsigned int err = 0;
+ indent++;
+ if (start != end)
+ indent++;
+
for (int nr = start; nr <= end; nr++) {
long long ret = probe_syscall(msb, nr);
if (ret != expect) {
- printf("[FAIL]\t %s returned %lld, but it should have returned %s\n",
+ fail("%s returned %lld, but it should have returned %s\n",
syscall_str(msb, nr, nr),
ret, expect_str);
err++;
}
}
+ if (start != end)
+ indent--;
+
if (err) {
nerr += err;
if (start != end)
- printf("[FAIL]\t %s had %u failure%s\n",
+ fail("%s had %u failure%s\n",
syscall_str(msb, start, end),
- err, (err == 1) ? "s" : "");
+ err, err == 1 ? "s" : "");
} else {
- printf("[OK]\t %s returned %s as expected\n",
- syscall_str(msb, start, end), expect_str);
+ ok("%s returned %s as expected\n",
+ syscall_str(msb, start, end), expect_str);
}
+ indent--;
+
return err;
}
@@ -137,35 +173,38 @@ static bool check_enosys(int msb, int nr)
static bool test_x32(void)
{
long long ret;
- long long mypid = getpid();
+ pid_t mypid = getpid();
+ bool with_x32;
- printf("[RUN]\tChecking for x32 by calling x32 getpid()\n");
+ run("Checking for x32 by calling x32 getpid()\n");
ret = probe_syscall(0, SYS_GETPID | X32_BIT);
+ indent++;
if (ret == mypid) {
- printf("[INFO]\t x32 is supported\n");
- return true;
+ info("x32 is supported\n");
+ with_x32 = true;
} else if (ret == -ENOSYS) {
- printf("[INFO]\t x32 is not supported\n");
- return false;
+ info("x32 is not supported\n");
+ with_x32 = false;
} else {
- printf("[FAIL]\t x32 getpid() returned %lld, but it should have returned either %lld or -ENOSYS\n", ret, mypid);
- nerr++;
- return true; /* Proceed as if... */
+ fail("x32 getpid() returned %lld, but it should have returned either %lld or -ENOSYS\n", ret, mypid);
+ with_x32 = false;
}
+ indent--;
+ return with_x32;
}
static void test_syscalls_common(int msb)
{
- printf("[RUN]\t Checking some common syscalls as 64 bit\n");
+ run("Checking some common syscalls as 64 bit\n");
check_zero(msb, SYS_READ);
check_zero(msb, SYS_WRITE);
- printf("[RUN]\t Checking some 64-bit only syscalls as 64 bit\n");
+ run("Checking some 64-bit only syscalls as 64 bit\n");
check_zero(msb, X64_READV);
check_zero(msb, X64_WRITEV);
- printf("[RUN]\t Checking out of range system calls\n");
+ run("Checking out of range system calls\n");
check_for(msb, -64, -1, -ENOSYS);
check_for(msb, X32_BIT-64, X32_BIT-1, -ENOSYS);
check_for(msb, -64-X32_BIT, -1-X32_BIT, -ENOSYS);
@@ -180,18 +219,18 @@ static void test_syscalls_with_x32(int msb)
* set. Calling them without the x32 bit set is
* nonsense and should not work.
*/
- printf("[RUN]\t Checking x32 syscalls as 64 bit\n");
+ run("Checking x32 syscalls as 64 bit\n");
check_for(msb, 512, 547, -ENOSYS);
- printf("[RUN]\t Checking some common syscalls as x32\n");
+ run("Checking some common syscalls as x32\n");
check_zero(msb, SYS_READ | X32_BIT);
check_zero(msb, SYS_WRITE | X32_BIT);
- printf("[RUN]\t Checking some x32 syscalls as x32\n");
+ run("Checking some x32 syscalls as x32\n");
check_zero(msb, X32_READV | X32_BIT);
check_zero(msb, X32_WRITEV | X32_BIT);
- printf("[RUN]\t Checking some 64-bit syscalls as x32\n");
+ run("Checking some 64-bit syscalls as x32\n");
check_enosys(msb, X64_IOCTL | X32_BIT);
check_enosys(msb, X64_READV | X32_BIT);
check_enosys(msb, X64_WRITEV | X32_BIT);
@@ -199,7 +238,7 @@ static void test_syscalls_with_x32(int msb)
static void test_syscalls_without_x32(int msb)
{
- printf("[RUN]\t Checking for absence of x32 system calls\n");
+ run("Checking for absence of x32 system calls\n");
check_for(msb, 0 | X32_BIT, 999 | X32_BIT, -ENOSYS);
}
@@ -217,14 +256,18 @@ static void test_syscall_numbering(void)
*/
for (size_t i = 0; i < sizeof(msbs)/sizeof(msbs[0]); i++) {
int msb = msbs[i];
- printf("[RUN]\tChecking system calls with msb = %d (0x%x)\n",
- msb, msb);
+ run("Checking system calls with msb = %d (0x%x)\n",
+ msb, msb);
+
+ indent++;
test_syscalls_common(msb);
if (with_x32)
test_syscalls_with_x32(msb);
else
test_syscalls_without_x32(msb);
+
+ indent--;
}
}
@@ -241,19 +284,16 @@ int main(void)
*/
nullfd = open("/dev/null", O_RDWR);
if (nullfd < 0) {
- printf("[FAIL]\tUnable to open /dev/null: %s\n",
- strerror(errno));
- printf("[SKIP]\tCannot execute test\n");
- return 71; /* EX_OSERR */
+ crit("Unable to open /dev/null: %s\n", strerror(errno));
}
test_syscall_numbering();
if (!nerr) {
- printf("[OK]\tAll system calls succeeded or failed as expected\n");
+ ok("All system calls succeeded or failed as expected\n");
return 0;
} else {
- printf("[FAIL]\tA total of %u system call%s had incorrect behavior\n",
- nerr, nerr != 1 ? "s" : "");
+ fail("A total of %u system call%s had incorrect behavior\n",
+ nerr, nerr != 1 ? "s" : "");
return 1;
}
}
--
2.31.1
next prev parent reply other threads:[~2021-05-18 19:13 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-18 19:12 [PATCH v4 0/6] x86/syscall: use int for x86-64 system calls H. Peter Anvin
2021-05-18 19:12 ` [PATCH v4 1/6] x86/syscall: update and extend selftest syscall_numbering_64 H. Peter Anvin
2021-05-20 13:23 ` [tip: x86/entry] selftests/x86/syscall: Update and extend syscall_numbering_64 tip-bot2 for H. Peter Anvin (Intel)
2021-05-18 19:12 ` H. Peter Anvin [this message]
2021-05-20 13:23 ` [tip: x86/entry] selftests/x86/syscall: Simplify message reporting in syscall_numbering tip-bot2 for H. Peter Anvin (Intel)
2021-05-18 19:13 ` [PATCH v4 3/6] x86/syscall: add tests under ptrace to syscall_numbering.c H. Peter Anvin
2021-05-20 13:23 ` [tip: x86/entry] selftests/x86/syscall: Add tests under ptrace to syscall_numbering_64 tip-bot2 for H. Peter Anvin (Intel)
2021-05-18 19:13 ` [PATCH v4 4/6] x86/syscall: sign-extend system calls on entry to int H. Peter Anvin
2021-05-20 13:23 ` [tip: x86/entry] x86/entry/64: Sign-extend " tip-bot2 for H. Peter Anvin (Intel)
2021-05-18 19:13 ` [PATCH v4 5/6] x86/syscall: treat out of range and gap system calls the same H. Peter Anvin
2021-05-20 13:23 ` [tip: x86/entry] x86/entry: Treat " tip-bot2 for H. Peter Anvin (Intel)
2021-05-18 19:13 ` [PATCH v4 6/6] x86/syscall: use int everywhere for system call numbers H. Peter Anvin
2021-05-20 8:53 ` Thomas Gleixner
2021-05-21 21:36 ` H. Peter Anvin
2021-05-22 13:19 ` David Laight
2021-05-25 8:13 ` [tip: x86/entry] x86/entry: Use " tip-bot2 for H. Peter Anvin (Intel)
2021-05-19 11:29 ` [PATCH v4 0/6] x86/syscall: use int for x86-64 system calls Ingo Molnar
2021-05-19 16:17 ` H. Peter Anvin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210518191303.4135296-3-hpa@zytor.com \
--to=hpa@zytor.com \
--cc=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).