linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Zhangjin Wu <falcon@tinylab.org>
To: w@1wt.eu
Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-riscv@lists.infradead.org, thomas@t-8ch.de
Subject: [PATCH v6 11/15] selftests/nolibc: add EXPECT_PTREQ, EXPECT_PTRNE and EXPECT_PTRER
Date: Fri,  7 Jul 2023 23:03:26 +0800	[thread overview]
Message-ID: <c8731f470b344d3fc8db30f6112c4e0c7d7d5765.1688739492.git.falcon@tinylab.org> (raw)
In-Reply-To: <cover.1688739492.git.falcon@tinylab.org>

The syscalls like sbrk() and mmap() return pointers, to test them, more
pointer compare test macros are required, add them:

- EXPECT_PTREQ() expects two equal pointers.
- EXPECT_PTRNE() expects two non-equal pointers.
- EXPECT_PTRER() expects failure with a specified errno.
- EXPECT_PTRER2() expects failure with one of two specified errnos.

Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 58 ++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index b759fb25d375..8be675debf28 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -364,6 +364,64 @@ static int expect_ptrnz(const void *expr, int llen)
 	return ret;
 }
 
+#define EXPECT_PTREQ(cond, expr, cmp)				\
+	do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptreq(expr, llen, cmp); } while (0)
+
+static int expect_ptreq(const void *expr, int llen, const void *cmp)
+{
+	int ret = 0;
+
+	llen += printf(" = <%p> ", expr);
+	if (expr != cmp) {
+		ret = 1;
+		llen += pad_spc(llen, 64, "[FAIL]\n");
+	} else {
+		llen += pad_spc(llen, 64, " [OK]\n");
+	}
+	return ret;
+}
+
+#define EXPECT_PTRNE(cond, expr, cmp)				\
+	do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrne(expr, llen, cmp); } while (0)
+
+static int expect_ptrne(const void *expr, int llen, const void *cmp)
+{
+	int ret = 0;
+
+	llen += printf(" = <%p> ", expr);
+	if (expr == cmp) {
+		ret = 1;
+		llen += pad_spc(llen, 64, "[FAIL]\n");
+	} else {
+		llen += pad_spc(llen, 64, " [OK]\n");
+	}
+	return ret;
+}
+
+#define EXPECT_PTRER2(cond, expr, expret, experr1, experr2)		\
+	do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_ptrerr2(expr, expret, experr1, experr2, llen); } while (0)
+
+#define EXPECT_PTRER(cond, expr, expret, experr)			\
+	EXPECT_PTRER2(cond, expr, expret, experr, 0)
+
+static int expect_ptrerr2(const void *expr, const void *expret, int experr1, int experr2, int llen)
+{
+	int ret = 0;
+	int _errno = errno;
+
+	llen += printf(" = <%p> %s ", expr, errorname(_errno));
+	if (expr != expret || (_errno != experr1 && _errno != experr2)) {
+		ret = 1;
+		if (experr2 == 0)
+			llen += printf(" != (<%p> %s) ", expret, errorname(experr1));
+		else
+			llen += printf(" != (<%p> %s %s) ", expret, errorname(experr1), errorname(experr2));
+		llen += pad_spc(llen, 64, "[FAIL]\n");
+	} else {
+		llen += pad_spc(llen, 64, " [OK]\n");
+	}
+	return ret;
+}
 
 #define EXPECT_STRZR(cond, expr)				\
 	do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_strzr(expr, llen); } while (0)
-- 
2.25.1


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  parent reply	other threads:[~2023-07-07 15:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-07 14:49 [PATCH v6 00/15] tools/nolibc: add a new syscall helper Zhangjin Wu
2023-07-07 14:50 ` [PATCH v6 01/15] tools/nolibc: arch-*.h: fix up code indent errors Zhangjin Wu
2023-07-09  9:17   ` Willy Tarreau
2023-07-07 14:52 ` [PATCH v6 02/15] toolc/nolibc: arch-*.h: clean up whitespaces after __asm__ Zhangjin Wu
2023-07-07 14:53 ` [PATCH v6 03/15] tools/nolibc: arch-loongarch.h: shrink with _NOLIBC_SYSCALL_CLOBBERLIST Zhangjin Wu
2023-07-07 14:54 ` [PATCH v6 04/15] tools/nolibc: arch-mips.h: " Zhangjin Wu
2023-07-07 14:55 ` [PATCH v6 05/15] tools/nolibc: add missing my_syscall6() for mips Zhangjin Wu
2023-07-07 14:56 ` [PATCH v6 06/15] tools/nolibc: __sysret: support syscalls who return a pointer Zhangjin Wu
2023-07-07 14:58 ` [PATCH v6 07/15] tools/nolibc: clean up mmap() routine Zhangjin Wu
2023-07-07 14:59 ` [PATCH v6 08/15] tools/nolibc: clean up sbrk() routine Zhangjin Wu
2023-07-07 15:01 ` [PATCH v6 09/15] selftests/nolibc: export argv0 for some tests Zhangjin Wu
2023-07-07 15:02 ` [PATCH v6 10/15] selftests/nolibc: prepare: create /dev/zero Zhangjin Wu
2023-07-07 15:03 ` Zhangjin Wu [this message]
2023-07-07 15:04 ` [PATCH v6 12/15] selftests/nolibc: add sbrk_0 to test current brk getting Zhangjin Wu
2023-07-07 15:05 ` [PATCH v6 13/15] selftests/nolibc: add mmap_bad test case Zhangjin Wu
2023-07-09  9:15   ` Willy Tarreau
2023-07-09 18:33     ` Zhangjin Wu
2023-07-10  7:04       ` Willy Tarreau
2023-07-07 15:07 ` [PATCH v6 14/15] selftests/nolibc: add munmap_bad " Zhangjin Wu
2023-07-07 15:08 ` [PATCH v6 15/15] selftests/nolibc: add mmap_munmap_good " Zhangjin Wu

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=c8731f470b344d3fc8db30f6112c4e0c7d7d5765.1688739492.git.falcon@tinylab.org \
    --to=falcon@tinylab.org \
    --cc=arnd@arndb.de \
    --cc=david.laight@aculab.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=thomas@t-8ch.de \
    --cc=w@1wt.eu \
    /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).