From patchwork Wed Nov 10 09:33:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 12611657 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4338C433F5 for ; Wed, 10 Nov 2021 09:41:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1D21610A2 for ; Wed, 10 Nov 2021 09:41:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230466AbhKJJnx (ORCPT ); Wed, 10 Nov 2021 04:43:53 -0500 Received: from esa5.hc1455-7.c3s2.iphmx.com ([68.232.139.130]:15192 "EHLO esa5.hc1455-7.c3s2.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbhKJJns (ORCPT ); Wed, 10 Nov 2021 04:43:48 -0500 X-Greylist: delayed 430 seconds by postgrey-1.27 at vger.kernel.org; Wed, 10 Nov 2021 04:43:47 EST IronPort-SDR: ig52yG2K8H7lMwcikA4iNUuzt97U2zeAQZx1K8GafHLgy9Kr8StrAiGGno7wlYwE7DJ18JyT/C r6i8TEOluupVBvL9z5COUG/jFsKUj7Ozj/A7A8yiwvByNYmy8UZNiszc86bVGBpmDljn6yk8Fa /bM4CH47OgoH6eyOheEi9LEpkGXtw+eXoJOQhXsiNczZqM8sLciYKtyH4ZhOp2EyJCXjU4nSRh H68EPwi592o7GfQB4NWsPRcmk2THFyknLnN04dgBIbfCOGgLwsywdOgNLz12d3C6SS+gK+BhmO 6CzxwoIOi8IjJ5DdQsTtOmHn X-IronPort-AV: E=McAfee;i="6200,9189,10163"; a="51705404" X-IronPort-AV: E=Sophos;i="5.87,223,1631545200"; d="scan'208";a="51705404" Received: from unknown (HELO oym-r1.gw.nic.fujitsu.com) ([210.162.30.89]) by esa5.hc1455-7.c3s2.iphmx.com with ESMTP; 10 Nov 2021 18:33:50 +0900 Received: from oym-m4.gw.nic.fujitsu.com (oym-nat-oym-m4.gw.nic.fujitsu.com [192.168.87.61]) by oym-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id 4921D14C4A6; Wed, 10 Nov 2021 18:33:48 +0900 (JST) Received: from oym-om3.fujitsu.com (oym-om3.o.css.fujitsu.com [10.85.58.163]) by oym-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 7BBCDAD00E; Wed, 10 Nov 2021 18:33:47 +0900 (JST) Received: from localhost.localdomain (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by oym-om3.fujitsu.com (Postfix) with ESMTP id 81D1F4006B62C; Wed, 10 Nov 2021 18:33:46 +0900 (JST) From: Shaopeng Tan To: Fenghua Yu , Reinette Chatre , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, tan.shaopeng@jp.fujitsu.com Subject: [PATCH 1/3] selftests/resctrl: Make resctrl_tests run using kselftest framework Date: Wed, 10 Nov 2021 18:33:13 +0900 Message-Id: <20211110093315.3219191-2-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211110093315.3219191-1-tan.shaopeng@jp.fujitsu.com> References: <20211110093315.3219191-1-tan.shaopeng@jp.fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: "Tan, Shaopeng" This commit enables kselftest to be built/run in resctrl framework. Build/run resctrl_tests by build/run all tests of kselftest, or by using the "TARGETS" variable on the make command line to specify resctrl_tests. To make resctrl_tests run using kselftest framework, this commit modified the Makefile of kernel kselftest set and the Makefile of resctrl_tests. To ensure the resctrl_tests finish in limited time, this commit changed the default limited time(45s) to 120 seconds for resctrl_tests by adding "setting" file. Signed-off-by: Shaopeng Tan --- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/resctrl/Makefile | 21 +++++++++------------ tools/testing/selftests/resctrl/settings | 1 + 3 files changed, 11 insertions(+), 12 deletions(-) create mode 100644 tools/testing/selftests/resctrl/settings diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index c852eb4..7df397c 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -51,6 +51,7 @@ TARGETS += proc TARGETS += pstore TARGETS += ptrace TARGETS += openat2 +TARGETS += resctrl TARGETS += rlimits TARGETS += rseq TARGETS += rtc diff --git a/tools/testing/selftests/resctrl/Makefile b/tools/testing/selftests/resctrl/Makefile index 6bcee2e..3786cbb 100644 --- a/tools/testing/selftests/resctrl/Makefile +++ b/tools/testing/selftests/resctrl/Makefile @@ -1,17 +1,14 @@ -CC = $(CROSS_COMPILE)gcc -CFLAGS = -g -Wall -O2 -D_FORTIFY_SOURCE=2 -SRCS=$(wildcard *.c) -OBJS=$(SRCS:.c=.o) +# SPDX-License-Identifier: GPL-2.0 +# Makefile for resctrl selftests -all: resctrl_tests +CFLAGS += -g -Wall -O2 -D_FORTIFY_SOURCE=2 +LDLIBS += -lnuma -$(OBJS): $(SRCS) - $(CC) $(CFLAGS) -c $(SRCS) +TEST_GEN_PROGS := resctrl_tests +EXTRA_SOURCES := $(wildcard *.c) -resctrl_tests: $(OBJS) - $(CC) $(CFLAGS) -o $@ $^ +all: $(TEST_GEN_PROGS) -.PHONY: clean +$(TEST_GEN_PROGS): $(EXTRA_SOURCES) -clean: - $(RM) $(OBJS) resctrl_tests +include ../lib.mk diff --git a/tools/testing/selftests/resctrl/settings b/tools/testing/selftests/resctrl/settings new file mode 100644 index 0000000..6091b45 --- /dev/null +++ b/tools/testing/selftests/resctrl/settings @@ -0,0 +1 @@ +timeout=120 From patchwork Wed Nov 10 09:33:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 12611647 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19CF1C433EF for ; Wed, 10 Nov 2021 09:34:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F04BC61241 for ; Wed, 10 Nov 2021 09:34:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230516AbhKJJgt (ORCPT ); Wed, 10 Nov 2021 04:36:49 -0500 Received: from esa1.hc1455-7.c3s2.iphmx.com ([207.54.90.47]:62495 "EHLO esa1.hc1455-7.c3s2.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230513AbhKJJgs (ORCPT ); Wed, 10 Nov 2021 04:36:48 -0500 IronPort-SDR: qwabvvmXmXMsZ6Uged9VN3Zdmzq+u2GIE/6vgKI8uZ8tFbhwx0KyRILaQuhPuTzE6N4p0OajWL w1XrJxSaoYOkWZy+QMU7iBNJYU35omjjplqk+0W5MYW3rmCOabbZpfujgzdMvJ67av2O09SGrO owpBcssdlsbvD9sJtxfY3dmRtu4Ye19ciAjUPvSS8mAro8R3991iK/vbeSt6MQsRXvhBTqjXkl uNYIeRC35qhyT8PEJXmCeeXyti8TypDwXU/XMi/X4gE0wY/zsppBtucHjpNn2P6+a6BBixBLa4 kR3hTmaERAY+/qh0X30c4F6r X-IronPort-AV: E=McAfee;i="6200,9189,10163"; a="52113929" X-IronPort-AV: E=Sophos;i="5.87,223,1631545200"; d="scan'208";a="52113929" Received: from unknown (HELO yto-r1.gw.nic.fujitsu.com) ([218.44.52.217]) by esa1.hc1455-7.c3s2.iphmx.com with ESMTP; 10 Nov 2021 18:33:59 +0900 Received: from yto-m3.gw.nic.fujitsu.com (yto-nat-yto-m3.gw.nic.fujitsu.com [192.168.83.66]) by yto-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id 4F3B41013B7; Wed, 10 Nov 2021 18:33:58 +0900 (JST) Received: from oym-om3.fujitsu.com (oym-om3.o.css.fujitsu.com [10.85.58.163]) by yto-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id 9B04BA56E6; Wed, 10 Nov 2021 18:33:57 +0900 (JST) Received: from localhost.localdomain (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by oym-om3.fujitsu.com (Postfix) with ESMTP id 85F254006B62C; Wed, 10 Nov 2021 18:33:56 +0900 (JST) From: Shaopeng Tan To: Fenghua Yu , Reinette Chatre , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, tan.shaopeng@jp.fujitsu.com Subject: [PATCH 2/3] selftests/resctrl: Return KSFT_SKIP(4) if resctrl filessystem is not supported or resctrl is not run as root Date: Wed, 10 Nov 2021 18:33:14 +0900 Message-Id: <20211110093315.3219191-3-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211110093315.3219191-1-tan.shaopeng@jp.fujitsu.com> References: <20211110093315.3219191-1-tan.shaopeng@jp.fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: "Tan, Shaopeng" To unify the return code of resctrl_tests with the return code of selftest set, return KSFT_SKIP (4) if resctrl filessystem is not supported or resctrl is not run as root. Signed-off-by: Shaopeng Tan --- tools/testing/selftests/resctrl/resctrl_tests.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 973f09a..3be0895 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -205,7 +205,7 @@ int main(int argc, char **argv) * 2. We execute perf commands */ if (geteuid() != 0) - return ksft_exit_fail_msg("Not running as root, abort testing.\n"); + return ksft_exit_skip("Not running as root, abort testing.\n"); /* Detect AMD vendor */ detect_amd(); @@ -235,7 +235,7 @@ int main(int argc, char **argv) sprintf(bm_type, "fill_buf"); if (!check_resctrlfs_support()) - return ksft_exit_fail_msg("resctrl FS does not exist\n"); + return ksft_exit_skip("resctrl FS does not exist\n"); filter_dmesg(); From patchwork Wed Nov 10 09:33:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaopeng Tan X-Patchwork-Id: 12611659 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B372C433F5 for ; Wed, 10 Nov 2021 09:41:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 23D29610A2 for ; Wed, 10 Nov 2021 09:41:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbhKJJoK (ORCPT ); Wed, 10 Nov 2021 04:44:10 -0500 Received: from esa10.hc1455-7.c3s2.iphmx.com ([139.138.36.225]:23931 "EHLO esa10.hc1455-7.c3s2.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbhKJJoJ (ORCPT ); Wed, 10 Nov 2021 04:44:09 -0500 X-Greylist: delayed 431 seconds by postgrey-1.27 at vger.kernel.org; Wed, 10 Nov 2021 04:44:09 EST IronPort-SDR: bWkE/8CVZN6aB59nqE37nke6m5X/XtuRrZroitYpMQdjef8ChAQvu8mUpTX9ygOcby4KEUuMg4 S8poeq+YVmBGyr5EBC7/9H17WcZgJiqxj1OMNrht8Toe0so/Xkw1COITSI5rnbCCTTKdgP0eBC IY/JMEfiCbVVY010txtUtyaY8TGhEVx2KvqTIV/omYk0Sj/hWn0/LdOxU92FFvq6UTkp0XlYDh MOlSmI8gnAYkW1aRQ3j7gcIf+pEfirkXObW5MvU5XO156q8HlEjldFEoZXc4TSooZ9qGtjM9S2 dHzyhI7636GaSg6rMulimBqy X-IronPort-AV: E=McAfee;i="6200,9189,10163"; a="39914653" X-IronPort-AV: E=Sophos;i="5.87,223,1631545200"; d="scan'208";a="39914653" Received: from unknown (HELO yto-r1.gw.nic.fujitsu.com) ([218.44.52.217]) by esa10.hc1455-7.c3s2.iphmx.com with ESMTP; 10 Nov 2021 18:34:05 +0900 Received: from yto-m2.gw.nic.fujitsu.com (yto-nat-yto-m2.gw.nic.fujitsu.com [192.168.83.65]) by yto-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id 250C91013BD; Wed, 10 Nov 2021 18:34:05 +0900 (JST) Received: from oym-om3.fujitsu.com (oym-om3.o.css.fujitsu.com [10.85.58.163]) by yto-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id 1524EE681E; Wed, 10 Nov 2021 18:34:04 +0900 (JST) Received: from localhost.localdomain (n3235113.np.ts.nmh.cs.fujitsu.co.jp [10.123.235.113]) by oym-om3.fujitsu.com (Postfix) with ESMTP id F30924006D3A2; Wed, 10 Nov 2021 18:34:02 +0900 (JST) From: Shaopeng Tan To: Fenghua Yu , Reinette Chatre , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, tan.shaopeng@jp.fujitsu.com Subject: [PATCH 3/3] selftests/resctrl: Kill the child process created by fork() when the SIGTERM signal comes Date: Wed, 10 Nov 2021 18:33:15 +0900 Message-Id: <20211110093315.3219191-4-tan.shaopeng@jp.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211110093315.3219191-1-tan.shaopeng@jp.fujitsu.com> References: <20211110093315.3219191-1-tan.shaopeng@jp.fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: "Tan, Shaopeng" In kselftest framework there is a limited time for each sub test, when the time limit comes SIGTEM signal will be sent to sub test by "timeout --foregroup " command. In resctrl_tests, fork() is used to create a child process. This commit ensures child process to be killed before parent process exiting if SIGTERM signal comes. Signed-off-by: Shaopeng Tan --- tools/testing/selftests/resctrl/resctrl_val.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index 9522434..b32b963 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -678,6 +678,7 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) sigemptyset(&sigact.sa_mask); sigact.sa_flags = SA_SIGINFO; if (sigaction(SIGINT, &sigact, NULL) || + sigaction(SIGTERM, &sigact, NULL) || sigaction(SIGHUP, &sigact, NULL)) { perror("# sigaction"); ret = errno;