From patchwork Thu Oct 24 12:41:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 2001703 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=suM3nyVm; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=QNd36G+2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XZ5BT4s6dz1xwy for ; Thu, 24 Oct 2024 23:41:21 +1100 (AEDT) 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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xqpdUkNTv6vp3No4GPoR+Gw4+5EokDoxLWnA2KE33f4=; b=suM3nyVm/a2/75 aUNIGf0fPR/wskDMbuLVj9c48Ua7TpnSaQN/BCjK+qAcovs476NChby556KZaoliZGFXoHv5nimen 6c+X/ZMzBwKTRlqZVlguoBNodjcDg3VD9gkQ5QTfShbF1bijAadpsf9S5KzCCjbfO1NqTqyiYbqtq 8y8Il20ubBLfNJxHagp0lAX3wibHjxV/BiaGaDuRBU7HIX/dD4FeGFe/r9MtolMfi1xUYb/ryXA3s vpkA7k3orTjIPIzr+Hmf3YlVxI08d2nyG1OqIx0DqpWlq5bBdOKFYguoESRvKjeYY8zdqkNlBivUf 2V9blZSaRDNYbe1JqseA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3x9U-00000000NfO-1vaO; Thu, 24 Oct 2024 12:41:20 +0000 Received: from out-171.mta0.migadu.com ([91.218.175.171]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3x9R-00000000Ndc-0dCJ for kvm-riscv@lists.infradead.org; Thu, 24 Oct 2024 12:41:18 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1729773675; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QnzhILkgt6W7qUGP952fPh9ASE4oX3Lkb/mnr8vnxOg=; b=QNd36G+2pIGqhfi7YKvRsKRGLVp+glMURAbY2rebwN6DcCMVhRPzJOSoNuoWe5K59MhPgA l1TRljSRsYJ6ZaMUWlBjguFVMngDBDVWQOQyiqxtwLgbspOyQUDG/U8Zsn88TroS5NAES+ HFmHuLT1tCWu03JTT3wwIjX2znquRSg= From: Andrew Jones To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: atishp@rivosinc.com, jamestiotio@gmail.com Subject: [kvm-unit-tests PATCH 2/3] riscv: sbi: Clean up env checking Date: Thu, 24 Oct 2024 14:41:04 +0200 Message-ID: <20241024124101.73405-7-andrew.jones@linux.dev> In-Reply-To: <20241024124101.73405-5-andrew.jones@linux.dev> References: <20241024124101.73405-5-andrew.jones@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241024_054117_350575_3589BC31 X-CRM114-Status: UNSURE ( 9.63 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add a couple helpers to cleanup checking of test configuration environment variables. Signed-off-by: Andrew Jones --- riscv/sbi.c | 32 +++++++++++++++++++ 1 file changed, 19 insertions(+), 13 deletions(-) Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [91.218.175.171 listed in sa-trusted.bondedsender.org] 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [91.218.175.171 listed in bl.score.senderscore.com] 0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [91.218.175.171 listed in sa-accredit.habeas.com] 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: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add a couple helpers to cleanup checking of test configuration environment variables. Signed-off-by: Andrew Jones --- riscv/sbi.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/riscv/sbi.c b/riscv/sbi.c index d46befa1c6c1..1e7314ec8d98 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -74,6 +74,20 @@ static phys_addr_t get_highest_addr(void) return highest_end - 1; } +static bool env_enabled(const char *env) +{ + char *s = getenv(env); + + return s && (*s == '1' || *s == 'y' || *s == 'Y'); +} + +static bool env_disabled(const char *env) +{ + char *s = getenv(env); + + return !(s && (*s == '0' || *s == 'n' || *s == 'N')); +} + static bool env_or_skip(const char *env) { if (!getenv(env)) { @@ -348,7 +362,6 @@ static void check_dbcn(void) bool highmem_supported = true; phys_addr_t paddr; struct sbiret ret; - const char *tmp; char *buf; report_prefix_push("dbcn"); @@ -371,13 +384,11 @@ static void check_dbcn(void) dbcn_write_test(&buf[PAGE_SIZE - num_bytes / 2], num_bytes, false); report_prefix_pop(); - tmp = getenv("SBI_HIGHMEM_NOT_SUPPORTED"); - if (tmp && atol(tmp) != 0) + if (env_enabled("SBI_HIGHMEM_NOT_SUPPORTED")) highmem_supported = false; report_prefix_push("high boundary"); - tmp = getenv("SBI_DBCN_SKIP_HIGH_BOUNDARY"); - if (!tmp || atol(tmp) == 0) + if (env_disabled("SBI_DBCN_SKIP_HIGH_BOUNDARY")) dbcn_high_write_test(DBCN_WRITE_TEST_STRING, num_bytes, HIGH_ADDR_BOUNDARY - PAGE_SIZE, PAGE_SIZE - num_bytes / 2, highmem_supported); @@ -386,12 +397,8 @@ static void check_dbcn(void) report_prefix_pop(); report_prefix_push("high page"); - tmp = getenv("SBI_DBCN_SKIP_HIGH_PAGE"); - if (!tmp || atol(tmp) == 0) { - paddr = HIGH_ADDR_BOUNDARY; - tmp = getenv("HIGH_PAGE"); - if (tmp) - paddr = strtoull(tmp, NULL, 0); + if (env_disabled("SBI_DBCN_SKIP_HIGH_PAGE")) { + paddr = getenv("HIGH_PAGE") ? strtoull(getenv("HIGH_PAGE"), NULL, 0) : HIGH_ADDR_BOUNDARY; dbcn_high_write_test(DBCN_WRITE_TEST_STRING, num_bytes, paddr, 0, highmem_supported); } else { report_skip("user disabled"); @@ -400,8 +407,7 @@ static void check_dbcn(void) /* Bytes are read from memory and written to the console */ report_prefix_push("invalid parameter"); - tmp = getenv("INVALID_ADDR_AUTO"); - if (tmp && atol(tmp) == 1) { + if (env_enabled("INVALID_ADDR_AUTO")) { paddr = get_highest_addr() + 1; do_invalid_addr = true; } else if (env_or_skip("INVALID_ADDR")) {