* [kvm-unit-tests PATCH v2 1/2] lib: Add STR_IS_Y and STR_IS_N for checking env vars
@ 2025-07-08 15:48 Jesse Taube
2025-07-08 15:48 ` [kvm-unit-tests PATCH v2 2/2] riscv: lib: Add sbi-exit-code to configure and environment Jesse Taube
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jesse Taube @ 2025-07-08 15:48 UTC (permalink / raw)
To: kvm, kvm-riscv, linux-kselftest
Cc: Clément Léger, Charlie Jenkins, Jesse Taube,
Andrew Jones, James Raphael Tiovalen, Sean Christopherson,
Cade Richard
the line:
(s && (*s == '1' || *s == 'y' || *s == 'Y'))
is used in a few places add a macro for it and it's 'n' counterpart.
Add GET_CONFIG_OR_ENV for CONFIG values which can be overridden by
the environment.
Signed-off-by: Jesse Taube <jesse@rivosinc.com>
---
lib/argv.h | 13 +++++++++++++
lib/errata.h | 7 ++++---
riscv/sbi-tests.h | 3 ++-
3 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/lib/argv.h b/lib/argv.h
index 0fa77725..ecbb40d7 100644
--- a/lib/argv.h
+++ b/lib/argv.h
@@ -14,4 +14,17 @@ extern void setup_args_progname(const char *args);
extern void setup_env(char *env, int size);
extern void add_setup_arg(const char *arg);
+#define STR_IS_Y(s) (s && (*s == '1' || *s == 'y' || *s == 'Y'))
+#define STR_IS_N(s) (s && (*s == '0' || *s == 'n' || *s == 'N'))
+
+/*
+ * Get the boolean value of CONFIG_{name}
+ * which can be overridden by the {name}
+ * variable in the environment if present.
+ */
+#define GET_CONFIG_OR_ENV(name) ({ \
+ const char *s = getenv(#name); \
+ s ? STR_IS_Y(s) : CONFIG_##name; \
+})
+
#endif
diff --git a/lib/errata.h b/lib/errata.h
index de8205d8..78007243 100644
--- a/lib/errata.h
+++ b/lib/errata.h
@@ -7,6 +7,7 @@
#ifndef _ERRATA_H_
#define _ERRATA_H_
#include <libcflat.h>
+#include <argv.h>
#include "config.h"
@@ -28,7 +29,7 @@ static inline bool errata_force(void)
return true;
s = getenv("ERRATA_FORCE");
- return s && (*s == '1' || *s == 'y' || *s == 'Y');
+ return STR_IS_Y(s);
}
static inline bool errata(const char *erratum)
@@ -40,7 +41,7 @@ static inline bool errata(const char *erratum)
s = getenv(erratum);
- return s && (*s == '1' || *s == 'y' || *s == 'Y');
+ return STR_IS_Y(s);
}
static inline bool errata_relaxed(const char *erratum)
@@ -52,7 +53,7 @@ static inline bool errata_relaxed(const char *erratum)
s = getenv(erratum);
- return !(s && (*s == '0' || *s == 'n' || *s == 'N'));
+ return !STR_IS_N(s);
}
#endif
diff --git a/riscv/sbi-tests.h b/riscv/sbi-tests.h
index c1ebf016..4e051dca 100644
--- a/riscv/sbi-tests.h
+++ b/riscv/sbi-tests.h
@@ -37,6 +37,7 @@
#ifndef __ASSEMBLER__
#include <libcflat.h>
+#include <argv.h>
#include <asm/sbi.h>
#define __sbiret_report(kfail, ret, expected_error, expected_value, \
@@ -94,7 +95,7 @@ static inline bool env_enabled(const char *env)
{
char *s = getenv(env);
- return s && (*s == '1' || *s == 'y' || *s == 'Y');
+ return STR_IS_Y(s);
}
void split_phys_addr(phys_addr_t paddr, unsigned long *hi, unsigned long *lo);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [kvm-unit-tests PATCH v2 2/2] riscv: lib: Add sbi-exit-code to configure and environment
2025-07-08 15:48 [kvm-unit-tests PATCH v2 1/2] lib: Add STR_IS_Y and STR_IS_N for checking env vars Jesse Taube
@ 2025-07-08 15:48 ` Jesse Taube
2025-07-09 10:11 ` Andrew Jones
2025-07-09 10:09 ` [kvm-unit-tests PATCH v2 1/2] lib: Add STR_IS_Y and STR_IS_N for checking env vars Andrew Jones
2025-07-09 10:14 ` Andrew Jones
2 siblings, 1 reply; 5+ messages in thread
From: Jesse Taube @ 2025-07-08 15:48 UTC (permalink / raw)
To: kvm, kvm-riscv, linux-kselftest
Cc: Clément Léger, Charlie Jenkins, Jesse Taube,
Andrew Jones, James Raphael Tiovalen, Sean Christopherson,
Cade Richard
Add --[enable|disable]-sbi-exit-code to configure script.
With the default value as disabled.
Add a check for SBI_EXIT_CODE in the environment, so that passing
of the test status is configurable from both the
environment and the configure script
Signed-off-by: Jesse Taube <jesse@rivosinc.com>
---
configure | 11 +++++++++++
lib/riscv/io.c | 4 +++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/configure b/configure
index 20bf5042..7c949bdc 100755
--- a/configure
+++ b/configure
@@ -67,6 +67,7 @@ earlycon=
console=
efi=
efi_direct=
+sbi_exit_code=0
target_cpu=
# Enable -Werror by default for git repositories only (i.e. developer builds)
@@ -141,6 +142,9 @@ usage() {
system and run from the UEFI shell. Ignored when efi isn't enabled
and defaults to enabled when efi is enabled for riscv64.
(arm64 and riscv64 only)
+ --[enable|disable]-sbi-exit-code
+ Enable or disable sending pass/fail exit code to SBI SRST.
+ (disabled by default, riscv only)
EOF
exit 1
}
@@ -236,6 +240,12 @@ while [[ $optno -le $argc ]]; do
--disable-efi-direct)
efi_direct=n
;;
+ --enable-sbi-exit-code)
+ sbi_exit_code=1
+ ;;
+ --disable-sbi-exit-code)
+ sbi_exit_code=0
+ ;;
--enable-werror)
werror=-Werror
;;
@@ -551,6 +561,7 @@ EOF
elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then
echo "#define CONFIG_UART_EARLY_BASE ${uart_early_addr}" >> lib/config.h
[ "$console" = "sbi" ] && echo "#define CONFIG_SBI_CONSOLE" >> lib/config.h
+ echo "#define CONFIG_SBI_EXIT_CODE ${sbi_exit_code}" >> lib/config.h
echo >> lib/config.h
fi
echo "#endif" >> lib/config.h
diff --git a/lib/riscv/io.c b/lib/riscv/io.c
index b1163404..c46845de 100644
--- a/lib/riscv/io.c
+++ b/lib/riscv/io.c
@@ -6,6 +6,7 @@
* Copyright (C) 2023, Ventana Micro Systems Inc., Andrew Jones <ajones@ventanamicro.com>
*/
#include <libcflat.h>
+#include <argv.h>
#include <bitops.h>
#include <config.h>
#include <devicetree.h>
@@ -163,7 +164,8 @@ void halt(int code);
void exit(int code)
{
printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1);
- sbi_shutdown(code == 0);
+
+ sbi_shutdown(GET_CONFIG_OR_ENV(SBI_EXIT_CODE) ? code == 0 : true);
halt(code);
__builtin_unreachable();
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [kvm-unit-tests PATCH v2 1/2] lib: Add STR_IS_Y and STR_IS_N for checking env vars
2025-07-08 15:48 [kvm-unit-tests PATCH v2 1/2] lib: Add STR_IS_Y and STR_IS_N for checking env vars Jesse Taube
2025-07-08 15:48 ` [kvm-unit-tests PATCH v2 2/2] riscv: lib: Add sbi-exit-code to configure and environment Jesse Taube
@ 2025-07-09 10:09 ` Andrew Jones
2025-07-09 10:14 ` Andrew Jones
2 siblings, 0 replies; 5+ messages in thread
From: Andrew Jones @ 2025-07-09 10:09 UTC (permalink / raw)
To: Jesse Taube
Cc: kvm, kvm-riscv, linux-kselftest, Clément Léger,
Charlie Jenkins, James Raphael Tiovalen, Sean Christopherson,
Cade Richard
On Tue, Jul 08, 2025 at 08:48:10AM -0700, Jesse Taube wrote:
> the line:
> (s && (*s == '1' || *s == 'y' || *s == 'Y'))
> is used in a few places add a macro for it and it's 'n' counterpart.
^ its
>
> Add GET_CONFIG_OR_ENV for CONFIG values which can be overridden by
> the environment.
>
> Signed-off-by: Jesse Taube <jesse@rivosinc.com>
> ---
> lib/argv.h | 13 +++++++++++++
> lib/errata.h | 7 ++++---
> riscv/sbi-tests.h | 3 ++-
> 3 files changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/lib/argv.h b/lib/argv.h
> index 0fa77725..ecbb40d7 100644
> --- a/lib/argv.h
> +++ b/lib/argv.h
> @@ -14,4 +14,17 @@ extern void setup_args_progname(const char *args);
> extern void setup_env(char *env, int size);
> extern void add_setup_arg(const char *arg);
>
> +#define STR_IS_Y(s) (s && (*s == '1' || *s == 'y' || *s == 'Y'))
> +#define STR_IS_N(s) (s && (*s == '0' || *s == 'n' || *s == 'N'))
> +
> +/*
> + * Get the boolean value of CONFIG_{name}
> + * which can be overridden by the {name}
> + * variable in the environment if present.
> + */
> +#define GET_CONFIG_OR_ENV(name) ({ \
> + const char *s = getenv(#name); \
> + s ? STR_IS_Y(s) : CONFIG_##name; \
> +})
This requires CONFIG_##name to be defined, even if it's a 'no'. That's
probably OK, but a solution that allows it to be undefined, which then
means 'no' would be nice.
> +
> #endif
> diff --git a/lib/errata.h b/lib/errata.h
> index de8205d8..78007243 100644
> --- a/lib/errata.h
> +++ b/lib/errata.h
> @@ -7,6 +7,7 @@
> #ifndef _ERRATA_H_
> #define _ERRATA_H_
> #include <libcflat.h>
> +#include <argv.h>
>
> #include "config.h"
>
> @@ -28,7 +29,7 @@ static inline bool errata_force(void)
> return true;
>
> s = getenv("ERRATA_FORCE");
> - return s && (*s == '1' || *s == 'y' || *s == 'Y');
> + return STR_IS_Y(s);
> }
>
> static inline bool errata(const char *erratum)
> @@ -40,7 +41,7 @@ static inline bool errata(const char *erratum)
>
> s = getenv(erratum);
>
> - return s && (*s == '1' || *s == 'y' || *s == 'Y');
> + return STR_IS_Y(s);
> }
>
> static inline bool errata_relaxed(const char *erratum)
> @@ -52,7 +53,7 @@ static inline bool errata_relaxed(const char *erratum)
>
> s = getenv(erratum);
>
> - return !(s && (*s == '0' || *s == 'n' || *s == 'N'));
> + return !STR_IS_N(s);
> }
>
> #endif
> diff --git a/riscv/sbi-tests.h b/riscv/sbi-tests.h
> index c1ebf016..4e051dca 100644
> --- a/riscv/sbi-tests.h
> +++ b/riscv/sbi-tests.h
> @@ -37,6 +37,7 @@
>
> #ifndef __ASSEMBLER__
> #include <libcflat.h>
> +#include <argv.h>
> #include <asm/sbi.h>
>
> #define __sbiret_report(kfail, ret, expected_error, expected_value, \
> @@ -94,7 +95,7 @@ static inline bool env_enabled(const char *env)
> {
> char *s = getenv(env);
>
> - return s && (*s == '1' || *s == 'y' || *s == 'Y');
> + return STR_IS_Y(s);
> }
>
> void split_phys_addr(phys_addr_t paddr, unsigned long *hi, unsigned long *lo);
> --
> 2.43.0
>
Besides the typo, LGTM
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [kvm-unit-tests PATCH v2 2/2] riscv: lib: Add sbi-exit-code to configure and environment
2025-07-08 15:48 ` [kvm-unit-tests PATCH v2 2/2] riscv: lib: Add sbi-exit-code to configure and environment Jesse Taube
@ 2025-07-09 10:11 ` Andrew Jones
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Jones @ 2025-07-09 10:11 UTC (permalink / raw)
To: Jesse Taube
Cc: kvm, kvm-riscv, linux-kselftest, Clément Léger,
Charlie Jenkins, James Raphael Tiovalen, Sean Christopherson,
Cade Richard
On Tue, Jul 08, 2025 at 08:48:11AM -0700, Jesse Taube wrote:
> Add --[enable|disable]-sbi-exit-code to configure script.
> With the default value as disabled.
> Add a check for SBI_EXIT_CODE in the environment, so that passing
> of the test status is configurable from both the
> environment and the configure script
>
> Signed-off-by: Jesse Taube <jesse@rivosinc.com>
> ---
> configure | 11 +++++++++++
> lib/riscv/io.c | 4 +++-
> 2 files changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/configure b/configure
> index 20bf5042..7c949bdc 100755
> --- a/configure
> +++ b/configure
> @@ -67,6 +67,7 @@ earlycon=
> console=
> efi=
> efi_direct=
> +sbi_exit_code=0
> target_cpu=
>
> # Enable -Werror by default for git repositories only (i.e. developer builds)
> @@ -141,6 +142,9 @@ usage() {
> system and run from the UEFI shell. Ignored when efi isn't enabled
> and defaults to enabled when efi is enabled for riscv64.
> (arm64 and riscv64 only)
> + --[enable|disable]-sbi-exit-code
> + Enable or disable sending pass/fail exit code to SBI SRST.
> + (disabled by default, riscv only)
> EOF
> exit 1
> }
> @@ -236,6 +240,12 @@ while [[ $optno -le $argc ]]; do
> --disable-efi-direct)
> efi_direct=n
> ;;
> + --enable-sbi-exit-code)
> + sbi_exit_code=1
> + ;;
> + --disable-sbi-exit-code)
> + sbi_exit_code=0
> + ;;
> --enable-werror)
> werror=-Werror
> ;;
> @@ -551,6 +561,7 @@ EOF
> elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then
> echo "#define CONFIG_UART_EARLY_BASE ${uart_early_addr}" >> lib/config.h
> [ "$console" = "sbi" ] && echo "#define CONFIG_SBI_CONSOLE" >> lib/config.h
> + echo "#define CONFIG_SBI_EXIT_CODE ${sbi_exit_code}" >> lib/config.h
> echo >> lib/config.h
> fi
> echo "#endif" >> lib/config.h
> diff --git a/lib/riscv/io.c b/lib/riscv/io.c
> index b1163404..c46845de 100644
> --- a/lib/riscv/io.c
> +++ b/lib/riscv/io.c
> @@ -6,6 +6,7 @@
> * Copyright (C) 2023, Ventana Micro Systems Inc., Andrew Jones <ajones@ventanamicro.com>
> */
> #include <libcflat.h>
> +#include <argv.h>
> #include <bitops.h>
> #include <config.h>
> #include <devicetree.h>
> @@ -163,7 +164,8 @@ void halt(int code);
> void exit(int code)
> {
> printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1);
> - sbi_shutdown(code == 0);
> +
> + sbi_shutdown(GET_CONFIG_OR_ENV(SBI_EXIT_CODE) ? code == 0 : true);
> halt(code);
> __builtin_unreachable();
> }
> --
> 2.43.0
>
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [kvm-unit-tests PATCH v2 1/2] lib: Add STR_IS_Y and STR_IS_N for checking env vars
2025-07-08 15:48 [kvm-unit-tests PATCH v2 1/2] lib: Add STR_IS_Y and STR_IS_N for checking env vars Jesse Taube
2025-07-08 15:48 ` [kvm-unit-tests PATCH v2 2/2] riscv: lib: Add sbi-exit-code to configure and environment Jesse Taube
2025-07-09 10:09 ` [kvm-unit-tests PATCH v2 1/2] lib: Add STR_IS_Y and STR_IS_N for checking env vars Andrew Jones
@ 2025-07-09 10:14 ` Andrew Jones
2 siblings, 0 replies; 5+ messages in thread
From: Andrew Jones @ 2025-07-09 10:14 UTC (permalink / raw)
To: Jesse Taube
Cc: kvm, kvm-riscv, linux-kselftest, Clément Léger,
Charlie Jenkins, James Raphael Tiovalen, Sean Christopherson,
Cade Richard
On Tue, Jul 08, 2025 at 08:48:10AM -0700, Jesse Taube wrote:
> the line:
> (s && (*s == '1' || *s == 'y' || *s == 'Y'))
> is used in a few places add a macro for it and it's 'n' counterpart.
>
> Add GET_CONFIG_OR_ENV for CONFIG values which can be overridden by
> the environment.
>
> Signed-off-by: Jesse Taube <jesse@rivosinc.com>
> ---
> lib/argv.h | 13 +++++++++++++
> lib/errata.h | 7 ++++---
> riscv/sbi-tests.h | 3 ++-
> 3 files changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/lib/argv.h b/lib/argv.h
> index 0fa77725..ecbb40d7 100644
> --- a/lib/argv.h
> +++ b/lib/argv.h
> @@ -14,4 +14,17 @@ extern void setup_args_progname(const char *args);
> extern void setup_env(char *env, int size);
> extern void add_setup_arg(const char *arg);
>
> +#define STR_IS_Y(s) (s && (*s == '1' || *s == 'y' || *s == 'Y'))
> +#define STR_IS_N(s) (s && (*s == '0' || *s == 'n' || *s == 'N'))
> +
> +/*
> + * Get the boolean value of CONFIG_{name}
> + * which can be overridden by the {name}
> + * variable in the environment if present.
> + */
> +#define GET_CONFIG_OR_ENV(name) ({ \
This should be named GET_ENV_OR_CONFIG since the "first_or_second" naming
implies that if the first thing doesn't succeed, then try the second.
Thanks,
drew
> + const char *s = getenv(#name); \
> + s ? STR_IS_Y(s) : CONFIG_##name; \
> +})
> +
> #endif
> diff --git a/lib/errata.h b/lib/errata.h
> index de8205d8..78007243 100644
> --- a/lib/errata.h
> +++ b/lib/errata.h
> @@ -7,6 +7,7 @@
> #ifndef _ERRATA_H_
> #define _ERRATA_H_
> #include <libcflat.h>
> +#include <argv.h>
>
> #include "config.h"
>
> @@ -28,7 +29,7 @@ static inline bool errata_force(void)
> return true;
>
> s = getenv("ERRATA_FORCE");
> - return s && (*s == '1' || *s == 'y' || *s == 'Y');
> + return STR_IS_Y(s);
> }
>
> static inline bool errata(const char *erratum)
> @@ -40,7 +41,7 @@ static inline bool errata(const char *erratum)
>
> s = getenv(erratum);
>
> - return s && (*s == '1' || *s == 'y' || *s == 'Y');
> + return STR_IS_Y(s);
> }
>
> static inline bool errata_relaxed(const char *erratum)
> @@ -52,7 +53,7 @@ static inline bool errata_relaxed(const char *erratum)
>
> s = getenv(erratum);
>
> - return !(s && (*s == '0' || *s == 'n' || *s == 'N'));
> + return !STR_IS_N(s);
> }
>
> #endif
> diff --git a/riscv/sbi-tests.h b/riscv/sbi-tests.h
> index c1ebf016..4e051dca 100644
> --- a/riscv/sbi-tests.h
> +++ b/riscv/sbi-tests.h
> @@ -37,6 +37,7 @@
>
> #ifndef __ASSEMBLER__
> #include <libcflat.h>
> +#include <argv.h>
> #include <asm/sbi.h>
>
> #define __sbiret_report(kfail, ret, expected_error, expected_value, \
> @@ -94,7 +95,7 @@ static inline bool env_enabled(const char *env)
> {
> char *s = getenv(env);
>
> - return s && (*s == '1' || *s == 'y' || *s == 'Y');
> + return STR_IS_Y(s);
> }
>
> void split_phys_addr(phys_addr_t paddr, unsigned long *hi, unsigned long *lo);
> --
> 2.43.0
>
>
> --
> kvm-riscv mailing list
> kvm-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-07-09 10:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-08 15:48 [kvm-unit-tests PATCH v2 1/2] lib: Add STR_IS_Y and STR_IS_N for checking env vars Jesse Taube
2025-07-08 15:48 ` [kvm-unit-tests PATCH v2 2/2] riscv: lib: Add sbi-exit-code to configure and environment Jesse Taube
2025-07-09 10:11 ` Andrew Jones
2025-07-09 10:09 ` [kvm-unit-tests PATCH v2 1/2] lib: Add STR_IS_Y and STR_IS_N for checking env vars Andrew Jones
2025-07-09 10:14 ` Andrew Jones
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).