Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp964453lqt; Fri, 19 Apr 2024 16:55:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWZkQKsuTJYYtw+3pw3d9xeot/gfOFStPCWneRajlA4V0CALnEVnX9uF+z1c7wmIMWgx7cgpmEsYUiHhl2kW/zPCNQ332SITP60TZpVqQ== X-Google-Smtp-Source: AGHT+IHDpoqaNV0GGAY04KfpWD2ArvowXHya4N6ReH/R6eb7+c9Mff2ymCUfR+P6XLC8sdkZyInc X-Received: by 2002:ac8:5acb:0:b0:439:4929:bfc3 with SMTP id d11-20020ac85acb000000b004394929bfc3mr2776165qtd.25.1713570911233; Fri, 19 Apr 2024 16:55:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713570911; cv=pass; d=google.com; s=arc-20160816; b=UD14TDNFFBHzu2pE7NcZT725NO6M5qfcf1aaO76xbTY/XrlXsqN+FMCJCVBHFo9Gw2 qjl33Q3o2qARvu2UtrvT88V8OU1HvKBw5ntz+2/TIv6pvXmb+Ndw2heQvif6xc9YGWQE Ffs3xShCMfhOhMswWbfeIANi15Mr4/W79DWVsptU7CXp9/GF9bD6Z+31KqCRktcZjsct 0m5nekpr1E3nIkLrdAtJcBHF11oAhdPVD7vlkrzkjslvyKPt8wCr0btGzRwIvw3oRRqy b2AFKP4RcsTZY6iSacMeBGjoWKTj22g7m1RDEF2MApNwrooKJbAEq6vXm2tEf/S8aL7c FeLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=k8dppvgVnh54sEjPJluz+VPGn0XVIgbI5aDFYcuHKMk=; fh=z7fJWkZ4T7GjqwnZHLiFaBRNsKIE6v81MvuCrwEofW0=; b=jlccbPSmLMbqW4hfkb/8ULQp/a2pqExf8m5RX2MJVWEO/393jxEH206q2tvTSWv2YJ 2axC6KyGCOCWUwycsab/xiphTH1/BByYTwdJiFMbHgaurtc67LxJ80oT4gwbsAz7wHY4 HyrfGGxRuuE01KzYvIjwLFHPt3vQyCCH+/DsNEKeWuMrZYX4f4mf6sEbWiPOPfvB1Bnl sJ9R+XB2DIIb0s1ILeKZXz6xReroysXshXxhCvhYZZegAB8uuu7lLdr/PDGu1WiYThL5 6YJ2Q/QdcbKKdOeneh5OZjSo4R5kmvXUlbJp1LtTvTan2a1lGq1xvfk6H+I4GOKlwfao SOVA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=S9lTXw39; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-152047-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152047-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ay8-20020a05622a228800b004395f2b7526si972932qtb.370.2024.04.19.16.55.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 16:55:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152047-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=S9lTXw39; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-152047-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152047-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E1EF51C211C8 for ; Fri, 19 Apr 2024 23:55:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 168AA1420CA; Fri, 19 Apr 2024 23:48:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="S9lTXw39" Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 10816152E1D for ; Fri, 19 Apr 2024 23:48:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713570511; cv=none; b=oKyTPDjVfrlX4Hb728OrBEBgwQdymF/O44eLc/jL9xafwhUQrvTqGWAnuv5f90cP10zvXeHygKlXRrTHDaKb15T2jQWI4JpR03tuerI0wLneU395r9KSZUxOZq1QYAmFsYOyUJI3QSPJwLGPG+Irdkyq0gopeeMCLPCAqSFMfDk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713570511; c=relaxed/simple; bh=4h0IzOtLBFbHmqIztYQtJnRQ5i+JxAIa21rlgcy6DFI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JEnA1teYOTL8ewjmuLxMStUUKmxNenfDQSYeDMwXKXtM+s5HRf7vG/OCH/dXkowG6vcaR1V2siY7EcgX1Vvs2Yy1hZzU9QG8Sh82MkQ1PHe3R6zYlGcukyMCH/AYqXcCGWlsZ0ktAeHlZzKl0KnwSMDiaFS06CYkw3WxJxkLgRg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=S9lTXw39; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1e2c725e234so28949595ad.1 for ; Fri, 19 Apr 2024 16:48:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713570508; x=1714175308; 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=k8dppvgVnh54sEjPJluz+VPGn0XVIgbI5aDFYcuHKMk=; b=S9lTXw39LqEF6q16IzNx8R7TGXeFz2KodnuHcBXAzMzZclaSiFVpNmZT0akpKoNXOd pbiLhQEzyY91u+DP/AMKmVuC5DyOD6HAN7SJK0wQ0KeyBbPNqz6VvSO2MN5FUDgc8RNS kUsqyPq4EPqk+HrE84H5P7xY41dYb886gi7i3yXYZ2CrRyfQqNJWul+faTz1aaLsmce0 dnexzjx2xZVqrHA+FnFXwr2ldWm8iEgEILEFrCNmTabkVEvVd3SX8Sf5RTp4S/vtpzUh c1oVy+/gZ+AmxhYZcc/u+y4YtmROB9JPB4jeBOENbJA5lEAJV2rcxSU309TcvCvj3Sq2 2aIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713570508; x=1714175308; 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=k8dppvgVnh54sEjPJluz+VPGn0XVIgbI5aDFYcuHKMk=; b=HcPeIVRl8swH6Fz8ylx+kk4YBt7QgZe0/CClUyRajBwS4c7XiKd1KxlpKHoEmT6Nqb WtX69AVOL7dpYmjG8bvbc6kQu1bbGE67W+fF/YVunCN+a1uEUVVcSDhMr/S0xKV+2l+r xdsRzjyqW4pSYTo+sJ98w0maF7IguhPm79hQwT3Jpkx1t8+aCFtcU/joD3HTgI4HEQbI fe82C8PQTM/UsDdObEIi/3+IHMnazxZ6v/RKrjnvSHFkkEJeCGREECztjY3cc/RqW4Dh XUZ46VJ9ZGh/pQrN1hjTQWBTl943mFaa1UHl9Pjt5v3i/GedtEqrzNutY4r1JXM4Qd+t 1ahw== X-Gm-Message-State: AOJu0YyiujFxeGgI5S79TIvyiz3Sh6VfGsNDbETJlhb5R637VQokX8k/ XZu0bLqojN00jLOPzi2m3i8kArzwo0zMoBBgE+BPthMZdGs2aTrZgwLWO4btS0vBJCaFFAbRbDo K X-Received: by 2002:a17:903:41ca:b0:1e0:9964:76f4 with SMTP id u10-20020a17090341ca00b001e0996476f4mr5588251ple.14.1713570508238; Fri, 19 Apr 2024 16:48:28 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id w17-20020a170902d11100b001e42f215f33sm3924017plw.85.2024.04.19.16.48.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 16:48:27 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Andrew Jones , Ajay Kaher , Albert Ou , Alexandre Ghiti , Anup Patel , samuel.holland@sifive.com, Conor Dooley , Juergen Gross , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Shuah Khan , virtualization@lists.linux.dev, Will Deacon , x86@kernel.org Subject: [PATCH v8 24/24] KVM: riscv: selftests: Add commandline option for SBI PMU test Date: Sat, 20 Apr 2024 08:17:40 -0700 Message-Id: <20240420151741.962500-25-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240420151741.962500-1-atishp@rivosinc.com> References: <20240420151741.962500-1-atishp@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit SBI PMU test comprises of multiple tests and user may want to run only a subset depending on the platform. The most common case would be to run all to validate all the tests. However, some platform may not support all events or all ISA extensions. The commandline option allows user to disable any set of tests if they want to. Suggested-by: Andrew Jones Signed-off-by: Atish Patra --- .../selftests/kvm/riscv/sbi_pmu_test.c | 73 ++++++++++++++++--- 1 file changed, 64 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c b/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c index 0fd9b76ae838..69bb94e6b227 100644 --- a/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c +++ b/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c @@ -33,6 +33,13 @@ static unsigned long counter_mask_available; static bool illegal_handler_invoked; +#define SBI_PMU_TEST_BASIC BIT(0) +#define SBI_PMU_TEST_EVENTS BIT(1) +#define SBI_PMU_TEST_SNAPSHOT BIT(2) +#define SBI_PMU_TEST_OVERFLOW BIT(3) + +static int disabled_tests; + unsigned long pmu_csr_read_num(int csr_num) { #define switchcase_csr_read(__csr_num, __val) {\ @@ -608,19 +615,67 @@ static void test_vm_events_overflow(void *guest_code) test_vm_destroy(vm); } -int main(void) +static void test_print_help(char *name) +{ + pr_info("Usage: %s [-h] [-d ]\n", name); + pr_info("\t-d: Test to disable. Available tests are 'basic', 'events', 'snapshot', 'overflow'\n"); + pr_info("\t-h: print this help screen\n"); +} + +static bool parse_args(int argc, char *argv[]) +{ + int opt; + + while ((opt = getopt(argc, argv, "hd:")) != -1) { + switch (opt) { + case 'd': + if (!strncmp("basic", optarg, 5)) + disabled_tests |= SBI_PMU_TEST_BASIC; + else if (!strncmp("events", optarg, 6)) + disabled_tests |= SBI_PMU_TEST_EVENTS; + else if (!strncmp("snapshot", optarg, 8)) + disabled_tests |= SBI_PMU_TEST_SNAPSHOT; + else if (!strncmp("overflow", optarg, 8)) + disabled_tests |= SBI_PMU_TEST_OVERFLOW; + else + goto done; + break; + case 'h': + default: + goto done; + } + } + + return true; +done: + test_print_help(argv[0]); + return false; +} + +int main(int argc, char *argv[]) { - test_vm_basic_test(test_pmu_basic_sanity); - pr_info("SBI PMU basic test : PASS\n"); + if (!parse_args(argc, argv)) + exit(KSFT_SKIP); + + if (!(disabled_tests & SBI_PMU_TEST_BASIC)) { + test_vm_basic_test(test_pmu_basic_sanity); + pr_info("SBI PMU basic test : PASS\n"); + } - test_vm_events_test(test_pmu_events); - pr_info("SBI PMU event verification test : PASS\n"); + if (!(disabled_tests & SBI_PMU_TEST_EVENTS)) { + test_vm_events_test(test_pmu_events); + pr_info("SBI PMU event verification test : PASS\n"); + } - test_vm_events_snapshot_test(test_pmu_events_snaphost); - pr_info("SBI PMU event verification with snapshot test : PASS\n"); + if (!(disabled_tests & SBI_PMU_TEST_SNAPSHOT)) { + test_vm_events_snapshot_test(test_pmu_events_snaphost); + pr_info("SBI PMU event verification with snapshot test : PASS\n"); + } - test_vm_events_overflow(test_pmu_events_overflow); - pr_info("SBI PMU event verification with overflow test : PASS\n"); + if (!(disabled_tests & SBI_PMU_TEST_OVERFLOW)) { + test_vm_events_overflow(test_pmu_events_overflow); + pr_info("SBI PMU event verification with overflow test : PASS\n"); + } return 0; } -- 2.34.1