From patchwork Thu Feb 22 10:04:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Wieczor-Retman X-Patchwork-Id: 204662 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp149975dyb; Thu, 22 Feb 2024 02:06:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX9tPClvrYE23xkpm4cnh6DPKj2dPrKVVLpO+NgZT2weaHOr51sH0C9AIhnc0oQxFCBXmat0hunzShoJ2aRU/5vnj/ZAw== X-Google-Smtp-Source: AGHT+IEcnJUBoQ+aQ/JwfGo6BcX0vpsIi2svsLHTGJ6AuF7K1aZ4GLwuiB6o6Sd/tanIxZG2ISQx X-Received: by 2002:a05:6808:228b:b0:3c1:6005:4512 with SMTP id bo11-20020a056808228b00b003c160054512mr10540442oib.51.1708596362816; Thu, 22 Feb 2024 02:06:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708596362; cv=pass; d=google.com; s=arc-20160816; b=oW8+cZniwwEd0Dq5ckffJbEBbyhM0mVeBq9kY2RAer4+4LiZt4ZRnJCGxgao6S4X/z XoVf0Uz0QHG6PSHoQCb6QyfY7s8OIsP7f1eOWtv8PRicQjihSIkfU7aufg6gu7q0CqLJ PKrchYPOsNQhEOeItUmhQUjAp6k5B83pI09TI4MTu76kpiANvcbFnQ8yrGSK0k0gGFrr B+mqMeIdJr723TShtniO3+CZ4QdtjMNm1dgRJWtbnDGAGteTu/w5oRZwhkOLClQeoNje 0gJgxDeGSZZqYXRbwV7gU4BwXcftIPkI8pi5H7mt4jbOV8leMxwZSwAiYyAUwU8SRZTY fv2w== 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=Kz+Gt17KXu3MufKvcjoPUtuGH/UHQhj9Uv5dvuxf7Ik=; fh=/pACME0x50g4vorTSG5vEdNwgU981WFvy8LGbk4DPBk=; b=XnGt4Kf64A15OrOr+OXjlgS7AqNfAE8iwX2aCP8dCaBl6S5hsUzfcj9hCcPenM6elM zGFkNE59n/t9v2sFjH1LcwsZuZGLOo6E3EMNN5euCfWZiavo4kpvxXXNiH+CLcB8MJyS FV8d5CXWwcnpUVkmjLeutZ7MKfUjdKjanf7F1GxX/jB59lxWhp+p7NyzBQZvuWs4q5Pt lbnpEKLpymqSvEUKdW8wT+GkJnnww3CHiMEZjOt+Rv7z4/EapmVB9tWir2f/5i0BLWQO 3oyqhjBrOr1lUghOMKW09p69H7VwtDNdQED0Z3e245gh9WEVWh+GRdF1m2WZH+cZe+GA BUug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VaZBzezE; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-76291-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76291-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id r14-20020ac867ce000000b0042e4c2f9486si907422qtp.690.2024.02.22.02.06.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 02:06:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76291-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VaZBzezE; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-76291-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76291-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 935171C218D8 for ; Thu, 22 Feb 2024 10:06:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE9633E48E; Thu, 22 Feb 2024 10:05:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VaZBzezE" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 791C639FDC; Thu, 22 Feb 2024 10:05:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708596325; cv=none; b=IO9bezJsbrLPs8TH08H7sd+FgoDYcCtK9XxWct3z5bmW6fR51KtZF2XSCu89HaqtAuHvZ+ftKMKsNlwTeKz5mV0RcZS7TqJFP8MfZhSR7Y1Yx4MT0rSTPiiLjdgrGgQGzXdxL1SDYw4aGMCp+342Epxw1XYIU+SjzSkjBvKv/7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708596325; c=relaxed/simple; bh=Gi1VkP9GPyzQfNuuc0NAYEJ6mkbO6wyMOkVcf8T5EK0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HxtnV274viniheZM1k/597B+PSyTku7kaycS/CiIqQ+XbLlGgw4yOBLCILlokdyT1xZKNoARxgBut2tSh4KYhZxzxHaii0hRpLVlkspBjjSS4ivtHfhXOQWaDp8FSP+vqwY+JX0U8sP5jLqh5rUD1BR3PHDCapjQo8+75Frou1U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=VaZBzezE; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708596311; x=1740132311; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Gi1VkP9GPyzQfNuuc0NAYEJ6mkbO6wyMOkVcf8T5EK0=; b=VaZBzezERro6mMGYSi+ENTxKhb6n6BO27p2EmIgKHZaDQ3b8cpIuVD/9 FbOUeGubfYU/gA7p75ER4o+ZDzjFwMM02Ti8ButrG10e45We4Z3+mDiUJ dYM6/5SWtyjD3FLgaHrAlQjz5d1ljDVSCNtsQnosODExFWkr3XsaAjTr6 me3reEwxjbGDa7RJi8OgnokIwWzV0MtuhuE2xx4gcNV4xgNf4NrEho3Z3 2oq01WY6Q/CGRV/KNUhRWQ8SnwuZ1RKnLF9d1WgrKBoIE1kmpdPg+2bxc JXqnWyYgp+J9PsWjatABDLDKQ2SQqw0Jx0whEIcXupF1McFp0SiUmd97/ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10991"; a="2920696" X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="2920696" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 02:05:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="5753878" Received: from ksulimow-mobl1.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.213.23.120]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 02:05:02 -0800 From: Maciej Wieczor-Retman To: Fenghua Yu , Reinette Chatre , Shuah Khan Cc: ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 1/3] selftests/resctrl: Add cleanup function to test framework Date: Thu, 22 Feb 2024 11:04:28 +0100 Message-ID: <357fdb981c7dddcc474818f7bedb1f57a79e117c.1708596015.git.maciej.wieczor-retman@intel.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791593139858166143 X-GMAIL-MSGID: 1791593139858166143 Resctrl selftests use very similar functions to cleanup after themselves. This creates a lot of code duplication. Also not being hooked to the test framework means that ctrl-c handler isn't aware of what test is currently running and executes all cleanups even though only one is needed. Add a function pointer to the resctrl_test struct and attach to it cleanup functions from individual tests. Signed-off-by: Maciej Wieczor-Retman --- tools/testing/selftests/resctrl/cat_test.c | 1 + tools/testing/selftests/resctrl/cmt_test.c | 1 + tools/testing/selftests/resctrl/mba_test.c | 1 + tools/testing/selftests/resctrl/mbm_test.c | 1 + tools/testing/selftests/resctrl/resctrl.h | 2 ++ 5 files changed, 6 insertions(+) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 24af8310288a..2d2f69d3e5b7 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -299,4 +299,5 @@ struct resctrl_test l3_cat_test = { .resource = "L3", .feature_check = test_resource_feature_check, .run_test = cat_run_test, + .cleanup = cat_test_cleanup, }; diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c index dd5ca343c469..32ddee87e43d 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -178,4 +178,5 @@ struct resctrl_test cmt_test = { .resource = "L3", .feature_check = cmt_feature_check, .run_test = cmt_run_test, + .cleanup = cmt_test_cleanup, }; diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c index da256d2dbe5c..7cc4067ce930 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -180,4 +180,5 @@ struct resctrl_test mba_test = { .vendor_specific = ARCH_INTEL, .feature_check = mba_feature_check, .run_test = mba_run_test, + .cleanup = mba_test_cleanup, }; diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c index 34879e7b71a0..071e2d3808a7 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -150,4 +150,5 @@ struct resctrl_test mbm_test = { .vendor_specific = ARCH_INTEL, .feature_check = mbm_feature_check, .run_test = mbm_run_test, + .cleanup = mbm_test_cleanup, }; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index c52eaf46f24d..0f49df4961ea 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -70,6 +70,7 @@ struct user_params { * @disabled: Test is disabled * @feature_check: Callback to check required resctrl features * @run_test: Callback to run the test + * @cleanup: Callback to cleanup after the test */ struct resctrl_test { const char *name; @@ -79,6 +80,7 @@ struct resctrl_test { bool (*feature_check)(const struct resctrl_test *test); int (*run_test)(const struct resctrl_test *test, const struct user_params *uparams); + void (*cleanup)(void); }; /* From patchwork Thu Feb 22 10:04:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Wieczor-Retman X-Patchwork-Id: 204663 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp150114dyb; Thu, 22 Feb 2024 02:06:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWWqjTKwtYnF9GBJp7slyCbitalzE6TKUzpIrV1d6bvy4o4PI5JJoqSvLlBK5eCuZDGcdApTgEyd4Uy0RhuTvjx7xU3PA== X-Google-Smtp-Source: AGHT+IFFtr2ozbAHyTFjU9lD3zeJ1cAo812v8AyVr7oOcJXdSRV0KsMujoGUdBDv6ue0OnTug32d X-Received: by 2002:a17:906:aad1:b0:a3e:a3d6:eb6f with SMTP id kt17-20020a170906aad100b00a3ea3d6eb6fmr7029194ejb.48.1708596383889; Thu, 22 Feb 2024 02:06:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708596383; cv=pass; d=google.com; s=arc-20160816; b=umr2bAiAeou8y5req4lseK7gdl3p6DAbxIgYoBjIQguX8WFXgGzEqvL8lUJbilwM7v aD8Pj15rgwaTiF3atzgAHG/cGGOx7UmpxyzUz36287whMEBtY1C1VsReN37spgP79KkN FJAlD6WRAp+11m72Rg7hjKnlDHL239Eufg7gDZbibj4S3T//rqycqssx8jGAftV/Eks0 2V7cp2N8zgq90Is4X04PSA9KHZkn7WPDePcCYuafa9MEhzYMa0MNvuh0y9CpSOtsTI2q 8p3C7gB6xfSNi0XJ9ldXH7RynEP7D4ha5RKhb0p7xN+0wzD8FvdjW2JHhcuU4yvaZaxV O3nA== 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=bTE2V2Z2Uia/I5IJVNJwxpAyhemCUy7CYc+SCU9qzyo=; fh=/pACME0x50g4vorTSG5vEdNwgU981WFvy8LGbk4DPBk=; b=bwq7kMJk+EE3nTzjxAgWHxALg7jTedLzMDizRlzELWUIoUkyzMmQcQH9GgXnZ5+2t9 sqWczEIpvXHuAmzXlBxNaM834mKUYILjo3WGm7apCClcIaqXZC4repihCvr7xtZ6OInu XdAAxUusNxDWhfRm7BBA/CVQy6CB5n/ECU56FQ5NJRn0Ozc1bMohA7OCNkuL+dZoyWEr Uv5/jGgrfbsCI50VtfD2m+UeetE0rM7snkUBw1NUmlGKgU606dvnRsW8NIulAEDXaaD2 gUY+igl22k7gMpY2NkytOwcTPtuEgNniDK4WE2yvU04Mwa3jQrdL+7eTJULrvmrEyVZN vwGQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IkraqQS+; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-76292-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76292-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ha9-20020a170906a88900b00a3e999a1c02si3477232ejb.787.2024.02.22.02.06.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 02:06:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76292-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IkraqQS+; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-76292-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76292-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 57D771F25FD4 for ; Thu, 22 Feb 2024 10:06:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C84493BB3D; Thu, 22 Feb 2024 10:05:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="IkraqQS+" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 25DA938DD9; Thu, 22 Feb 2024 10:05:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708596330; cv=none; b=ugEeAlSqU9nTUJcXBQ1eYwF+UpV35CmYw9LokH7OKG4knagU68IcW1q6P7Mbj6SfbqNrx7VF+qgE/2XecIIqjR6TifDOH2U8xcEZ+vSQMQB5kN6Kr/MrzTeQNXkvtdfyKEmjYEe2hm5kIz69tY/fFUUrUtld3ji70sbePpdnc2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708596330; c=relaxed/simple; bh=2UTZs7x3PMzSPqopk6ukhMebJaPmC5bK7YeG/3265o0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=faF+WbILy40mvIGo7MYxZTSxABR+XLbkbFZ0HwvUgghlOZX+3FSmupro62/5/pTmHZiNh6DLEkVFOP14+UEUP1C4bduoFB6l4xfvs/bWUN1PwShWU3Hr+Z81FFm7f6Owvj59vrdtYvAV4y9utl/LIP1gtgvmOyNTsMIZSeETeRM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=IkraqQS+; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708596321; x=1740132321; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2UTZs7x3PMzSPqopk6ukhMebJaPmC5bK7YeG/3265o0=; b=IkraqQS+MrJ+KNiwACKQv7GKkXgWPeOKA7ADuavaD1XSbf9qEN0T26sd UsZkMGUQPYRYKJ9hFhJU45ro9JkIXALwPNqnvGhcH3sfLKWk8z0JJ4JU2 6rpx4AC8etMNaT4vHLmU5MyzvwRBOwxaj/qFww5xOezuOFpeRJglhyA8B m401pDPXkkRQdzqHtMhqjQyCatSCTUTiSMmFxJP2jzCfqxRe/A7hJnPZM BdjwAIp4oqdQnVNZFURolHqaz3e91Mi/RuRdB3e6C8qq2mrF2K7ssF6Zr oEYdw/QmlBf9clD6H3jNWxTHaPgg89eojyPRsdIpdLMKGMZzeOtMPsUHU g==; X-IronPort-AV: E=McAfee;i="6600,9927,10991"; a="2920717" X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="2920717" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 02:05:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="5753936" Received: from ksulimow-mobl1.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.213.23.120]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 02:05:12 -0800 From: Maciej Wieczor-Retman To: Fenghua Yu , Reinette Chatre , Shuah Khan Cc: ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 2/3] selftests/resctrl: Simplify cleanup in ctrl-c handler Date: Thu, 22 Feb 2024 11:04:29 +0100 Message-ID: <3a6639cd338a706bd2ed341aa6c717e1e79cc1f0.1708596015.git.maciej.wieczor-retman@intel.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791593161803181066 X-GMAIL-MSGID: 1791593161803181066 Ctrl-c handler isn't aware of what test is currently running. Because of that it executes all cleanups even if they aren't necessary. Since the ctrl-c handler uses the sa_sigaction system no parameters can be passed to it as function arguments. Add a global variable to make ctrl-c handler aware of the currently run test and only execute the correct cleanup callback. Signed-off-by: Maciej Wieczor-Retman --- Changelog v2: - Remove tests_cleanup() from resctrl.h. - Make current_test a const pointer only inside resctrl_val.c. (Ilpo) tools/testing/selftests/resctrl/resctrl.h | 3 +-- tools/testing/selftests/resctrl/resctrl_tests.c | 14 +++----------- tools/testing/selftests/resctrl/resctrl_val.c | 6 ++++-- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 0f49df4961ea..826783b29c9d 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -153,7 +153,6 @@ int resctrl_val(const struct resctrl_test *test, const struct user_params *uparams, const char * const *benchmark_cmd, struct resctrl_val_param *param); -void tests_cleanup(void); void mbm_test_cleanup(void); void mba_test_cleanup(void); unsigned long create_bit_mask(unsigned int start, unsigned int len); @@ -162,7 +161,7 @@ int get_full_cbm(const char *cache_type, unsigned long *mask); int get_mask_no_shareable(const char *cache_type, unsigned long *mask); int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size); void ctrlc_handler(int signum, siginfo_t *info, void *ptr); -int signal_handler_register(void); +int signal_handler_register(const struct resctrl_test *test); void signal_handler_unregister(void); void cat_test_cleanup(void); unsigned int count_bits(unsigned long n); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 75fc49ba3efb..161f5365b4f0 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -75,19 +75,11 @@ static void cmd_help(void) printf("\t-h: help\n"); } -void tests_cleanup(void) -{ - mbm_test_cleanup(); - mba_test_cleanup(); - cmt_test_cleanup(); - cat_test_cleanup(); -} - -static int test_prepare(void) +static int test_prepare(const struct resctrl_test *test) { int res; - res = signal_handler_register(); + res = signal_handler_register(test); if (res) { ksft_print_msg("Failed to register signal handler\n"); return res; @@ -130,7 +122,7 @@ static void run_single_test(const struct resctrl_test *test, const struct user_p ksft_print_msg("Starting %s test ...\n", test->name); - if (test_prepare()) { + if (test_prepare(test)) { ksft_exit_fail_msg("Abnormal failure when preparing for the test\n"); return; } diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index 5a49f07a6c85..d572815436f3 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -62,6 +62,7 @@ struct imc_counter_config { static char mbm_total_path[1024]; static int imcs; static struct imc_counter_config imc_counters_config[MAX_IMCS][2]; +const struct resctrl_test *current_test; void membw_initialize_perf_event_attr(int i, int j) { @@ -472,7 +473,7 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr) if (bm_pid) kill(bm_pid, SIGKILL); umount_resctrlfs(); - tests_cleanup(); + current_test->cleanup(); ksft_print_msg("Ending\n\n"); exit(EXIT_SUCCESS); @@ -482,13 +483,14 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr) * Register CTRL-C handler for parent, as it has to kill * child process before exiting. */ -int signal_handler_register(void) +int signal_handler_register(const struct resctrl_test *test) { struct sigaction sigact = {}; int ret = 0; bm_pid = 0; + current_test = test; sigact.sa_sigaction = ctrlc_handler; sigemptyset(&sigact.sa_mask); sigact.sa_flags = SA_SIGINFO; From patchwork Thu Feb 22 10:04:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Wieczor-Retman X-Patchwork-Id: 204664 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp150157dyb; Thu, 22 Feb 2024 02:06:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUCmpHegv2V+o6xk2hyhtq2/ALcTKgXdJAidEtmAAnMwNsg4g8ubn1ckBQEnAkhLYYzh8ztXhuzrks/eVh6iJDF2Vqw3w== X-Google-Smtp-Source: AGHT+IHs9wu4Rr3mG2hm836RC2jV5EdlAYXicpQN02AoL3mvGe6USsU0fC1yW2xJGgCptqmh7iCx X-Received: by 2002:a05:622a:a9a:b0:42e:4e36:c05 with SMTP id ku26-20020a05622a0a9a00b0042e4e360c05mr1113799qtb.18.1708596390421; Thu, 22 Feb 2024 02:06:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708596390; cv=pass; d=google.com; s=arc-20160816; b=ELix3EVur7eXXKKeWlYzC3oJnhHHR+uvW2JCAcvVMHwcln3zE6Y3h+oCmXwwr4k0YK havz/y/Bg3oyuU9N8Um8E82qr57hAhSlyt2spshMPv3LplrpkqeaLSamV2ZUBhnbuC0/ AalYnIJe651XuIMTvvD04nf3hEOVq9CeCO2XWKOTzIT0w8UIceLM3yipl4crqenpi2f0 Jlsvyw2MVA7mHmRTkqmK2g1yu3yFPIt2sIrn0RpYebbE5hMd467Kd6jSJAy+gTegu+Np 9Fi7z6hHJdOiHrSKjK7Upw5gybLXNRmAfopjSIwfY4GV5B5vhSNlMnIf3tAAgFybaWEm c/7g== 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=NxihSLL4vJPjCGLp9sxVO/A7Bz1gT1oUH3YTgmF0G/c=; fh=/pACME0x50g4vorTSG5vEdNwgU981WFvy8LGbk4DPBk=; b=EZonwna4R39WxdX/6S5jka+PNl83Ph00w99iSoGU64wj08xidS8fx6ORUNXDXdqN5s c3SfSOMehByJvYN1Gda/7hzCgupkLR0NTYa30spzKtvIgZjO5Lk5e9JDocvZTs8Mfvo6 GD7K+uCTaey5/yWuYvvYb/6wVv7E+152wkTKAMNhehylL8L+GfFuAewrWSv0s4C+8O9W uo/HIxDSj+12nV5lVCvNFkRHDA1vtahRakt13ynbGLG/o5ooVfXVBR9jq15weae1BCQY 7NU/cy8S3Ei3DT9yUkOI0Iaft+6EVRWYv4gsFiv+0EOEQr/2A3I3pBecj6qaVaN/+VVa tiwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Lf5YfxJi; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-76293-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76293-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h10-20020ac85e0a000000b0042c605fd8c7si13498955qtx.433.2024.02.22.02.06.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 02:06:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76293-ouuuleilei=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=@intel.com header.s=Intel header.b=Lf5YfxJi; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-76293-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76293-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 248071C22D37 for ; Thu, 22 Feb 2024 10:06:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4B413A278; Thu, 22 Feb 2024 10:05:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Lf5YfxJi" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 C3A2E3A1B9; Thu, 22 Feb 2024 10:05:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708596334; cv=none; b=B3IUxHcEuRFE2KtX4rcjUBeCKwidBOKIAgwuRCESLlImZ9P/BjODSl3m3aoN378nzecNJQow8uoUhqfPPwC3YpwsaGoHgefNGvbwtUFOIjrZU1Gcuhy+8/tk97MBu9zhVAsz5gULzhdYBRDlzZjNiPl/6brB1TRrSWpzrUcdMiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708596334; c=relaxed/simple; bh=HgyUJIc15qW7raXPSPT2a89MGSMGgVE+WXE4DuWEu1g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NKbOx21Schd/5fAN7LnCsp17ySyz93et8zUXaK08R0+cZ4u4GxppVdHtN9qDzS/3g13NhizWlgxMyxNZNRLPIN+nqFY5Lm/gH4mbaEqWfNKmNdAzIVc8eWhA9seeGJn7zpj5AXtzz2/gnfSUlieDw4XAa7S2/B+TnAUUlxzuKaw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Lf5YfxJi; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708596327; x=1740132327; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HgyUJIc15qW7raXPSPT2a89MGSMGgVE+WXE4DuWEu1g=; b=Lf5YfxJicl5Hz7fj71HBuhYPVfro2F0x+gZYyoYHan6UMON4KEB8hE3T LhNLRhPlWCkeYDu9QC3obD5pF9R1L016igji3mEvhIxHUElLlIX6Em5Oy yzoG3buaH6TibJh1yuR4ht3PClJUo8FCgfaThSOb5ezY60e88RSPqt8el AR9NZ+CPCkwcd45IcPUigoDeiVpo/8QQCEdaN7pjYL4QxOIizMEAVGQWn czJUAIIECpuFLs9UrZyJOFKvzXAdG1KywuI3a1ihUEAaJYoGUi/mkZOeA i57jSv/QvI9rqnL0uPBOte2MeQzBQsFn/HTrHlhj1+iRq103Vmxtv5t8+ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10991"; a="2920736" X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="2920736" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 02:05:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="5754014" Received: from ksulimow-mobl1.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.213.23.120]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 02:05:18 -0800 From: Maciej Wieczor-Retman To: Fenghua Yu , Reinette Chatre , Shuah Khan Cc: ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 3/3] selftests/resctrl: Move cleanups out of individual tests Date: Thu, 22 Feb 2024 11:04:30 +0100 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791593168515922862 X-GMAIL-MSGID: 1791593168515922862 Every test calls its cleanup function at the end of it's test function. After the cleanup function pointer is added to the test framework this can be simplified to executing the callback function at the end of the generic test running function. Make test cleanup functions static and call them from the end of run_single_test() from the resctrl_test's cleanup function pointer. Signed-off-by: Maciej Wieczor-Retman --- Changelog v2: - Change most goto out paths into return ret. (Ilpo) tools/testing/selftests/resctrl/cat_test.c | 7 ++----- tools/testing/selftests/resctrl/cmt_test.c | 3 +-- tools/testing/selftests/resctrl/mba_test.c | 7 ++----- tools/testing/selftests/resctrl/mbm_test.c | 7 ++----- tools/testing/selftests/resctrl/resctrl.h | 4 ---- tools/testing/selftests/resctrl/resctrl_tests.c | 2 ++ 6 files changed, 9 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 2d2f69d3e5b7..1d1efed6164e 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -128,7 +128,7 @@ static int check_results(struct resctrl_val_param *param, const char *cache_type return fail; } -void cat_test_cleanup(void) +static void cat_test_cleanup(void) { remove(RESULT_FILE_NAME); } @@ -284,13 +284,10 @@ static int cat_run_test(const struct resctrl_test *test, const struct user_param ret = cat_test(test, uparams, ¶m, span, start_mask); if (ret) - goto out; + return ret; ret = check_results(¶m, test->resource, cache_total_size, full_cache_mask, start_mask); -out: - cat_test_cleanup(); - return ret; } diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c index 32ddee87e43d..c477f3c9635f 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -91,7 +91,7 @@ static int check_results(struct resctrl_val_param *param, size_t span, int no_of MAX_DIFF, MAX_DIFF_PERCENT, runs - 1, true); } -void cmt_test_cleanup(void) +static void cmt_test_cleanup(void) { remove(RESULT_FILE_NAME); } @@ -161,7 +161,6 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param ksft_print_msg("Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n"); out: - cmt_test_cleanup(); free(span_str); return ret; diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c index 7cc4067ce930..a2f81d900900 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -137,7 +137,7 @@ static int check_results(void) return show_mba_info(bw_imc, bw_resc); } -void mba_test_cleanup(void) +static void mba_test_cleanup(void) { remove(RESULT_FILE_NAME); } @@ -158,13 +158,10 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param ret = resctrl_val(test, uparams, uparams->benchmark_cmd, ¶m); if (ret) - goto out; + return ret; ret = check_results(); -out: - mba_test_cleanup(); - return ret; } diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c index 071e2d3808a7..6589154c102e 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -105,7 +105,7 @@ static int mbm_setup(const struct resctrl_test *test, return ret; } -void mbm_test_cleanup(void) +static void mbm_test_cleanup(void) { remove(RESULT_FILE_NAME); } @@ -126,15 +126,12 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param ret = resctrl_val(test, uparams, uparams->benchmark_cmd, ¶m); if (ret) - goto out; + return ret; ret = check_results(DEFAULT_SPAN); if (ret && (get_vendor() == ARCH_INTEL)) ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n"); -out: - mbm_test_cleanup(); - return ret; } diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 826783b29c9d..428ce9174384 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -153,8 +153,6 @@ int resctrl_val(const struct resctrl_test *test, const struct user_params *uparams, const char * const *benchmark_cmd, struct resctrl_val_param *param); -void mbm_test_cleanup(void); -void mba_test_cleanup(void); unsigned long create_bit_mask(unsigned int start, unsigned int len); unsigned int count_contiguous_bits(unsigned long val, unsigned int *start); int get_full_cbm(const char *cache_type, unsigned long *mask); @@ -163,9 +161,7 @@ int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size void ctrlc_handler(int signum, siginfo_t *info, void *ptr); int signal_handler_register(const struct resctrl_test *test); void signal_handler_unregister(void); -void cat_test_cleanup(void); unsigned int count_bits(unsigned long n); -void cmt_test_cleanup(void); void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config); void perf_event_initialize_read_format(struct perf_event_read *pe_read); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 161f5365b4f0..bae08d1221ec 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -134,6 +134,8 @@ static void run_single_test(const struct resctrl_test *test, const struct user_p } ret = test->run_test(test, uparams); + if (test->cleanup) + test->cleanup(); ksft_test_result(!ret, "%s: test\n", test->name); cleanup: