riscv: sbi: Clean up multiple report prefix popping
Subsystems (4)
cover riscv: sbi: Clean up multiple report prefix popping
The first patch of this series adds a helper method to clear multiple prefixes at once. The second patch then uses this new helper method to tidy up the report prefix pops in the RISC-V SBI tests.
James Raphael Tiovalen (2):
lib/report: Add helper method to clear multiple prefixes
riscv: sbi: Tidy up report prefix pops
lib/libcflat.h | 1 + lib/report.c | 21 +++++++++++++++------ riscv/sbi.c | 17 +++++------------ 3 files changed, 21 insertions(+), 18 deletions(-)
--
2.43.0
PATCH 1/2 lib/report: Add helper method to clear multiple prefixes
Add a method to pop a specified number of prefixes. This method is useful when tests want to clear multiple prefixes at once.
--- lib/libcflat.h | 1 + lib/report.c | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-)
lib/libcflat.h +1 -0
@@ -96,6 +96,7 @@ void report_prefix_pushf(const char *prefix_fmt, ...) __attribute__((format(printf, 1, 2)));extern void report_prefix_push (const char *prefix);extern void report_prefix_pop (void ); +extern void report_prefix_popn (int n);extern void report (bool pass,const char *msg_fmt, ...) __attribute__((format (printf,2 ,3 ),nonnull (2 )));extern void report_xfail (bool xfail,bool pass,const char *msg_fmt, ...)
lib/report.c +15 -6
@@ -60,23 +60,32 @@ void report_prefix_push(const char *prefix)report_prefix_pushf ("%s" , prefix); } -void report_prefix_pop (void ) +static void __report_prefix_pop (void ) {char *p, *q; -spin_lock (&lock); - -if (!*prefixes) { -spin_unlock (&lock); +if (!*prefixes)return ; - }for (p = prefixes, q =strstr (p,PREFIX_DELIMITER ) +2 ; *q; p = q, q =strstr (p,PREFIX_DELIMITER ) +2 ) ; *p ='\0' ; +} +void report_prefix_pop (void ) +{ +spin_lock (&lock); +__report_prefix_pop (); +spin_unlock (&lock); +} + +void report_prefix_popn (int n) +{ +spin_lock (&lock); +while (n--) +__report_prefix_pop ();spin_unlock (&lock); }
Signature · 1 line
2.43.0
PATCH 2/2 riscv: sbi: Tidy up report prefix pops
In reply to James Raphael TiovalenReplace multiple consecutive calls of the report_prefix_pop function with the new report_prefix_popn function.
--- riscv/sbi.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)
riscv/sbi.c +5 -12
@@ -140,8 +140,7 @@ static void check_base(void)report_prefix_push ("unavailable" ); ret =sbi_base (SBI_EXT_BASE_PROBE_EXT ,0xb000000 );gen_report (&ret,0 ,0 ); -report_prefix_pop (); -report_prefix_pop (); +report_prefix_popn (2 );report_prefix_push ("mvendorid" );if (env_or_skip ("MVENDORID" )) {
@@ -166,9 +165,7 @@ static void check_base(void) ret =sbi_base (SBI_EXT_BASE_GET_MIMPID ,0 );gen_report (&ret,0 , expected); } -report_prefix_pop (); - -report_prefix_pop (); +report_prefix_popn (2 ); }struct timer_info {
@@ -281,8 +278,7 @@ static void check_time(void)local_irq_disable ();install_irq_handler (IRQ_S_TIMER ,NULL ); -report_prefix_pop (); -report_prefix_pop (); +report_prefix_popn (2 ); }#define DBCN_WRITE_TEST_STRING "DBCN_WRITE_TEST_STRING\n"
@@ -401,9 +397,7 @@ static void check_dbcn(void) ret =sbi_dbcn_write (1 , base_addr_lo, base_addr_hi);report (ret.error ==SBI_ERR_INVALID_PARAM ,"address (error=%ld)" , ret.error); } -report_prefix_pop (); - -report_prefix_pop (); +report_prefix_popn (2 );report_prefix_push ("write_byte" );puts ("DBCN_WRITE_BYTE TEST BYTE: " );
@@ -418,8 +412,7 @@ static void check_dbcn(void)report (ret.error ==SBI_SUCCESS ,"write success (error=%ld)" , ret.error);report (ret.value ==0 ,"expected ret.value (%ld)" , ret.value); -report_prefix_pop (); -report_prefix_pop (); +report_prefix_popn (2 ); }int main (int argc,char **argv)
Signature · 1 line
2.43.0
Quoted 8 lines · James Raphael Tiovalen
The first patch of this series adds a helper method to clear multiple prefixes at once. The second patch then uses this new helper method to tidy up the report prefix pops in the RISC-V SBI tests.
James Raphael Tiovalen (2):
lib/report: Add helper method to clear multiple prefixes
riscv: sbi: Tidy up report prefix pops
Quoted 8 lines
lib/libcflat.h | 1 + lib/report.c | 21 +++++++++++++++------ riscv/sbi.c | 17 +++++------------ 3 files changed, 21 insertions(+), 18 deletions(-)--
2.43.0
Looks good to me. There are no longer any double pops in riscv. Out of curiosity, I checked the other architectures. arm and ppc both had one instance of double pop, x86 didn't have any, but s390x had several. We can leave the adoption of popn to the respective maintainer's preferences though.
Applied to riscv/sbi, https://gitlab.com/jones-drew/kvm-unit-tests/-/commits/riscv/sbi
Thanks,
drew