From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68450C83F0A for ; Wed, 9 Jul 2025 12:03:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eXeVixmK88SUQKte9RfrEy1Ug7ssMXHqpFZy0MH1pKM=; b=RJFgHk7uyy8/t/ W0m4MRv5E9ZYN6PRwh2WgRL8dZb8L27mKoRWtVvXSsjmg+51L0S6I8NZqocI95etkad3Y5dFHZujE pjrE4S4BCQmAn9EWr0LVPCGgYNKiQ+6ikSeKVI3PVFIobMPPENQhWLbyFfM4QKMSaOlib5RM6aFW1 Mn2XZwg3wymMQLRqjAkAnajM6S7z5GbR9Bf9/uNEMFQMb7tm3BPvv5PrmwxKxEXz6BBUK7jZzUjv8 85W6H6l5LB6nNxt2IBSwUJ1x9F6XpKkLd0XyUY5V3szdIHF104xAuPabYznER+8wDs96ueLDNgDBE CrRVJtiuvK43msQ7K0IA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uZTW1-00000008Zlc-325x; Wed, 09 Jul 2025 12:03:09 +0000 Received: from out-179.mta0.migadu.com ([91.218.175.179]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uZRkG-00000008Fsi-2n3j for kvm-riscv@lists.infradead.org; Wed, 09 Jul 2025 10:09:46 +0000 Date: Wed, 9 Jul 2025 12:09:36 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1752055779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=T/m36q47DzH0sZai6UBloJIaV9zTL7B9oaqtL4C7wzU=; b=mD+1PGqtDf42qbyO1yo0DC3cSlUh9yJBWScJ/iE5gE0yjCggTZ3XEAVOFz0mp9OgGKi9RK HhXXex9A+nWWC4qQHOGekyAXg4sckQUeXKPQot9BXqTg/pdQYLOw12LZE4PJGBitM+cx8M iU/2fynj3fbKnrE8sjKOQMwoENGNZgw= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Andrew Jones To: Jesse Taube Cc: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, =?utf-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= , Charlie Jenkins , James Raphael Tiovalen , Sean Christopherson , Cade Richard Subject: Re: [kvm-unit-tests PATCH v2 1/2] lib: Add STR_IS_Y and STR_IS_N for checking env vars Message-ID: <20250709-a6dd287628433e8bdf5ea51c@orel> References: <20250708154811.1888319-1-jesse@rivosinc.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250708154811.1888319-1-jesse@rivosinc.com> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250709_030945_151686_D44E79FD X-CRM114-Status: GOOD ( 19.66 ) X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+kvm-riscv=archiver.kernel.org@lists.infradead.org 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 > --- > 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 > +#include > > #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 > +#include > #include > > #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 -- kvm-riscv mailing list kvm-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kvm-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C8E8280308 for ; Wed, 9 Jul 2025 10:09:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752055785; cv=none; b=nk7rpKXYkljWt4dLCNPIvjFFLhdfOTQkTiaNdcuefqc+nwpyNsaCmK9bWQiDcgQ3c7GVlEIsX3O9+bIc/d1UYHnghKOnZLzOi6ph1ArmtlgGOcNBjMJbJJ5X5LVdXFJztPcM0c+pdZeJsLeJAeTW/b6nolnWQMm6kTeEu2IqF+U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752055785; c=relaxed/simple; bh=WvppvSdJdTLlcTn66Yg4ZPNZ7uf4597BV3t3nEa5sgY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nZidn6qXs8lrGgJslxk8U+PGStWEYEheskBIgmgLLsfwziZKvGcLLXmAVG62hyy7+cqknwErBcLOb7/Hos1g1p31qOgoxD7truhy9Hx/DNUs6QOnPhEWUacgX+gbvPAsLefFCZRQ8FDSJxd0PJItwby2as3SOTBwdR5J2l6GybI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=mD+1PGqt; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="mD+1PGqt" Date: Wed, 9 Jul 2025 12:09:36 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1752055779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=T/m36q47DzH0sZai6UBloJIaV9zTL7B9oaqtL4C7wzU=; b=mD+1PGqtDf42qbyO1yo0DC3cSlUh9yJBWScJ/iE5gE0yjCggTZ3XEAVOFz0mp9OgGKi9RK HhXXex9A+nWWC4qQHOGekyAXg4sckQUeXKPQot9BXqTg/pdQYLOw12LZE4PJGBitM+cx8M iU/2fynj3fbKnrE8sjKOQMwoENGNZgw= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Andrew Jones To: Jesse Taube Cc: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, =?utf-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= , Charlie Jenkins , James Raphael Tiovalen , Sean Christopherson , Cade Richard Subject: Re: [kvm-unit-tests PATCH v2 1/2] lib: Add STR_IS_Y and STR_IS_N for checking env vars Message-ID: <20250709-a6dd287628433e8bdf5ea51c@orel> References: <20250708154811.1888319-1-jesse@rivosinc.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250708154811.1888319-1-jesse@rivosinc.com> X-Migadu-Flow: FLOW_OUT 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 > --- > 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 > +#include > > #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 > +#include > #include > > #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