kvm-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Jones <andrew.jones@linux.dev>
To: kvm-riscv@lists.infradead.org
Cc: cleger@rivosinc.com, atishp@rivosinc.com
Subject: [kvm-unit-tests PATCH v2 3/3] riscv: sbi: Add sbiret_report_error
Date: Tue, 18 Feb 2025 19:54:04 +0100	[thread overview]
Message-ID: <20250218185401.41250-8-andrew.jones@linux.dev> (raw)
In-Reply-To: <20250218185401.41250-5-andrew.jones@linux.dev>

An sbiret value may be unspecified in the case of errors, and even in
the case of success when the function doesn't return anything.
Provide an sbiret report function that only checks sbiret.error.

sbiret_report_error() has a different PASS format than
sbiret_report(). The former will always output the stringized
expected error so the format string doesn't need to contain it, e.g.

  PASS: sbi: test foo: SBI_SUCCESS
  PASS: sbi: test event id 0x0: SBI_INVALID_PARAM

Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
 riscv/sbi-tests.h | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/riscv/sbi-tests.h b/riscv/sbi-tests.h
index 2bdc9440d82d..7a24e083a7b8 100644
--- a/riscv/sbi-tests.h
+++ b/riscv/sbi-tests.h
@@ -36,20 +36,35 @@
 #ifndef __ASSEMBLY__
 #include <asm/sbi.h>
 
-#define sbiret_report(ret, expected_error, expected_value, fmt, ...) ({						\
+#define __sbiret_report(ret, expected_error, expected_value, has_value, expected_error_name, fmt, ...) ({	\
 	long ex_err = expected_error;										\
 	long ex_val = expected_value;										\
+	bool has_val = !!(has_value);										\
 	bool ch_err = (ret)->error == ex_err;									\
 	bool ch_val = (ret)->value == ex_val;									\
-	bool pass = report(ch_err && ch_val, fmt, ##__VA_ARGS__);						\
+	bool pass;												\
 														\
-	if (!pass)												\
+	if (has_val)												\
+		pass = report(ch_err && ch_val, fmt, ##__VA_ARGS__);						\
+	else													\
+		pass = report(ch_err, fmt ": %s", ##__VA_ARGS__, expected_error_name);				\
+														\
+	if (!pass && has_val)											\
 		report_info(fmt ": expected (error: %ld, value: %ld), received: (error: %ld, value %ld)",	\
 			    ##__VA_ARGS__, ex_err, ex_val, (ret)->error, (ret)->value);				\
+	else if (!pass)												\
+		report_info(fmt ": %s (%ld): received error %ld",						\
+			    ##__VA_ARGS__, expected_error_name, ex_err, (ret)->error);				\
 														\
 	pass;													\
 })
 
+#define sbiret_report(ret, expected_error, expected_value, ...) \
+	__sbiret_report(ret, expected_error, expected_value, true, #expected_error, __VA_ARGS__)
+
+#define sbiret_report_error(ret, expected_error, ...) \
+	__sbiret_report(ret, expected_error, 0, false, #expected_error, __VA_ARGS__)
+
 #define sbiret_check(ret, expected_error, expected_value) \
 	sbiret_report(ret, expected_error, expected_value, "check sbi.error and sbi.value")
 
-- 
2.48.1


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

  parent reply	other threads:[~2025-02-18 19:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-18 18:54 [kvm-unit-tests PATCH v2 0/3] riscv: sbi: Provide sbiret_report/check Andrew Jones
2025-02-18 18:54 ` [kvm-unit-tests PATCH v2 1/3] riscv: sbi: Improve gen_report Andrew Jones
2025-02-18 18:54 ` [kvm-unit-tests PATCH v2 2/3] riscv: sbi: Export sbiret_report/check Andrew Jones
2025-02-18 18:54 ` Andrew Jones [this message]
2025-02-25 10:10   ` [kvm-unit-tests PATCH v2 3/3] riscv: sbi: Add sbiret_report_error Clément Léger
2025-03-04  9:32 ` [kvm-unit-tests PATCH v2 0/3] riscv: sbi: Provide sbiret_report/check Andrew Jones

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=20250218185401.41250-8-andrew.jones@linux.dev \
    --to=andrew.jones@linux.dev \
    --cc=atishp@rivosinc.com \
    --cc=cleger@rivosinc.com \
    --cc=kvm-riscv@lists.infradead.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 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).