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 1/3] riscv: sbi: Improve gen_report
Date: Tue, 18 Feb 2025 19:54:02 +0100 [thread overview]
Message-ID: <20250218185401.41250-6-andrew.jones@linux.dev> (raw)
In-Reply-To: <20250218185401.41250-5-andrew.jones@linux.dev>
Make several improvements to gen_report(), starting by renaming it
to something less generic (sbiret_report) and then, instead of
relying on report prefix to link the report_info with the unexpected
return values to the failed test, use the test string itself, by
taking it as a parameter. And, reporting sbiret.error and
sbiret.value separately was more verbose than necessary since the
report_info can be used to see which one failed, so combine them.
Finally, return the pass/fail result of the test in case a caller
wants to use it.
Tested-by: Clément Léger <cleger@rivosinc.com>
Reviewed-by: Clément Léger <cleger@rivosinc.com>
Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
riscv/sbi.c | 45 ++++++++++++++++++++++++---------------------
1 file changed, 24 insertions(+), 21 deletions(-)
diff --git a/riscv/sbi.c b/riscv/sbi.c
index 6f4ddaf13df3..9f591f8ff76a 100644
--- a/riscv/sbi.c
+++ b/riscv/sbi.c
@@ -156,19 +156,22 @@ static bool get_invalid_addr(phys_addr_t *paddr, bool allow_default)
return false;
}
-static void gen_report(struct sbiret *ret,
- long expected_error, long expected_value)
-{
- bool check_error = ret->error == expected_error;
- bool check_value = ret->value == expected_value;
-
- if (!check_error || !check_value)
- report_info("expected (error: %ld, value: %ld), received: (error: %ld, value %ld)",
- expected_error, expected_value, ret->error, ret->value);
-
- report(check_error, "expected sbi.error");
- report(check_value, "expected sbi.value");
-}
+#define sbiret_report(ret, expected_error, expected_value, fmt, ...) ({ \
+ long ex_err = expected_error; \
+ long ex_val = expected_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__); \
+ \
+ if (!pass) \
+ report_info(fmt ": expected (error: %ld, value: %ld), received: (error: %ld, value %ld)", \
+ ##__VA_ARGS__, ex_err, ex_val, (ret)->error, (ret)->value); \
+ \
+ pass; \
+})
+
+#define sbiret_check(ret, expected_error, expected_value) \
+ sbiret_report(ret, expected_error, expected_value, "check sbi.error and sbi.value")
static void check_base(void)
{
@@ -184,7 +187,7 @@ static void check_base(void)
expected = (long)strtoul(getenv("SBI_SPEC_VERSION"), NULL, 0);
assert_msg(!(expected & BIT(31)), "SBI spec version bit 31 must be zero");
assert_msg(__riscv_xlen == 32 || !(expected >> 32), "SBI spec version bits greater than 31 must be zero");
- gen_report(&ret, 0, expected);
+ sbiret_check(&ret, 0, expected);
}
report_prefix_pop();
@@ -199,7 +202,7 @@ static void check_base(void)
if (env_or_skip("SBI_IMPL_ID")) {
expected = (long)strtoul(getenv("SBI_IMPL_ID"), NULL, 0);
ret = sbi_base(SBI_EXT_BASE_GET_IMP_ID, 0);
- gen_report(&ret, 0, expected);
+ sbiret_check(&ret, 0, expected);
}
report_prefix_pop();
@@ -207,17 +210,17 @@ static void check_base(void)
if (env_or_skip("SBI_IMPL_VERSION")) {
expected = (long)strtoul(getenv("SBI_IMPL_VERSION"), NULL, 0);
ret = sbi_base(SBI_EXT_BASE_GET_IMP_VERSION, 0);
- gen_report(&ret, 0, expected);
+ sbiret_check(&ret, 0, expected);
}
report_prefix_pop();
report_prefix_push("probe_ext");
expected = getenv("SBI_PROBE_EXT") ? (long)strtoul(getenv("SBI_PROBE_EXT"), NULL, 0) : 1;
ret = sbi_base(SBI_EXT_BASE_PROBE_EXT, SBI_EXT_BASE);
- gen_report(&ret, 0, expected);
+ sbiret_check(&ret, 0, expected);
report_prefix_push("unavailable");
ret = sbi_base(SBI_EXT_BASE_PROBE_EXT, 0xb000000);
- gen_report(&ret, 0, 0);
+ sbiret_check(&ret, 0, 0);
report_prefix_popn(2);
report_prefix_push("mvendorid");
@@ -225,7 +228,7 @@ static void check_base(void)
expected = (long)strtoul(getenv("MVENDORID"), NULL, 0);
assert(__riscv_xlen == 32 || !(expected >> 32));
ret = sbi_base(SBI_EXT_BASE_GET_MVENDORID, 0);
- gen_report(&ret, 0, expected);
+ sbiret_check(&ret, 0, expected);
}
report_prefix_pop();
@@ -233,7 +236,7 @@ static void check_base(void)
if (env_or_skip("MARCHID")) {
expected = (long)strtoul(getenv("MARCHID"), NULL, 0);
ret = sbi_base(SBI_EXT_BASE_GET_MARCHID, 0);
- gen_report(&ret, 0, expected);
+ sbiret_check(&ret, 0, expected);
}
report_prefix_pop();
@@ -241,7 +244,7 @@ static void check_base(void)
if (env_or_skip("MIMPID")) {
expected = (long)strtoul(getenv("MIMPID"), NULL, 0);
ret = sbi_base(SBI_EXT_BASE_GET_MIMPID, 0);
- gen_report(&ret, 0, expected);
+ sbiret_check(&ret, 0, expected);
}
report_prefix_popn(2);
}
--
2.48.1
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
next prev 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 ` Andrew Jones [this message]
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 ` [kvm-unit-tests PATCH v2 3/3] riscv: sbi: Add sbiret_report_error Andrew Jones
2025-02-25 10:10 ` 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-6-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).