From patchwork Tue Sep 10 15:08:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 13798702 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56482199389 for ; Tue, 10 Sep 2024 15:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725980940; cv=none; b=n7DIL1nSPR+77gm2VLl/TXUpoyMzFzbNeBBpCXmuFnxVLbkC0QE5bK6CAkUwvU0zuUN/8YvrHK8VLdmmhNmKPu9L3UYuevZr54j9OaziDpXS6s2JGHs7TkTQQ5EUL4PuTdkrX3alFU8/XgE8dfd6HFqCPMP+2RDqVKR3246Pc9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725980940; c=relaxed/simple; bh=EEgrZ3NBfO/BMgHEa+wmeTsPBRCMjb5z/lIDoDQAkso=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i/4tGVJ8NDzPpdSIoU3HCof6z2JfeEDK+bWZtaohdoSWMS+/bkjwpjH6ILeUSipwWQb7oKBGSW4TQtojElea84PBerPJyRC3YBheyIk3dU+3XIhdXR6O2cI1b/f1kfNlsJ4w2imH7vB3Q4zlC/D2PHkEW+N5flw7FLUGUdAFpq8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IY36+MD+; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IY36+MD+" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2d8881850d9so642096a91.3 for ; Tue, 10 Sep 2024 08:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725980938; x=1726585738; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jJ0SGbueLL+CmiAymH1gcSoFZqvjzIWyBVOl8YOSxQk=; b=IY36+MD+jmjGV9HQnVujfW7hlVwWgTudgNwI3VpKZdJdIscyQ1z5afAFsEBBsb3Dun umS/IGyVn344FaWJPkGWi0+e/Gwxhu6qa47/qrMswqi4iZHH8w0RLKQexkDemfBl2rnA +6ccjJgjY+rmTsQ93b5xx1LKkGXmKQKIrRTQBhVnWuZ65E0rEt2fSoTm8RVoCLZmk4OW GaKhnUgDsuKF8iXae/Nlr50RKQyRzZrXksFRN66lHfzIJm7HEVlzBgD98+K9/WJdH7OL QuszAL1Jh1MliakvPoajTuIioTRd+3zM8yXD21UkKIbM2qPE6cIcMN0Rqbg7nh6tNSPF pPhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725980938; x=1726585738; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jJ0SGbueLL+CmiAymH1gcSoFZqvjzIWyBVOl8YOSxQk=; b=SGjV3lkeoxpdrgnVctaIdrEN4Xd0kpkTKPNgu9/JKLxA+scVR8SlG5QsBc4+fppCql jivP7ShB+h15hjwtOX9h3MuVRfjMMO56pz1GY+DMxu103neBj7XCg4fiXffXSAr7U6EI lAPJTzqjoProMlIWJV9ua/YjxpQNoloXHKvKUVgvJUk+Y8dUhk59x6GdwlRCiVECOVg5 G9Q91ziEGNOo3M9C2Vo/nR6tJNy+Wwf4tu/M64+vJqJO67I3pdKIEmSZlekmbDlDjF8L +vKBa3eemt+TOJE0lfj7KMl8J3zolmS1e0hCiRf+iSLdo0yKDzMOKU7FPt3PCGYgRLWT btLg== X-Gm-Message-State: AOJu0YwTu8l8Y9VvSMqZZB9BnPBk7qTQ6ku9wTNTcuAC4FSxJnG57sgz HErt0MhmeYm8AC5917sTUvLXTwWRJYFDYveoRxrASPBVoc/Q/u10VwxVCsC2 X-Google-Smtp-Source: AGHT+IG0iyMqvqxpu0X/2Og0DCIqsyuVLf32tPr2K/8TAm+mC5FKKAucoitOwNcYmiCvgmXTVcflaA== X-Received: by 2002:a17:90b:3b8b:b0:2d8:84df:fa0a with SMTP id 98e67ed59e1d1-2dad50e8778mr14157637a91.32.1725980937974; Tue, 10 Sep 2024 08:08:57 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db041a02c7sm6615120a91.19.2024.09.10.08.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 08:08:57 -0700 (PDT) From: James Raphael Tiovalen To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: andrew.jones@linux.dev, atishp@rivosinc.com, cade.richard@berkeley.edu, James Raphael Tiovalen Subject: [kvm-unit-tests PATCH 1/2] lib/report: Add helper method to clear multiple prefixes Date: Tue, 10 Sep 2024 23:08:41 +0800 Message-ID: <20240910150842.156949-2-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240910150842.156949-1-jamestiotio@gmail.com> References: <20240910150842.156949-1-jamestiotio@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a method to pop a specified number of prefixes. This method is useful when tests want to clear multiple prefixes at once. Suggested-by: Andrew Jones Signed-off-by: James Raphael Tiovalen --- lib/libcflat.h | 1 + lib/report.c | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/libcflat.h b/lib/libcflat.h index 16a83880..eec34c3f 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -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, ...) diff --git a/lib/report.c b/lib/report.c index 7f3c4f05..0756e64e 100644 --- a/lib/report.c +++ b/lib/report.c @@ -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); } From patchwork Tue Sep 10 15:08:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 13798703 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1710119994E for ; Tue, 10 Sep 2024 15:09:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725980943; cv=none; b=mEnMnuM9F5XNHIukMeZ/E/sZgrpua3GqnvwzoM0767WLa6OjM0pAxHcvdAEcq2DJlI6GDzXva+timhIGtIKDAbuBA8ptwCRh0fakaEaU0Wy2FQ6hl64R2uN9PW58fxImE0O+DPQCUjRlKH7aObJ87RVDz1YdC8rG2y2lwxTPKc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725980943; c=relaxed/simple; bh=e0yLn4OQcCUOSUKXnCM9m4Gsgh4KiaEcRL2S3Z/9s4c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O1cBkYunyQrNMP+62lyeCzKLPPxeEH7Qb4tO3hqw0SthgqKjix6CF9kGbiF60PBuJDqV/MsUKYTJFiVxJqR7vtXWVbTmurAitTHi5lRE7hHN100BP9dYxC6F7Cr+yGSf1nrQNh+QJGK93v4mT7ExfZLFfa3wsKWszbZzbMSyWoQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=j8uSenXQ; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j8uSenXQ" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2d8b96c18f0so4433533a91.2 for ; Tue, 10 Sep 2024 08:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725980941; x=1726585741; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J/LNwaUAGrr1fu/pOWbGaVjGYKY8WsxJd5roKC5v5Io=; b=j8uSenXQQQB22a+J1rkWd7+CGAEqYM0v/53TzzSKIkyFGTz5EFArSfN1uj6R3irzaK vpyaH4Iraab/zr54tN0NINIj7DMmv3KdLvqhm72z5uCb8vNNkip+82TmKNdJWUzO2LuS sA61cUbrhtV7FNZA5vYmlXVDDeuqwvyEVhwX6S/wEabKrQBFZb7UeNTxtCfxSwjjtXoS /tr8FKZFeeFiw+VTBZkN6mfItUDHCNaqzpIq2hzPkYeG6+uGBvs9gtw/Zia9ZTcxR8UW jLBc4B8tukUE/xPeyJuDWQ/kfz9HKlL7tW1eWJ/mVdpwqYfHEqy2Gk95X0hy7xzBHn0y +EZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725980941; x=1726585741; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J/LNwaUAGrr1fu/pOWbGaVjGYKY8WsxJd5roKC5v5Io=; b=BqW6AdwJ/37czxLF01GFoEW1SCAvUxeSDtNRWi4guSDq0M4i7AXFWIBhXJnuMt/X8k ccIa4DkfHOocJaAx1NkSVehWq7nW/5nJIQTuJ4QqL9GqG6qPnVkQV9bYqp3cQmF93gx5 9k44RHyzrWZm65H+dy3bib1ZLZiEa51njM7XWa/rBoj43y05RfVys+ohUcDPHVsLcoBg 2a0SMEiVZR53undzBEfPvXJYyTp+kIfZ8qsDqWvhy6AfUTdMed6qPPq1S6ZB7FUI6/BO 6yS5iAFs/Hk9IaKtkBaTZ9Ph44V37Z8kIyz9VJY0ltoYw2B7C8uoxyuf92+2ZW6CsL2m g1aQ== X-Gm-Message-State: AOJu0Yy3iW2y8sAidRq99ZWYFk8GlOI1fIkAsUanLytBTnXZd1doCGYj BrO1UzdjLExPGK4AEwd/3mJ31+a2H1IKrqj0GYeFRl+LfMhEvmUjsnDA7Rwf X-Google-Smtp-Source: AGHT+IGZfZBU54LIQhQtpYZ+otDovhuOB67i3DfWln9A/RUYV0lneOXqkrj/lcHR6A+PYPm2h9fbRQ== X-Received: by 2002:a17:90a:d143:b0:2d8:905e:d25b with SMTP id 98e67ed59e1d1-2dad4ef223emr17362068a91.9.1725980941059; Tue, 10 Sep 2024 08:09:01 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db041a02c7sm6615120a91.19.2024.09.10.08.08.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 08:09:00 -0700 (PDT) From: James Raphael Tiovalen To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: andrew.jones@linux.dev, atishp@rivosinc.com, cade.richard@berkeley.edu, James Raphael Tiovalen Subject: [kvm-unit-tests PATCH 2/2] riscv: sbi: Tidy up report prefix pops Date: Tue, 10 Sep 2024 23:08:42 +0800 Message-ID: <20240910150842.156949-3-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240910150842.156949-1-jamestiotio@gmail.com> References: <20240910150842.156949-1-jamestiotio@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replace multiple consecutive calls of the `report_prefix_pop` function with the new `report_prefix_popn` function. Signed-off-by: James Raphael Tiovalen --- riscv/sbi.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/riscv/sbi.c b/riscv/sbi.c index 093c20a0..f88bf700 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -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)