Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1284096rdb; Fri, 16 Feb 2024 10:33:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWpcA8G+f48feyUsQiVPryZOwqG3QP3n0Amr2Lzlg47sCA6FSuXMBol+CgNtpfdt1a9ePLDaPFODMnN2IGtbIJSXTTUZX3c7TLiu58XvA== X-Google-Smtp-Source: AGHT+IFnc6d7ej93c4KlahdsRoHVJB8TiHcNsUrOvwCMSCos2mOT7VLwwiVP2NVaaBokMT7qCSTX X-Received: by 2002:a17:902:f551:b0:1db:8d20:aa65 with SMTP id h17-20020a170902f55100b001db8d20aa65mr5864444plf.31.1708108436151; Fri, 16 Feb 2024 10:33:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708108436; cv=pass; d=google.com; s=arc-20160816; b=opg5WcyPWvMSLGckCMGVONnMXrXqmXMn2xd/4cjevLemIxzbJj0w2YgAmBZS5uo+0j fzr5NrdeQNARV+oHLgDK2KU0UP7SvDAkjmhdAknDcF1cuvHOG0zG6ab/NFbPWHVNXsVB kOwXehNlia/kDSHWEhQJNOJT9mdSOly3XdkKfmcIcoLqvoYNp4RAcozgMxQfMT1mwQ2H wV9njEuh6M/LSmzEwfHYGPT3PeQizJb56HClXF33P+rGQ4UXSh1HHRFSpxgwpGA95SPb I4uUi0p+KJSb1akJ5XUpt1s8B3kU+nTl9yGZy2jrJ5IeNFoL+txSSRaAgECcbDaApvkk OQPA== 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=CDhDd9Kfjsqh4jLKpVf7J36w/JnuAi2f5V71QMuGAEk=; fh=4pJ4mchRYFrfBfvhSl5jDG/kQHpiAx8Hz7po5TFQYfc=; b=hVSPGjMIYDi7GBUR3OshmcxAyt0pu+BDCNoF4whWDUxRofeNkaf+VbAsbPpZfZfsHc 9apuEgYOKRWNxh7S+dCwAwWCQ0hONh9/G489CNqBknr9fNJ9XmR9Npw8UQTgkKXxyp2J 5ZSZBOYF1wAnaf7LgmEI1pw2TGsNs6g8qeLxVJWf9h6q5zTNaA39uR6p0FvXtZbfeZA9 /sFGC3oj4YJg8OVYR/gZAoaAE1pI+dgtmBKMXfu/SVODu27CafmkxURYbKbTpt+vG3E4 GG2fhMXWqOQaC9dt6SPA4yh9HzO5gvMMENeX/FCtAw+KfHAd6MtPyOGBlmmnnt5RGWVz +FjA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=T1FQqQW9; arc=pass (i=1 spf=pass spfdomain=joelfernandes.org dkim=pass dkdomain=joelfernandes.org); spf=pass (google.com: domain of linux-kernel+bounces-69168-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69168-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id v4-20020a170903238400b001d95f009fd0si233916plh.367.2024.02.16.10.33.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 10:33:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69168-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=T1FQqQW9; arc=pass (i=1 spf=pass spfdomain=joelfernandes.org dkim=pass dkdomain=joelfernandes.org); spf=pass (google.com: domain of linux-kernel+bounces-69168-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69168-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D226D282D18 for ; Fri, 16 Feb 2024 18:33:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D6CF613B289; Fri, 16 Feb 2024 18:32:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="T1FQqQW9" Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (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 1ECFB134CCE for ; Fri, 16 Feb 2024 18:31:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708108319; cv=none; b=m35VZ1lFWRBhaEtmLG7oMsQl9LdRpRRKvaB18PsVFnxq3k+y2rqDImRc9b5bqP8KUTwDm8IXIVPwwQkVC+6TFyC0WoKC4LIb6hu/3lrSIjpwSwW9FJXbAacgAMtttmOiCZPl1MXBYgOpTGQGXoq9d96C75jRhsmEP65a6P98WVg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708108319; c=relaxed/simple; bh=mZ2gOIXcUxYPUWs6+iWh+plbgTcX3Uoy+H9V33hkCIo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QkXXf+iTroUwqpWgtgTcwzpeVQmzY8fwEDEd+QO11aqc1tpXe25QC74HSzz1zDu+vslG5ecW8DRubooIJ8+R6n14MOU8c1yLibMmhFSPn4PFD3NccxzJFAJ6yWoUTth0GyuChJu1OY4jxdpue5au4vYr4UO8dPEn93epnf1wVX4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joelfernandes.org; spf=pass smtp.mailfrom=joelfernandes.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b=T1FQqQW9; arc=none smtp.client-ip=209.85.219.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joelfernandes.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=joelfernandes.org Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-686a92a8661so11902706d6.0 for ; Fri, 16 Feb 2024 10:31:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1708108314; x=1708713114; 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=CDhDd9Kfjsqh4jLKpVf7J36w/JnuAi2f5V71QMuGAEk=; b=T1FQqQW9TyHh7HgT+F67Khdj1PilhW3VPjsjqYihnfFaIn7pw8ggciDJAkQGDTSSBI iqoTmDz6YS4G1PF1+7y7A17Uu3oZhNRu0a1tRPTOqV+6v3KDzJ2nGLwkEIUejXwMqCkv bEyROjqgxfZs9uHnGSFc68A/67hVrl3WKckNk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708108314; x=1708713114; 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=CDhDd9Kfjsqh4jLKpVf7J36w/JnuAi2f5V71QMuGAEk=; b=lI3ISlLeHh3kPa+wHgN3Ii5S+WxW5iHf78G/gZDmtEkA+OaYDlAwjdbqXsXwUW4pji Y0atdckzYXe5M4Gn654kAzRRsPsuZcg1fQ6SyvI5BZK74pY258lKOGdSGPyZ67Gz5zlm vUkrr2s51tp3+fDCM8aNde8pIeWo+SYiSvV8cb8Yw+OEZUA4y8vAH7DlLxouJjVF7Qct yVDnR7x6IDWqpf4LUJqW+CPMlof2GhKsYJ4zg/S4ltRFqYmYqN75NgBFp6oolrzHME8+ slxky6gvzSCzxtu2fof+m12UipATb072nLchOLKsFGgpo6EQ+egLAVTONybV28kmOMMG 7EBQ== X-Gm-Message-State: AOJu0YyR721HDtnq1q6diSwu93X/KZ89iTEW4wBgRSoPVrcNo1/z9/FN +Qgs5QXYC7w2eNCyO7nR5aHmi+1nPIoOGKP6I5V0L/3ECOg8HIh+7OyIDO1yuXmz1zdACo2DdVq n X-Received: by 2002:a05:6214:5904:b0:68c:668b:c610 with SMTP id qo4-20020a056214590400b0068c668bc610mr7398414qvb.2.1708108314017; Fri, 16 Feb 2024 10:31:54 -0800 (PST) Received: from joelbox2.. (c-98-249-43-138.hsd1.va.comcast.net. [98.249.43.138]) by smtp.gmail.com with ESMTPSA id nd13-20020a056214420d00b0068cdadb5e7esm159722qvb.31.2024.02.16.10.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 10:31:53 -0800 (PST) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org, Shuah Khan Cc: Suleiman Souhlal , Youssef Esmat , Steven Rostedt , David Vernet , Thomas Gleixner , "Paul E . McKenney" , joseph.salisbury@canonical.com, Dietmar Eggemann , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Luca Abeni , Tommaso Cucinotta , Vineeth Pillai , Shuah Khan , Phil Auld , "Joel Fernandes (Google)" , linux-kselftest@vger.kernel.org Subject: [PATCH 08/10] selftests/sched: Migrate cs_prctl_test to kselfttest Date: Fri, 16 Feb 2024 13:31:06 -0500 Message-Id: <20240216183108.1564958-9-joel@joelfernandes.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240216183108.1564958-1-joel@joelfernandes.org> References: <20240216183108.1564958-1-joel@joelfernandes.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This test begs to be a kselftest, is in the kselftest hierarchy and does not even use a single kselftest API. Convert it. It simplifies some of the code and the output also looks much nicer now: Totals: pass:17 fail:0 xfail:0 xpass:0 skip:0 error:0 Signed-off-by: Joel Fernandes (Google) --- tools/testing/selftests/sched/Makefile | 6 +- tools/testing/selftests/sched/cs_prctl_test.c | 74 ++++++++++--------- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/tools/testing/selftests/sched/Makefile b/tools/testing/selftests/sched/Makefile index f491d741cb45..90c53bc1337e 100644 --- a/tools/testing/selftests/sched/Makefile +++ b/tools/testing/selftests/sched/Makefile @@ -1,9 +1,11 @@ # SPDX-License-Identifier: GPL-2.0+ TEST_GEN_PROGS := cs_dlserver_test - -cs_dlserver_test: cs_dlserver_test.c common.c +TEST_GEN_PROGS += cs_prctl_test CFLAGS += $(KHDR_INCLUDES) CFLAGS += -Wall include ../lib.mk + +$(OUTPUT)/cs_dlserver_test: cs_dlserver_test.c common.c +$(OUTPUT)/cs_prctl_test: cs_prctl_test.c common.c diff --git a/tools/testing/selftests/sched/cs_prctl_test.c b/tools/testing/selftests/sched/cs_prctl_test.c index 7ba057154343..bb7aee703cdf 100644 --- a/tools/testing/selftests/sched/cs_prctl_test.c +++ b/tools/testing/selftests/sched/cs_prctl_test.c @@ -28,10 +28,11 @@ #include #include #include -#include #include #include +#include "common.h" + #if __GLIBC_PREREQ(2, 30) == 0 #include static pid_t gettid(void) @@ -80,7 +81,7 @@ static int _prctl(int option, unsigned long arg2, unsigned long arg3, unsigned l int res; res = prctl(option, arg2, arg3, arg4, arg5); - printf("%d = prctl(%d, %ld, %ld, %ld, %lx)\n", res, option, (long)arg2, (long)arg3, + ksft_print_msg("%d = prctl(%d, %ld, %ld, %ld, %lx)\n", res, option, (long)arg2, (long)arg3, (long)arg4, arg5); return res; } @@ -91,21 +92,20 @@ static int _prctl(int option, unsigned long arg2, unsigned long arg3, unsigned l static void __handle_error(char *fn, int ln, char *msg) { int pidx; - printf("(%s:%d) - ", fn, ln); + ksft_print_msg("(%s:%d) - ", fn, ln); perror(msg); if (need_cleanup) { for (pidx = 0; pidx < num_processes; ++pidx) kill(procs[pidx].cpid, 15); need_cleanup = 0; } - exit(EXIT_FAILURE); + ksft_exit_fail(); } static void handle_usage(int rc, char *msg) { - puts(USAGE); - puts(msg); - putchar('\n'); + ksft_print_msg("%s\n", USAGE); + ksft_print_msg("%s\n\n", msg); exit(rc); } @@ -117,7 +117,7 @@ static unsigned long get_cs_cookie(int pid) ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, pid, PIDTYPE_PID, (unsigned long)&cookie); if (ret) { - printf("Not a core sched system\n"); + ksft_print_msg("Not a core sched system\n"); return -1UL; } @@ -160,7 +160,7 @@ static int child_func_process(void *arg) ret = write(ca->pfd[1], &ca->thr_tids, sizeof(int) * ca->num_threads); if (ret == -1) - printf("write failed on pfd[%d] - error (%s)\n", + ksft_print_msg("write failed on pfd[%d] - error (%s)\n", ca->pfd[1], strerror(errno)); close(ca->pfd[1]); @@ -192,7 +192,7 @@ void create_processes(int num_processes, int num_threads, struct child_args proc for (i = 0; i < num_processes; ++i) { ret = read(proc[i].pfd[0], &proc[i].thr_tids, sizeof(int) * proc[i].num_threads); if (ret == -1) - printf("read failed on proc[%d].pfd[0] error (%s)\n", + ksft_print_msg("read failed on proc[%d].pfd[0] error (%s)\n", i, strerror(errno)); close(proc[i].pfd[0]); } @@ -202,30 +202,29 @@ void disp_processes(int num_processes, struct child_args proc[]) { int i, j; - printf("tid=%d, / tgid=%d / pgid=%d: %lx\n", gettid(), getpid(), getpgid(0), + ksft_print_msg("tid=%d, / tgid=%d / pgid=%d: %lx\n", gettid(), getpid(), getpgid(0), get_cs_cookie(getpid())); for (i = 0; i < num_processes; ++i) { - printf(" tid=%d, / tgid=%d / pgid=%d: %lx\n", proc[i].cpid, proc[i].cpid, + ksft_print_msg(" tid=%d, / tgid=%d / pgid=%d: %lx\n", proc[i].cpid, proc[i].cpid, getpgid(proc[i].cpid), get_cs_cookie(proc[i].cpid)); for (j = 0; j < proc[i].num_threads; ++j) { - printf(" tid=%d, / tgid=%d / pgid=%d: %lx\n", proc[i].thr_tids[j], + ksft_print_msg(" tid=%d, / tgid=%d / pgid=%d: %lx\n", proc[i].thr_tids[j], proc[i].cpid, getpgid(0), get_cs_cookie(proc[i].thr_tids[j])); } } puts("\n"); } -static int errors; - #define validate(v) _validate(__LINE__, v, #v) void _validate(int line, int val, char *msg) { if (!val) { - ++errors; - printf("(%d) FAILED: %s\n", line, msg); + ksft_print_msg("(%d) FAILED: %s\n", line, msg); + ksft_inc_fail_cnt(); } else { - printf("(%d) PASSED: %s\n", line, msg); + ksft_print_msg("(%d) PASSED: %s\n", line, msg); + ksft_inc_pass_cnt(); } } @@ -254,13 +253,17 @@ int main(int argc, char *argv[]) keypress = 1; break; case 'h': - printf(USAGE); + ksft_print_msg(USAGE); exit(EXIT_SUCCESS); default: handle_usage(20, "unknown option"); } } + if (!hyperthreading_enabled()) { + ksft_exit_skip("This test requires hyperthreading to be enabled\n"); + } + if (num_processes < 1 || num_processes > MAX_PROCESSES) handle_usage(1, "Bad processes value"); @@ -272,17 +275,22 @@ int main(int argc, char *argv[]) srand(time(NULL)); - /* put into separate process group */ + /* Put into separate process group */ if (setpgid(0, 0) != 0) handle_error("process group"); - printf("\n## Create a thread/process/process group hiearchy\n"); + ksft_print_header(); + + /* Increase the count if adding more validate() statements. */ + ksft_set_plan(17); + + ksft_print_msg("\n## Create a thread/process/process group hiearchy\n"); create_processes(num_processes, num_threads, procs); need_cleanup = 1; disp_processes(num_processes, procs); validate(get_cs_cookie(0) == 0); - printf("\n## Set a cookie on entire process group\n"); + ksft_print_msg("\n## Set a cookie on entire process group\n"); if (_prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, 0, PIDTYPE_PGID, 0) < 0) handle_error("core_sched create failed -- PGID"); disp_processes(num_processes, procs); @@ -296,7 +304,7 @@ int main(int argc, char *argv[]) validate(get_cs_cookie(0) == get_cs_cookie(pid)); validate(get_cs_cookie(0) == get_cs_cookie(procs[pidx].thr_tids[0])); - printf("\n## Set a new cookie on entire process/TGID [%d]\n", pid); + ksft_print_msg("\n## Set a new cookie on entire process/TGID [%d]\n", pid); if (_prctl(PR_SCHED_CORE, PR_SCHED_CORE_CREATE, pid, PIDTYPE_TGID, 0) < 0) handle_error("core_sched create failed -- TGID"); disp_processes(num_processes, procs); @@ -305,7 +313,7 @@ int main(int argc, char *argv[]) validate(get_cs_cookie(pid) != 0); validate(get_cs_cookie(pid) == get_cs_cookie(procs[pidx].thr_tids[0])); - printf("\n## Copy the cookie of current/PGID[%d], to pid [%d] as PIDTYPE_PID\n", + ksft_print_msg("\n## Copy the cookie of current/PGID[%d], to pid [%d] as PIDTYPE_PID\n", getpid(), pid); if (_prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_TO, pid, PIDTYPE_PID, 0) < 0) handle_error("core_sched share to itself failed -- PID"); @@ -315,7 +323,7 @@ int main(int argc, char *argv[]) validate(get_cs_cookie(pid) != 0); validate(get_cs_cookie(pid) != get_cs_cookie(procs[pidx].thr_tids[0])); - printf("\n## Copy cookie from a thread [%d] to current/PGID [%d] as PIDTYPE_PID\n", + ksft_print_msg("\n## Copy cookie from a thread [%d] to current/PGID [%d] as PIDTYPE_PID\n", procs[pidx].thr_tids[0], getpid()); if (_prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_FROM, procs[pidx].thr_tids[0], PIDTYPE_PID, 0) < 0) @@ -325,7 +333,7 @@ int main(int argc, char *argv[]) validate(get_cs_cookie(0) == get_cs_cookie(procs[pidx].thr_tids[0])); validate(get_cs_cookie(pid) != get_cs_cookie(procs[pidx].thr_tids[0])); - printf("\n## Copy cookie from current [%d] to current as pidtype PGID\n", getpid()); + ksft_print_msg("\n## Copy cookie from current [%d] to current as pidtype PGID\n", getpid()); if (_prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_TO, 0, PIDTYPE_PGID, 0) < 0) handle_error("core_sched share to self failed -- PGID"); disp_processes(num_processes, procs); @@ -340,20 +348,16 @@ int main(int argc, char *argv[]) validate(_prctl(PR_SCHED_CORE, PR_SCHED_CORE_SHARE_TO, 0, PIDTYPE_PGID, 1) < 0 && errno == EINVAL); - if (errors) { - printf("TESTS FAILED. errors: %d\n", errors); - res = 10; - } else { - printf("SUCCESS !!!\n"); - } - - if (keypress) + if (keypress) { + ksft_print_msg("Waiting for keypress to exit\n"); getchar(); - else + } else { sleep(delay); + } for (pidx = 0; pidx < num_processes; ++pidx) kill(procs[pidx].cpid, 15); + ksft_finished(); return res; } -- 2.34.1