All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Mailhol <mailhol@kernel.org>
To: Chris Li <sparse@chrisli.org>, linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Vincent Mailhol <mailhol@kernel.org>
Subject: [PATCH] vadidation: add used-to-be-signed unit tests
Date: Tue, 23 Sep 2025 00:53:21 +0900	[thread overview]
Message-ID: <20250922155415.3289196-1-mailhol@kernel.org> (raw)
In-Reply-To: <CACePvbWQVBNQAAreW-Mzkp8ircGtV+K=gNk39HmUC0TNDOBCwQ@mail.gmail.com>

Add unit tests for the new used-to-be-signed check as introduced in [1]:

Results before applying [1]:

  $ ./test-suite used-to-be-signed.c
    TEST    used-to-be-signed (used-to-be-signed.c)
  error: actual error text does not match expected error text.
  error: see used-to-be-signed.c.error.* for further investigation.
  --- used-to-be-signed.c.error.expected	2025-09-23 00:50:07.079654644 +0900
  +++ used-to-be-signed.c.error.got	2025-09-23 00:50:07.073654719 +0900
  @@ -1,8 +0,0 @@
  -used-to-be-signed.c:8:19: warning: unsigned value that used to be signed checked against zero?
  -used-to-be-signed.c:6:33: signed value source
  -used-to-be-signed.c:11:17: warning: unsigned value that used to be signed checked against zero?
  -used-to-be-signed.c:6:33: signed value source
  -used-to-be-signed.c:14:20: warning: unsigned value that used to be signed checked against zero?
  -used-to-be-signed.c:6:33: signed value source
  -used-to-be-signed.c:17:18: warning: unsigned value that used to be signed checked against zero?
  -used-to-be-signed.c:6:33: signed value source
  error: FAIL: test 'used-to-be-signed.c' failed
  KO: out of 1 tests, 0 passed, 1 failed

...and after:

  $ ./test-suite used-to-be-signed.c
    TEST    used-to-be-signed (used-to-be-signed.c)
  OK: out of 1 tests, 1 passed, 0 failed

[1] Warn about "unsigned value that used to be signed against zero"
Link: https://lore.kernel.org/linux-sparse/20250921061337.3047616-1-mailhol@kernel.org/

Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
---
Hi Chris,

Thanks for your guidance. I added more tests.

Because you asked me for my preference, I went for the single file.
But if you finally have a preference to split, tell me and I will
update.
---
 validation/used-to-be-signed.c | 49 ++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 validation/used-to-be-signed.c

diff --git a/validation/used-to-be-signed.c b/validation/used-to-be-signed.c
new file mode 100644
index 00000000..75eab7f3
--- /dev/null
+++ b/validation/used-to-be-signed.c
@@ -0,0 +1,49 @@
+void error(void);
+int check(void);
+
+static void positive_tests(unsigned int val)
+{
+	unsigned int ret = check();
+
+	if (ret < 0)
+		error();
+
+	if (0 > ret)
+		error();
+
+	if (ret >= 0)
+		/* Do stuff */;
+
+	if (0 <= ret)
+		/* Do stuff */;
+}
+
+static void negative_tests(unsigned int val)
+{
+	if (val < 0 || val > 42)
+		error();
+
+	if (0 > val || 42 < val)
+		error();
+
+	if (val >= 0 && val < 42)
+		/* Do stuff */;
+
+	if (0 <= val && 42 > val)
+		/* Do stuff */;
+}
+
+/*
+ * check-name: used-to-be-signed
+ *
+ * check-error-start
+used-to-be-signed.c:8:19: warning: unsigned value that used to be signed checked against zero?
+used-to-be-signed.c:6:33: signed value source
+used-to-be-signed.c:11:17: warning: unsigned value that used to be signed checked against zero?
+used-to-be-signed.c:6:33: signed value source
+used-to-be-signed.c:14:20: warning: unsigned value that used to be signed checked against zero?
+used-to-be-signed.c:6:33: signed value source
+used-to-be-signed.c:17:18: warning: unsigned value that used to be signed checked against zero?
+used-to-be-signed.c:6:33: signed value source
+ * check-error-end
+ */
-- 
2.49.1


  reply	other threads:[~2025-09-22 15:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-21  6:12 [PATCH] Warn about "unsigned value that used to be signed against zero" Vincent Mailhol
2025-09-21 15:16 ` Linus Torvalds
2025-09-22 12:10   ` Chris Li
2025-09-22 16:16     ` Linus Torvalds
2025-09-24  7:07       ` Chris Li
2025-09-24  8:54         ` Vincent Mailhol
2025-09-24 17:44           ` Chris Li
2025-09-22 12:02 ` Chris Li
2025-09-22 13:00   ` Vincent Mailhol
2025-09-22 14:58     ` Chris Li
2025-09-22 15:53       ` Vincent Mailhol [this message]
2025-09-24  7:03         ` [PATCH] vadidation: add used-to-be-signed unit tests Chris Li
2025-09-24  9:27           ` Vincent Mailhol
2025-09-24 17:47             ` Chris Li

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=20250922155415.3289196-1-mailhol@kernel.org \
    --to=mailhol@kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    --cc=rostedt@goodmis.org \
    --cc=sparse@chrisli.org \
    --cc=torvalds@linux-foundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.