From patchwork Tue Jul 26 22:13:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Nowakowski-Krijger X-Patchwork-Id: 1661029 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=guYnTTpn; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lsrmg0D5Jz9sFk for ; Wed, 27 Jul 2022 08:14:26 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B5C853C25F5 for ; Wed, 27 Jul 2022 00:14:24 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 7B52D3C1ADE for ; Wed, 27 Jul 2022 00:14:09 +0200 (CEST) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id AE6AC10005B4 for ; Wed, 27 Jul 2022 00:14:08 +0200 (CEST) Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 37DAF3F14B for ; Tue, 26 Jul 2022 22:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1658873648; bh=sH5K3oAQ/567wS6owWEwDYhTAKYaPG5lAbHsrg05TQ4=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=guYnTTpnW+OFmFz0EBuMYVoiBDnwNe/RDpkVGJDSFD8YyZw4kyLHVBrwxAdyNOHCC z81yJC6+OcVmVu8dabkm8T+XTTxrDS3ppq+4PqTfXEvDobVpDC6PW/yfpa5A366PBz 5TKBDDfKzYXdSjnGTOanijDmWteV75s+XHWxtwBxAaptqTqlX/dtTzI+jNWZXhF9C7 nd9J5iKxYbW5WpDBn4wFWY3Uo7FdV2V3rvMxcrzYO3Z/3voOM3HIMFpSo5KENrLEtT hLEMEhl1kej08NngfcjC0by+LpRGeR7yhEOEtp31t/GxmsrnIzDBT9oEw7wlUFZWRU alF6Z7OyCM3rQ== Received: by mail-pl1-f197.google.com with SMTP id c15-20020a170902d48f00b0016c01db365cso9100605plg.20 for ; Tue, 26 Jul 2022 15:14:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=sH5K3oAQ/567wS6owWEwDYhTAKYaPG5lAbHsrg05TQ4=; b=EiXyGJGGjLk92vJvEGrSYFXtezwVQJSPodhq5g6utTmBIvG9Xhj7BYVdvkduz5d6Vo +8+gNgV+IlpTFDoRS4Kw/8JRAu+v2OxAfIatDSXQ65tvT4aaCuAITJ5S2VSsCpuNHeI5 Dq9OBmvmqzCA9GPFdXz/T1ZM/zk0mLNESZjCx2wn9yxwRTJPDQFHmP8O/XFMYCE2X7kL s55tYSBUWbb3nmDyBm9ZeaDE0kxjhimEp6rdWNMVY+2xRJRmObMgt42GKjwGn7awMEGJ YB0CQc4Ze3BFjQvXBXWnjib4Dbc8G0mOu3P4V465KA6seRChyeSwTPvlS7EIjOhBKJ22 CRAA== X-Gm-Message-State: AJIora9Y/RZM2qNTjTFR/qgRmhaer7CuBse3MyuybmT2y0re8+9sIq+j usDevn4OAuvK+53chlgMXn/wrIVYgW7w2oVAd6TfLHpWUWueI3rdbiXNhrWGuZjduXGtay7Ze6n QrSLT4N4nNbBff29nQmM+CWelND70 X-Received: by 2002:a63:5504:0:b0:416:2152:431a with SMTP id j4-20020a635504000000b004162152431amr16676416pgb.97.1658873646630; Tue, 26 Jul 2022 15:14:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1unCVwx2L4RKnno2WJUZK+jd6h7rZe11nSnOW/xqbAt5hORv5rRyg6qGvwMADSGuf2ouphH5A== X-Received: by 2002:a63:5504:0:b0:416:2152:431a with SMTP id j4-20020a635504000000b004162152431amr16676407pgb.97.1658873646408; Tue, 26 Jul 2022 15:14:06 -0700 (PDT) Received: from luke-ubuntu.buildd (cpe-75-80-146-43.san.res.rr.com. [75.80.146.43]) by smtp.gmail.com with ESMTPSA id a13-20020a1709027e4d00b0015e9f45c1f4sm12069308pln.186.2022.07.26.15.14.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 15:14:05 -0700 (PDT) From: Luke Nowakowski-Krijger To: ltp@lists.linux.it, rpalethorpe@suse.de, liwang@redhat.com, pvorel@suse.cz, chrubis@suse.cz Date: Tue, 26 Jul 2022 15:13:17 -0700 Message-Id: <5e6668a49ad97716816dba94b024970e7b60b12c.1658872195.git.luke.nowakowskikrijger@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v6 01/10] testcases/lib: Implement tst_cgctl binary X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Implement a binary utility that creates an interface to make calls to the cgroup C API. This will effectively allow shell scripts to make calls to the cgroup C api. Signed-off-by: Luke Nowakowski-Krijger --- v2->v6: Added cgctl_usage() and replaced define string usage with function. testcases/lib/Makefile | 2 +- testcases/lib/tst_cgctl.c | 87 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 testcases/lib/tst_cgctl.c diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile index f2de0c832..f4f8c8524 100644 --- a/testcases/lib/Makefile +++ b/testcases/lib/Makefile @@ -12,6 +12,6 @@ MAKE_TARGETS := tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\ tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\ tst_getconf tst_supported_fs tst_check_drivers tst_get_unused_port\ tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill\ - tst_check_kconfigs + tst_check_kconfigs tst_cgctl include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/lib/tst_cgctl.c b/testcases/lib/tst_cgctl.c new file mode 100644 index 000000000..8ef615a56 --- /dev/null +++ b/testcases/lib/tst_cgctl.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 Canonical Ltd. + */ + +#include +#include +#include +#include +#include +#include "tst_cgroup.h" + +static void cgctl_usage(void) +{ + fprintf(stderr, "Usage: tst_cgctl require [controller] [test_pid]\n\tcleanup [config (output of tst_cg_print_config)]\n\tprint\n\t help\n"); +} + +static int cgctl_require(const char *ctrl, int test_pid) +{ + struct tst_cg_opts opts; + + memset(&opts, 0, sizeof(opts)); + opts.test_pid = test_pid; + + tst_cg_require(ctrl, &opts); + tst_cg_print_config(); + + return 0; +} + +static int cgctl_cleanup(const char *const config) +{ + tst_cg_scan(); + tst_cg_load_config(config); + tst_cg_cleanup(); + + return 0; +} + +static int cgctl_print(void) +{ + tst_cg_scan(); + tst_cg_print_config(); + + return 0; +} + +int main(int argc, char *argv[]) +{ + int test_pid; + const char *cmd_name = argv[1]; + + if (argc < 2) + goto error; + + if (!strcmp(cmd_name, "require")) { + if (argc != 4) + goto arg_num_error; + test_pid = atoi(argv[3]); + if (!test_pid) { + fprintf(stderr, "tst_cgctl: Invalid test_pid '%s' given\n", + argv[3]); + goto error; + } + return cgctl_require(argv[2], test_pid); + } else if (!strcmp(cmd_name, "cleanup")) { + if (argc != 3) + goto arg_num_error; + return cgctl_cleanup(argv[2]); + } else if (!strcmp(cmd_name, "print")) { + return cgctl_print(); + } else if (!strcmp(cmd_name, "help")) { + cgctl_usage(); + return 0; + } + + fprintf(stderr, "tst_cgctl: Unknown command '%s' given\n", cmd_name); + goto error; + +arg_num_error: + fprintf(stderr, + "tst_cgctl: Invalid number of arguments given for command '%s'\n", + cmd_name); +error: + cgctl_usage(); + return 1; +} From patchwork Tue Jul 26 22:13:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Nowakowski-Krijger X-Patchwork-Id: 1661030 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=hsA6FgJs; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lsrmx1XzQz9sFk for ; Wed, 27 Jul 2022 08:14:40 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C0BE63C20CC for ; Wed, 27 Jul 2022 00:14:37 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id A17203C2150 for ; Wed, 27 Jul 2022 00:14:14 +0200 (CEST) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 1764010005B4 for ; Wed, 27 Jul 2022 00:14:13 +0200 (CEST) Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 435373F142 for ; Tue, 26 Jul 2022 22:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1658873653; bh=rM0ywzac0+9xAQxJOA3osJ4pwm0bcCnKLVaqV+gyTpY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hsA6FgJsrBXwzGmTo0HlvhuK7lZbTC7RFb2n95s/L89c9wchg7qzqEphINIXc8H4J K43xDR6kQ2Jhqsb3rx1nBBNoXPMEn3ddHukjzC3mZXQ6iM9wbfBCdUaigxJC/KEISu WT1abPWqrc/P/GTo9dFHNUpaSouIQV/Za+RD2G6UYnmVMUcePHmRBUgXPEagtNEkjv s984wKkc09yNwgO6U345pMRnOlpopmXv9AtpwsnShZG6CvxDMojVOWgCiZ/JHU8On9 eh7+SUse7glkAFNAwle+zxl43uSTi4cmRR9EWNC7swgxPoUSAV0BX6DVUKICMZqm9r BrvW9hXIFIVGg== Received: by mail-pl1-f200.google.com with SMTP id u4-20020a170902e5c400b0016d6a70a282so4661770plf.10 for ; Tue, 26 Jul 2022 15:14:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=rM0ywzac0+9xAQxJOA3osJ4pwm0bcCnKLVaqV+gyTpY=; b=bSLpdVGI13jIKftLnDOmDJJsv1Tfz9LmYdiHILunTl1Vf3n/TBBuyTWFk3+/S1ZS7U /IMpq6fyx+OgSV447NSCb2VVSVDuC7jENuCk1a1kOG/ks09EsCij/KfZrcFGsfw8zpN9 xJZ4e+e+PQGUViR1l7J44OnIttx0v28r71h228sqiASpcWjQbqHkkGepJ5ef5tvoLqmG 2Snsd/616v7oVNCS+UzodVhtfQZZimP84io5vM5DHo6VWLohzylGPBzfXGUn83jkYaSn krP8WXFiEB9WIir7ZwxOvMk5+8ocF3yNgQa+Gj8iF3KhHhUVemHhWSf39xu+gXgvJMeD ZqLw== X-Gm-Message-State: AJIora+KWxf+r2QdcRLT9DOEVCJeeP8R5ZP/nLot3LMW/Wn9OnJHEmbq 3M/V+1q7cB85+kVK42wDNLiHvIaNYFv7F6+uhNG/0fTPXxzhQYmQ4IYGQYuJkF4G6hlkGkQut1U qvgYDB9uxBulSJXInKzCR5DBsxXXI X-Received: by 2002:a05:6a00:2449:b0:528:3a29:e79d with SMTP id d9-20020a056a00244900b005283a29e79dmr19299697pfj.39.1658873648392; Tue, 26 Jul 2022 15:14:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sQHxIRk6dgRgY4oiQvMW3fpO4zo06NV69bOYrcwp6Hf63QoTEBmd3C0Cop5+wNvLt1vQwJkg== X-Received: by 2002:a05:6a00:2449:b0:528:3a29:e79d with SMTP id d9-20020a056a00244900b005283a29e79dmr19299669pfj.39.1658873647810; Tue, 26 Jul 2022 15:14:07 -0700 (PDT) Received: from luke-ubuntu.buildd (cpe-75-80-146-43.san.res.rr.com. [75.80.146.43]) by smtp.gmail.com with ESMTPSA id a13-20020a1709027e4d00b0015e9f45c1f4sm12069308pln.186.2022.07.26.15.14.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 15:14:07 -0700 (PDT) From: Luke Nowakowski-Krijger To: ltp@lists.linux.it, rpalethorpe@suse.de, liwang@redhat.com, pvorel@suse.cz, chrubis@suse.cz Date: Tue, 26 Jul 2022 15:13:18 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v6 02/10] controllers: Expand cgroup_lib shell library X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Expand the cgroup_lib library by using the tst_cgctl binary utility to make calls to the Cgroup C API to simplify and centralize the mounting and cleanup process of Cgroups Signed-off-by: Luke Nowakowski-Krijger --- v5->v6: Added $ret to capture return code and added return $ret after tst_brk calls. testcases/kernel/controllers/cgroup_lib.sh | 137 ++++++++++++++++++--- 1 file changed, 117 insertions(+), 20 deletions(-) diff --git a/testcases/kernel/controllers/cgroup_lib.sh b/testcases/kernel/controllers/cgroup_lib.sh index 56c9a7521..5fe2252be 100644 --- a/testcases/kernel/controllers/cgroup_lib.sh +++ b/testcases/kernel/controllers/cgroup_lib.sh @@ -2,38 +2,135 @@ # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (c) 2019-2022 Petr Vorel # Copyright (c) 2018-2019 ARM Ltd. All Rights Reserved. +# Copyright (c) 2022 Canonical Ltd. -# Find mountpoint to given subsystem -# get_cgroup_mountpoint SUBSYSTEM -# RETURN: 0 if mountpoint found, otherwise 1 -get_cgroup_mountpoint() +_cgroup_state= + +# Find mountpoint of the given controller +# USAGE: cgroup_get_mountpoint CONTROLLER +# RETURNS: Prints the mountpoint of the given controller +# Must call cgroup_require before calling +cgroup_get_mountpoint() +{ + local ctrl="$1" + local mountpoint + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_get_mountpoint: controller not defined" + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_get_mountpoint: No previous state found. Forgot to call cgroup_require?" + + mountpoint=$(echo "$_cgroup_state" | grep -w "^$ctrl" | awk '{ print $4 }') + echo "$mountpoint" + + return 0 +} + +# Get the test path of a given controller that has been created by the cgroup C API +# USAGE: cgroup_get_test_path CONTROLLER +# RETURNS: Prints the path to the test direcory +# Must call cgroup_require before calling +cgroup_get_test_path() +{ + local ctrl="$1" + local mountpoint + local test_path + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_get_test_path: controller not defined" + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_get_test_path: No previous state found. Forgot to call cgroup_require?" + + mountpoint=$(cgroup_get_mountpoint "$ctrl") + + test_path="$mountpoint/ltp/test-$$" + + [ ! -e "$test_path" ] && tst_brk TBROK "cgroup_get_test_path: No test path found. Forgot to call cgroup_require?" + + echo "$test_path" + + return 0 +} + +# Gets the cgroup version of the given controller +# USAGE: cgroup_get_version CONTROLLER +# RETURNS: "1" if version 1 and "2" if version 2 +# Must call cgroup_require before calling +cgroup_get_version() { - local subsystem=$1 - local mntpoint + local ctrl="$1" + local version - [ $# -eq 0 ] && tst_brk TBROK "get_cgroup_mountpoint: subsystem not defined" + [ $# -eq 0 ] && tst_brk TBROK "cgroup_get_version: controller not defined" + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_get_version: No previous state found. Forgot to call cgroup_require?" - mntpoint=$(grep cgroup /proc/mounts | grep -w $subsystem | awk '{ print $2 }') - [ -z "$mntpoint" ] && return 1 + version=$(echo "$_cgroup_state" | grep -w "^$ctrl" | awk '{ print $2 }') + [ "$version" = "" ] && tst_brk TBROK "cgroup_get_version: Could not find controller $ctrl" + + echo "$version" - echo $mntpoint return 0 } -# Check if given subsystem is supported and enabled -# is_cgroup_subsystem_available_and_enabled SUBSYSTEM -# RETURN: 0 if subsystem supported and enabled, otherwise 1 -is_cgroup_subsystem_available_and_enabled() +# Cleans up any setup done by calling cgroup_require. +# USAGE: cgroup_cleanup +# Can be safely called even when no setup has been done +cgroup_cleanup() { - local val - local subsystem=$1 + [ "$_cgroup_state" = "" ] && return 0 - [ $# -eq 0 ] && tst_brk TBROK "is_cgroup_subsystem_available_and_enabled: subsystem not defined" + ROD tst_cgctl cleanup "$_cgroup_state" - val=$(grep -w $subsystem /proc/cgroups | awk '{ print $4 }') - [ "$val" = "1" ] && return 0 + _cgroup_state= - return 1 + return 0 +} + +# Get the task list of the given controller +# USAGE: cgroup_get_task_list CONTROLLER +# RETURNS: prints out "cgroup.procs" if version 2 otherwise "tasks" +# Must call cgroup_require before calling +cgroup_get_task_list() +{ + local ctrl="$1" + local version + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_get_task_list: controller not defined" + + version=$(cgroup_get_version "$ctrl") + + if [ "$version" = "2" ]; then + echo "cgroup.procs" + else + echo "tasks" + fi + + return 0 +} + +# Mounts and configures the given controller +# USAGE: cgroup_require CONTROLLER +cgroup_require() +{ + local ctrl="$1" + local ret + + [ $# -eq 0 ] && tst_brk TBROK "cgroup_require: controller not defined" + + [ ! -f /proc/cgroups ] && tst_brk TCONF "Kernel does not support control groups" + + _cgroup_state=$(tst_cgctl require "$ctrl" $$) + ret=$? + + if [ $ret -eq 32 ]; then + tst_brk TCONF "'tst_cgctl require' exited. Controller is probably not available?" + return $ret + fi + + if [ $ret -ne 0 ]; then + tst_brk TBROK "'tst_cgctl require' exited." + return $ret + fi + + [ "$_cgroup_state" = "" ] && tst_brk TBROK "cgroup_require: No state was set after call to tst_cgctl require?" + + return 0 } . tst_test.sh From patchwork Tue Jul 26 22:13:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Nowakowski-Krijger X-Patchwork-Id: 1661031 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=lkVA+Vi8; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lsrn73Wlbz9sFk for ; Wed, 27 Jul 2022 08:14:51 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 201EF3C2168 for ; Wed, 27 Jul 2022 00:14:49 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id BC2333C4FC3 for ; Wed, 27 Jul 2022 00:14:16 +0200 (CEST) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id B8C012003AE for ; Wed, 27 Jul 2022 00:14:14 +0200 (CEST) Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 4B2793F144 for ; Tue, 26 Jul 2022 22:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1658873653; bh=5NDuYRdJWfrlw81IGiHcEXGiDDULPFsJxsblOxHF/qI=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lkVA+Vi8fbOsEjjrB1IoxwrC1BSFSvPsGq2pIqEZyautz595RumJNA61YB4YOcXT5 SUbyIzbD3+qCdRKN3PShpuPsSvqq/uyGoTTxaYCEx/EghqJ2GM3DEK1Jx0vVIbPAP1 cACCAQTnmKpB7Tjw6k8BKIYOVtp9JNDDsGott0DBSiomS+ff14Xcc5l73vS2gijZNb vxDV5E9S3cek9mya3KiSR4AEwFE3bluc/h39b+hdhThceuEV897RyRgu4Uzh9cojxd JmOWSHFKIimzaT4iPprKIe8qLGYBXaxRluJt+lzero+npONY2ch7cWHQUVU2IMUI1E V6ZKYlYjFGQEQ== Received: by mail-pl1-f199.google.com with SMTP id k11-20020a170902ce0b00b0016a15fe2627so9076122plg.22 for ; Tue, 26 Jul 2022 15:14:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=5NDuYRdJWfrlw81IGiHcEXGiDDULPFsJxsblOxHF/qI=; b=u1+rqjH0WuYZHZSnC6QbD7voH9k7yXX01LnUM7p+WyoJU2UdWlQtAvHbKEGBsz6kal mwwMIBKN9THsMDHFNK36tZLgOMYcDY1lc5HcWhHVdgI3ULwSV4jzWlY3s91K7bNFD2zI GqzPC0QlA92AlJNm8oeqnIFYy9ysT4Yt5VR7Dh0J2PBSU/puSeTGclcf/Iwa5PKr0Rfy sB9utiaRoHsbiVliP72pfrwGruLix1lxLrzqlNW4e/V+Un6UKku+H17sptS9e+DTmWST seqysUQnzLCZ8WhXr55D6SL7rIMHsybz7KF3H2W6YIGPdZe1thc3YgBG7IXZFpfsymoH v63Q== X-Gm-Message-State: AJIora9qsuyigTrWz3fB5RWt7XHjIGRmOA50uMGxAcXRI8VoFXY+vxbH qw12gDMpX/Cnv7KSLa1oBA5Wl0fHRFgrmP+etI23jsxQ7i/z3rDHyHIHP7Vd0MBtMxFCiGPhI/D K6wMxxTmiySlqMj5i2T2JbV4SzOdV X-Received: by 2002:a17:902:f608:b0:16d:c44:137 with SMTP id n8-20020a170902f60800b0016d0c440137mr18811429plg.173.1658873650077; Tue, 26 Jul 2022 15:14:10 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uYPTijTBBU8YuAnKbLpYUjWcgj/0SR4Avjhs3fc81CBzN+v3AypY5rgZ6AeoCb0PqN8w/Myw== X-Received: by 2002:a17:902:f608:b0:16d:c44:137 with SMTP id n8-20020a170902f60800b0016d0c440137mr18811397plg.173.1658873649342; Tue, 26 Jul 2022 15:14:09 -0700 (PDT) Received: from luke-ubuntu.buildd (cpe-75-80-146-43.san.res.rr.com. [75.80.146.43]) by smtp.gmail.com with ESMTPSA id a13-20020a1709027e4d00b0015e9f45c1f4sm12069308pln.186.2022.07.26.15.14.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 15:14:08 -0700 (PDT) From: Luke Nowakowski-Krijger To: ltp@lists.linux.it, rpalethorpe@suse.de, liwang@redhat.com, pvorel@suse.cz, chrubis@suse.cz Date: Tue, 26 Jul 2022 15:13:19 -0700 Message-Id: <0e8c51c03eabc0b382e6569e14b6434ddc6f1237.1658872195.git.luke.nowakowskikrijger@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v6 03/10] controllers: Update cgroup_fj_* to use newer cgroup lib and test lib X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Update the cgroup_fj_* tests to use the newer test lib and to use the updated version of the cgroup lib which handles mounting and unmounting for both v1 and v2 controllers. The tests were modified to accommodate testing the v2 controller interfaces where it still made sense, and in other places tests were skipped as they were testing using specific parts of the v1 interface that doesn't exist on v2 controllers. Also updated the licensing info at the beginning of the file with SPDX license identifier. Signed-off-by: Luke Nowakowski-Krijger --- v3->v6: Added $pid check in cleanup function in case setup fails and pid is not set .../controllers/cgroup_fj/cgroup_fj_common.sh | 115 ++++-------- .../cgroup_fj/cgroup_fj_function.sh | 173 ++++++++++-------- .../controllers/cgroup_fj/cgroup_fj_proc.c | 24 +-- .../controllers/cgroup_fj/cgroup_fj_stress.sh | 171 +++++++++-------- 4 files changed, 219 insertions(+), 264 deletions(-) diff --git a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_common.sh b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_common.sh index 53ab637e8..6d5586534 100755 --- a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_common.sh +++ b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_common.sh @@ -1,43 +1,17 @@ #!/bin/sh - -################################################################################ -## ## -## Copyright (c) 2009 FUJITSU LIMITED ## -## Author: Shi Weihua ## -## Copyright (c) 2015 Cedric Hnyda ## -## Copyright (c) 2015-2016 Cyril Hrubis ## -## ## -## This program is free software; you can redistribute it and#or modify ## -## it under the terms of the GNU General Public License as published by ## -## the Free Software Foundation; either version 2 of the License, or ## -## (at your option) any later version. ## -## ## -## This program is distributed in the hope that it will be useful, but ## -## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## -## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## -## for more details. ## -## ## -## You should have received a copy of the GNU General Public License ## -## along with this program; if not, write to the Free Software Foundation, ## -## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## -## ## -################################################################################ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2009 FUJITSU LIMITED +# Copyright (c) 2015 Cedric Hnyda +# Copyright (c) 2015-2016 Cyril Hrubis +# Author: Shi Weihua for arg; do TCID="${TCID}_$arg" done -. test.sh - -exist_subsystem() -{ - local subsystem="$1" - local exist=`grep -w $subsystem /proc/cgroups | cut -f1` - - if [ -z "$exist" ]; then - tst_brkm TCONF "Subsystem $subsystem not supported" - fi -} +TST_NEEDS_CMDS="rmdir killall" +TST_NEEDS_ROOT=1 +TST_NEEDS_TMPDIR=1 attach_and_check() { @@ -46,13 +20,13 @@ attach_and_check() local task shift - tst_resm TINFO "Attaching task $pid to $path" + tst_res TINFO "Attaching task $pid to $path" - ROD echo "$pid" \> "$path/tasks" + ROD echo "$pid" \> "$path/$task_list" - for task in $(cat "$path/tasks"); do + for task in $(cat "$path/$task_list"); do if [ "$task" -ne "$pid" ]; then - tst_resm TINFO "Unexpected pid $task in $path/tasks, expected $pid" + tst_res TINFO "Unexpected pid $task in $path/$task_list, expected $pid" return 1 fi done @@ -64,11 +38,13 @@ create_subgroup() { path="$1" - ROD mkdir "$path" + [ ! -d "$path" ] && ROD mkdir "$path" # cpuset.cpus and cpuset.mems must be initialized with suitable value - # before any pids are attached - if [ "$subsystem" = "cpuset" ]; then + # before any pids are attached. + # Only needs to be done for cgroup v1 as sets are inherited from parents + # by default in cgroup v2. + if [ "$cgroup_version" = "1" ] && [ "$subsystem" = "cpuset" ]; then if [ -e "$mount_point/cpus" ]; then ROD cat "$mount_point/cpus" \> "$path/cpus" ROD cat "$mount_point/mems" \> "$path/mems" @@ -79,54 +55,27 @@ create_subgroup() fi } - -setup() +common_setup() { - tst_require_root - tst_require_cmds killall - - if [ ! -f /proc/cgroups ]; then - tst_brkm TCONF "Kernel does not support for control groups" - fi - - exist_subsystem "$subsystem" - - tst_tmpdir - TST_CLEANUP=cleanup - - mount_point=`grep -w $subsystem /proc/mounts | grep -w "cgroup" | \ - cut -f 2 | cut -d " " -f2` - - if [ -z "$mount_point" ]; then - try_umount=1 - mount_point="/dev/cgroup" - tst_resm TINFO "Subsystem $subsystem is not mounted, mounting it at $mount_point" - ROD mkdir $mount_point - ROD mount -t cgroup -o "$subsystem" "ltp_cgroup" "$mount_point" - else - tst_resm TINFO "Subsystem $subsystem is mounted at $mount_point" - fi + cgroup_require "$subsystem" + mount_point=$(cgroup_get_mountpoint "$subsystem") + start_path=$(cgroup_get_test_path "$subsystem") + cgroup_version=$(cgroup_get_version "$subsystem") + task_list=$(cgroup_get_task_list "$subsystem") + + [ "$cgroup_version" = "2" ] && ROD echo "+$subsystem" \> "$start_path/cgroup.subtree_control" + tst_res TINFO "test starts with cgroup version $cgroup_version" } -cleanup() +common_cleanup() { - tst_rmdir - killall -9 cgroup_fj_proc >/dev/null 2>&1 - tst_resm TINFO "Removing all ltp subgroups..." - - find "$mount_point/ltp/" -depth -type d -exec rmdir '{}' \; + tst_res TINFO "Removing all ltp subgroups..." - if [ -z "$try_umount" ]; then - return - fi - - if grep -q "$mount_point" /proc/mounts; then - EXPECT_PASS umount "$mount_point" - fi + [ -d "$start_path" ] && find "$start_path" -depth -type d -exec rmdir '{}' \; - if [ -e "$mount_point" ]; then - EXPECT_PASS rmdir "$mount_point" - fi + cgroup_cleanup } + +. cgroup_lib.sh diff --git a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_function.sh b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_function.sh index fc3ad1b63..b0c9410ca 100755 --- a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_function.sh +++ b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_function.sh @@ -1,32 +1,16 @@ #!/bin/sh - -################################################################################ -## ## -## Copyright (c) 2009 FUJITSU LIMITED ## -## Author: Shi Weihua ## -## Copyright (c) 2015 Cedric Hnyda ## -## Copyright (c) 2015-2016 Cyril Hrubis ## -## ## -## This program is free software; you can redistribute it and#or modify ## -## it under the terms of the GNU General Public License as published by ## -## the Free Software Foundation; either version 2 of the License, or ## -## (at your option) any later version. ## -## ## -## This program is distributed in the hope that it will be useful, but ## -## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## -## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## -## for more details. ## -## ## -## You should have received a copy of the GNU General Public License ## -## along with this program; if not, write to the Free Software Foundation, ## -## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## -## ## -################################################################################ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2009 FUJITSU LIMITED +# Copyright (c) 2015 Cedric Hnyda +# Copyright (c) 2015-2016 Cyril Hrubis +# Author: Shi Weihua TCID="cgroup_fj_function2" -TST_TOTAL=7 - -. cgroup_fj_common.sh +TST_TESTFUNC=test +TST_SETUP=setup +TST_CLEANUP=cleanup +TST_CNT=9 +TST_POS_ARGS=1 subsystem=$1 @@ -36,7 +20,7 @@ usage_and_exit() echo " ./cgroup_fj_function2.sh subsystem" echo "example: ./cgroup_fj_function2.sh cpuset" - tst_brkm TBROK "$1" + tst_brk TBROK "$1" } if [ "$#" -ne "1" ]; then @@ -46,49 +30,67 @@ fi # Move a task from group to group test1() { + # mv'ing cgroups is not available in cgroup2 + if [ "$cgroup_version" = "2" ]; then + tst_res TCONF "Controller mounted on cgroup2 hierarchy, skipping test" + return + fi + if ! attach_and_check "$pid" "$start_path/ltp_1"; then - tst_resm TFAIL "Failed to attach task" + tst_res TFAIL "Failed to attach task" return fi if ! attach_and_check "$pid" "$start_path"; then - tst_resm TFAIL "Failed to attach task" + tst_res TFAIL "Failed to attach task" return fi - tst_resm TPASS "Task attached succesfully" + tst_res TPASS "Task attached successfully" } # Group can be renamed with mv test2() { + # mv'ing cgroups is not available in cgroup2 + if [ "$cgroup_version" = "2" ]; then + tst_res TCONF "Controller mounted on cgroup2 hierarchy, skipping test" + return + fi + create_subgroup "$start_path/ltp_2" if ! mv "$start_path/ltp_2" "$start_path/ltp_3"; then - tst_resm TFAIL "Failed to move $start_path/ltp_2 to $start_path/ltp_3" + tst_res TFAIL "Failed to move $start_path/ltp_2 to $start_path/ltp_3" rmdir "$start_path/ltp_2" return fi if ! rmdir "$start_path/ltp_3"; then - tst_resm TFAIL "Failed to remove $start_path/ltp_3" + tst_res TFAIL "Failed to remove $start_path/ltp_3" return fi - tst_resm TPASS "Successfully moved $start_path/ltp_2 to $start_path/ltp_3" + tst_res TPASS "Successfully moved $start_path/ltp_2 to $start_path/ltp_3" } # Group can be renamed with mv unless the target name exists test3() { + # mv'ing cgroups is not available in cgroup2 + if [ "$cgroup_version" = "2" ]; then + tst_res TCONF "Controller mounted on cgroup2 hierarchy, skipping test" + return + fi + create_subgroup "$start_path/ltp_2" if mv "$start_path/ltp_2" "$start_path/ltp_1" > /dev/null 2>&1; then - tst_resm TFAIL "Moved $start_path/ltp_2 over existing $start_path/ltp_1" + tst_res TFAIL "Moved $start_path/ltp_2 over existing $start_path/ltp_1" return fi - tst_resm TPASS "Failed to move $start_path/ltp_2 over existing $start_path/ltp_1" + tst_res TPASS "Failed to move $start_path/ltp_2 over existing $start_path/ltp_1" ROD rmdir "$start_path/ltp_2" } @@ -97,77 +99,104 @@ test3() test4() { if ! attach_and_check "$pid" "$start_path/ltp_1"; then - tst_resm TFAIL "Failed to attach $pid to $start_path/ltp_1" + tst_res TFAIL "Failed to attach $pid to $start_path/ltp_1" return fi if rmdir "$start_path/ltp_1" > /dev/null 2>&1; then - tst_resm TFAIL "Removed $start_path/ltp_1 which contains task $pid" - create_subgroup "$start_path/ltp_1" + tst_res TFAIL "Removed $start_path/ltp_1 which contains task $pid" return fi - tst_resm TPASS "Group $start_path/ltp_1 with task $pid cannot be removed" + tst_res TPASS "Group $start_path/ltp_1 with task $pid cannot be removed" } # Group with a subgroup cannot be removed test5() { + # We need to move the tasks back to root to create a subgroup + if [ "$cgroup_version" = "2" ]; then + for pid in $(cat "$start_path/ltp_1/$task_list"); do + echo $pid > "$mount_point/$task_list" 2> /dev/null + done + + ROD echo "+$subsystem" \> "$start_path/ltp_1/cgroup.subtree_control" + fi + create_subgroup "$start_path/ltp_1/a" if rmdir "$start_path/ltp_1" > /dev/null 2>&1; then - tst_resm TFAIL "Removed $start_path/ltp_1 which contains subdir 'a'" + tst_res TFAIL "Removed $start_path/ltp_1 which contains subdir 'a'" return fi - tst_resm TPASS "Dir $start_path/ltp_1 with subdir 'a' cannot be removed" + tst_res TPASS "Dir $start_path/ltp_1 with subdir 'a' cannot be removed" ROD rmdir "$start_path/ltp_1/a" - ROD echo "$pid" \> "$start_path/tasks" + [ "$cgroup_version" = "2" ] && ROD echo "-$subsystem" \> "$start_path/ltp_1/cgroup.subtree_control" + ROD echo "$pid" \> "$start_path/ltp_1/$task_list" } # Group cannot be moved outside of hierarchy test6() { + # mv'ing cgroups is not available in cgroup2 + if [ "$cgroup_version" = "2" ]; then + tst_res TCONF "Controller mounted on cgroup2 hierarchy, skipping test" + return + fi + if mv "$start_path/ltp_1" "$PWD/ltp" > /dev/null 2>&1; then - tst_resm TFAIL "Subgroup $start_path/ltp_1 outside hierarchy to $PWD/ltp" + tst_res TFAIL "Subgroup $start_path/ltp_1 outside hierarchy to $PWD/ltp" return fi - tst_resm TPASS "Subgroup $start_path/ltp_1 cannot be moved to $PWD/ltp" + tst_res TPASS "Subgroup $start_path/ltp_1 cannot be moved to $PWD/ltp" } # Tasks file cannot be removed test7() { - if rm "$start_path/ltp_1/tasks" > /dev/null 2>&1; then - tst_resm TFAIL "Tasks file $start_path/ltp_1/tasks could be removed" + if rm "$start_path/ltp_1/$task_list" > /dev/null 2>&1; then + tst_res TFAIL "Tasks file $start_path/ltp_1/$task_list could be removed" return fi - tst_resm TPASS "Tasks file $start_path/ltp_1/tasks cannot be removed" + tst_res TPASS "Tasks file $start_path/ltp_1/tasks cannot be removed" } # Test notify_on_release with invalid inputs test8() { + # notify_on_release is not available in cgroup2 so skip the test + if [ "$cgroup_version" = "2" ]; then + tst_res TCONF "Controller mounted on cgroup2 hierarchy, skipping test" + return + fi + if echo "-1" > "$start_path/ltp_1/notify_on_release" 2>/dev/null; then - tst_resm TFAIL "Can write -1 to $start_path/ltp_1/notify_on_release" + tst_res TFAIL "Can write -1 to $start_path/ltp_1/notify_on_release" return fi if echo "ltp" > "$start_path/ltp_1/notify_on_release" 2>/dev/null; then - tst_resm TFAIL "Can write ltp to $start_path/ltp_1/notify_on_release" + tst_res TFAIL "Can write ltp to $start_path/ltp_1/notify_on_release" return fi - tst_resm TPASS "Cannot write invalid values to $start_path/ltp_1/notify_on_release" + tst_res TPASS "Cannot write invalid values to $start_path/ltp_1/notify_on_release" } # Test that notify_on_release can be changed test9() { + # notify_on_release is not available in cgroup2 so skip the test + if [ "$cgroup_version" = "2" ]; then + tst_res TCONF "Controller mounted on cgroup2 hierarchy, skipping test" + return + fi + local notify=$(ROD cat "$start_path/ltp_1/notify_on_release") local value @@ -178,37 +207,33 @@ test9() fi if ! echo "$value" > "$start_path/ltp_1/notify_on_release"; then - tst_resm TFAIL "Failed to set $start_path/ltp_1/notify_on_release to $value" + tst_res TFAIL "Failed to set $start_path/ltp_1/notify_on_release to $value" return fi ROD echo "$notify" \> "$start_path/ltp_1/notify_on_release" - tst_resm TPASS "Set $start_path/ltp_1/notify_on_release to $value" + tst_res TPASS "Set $start_path/ltp_1/notify_on_release to $value" } -setup - -cgroup_fj_proc& -pid=$! - -start_path="$mount_point/ltp" - -create_subgroup "$start_path" -create_subgroup "$start_path/ltp_1" +setup() +{ + common_setup + cgroup_fj_proc& + pid=$! + create_subgroup "$start_path/ltp_1" +} -test1 -test2 -test3 -test4 -test5 -test6 -test7 -test8 -test9 +cleanup() +{ + if [ -n "$pid" ]; then + kill -9 $pid >/dev/null 2>&1 + wait $pid >/dev/null 2>&1 + fi -ROD kill -9 $pid -wait $pid -ROD rmdir "$start_path/ltp_1" + rmdir "$start_path/ltp_1" >/dev/null 2>&1 + common_cleanup +} -tst_exit +. cgroup_fj_common.sh +tst_run diff --git a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_proc.c b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_proc.c index 93bc8b744..e3c1153cb 100644 --- a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_proc.c +++ b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_proc.c @@ -1,24 +1,6 @@ -/******************************************************************************/ -/* */ -/* Copyright (c) 2009 FUJITSU LIMITED */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ -/* the GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* */ -/* Author: Shi Weihua */ -/* */ -/******************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright (c) 2009 FUJITSU LIMITED +// Author: Shi Weihua #include #include diff --git a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_stress.sh b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_stress.sh index 01c2517c9..d80b83bbd 100755 --- a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_stress.sh +++ b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_stress.sh @@ -1,32 +1,16 @@ #!/bin/sh - -################################################################################ -## ## -## Copyright (c) 2009 FUJITSU LIMITED ## -## Author: Shi Weihua ## -## Copyright (c) 2015 Cedric Hnyda ## -## Copyright (c) 2015-2016 Cyril Hrubis ## -## ## -## This program is free software; you can redistribute it and#or modify ## -## it under the terms of the GNU General Public License as published by ## -## the Free Software Foundation; either version 2 of the License, or ## -## (at your option) any later version. ## -## ## -## This program is distributed in the hope that it will be useful, but ## -## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## -## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## -## for more details. ## -## ## -## You should have received a copy of the GNU General Public License ## -## along with this program; if not, write to the Free Software Foundation, ## -## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## -## ## -################################################################################ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2009 FUJITSU LIMITED +# Copyright (c) 2015 Cedric Hnyda +# Copyright (c) 2015-2016 Cyril Hrubis +# Author: Shi Weihua TCID="cgroup_fj_stress" -TST_TOTAL=1 - -. cgroup_fj_common.sh +TST_CNT=1 +TST_TESTFUNC=test +TST_SETUP=setup +TST_CLEANUP=cleanup +TST_POS_ARGS=4 subsystem="$1" subgroup_num="$2" @@ -47,35 +31,9 @@ usage_and_exit() echo " each - attach process to each subgroup" echo "example: ./cgroup_fj_stress.sh cpuset 1 1 one" echo - tst_brkm TBROK "$1" + tst_brk TBROK "$1" } -if [ "$#" -ne "4" ]; then - usage_and_exit "Wrong number of parameters, expected 4" -fi - -case $subgroup_num in - ''|*[!0-9]*) usage_and_exit "Number of subgroups must be positive integer";; - *) ;; -esac - -case $subgroup_depth in - ''|*[!0-9]*) usage_and_exit "Depth of the subgroup tree must be positive integer";; - *) ;; -esac - -case $attach_operation in - 'none'|'one'|'each');; - *) usage_and_exit "Invalid attach operation: $attach_operation";; -esac - -setup - -export TMPFILE=./tmp_tasks.$$ - -count=0 -collected_pids= - build_subgroups() { local cur_path="$1" @@ -87,6 +45,12 @@ build_subgroups() fi create_subgroup "$cur_path" + + # We can only attach processes to the leaves of the tree in cgroup v2 which + # means we need to enable the controllers everywhere inbetween. + if [ "$cgroup_version" = "2" ] && [ "$cur_depth" -ne "$subgroup_depth" ]; then + ROD echo "+$subsystem" \> "$cur_path/cgroup.subtree_control" + fi count=$((count+1)) for i in $(seq 1 $subgroup_num); do @@ -113,8 +77,10 @@ attach_task() pid="$ppid" fi - if ! attach_and_check "$pid" "$cur_path"; then + if [ "$cgroup_version" = "2" ] && [ $cur_depth -eq $subgroup_depth ] || [ "$cgroup_version" = "1" ]; then + if ! attach_and_check "$pid" "$cur_path"; then fail=1 + fi fi for i in $(seq 1 $subgroup_num); do @@ -123,46 +89,79 @@ attach_task() done if [ -n "$ppid" ]; then - if ! attach_and_check "$pid" "$cur_path"; then - fail=1 + if [ "$cgroup_version" = "2" ] && [ $cur_depth -eq $subgroup_depth ] || [ "$cgroup_version" = "1" ]; then + if ! attach_and_check "$pid" "$cur_path"; then + fail=1 + fi fi fi } -start_path="$mount_point/ltp" +setup() +{ + export TMPFILE=./tmp_tasks.$$ + count=0 + collected_pids= + + case $subgroup_num in + ''|*[!0-9]*) usage_and_exit "Number of subgroups must be possitive integer";; + *) ;; + esac + + case $subgroup_depth in + ''|*[!0-9]*) usage_and_exit "Depth of the subgroup tree must be possitive integer";; + *) ;; + esac + + case $attach_operation in + 'none'|'one'|'each');; + *) usage_and_exit "Invalid attach operation: $attach_operation";; + esac + + common_setup +} -tst_resm TINFO "Creating subgroups ..." +cleanup() +{ + common_cleanup +} + +test() +{ + tst_res TINFO "Creating subgroups ..." -build_subgroups "$start_path" 0 + build_subgroups "$start_path" 0 -tst_resm TINFO "... mkdired $count times" + tst_res TINFO "... mkdired $count times" -case $attach_operation in -"one" ) - cgroup_fj_proc & - pid=$! + case $attach_operation in + "one" ) + cgroup_fj_proc & + pid=$! - tst_resm TINFO "Moving one task around" - attach_task "$start_path" 0 "$pid" - ROD kill -9 "$pid" - wait "$pid" - ;; -"each" ) - tst_resm TINFO "Attaching task to each subgroup" - attach_task "$start_path" 0 - for pid in $collected_pids; do + tst_res TINFO "Moving one task around" + attach_task "$start_path" 0 "$pid" ROD kill -9 "$pid" wait "$pid" - done - ;; -* ) - ;; -esac - -if [ -n "$fail" ]; then - tst_resm TFAIL "Attaching tasks failed!" -else - tst_resm TPASS "All done!" -fi - -tst_exit + ;; + "each" ) + tst_res TINFO "Attaching task to each subgroup" + attach_task "$start_path" 0 + for pid in $collected_pids; do + ROD kill -9 "$pid" + wait "$pid" + done + ;; + * ) + ;; + esac + + if [ -n "$fail" ]; then + tst_res TFAIL "Attaching tasks failed!" + else + tst_res TPASS "All done!" + fi +} + +. cgroup_fj_common.sh +tst_run From patchwork Tue Jul 26 22:13:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Nowakowski-Krijger X-Patchwork-Id: 1661032 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=IKe6a/Kj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LsrnN4JV9z9sFk for ; Wed, 27 Jul 2022 08:15:04 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 504C53C4DBB for ; Wed, 27 Jul 2022 00:15:02 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 039933C2297 for ; Wed, 27 Jul 2022 00:14:16 +0200 (CEST) Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 60B471400747 for ; Wed, 27 Jul 2022 00:14:15 +0200 (CEST) Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 64EAC3F12F for ; Tue, 26 Jul 2022 22:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1658873653; bh=09PLHaH2fA6Q9kLpKKswDghZk0sUAqN4tNNvv4jx4Ak=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IKe6a/KjRRvQ42Pqnwhav23UplFo8vZXqk3dLwsJK5q7W9Axz64L50Vk9UXy22j1t FS8fHQlDIXndM1qW0OOHJdUQeOT1aMnyIZz/Euaa8QUs2IGqJoNniYgHeVBHu/0n5U nRqiDFZdu2ct6UChXgfw/QAwDMkP/pCGdypU1iZuIUqkOBnN6i7oW+g3WG9SykIRwx mm+Rs3dHgYAoMuhJ4pG0YFuSUXyLs1QByNjtYfrLPV0cNizd9AuYpCdoQRQe6WPSJw 6JwoSn654NMWR16uzKQp1sigaY7K9k7z1XOLd1s8PZGrzHaKs4agH3YYdv1zAZ6auH lWFxi6IR6caHA== Received: by mail-pl1-f198.google.com with SMTP id u4-20020a170902e5c400b0016d6a70a282so4661809plf.10 for ; Tue, 26 Jul 2022 15:14:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=09PLHaH2fA6Q9kLpKKswDghZk0sUAqN4tNNvv4jx4Ak=; b=FlVixIXbLNDMcNc39w+eN26uMFBo656YwpKibGIDb9F7+yV722N7/2p78ywUzihkjm 8DSdoFDeYpW+NSUVW4QcmsMna3lfBpN81xnbW+M9uvwvCevj+GsI6pQ8maI+kwXUtz56 w7XSGAHqDkNTLUdVtjZsj+As4Q+7oJc9ZbfCFsnQUpUxfuA0vBfZxBsNzdcTpwIa83C6 yj21QQQBd5xtn0UA76PTfEbZzotf1q1o4qAxoyAmsp/23x4nppPBurY1yhMpYNXRJxB2 qBSsaZkKFvTYRqgAFwu0COkMNdzeAiaDAKRiYw61YIHjBTFiirqVTZJMo9s+OCE63tIl Tt0A== X-Gm-Message-State: AJIora82lH9lyKPJVBpWjbhTeJG/uSess9caDZg8JSeOqHNBEw5ASTp/ atBzl3SYQzSdVccX9dWUAHfYG1sQ4pSWWHyFozPi0bneB0IxxszlUNaCzJAmUDbcLMon20pQ5y9 428Eg2DP5tKlHMPjYyx+5m1pq2voC X-Received: by 2002:a05:6a00:1708:b0:52b:c765:9688 with SMTP id h8-20020a056a00170800b0052bc7659688mr19036300pfc.19.1658873650858; Tue, 26 Jul 2022 15:14:10 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u8ISjrfD6mAmSua8DqapNQeNLFGS0sKGGFzKhWQTgw+BMVw7vDwwOVMl0+oglNnAspMS48iA== X-Received: by 2002:a05:6a00:1708:b0:52b:c765:9688 with SMTP id h8-20020a056a00170800b0052bc7659688mr19036277pfc.19.1658873650543; Tue, 26 Jul 2022 15:14:10 -0700 (PDT) Received: from luke-ubuntu.buildd (cpe-75-80-146-43.san.res.rr.com. [75.80.146.43]) by smtp.gmail.com with ESMTPSA id a13-20020a1709027e4d00b0015e9f45c1f4sm12069308pln.186.2022.07.26.15.14.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 15:14:10 -0700 (PDT) From: Luke Nowakowski-Krijger To: ltp@lists.linux.it, rpalethorpe@suse.de, liwang@redhat.com, pvorel@suse.cz, chrubis@suse.cz Date: Tue, 26 Jul 2022 15:13:20 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v6 04/10] controllers: Update memcg_control_test to newer test lib and cgroup lib X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Update memcg_control_test to use the newer test lib and to use the newer cgroup lib which enables the memory v1 and v2 controller to be tested. Also updated to newer SPDX license identifier. Signed-off-by: Luke Nowakowski-Krijger --- v3->v6: None .../controllers/memcg/control/mem_process.c | 28 +--- .../memcg/control/memcg_control_test.sh | 149 +++++------------- 2 files changed, 39 insertions(+), 138 deletions(-) diff --git a/testcases/kernel/controllers/memcg/control/mem_process.c b/testcases/kernel/controllers/memcg/control/mem_process.c index 6c1b36ca6..8ecabb272 100644 --- a/testcases/kernel/controllers/memcg/control/mem_process.c +++ b/testcases/kernel/controllers/memcg/control/mem_process.c @@ -1,28 +1,6 @@ -/*****************************************************************************/ -/* */ -/* Copyright (c) 2010 Mohamed Naufal Basheer */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ -/* the GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* */ -/* File: mem_process.c */ -/* */ -/* Purpose: act as a memory hog for the memcg_control tests */ -/* */ -/* Author: Mohamed Naufal Basheer */ -/* */ -/*****************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright (c) 2010 Mohamed Naufal Basheer +// Author: Mohamed Naufal Basheer #include #include diff --git a/testcases/kernel/controllers/memcg/control/memcg_control_test.sh b/testcases/kernel/controllers/memcg/control/memcg_control_test.sh index 4d9f1bb5d..f96ed3abb 100644 --- a/testcases/kernel/controllers/memcg/control/memcg_control_test.sh +++ b/testcases/kernel/controllers/memcg/control/memcg_control_test.sh @@ -1,45 +1,14 @@ #!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2010 Mohamed Naufal Basheer +# Author: Mohamed Naufal Basheer -################################################################################ -## ## -## Copyright (c) 2010 Mohamed Naufal Basheer ## -## ## -## This program is free software; you can redistribute it and/or modify ## -## it under the terms of the GNU General Public License as published by ## -## the Free Software Foundation; either version 2 of the License, or ## -## (at your option) any later version. ## -## ## -## This program is distributed in the hope that it will be useful, ## -## but WITHOUT ANY WARRANTY; without even the implied warranty of ## -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See ## -## the GNU General Public License for more details. ## -## ## -## You should have received a copy of the GNU General Public License ## -## along with this program; if not, write to the Free Software ## -## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## -## ## -## ## -## File: memcg_control_test.sh ## -## ## -## Purpose: Implement various memory controller tests ## -## ## -## Author: Mohamed Naufal Basheer ## -## ## -################################################################################ - -if [ "x$(grep -w memory /proc/cgroups | cut -f4)" != "x1" ]; then - echo "WARNING:" - echo "Either kernel does not support memory resource controller or feature not enabled" - echo "Skipping all memcg_control testcases...." - exit 0 -fi - -export TCID="memcg_control" -export TST_TOTAL=1 -export TST_COUNT=0 - -export TMP=${TMP:-/tmp} -cd $TMP +TST_TESTFUNC=test +TST_SETUP=setup +TST_CLEANUP=cleanup +TST_CNT=1 +TST_NEEDS_ROOT=1 +TST_NEEDS_TMPDIR=1 PAGE_SIZE=$(tst_getconf PAGESIZE) @@ -47,20 +16,14 @@ TOT_MEM_LIMIT=$PAGE_SIZE ACTIVE_MEM_LIMIT=$PAGE_SIZE PROC_MEM=$((PAGE_SIZE * 2)) -TST_PATH=$PWD -STATUS_PIPE="$TMP/status_pipe" - -PASS=0 -FAIL=1 +STATUS_PIPE="status_pipe" # Check if the test process is killed on crossing boundary test_proc_kill() { - cd $TMP mem_process -m $PROC_MEM & - cd $OLDPWD sleep 1 - echo $! > tasks + ROD echo $! > "$test_dir/$task_list" #Instruct the test process to start acquiring memory echo m > $STATUS_PIPE @@ -77,87 +40,47 @@ test_proc_kill() } # Validate the memory usage limit imposed by the hierarchically topmost group -testcase_1() +test1() { - TST_COUNT=1 - tst_resm TINFO "Test #1: Checking if the memory usage limit imposed by the topmost group is enforced" + cd $TST_TMPDIR + + tst_res TINFO "Test #1: Checking if the memory usage limit imposed by the topmost group is enforced" - echo "$ACTIVE_MEM_LIMIT" > $TST_PATH/mnt/$TST_NUM/memory.limit_in_bytes - echo "$TOT_MEM_LIMIT" > $TST_PATH/mnt/$TST_NUM/memory.memsw.limit_in_bytes + ROD echo "$ACTIVE_MEM_LIMIT" > "$test_dir/$memory_limit" + ROD echo "$TOT_MEM_LIMIT" > "$test_dir/$memsw_memory_limit" - mkdir sub - (cd sub KILLED_CNT=0 test_proc_kill if [ $PROC_MEM -gt $TOT_MEM_LIMIT ] && [ $KILLED_CNT -eq 0 ]; then - result $FAIL "Test #1: failed" + tst_res TFAIL "Test #1: failed" else - result $PASS "Test #1: passed" - fi) - rmdir sub + tst_res TPASS "Test #1: passed" + fi } -# Record the test results -# -# $1: Result of the test case, $PASS or $FAIL -# $2: Output information -result() +setup() { - RES=$1 - INFO=$2 - - if [ $RES -eq $PASS ]; then - tst_resm TPASS "$INFO" + cgroup_require "memory" + cgroup_version=$(cgroup_get_version "memory") + test_dir=$(cgroup_get_test_path "memory") + task_list=$(cgroup_get_task_list "memory") + + if [ "$cgroup_version" = "2" ]; then + memory_limit="memory.max" + memsw_memory_limit="memory.swap.max" else - : $((FAILED_CNT += 1)) - tst_resm TFAIL "$INFO" + memory_limit="memory.limit_in_bytes" + memsw_memory_limit="memory.memsw.limit_in_bytes" fi -} -cleanup() -{ - if [ -e $TST_PATH/mnt ]; then - umount $TST_PATH/mnt 2> /dev/null - rm -rf $TST_PATH/mnt - fi + tst_res TINFO "Test starts with cgroup version $cgroup_version" } -do_mount() +cleanup() { - cleanup - - mkdir $TST_PATH/mnt - mount -t cgroup -o memory cgroup $TST_PATH/mnt 2> /dev/null - if [ $? -ne 0 ]; then - tst_brkm TBROK NULL "Mounting cgroup to temp dir failed" - rmdir $TST_PATH/mnt - exit 1 - fi + cgroup_cleanup } -do_mount - -echo 1 > mnt/memory.use_hierarchy 2> /dev/null - -FAILED_CNT=0 - -TST_NUM=1 -while [ $TST_NUM -le $TST_TOTAL ]; do - mkdir $TST_PATH/mnt/$TST_NUM - (cd $TST_PATH/mnt/$TST_NUM && testcase_$TST_NUM) - rmdir $TST_PATH/mnt/$TST_NUM - : $((TST_NUM += 1)) -done - -echo 0 > mnt/memory.use_hierarchy 2> /dev/null - -cleanup - -if [ "$FAILED_CNT" -ne 0 ]; then - tst_resm TFAIL "memcg_control: failed" - exit 1 -else - tst_resm TPASS "memcg_control: passed" - exit 0 -fi +. cgroup_lib.sh +tst_run From patchwork Tue Jul 26 22:13:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Nowakowski-Krijger X-Patchwork-Id: 1661034 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=lhvyly1g; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lsrns2CR1z9sFk for ; Wed, 27 Jul 2022 08:15:29 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 44EF53C1C35 for ; Wed, 27 Jul 2022 00:15:26 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 8B4533C4FC3 for ; Wed, 27 Jul 2022 00:14:18 +0200 (CEST) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 482F91A006E2 for ; Wed, 27 Jul 2022 00:14:17 +0200 (CEST) Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 194BE3F139 for ; Tue, 26 Jul 2022 22:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1658873656; bh=ZuVY8no/fWBnELDTC6K1fkmuhAGgeb2cZw58LNI18P0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lhvyly1g9wKbuWWx9uqDmmE3LXOOcc+6uVmMuUvlaejEyFaF4AYR8Mgp2A+3qPwUx Dsvn06x0Q4QUCUylworkf2yNlgvtlcoEllndn9QR7GkqrGmvS0qr2Ei9xiYjyKopI+ rJ2g6PB7rJnHsBo7oYLST/f39x0mCmPOEi7t0DMGu6snXu1tpxsbZmNwZvITYrFU2h gqtFXr7q6wClDovcoFxkZ40xHgV2/SmOF3afSt76eENlBPh0DnV3AuzH4+QXaJa/xo 4O+KLDGXcZBZ4+829TrA4kqrqredz7B1NirDQXcEfhZ8j+f7Yz3geKUVTKr7Ad8kLd zdtj3blFWMIwQ== Received: by mail-pf1-f198.google.com with SMTP id y10-20020a056a00180a00b0052b10093100so5120704pfa.4 for ; Tue, 26 Jul 2022 15:14:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=ZuVY8no/fWBnELDTC6K1fkmuhAGgeb2cZw58LNI18P0=; b=WwXKKNJKzUDimQ3OcY2NwHADTt/sJVKPHGD8ekfvgGXPzVost7uX9WVawgC2aQ4sWk l+HrjrTHNTNLNJAJs0nI/E33O5HUfvtN+59xUvK4iHPpB1fYUnphWR8McrHuM0E2BRhX Guq0bE7e43YLfFqU8lJi7yuVCsdKoUCA+YlwY1mTy3uFu9rGnzazKo/MKbfDwI8WzCfF dVfgtkhgD600EornmzpnTiKyTC+DQW25vfqT+vB6adcHpnr21JUTgdxHdaNB5UGFhMXG /UmqWYqxamykZIwoq5Z9OtFWn8J3o4jZ9Pua4hIFppbgqlNUBjNyYIbLkGnm3KcThtVv s2Pg== X-Gm-Message-State: AJIora89MUW+37uieoVaDje22bPF7WpdcOJE+xyaiiey0CXkYy4HW1Mj EDGeWOdORMDQ0rGuAQtz6XcyvWMt6Uku4OyrV671D4ZhgplBov2M+VLnwKJDNCbRZtxbtkgQSc8 yxiwkL/4H55ttXe0SjiCXz6cCaH+E X-Received: by 2002:a62:ee01:0:b0:52b:bfb3:6fe8 with SMTP id e1-20020a62ee01000000b0052bbfb36fe8mr19143554pfi.28.1658873652564; Tue, 26 Jul 2022 15:14:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1twLGJ5yrkpBhzaKFklhB2CfnCPDBBf1RQr/ouHLUe0FALfB0D2mEgIwsG3pjVq0sGxGA6GBw== X-Received: by 2002:a62:ee01:0:b0:52b:bfb3:6fe8 with SMTP id e1-20020a62ee01000000b0052bbfb36fe8mr19143523pfi.28.1658873651982; Tue, 26 Jul 2022 15:14:11 -0700 (PDT) Received: from luke-ubuntu.buildd (cpe-75-80-146-43.san.res.rr.com. [75.80.146.43]) by smtp.gmail.com with ESMTPSA id a13-20020a1709027e4d00b0015e9f45c1f4sm12069308pln.186.2022.07.26.15.14.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 15:14:11 -0700 (PDT) From: Luke Nowakowski-Krijger To: ltp@lists.linux.it, rpalethorpe@suse.de, liwang@redhat.com, pvorel@suse.cz, chrubis@suse.cz Date: Tue, 26 Jul 2022 15:13:21 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v6 05/10] controllers: Update memcg/regression/* to new test and cgroup lib X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Update the tests in memcg/regression/* to use the new test lib and the newer cgroup lib to enable testing when either v1 or v2 memory controller is mounted. Only some tests still made sense to be testing with the v2 memory controller, otherwise they were skipped. Also updated to the newer SPDX license identifier. Signed-off-by: Luke Nowakowski-Krijger --- v3->v6: Added newline after decleration to fix checkpatch complaint .../memcg/regression/memcg_regression_test.sh | 203 +++++++++--------- .../memcg/regression/memcg_test_1.c | 40 ++-- .../memcg/regression/memcg_test_2.c | 24 +-- .../memcg/regression/memcg_test_3.c | 37 ++-- .../memcg/regression/memcg_test_4.c | 24 +-- .../memcg/regression/memcg_test_4.sh | 50 ++--- 6 files changed, 160 insertions(+), 218 deletions(-) diff --git a/testcases/kernel/controllers/memcg/regression/memcg_regression_test.sh b/testcases/kernel/controllers/memcg/regression/memcg_regression_test.sh index c91a4069e..bc8a1c661 100755 --- a/testcases/kernel/controllers/memcg/regression/memcg_regression_test.sh +++ b/testcases/kernel/controllers/memcg/regression/memcg_regression_test.sh @@ -1,50 +1,16 @@ #! /bin/sh - -################################################################################ -## ## -## Copyright (c) 2009 FUJITSU LIMITED ## -## ## -## This program is free software; you can redistribute it and#or modify ## -## it under the terms of the GNU General Public License as published by ## -## the Free Software Foundation; either version 2 of the License, or ## -## (at your option) any later version. ## -## ## -## This program is distributed in the hope that it will be useful, but ## -## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## -## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## -## for more details. ## -## ## -## You should have received a copy of the GNU General Public License ## -## along with this program; if not, write to the Free Software ## -## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## -## ## -## Author: Li Zefan ## -## Added memcg enable/disable functinality: Rishikesh K Rajak ## -## +# Added memcg enable/disable functionality: Rishikesh K Rajak + +TST_ID="memcg_regression_test" +TST_CLEANUP=cleanup +TST_SETUP=setup +TST_TESTFUNC=test_ +TST_NEEDS_ROOT=1 +TST_NEEDS_CMDS="killall kill" +TST_CNT=4 #buffer can rotate and number of found bugs can actually go down #so clear the buffer to avoid this @@ -70,16 +36,16 @@ check_kernel_bug() # some kernel bug is detected if [ $new_bug -gt $nr_bug ]; then - tst_resm TFAIL "kernel BUG was detected!" + tst_res TFAIL "kernel BUG was detected!" fi if [ $new_warning -gt $nr_warning ]; then - tst_resm TFAIL "kernel WARNING was detected!" + tst_res TFAIL "kernel WARNING was detected!" fi if [ $new_null -gt $nr_null ]; then - tst_resm "kernel NULL pointer dereference!" + tst_res TWARN "kernel NULL pointer dereference!" fi if [ $new_lockdep -gt $nr_lockdep ]; then - tst_resm "kernel lockdep warning was detected!" + tst_res TWARN "kernel lockdep warning was detected!" fi nr_bug=$new_bug @@ -89,10 +55,49 @@ check_kernel_bug() echo "check_kernel_bug found something!" dmesg - failed=1 return 0 } +setup() +{ + if tst_kvcmp -lt "2.6.30"; then + tst_brk TBROK "Test should be run with kernel 2.6.30 or newer" + fi + + cgroup_require "memory" + cgroup_version=$(cgroup_get_version "memory") + mount_point=$(cgroup_get_mountpoint "memory") + test_dir=$(cgroup_get_test_path "memory") + task_list=$(cgroup_get_task_list "memory") + if [ "$cgroup_version" = "2" ]; then + memory_limit="memory.max" + else + memory_limit="memory.limit_in_bytes" + fi + + [ "$cgroup_version" = "2" ] && ROD echo "+memory" \> "$test_dir/cgroup.subtree_control" + + tst_res TINFO "test starts with cgroup version $cgroup_version" +} + +cleanup() +{ + cleanup_testpath "$test_dir/0" + cgroup_cleanup +} + +create_testpath() +{ + local path="$1" + [ ! -e "$path" ] && ROD mkdir "$path" +} + +cleanup_testpath() +{ + local path="$1" + [ -e "$path" ] && ROD rmdir "$path" +} + #--------------------------------------------------------------------------- # Bug: The bug was, while forking mass processes, trigger memcgroup OOM, # then NULL pointer dereference may be hit. @@ -102,16 +107,19 @@ check_kernel_bug() #--------------------------------------------------------------------------- test_1() { - mkdir memcg/0/ - echo 0 > memcg/0/memory.limit_in_bytes + local test_path + test_path="$test_dir/0" - ./memcg_test_1 + create_testpath "$test_path" + ROD echo 0 > "$test_path/$memory_limit" - rmdir memcg/0/ + ./memcg_test_1 "$test_path/$task_list" + + cleanup_testpath "$test_path" check_kernel_bug if [ $? -eq 1 ]; then - tst_resm TPASS "no kernel bug was found" + tst_res TPASS "no kernel bug was found" fi } @@ -124,19 +132,31 @@ test_1() #--------------------------------------------------------------------------- test_2() { + local test_path + + # for cgroup2 writing to memory.max first checks the new limit against the + # current usage and will start killing processes if oom, therefore we do not + # expect EBUSY to be returned by the shrink operation. + if [ "$cgroup_version" = "2" ]; then + tst_res TCONF "Cgroup v2 found, skipping test" + return + fi + + test_path="$test_dir/0" + ./memcg_test_2 & pid1=$! sleep 1 - mkdir memcg/0 - echo $pid1 > memcg/0/tasks + create_testpath "$test_path" + ROD echo $pid1 > "$test_path"/tasks # let pid1 'test_2' allocate memory /bin/kill -SIGUSR1 $pid1 sleep 1 # shrink memory - echo 1 > memcg/0/memory.limit_in_bytes 2>&1 & + echo 1 > "$test_path"/memory.limit_in_bytes 2>&1 & pid2=$! # check if 'echo' will exit and exit with failure @@ -146,26 +166,25 @@ test_2() if [ $? -ne 0 ]; then wait $pid2 if [ $? -eq 0 ]; then - tst_resm TFAIL "echo should return failure" - failed=1 + tst_res TFAIL "echo should return failure" kill -9 $pid1 $pid2 > /dev/null 2>&1 wait $pid1 $pid2 - rmdir memcg/0 + cleanup_testpath "$test_path" + return fi break fi done if [ $tmp -eq 5 ]; then - tst_resm TFAIL "'echo' doesn't exit!" - failed=1 + tst_res TFAIL "'echo' doesn't exit!" else - tst_resm TPASS "EBUSY was returned as expected" + tst_res TPASS "EBUSY was returned as expected" fi kill -9 $pid1 $pid2 > /dev/null 2>&1 wait $pid1 $pid2 > /dev/null 2>&1 - rmdir memcg/0 + cleanup_testpath "$test_path" } #--------------------------------------------------------------------------- @@ -176,19 +195,22 @@ test_2() #--------------------------------------------------------------------------- test_3() { - mkdir memcg/0 - for pid in `cat memcg/tasks`; do - echo $pid > memcg/0/tasks 2> /dev/null + local test_path + test_path="$test_dir/0" + create_testpath "$test_path" + + for pid in $(cat "$mount_point/$task_list"); do + echo $pid > "$test_path/$task_list" 2> /dev/null done - for pid in `cat memcg/0/tasks`; do - echo $pid > memcg/tasks 2> /dev/null + for pid in $(cat "$test_path/$task_list"); do + echo $pid > "$mount_point/$task_list" 2> /dev/null done - rmdir memcg/0 + cleanup_testpath "$test_path" check_kernel_bug if [ $? -eq 1 ]; then - tst_resm TPASS "no kernel bug was found" + tst_res TPASS "no kernel bug was found" fi } @@ -200,11 +222,15 @@ test_3() #--------------------------------------------------------------------------- test_4() { - ./memcg_test_4.sh + local test_path + test_path="$test_dir/0" + create_testpath "$test_path" + + ./memcg_test_4.sh "$cgroup_version" "$mount_point" "$test_path" check_kernel_bug if [ $? -eq 1 ]; then - tst_resm TPASS "no kernel bug was found" + tst_res TPASS "no kernel bug was found" fi # test_4.sh might be killed by oom, so do clean up here @@ -212,31 +238,10 @@ test_4() killall -9 memcg_test_4.sh 2> /dev/null # if test_4.sh gets killed, it won't clean cgroup it created - rmdir memcg/0 2> /dev/null + cleanup_testpath "$test_path" swapon -a } -# main -failed=0 -mkdir memcg/ - -for cur in $(seq 1 $TST_TOTAL); do - export TST_COUNT=$cur - - mount -t cgroup -o memory xxx memcg/ - if [ $? -ne 0 ]; then - tst_resm TFAIL "failed to mount memory subsystem" - failed=1 - continue - fi - - test_$cur - - umount memcg/ -done - -rmdir memcg/ - -exit $failed - +. cgroup_lib.sh +tst_run diff --git a/testcases/kernel/controllers/memcg/regression/memcg_test_1.c b/testcases/kernel/controllers/memcg/regression/memcg_test_1.c index c7fb948fe..95f1aabb3 100644 --- a/testcases/kernel/controllers/memcg/regression/memcg_test_1.c +++ b/testcases/kernel/controllers/memcg/regression/memcg_test_1.c @@ -1,24 +1,6 @@ -/******************************************************************************/ -/* */ -/* Copyright (c) 2009 FUJITSU LIMITED */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ -/* the GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* */ -/* Author: Li Zefan */ -/* */ -/******************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright (c) 2009 FUJITSU LIMITED +// Author: Li Zefan #include #include @@ -33,17 +15,25 @@ #define FORKED_PROC_COUNT 10 -int main(void) +int main(int argc, char *argv[]) { char buf[10]; int i; int loop; int pid; + int fd; int size = getpagesize(); - int fd = open("memcg/0/tasks", O_WRONLY); - if (fd < 0) - return 1; + if (argc != 2) { + perror("Invalid num of args"); + exit(1); + } + + fd = open(argv[1], O_WRONLY); + if (fd < 0) { + perror("Could not open tasklist"); + exit(1); + } for (loop = 0; loop < LOOP; loop++) { for (i = 0; i < FORKED_PROC_COUNT; i++) { diff --git a/testcases/kernel/controllers/memcg/regression/memcg_test_2.c b/testcases/kernel/controllers/memcg/regression/memcg_test_2.c index 843b07816..c118d4559 100644 --- a/testcases/kernel/controllers/memcg/regression/memcg_test_2.c +++ b/testcases/kernel/controllers/memcg/regression/memcg_test_2.c @@ -1,24 +1,6 @@ -/******************************************************************************/ -/* */ -/* Copyright (c) 2009 FUJITSU LIMITED */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ -/* the GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* */ -/* Author: Li Zefan */ -/* */ -/******************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright (c) 2009 FUJITSU LIMITED +// Author: Li Zefan #include #include diff --git a/testcases/kernel/controllers/memcg/regression/memcg_test_3.c b/testcases/kernel/controllers/memcg/regression/memcg_test_3.c index 75a6e1545..4bf4270bb 100644 --- a/testcases/kernel/controllers/memcg/regression/memcg_test_3.c +++ b/testcases/kernel/controllers/memcg/regression/memcg_test_3.c @@ -17,12 +17,10 @@ #include #include #include "tst_test.h" +#include "tst_cgroup.h" -#define MNTPOINT "memcg" -#define SUBDIR "memcg/testdir" - -static int mount_flag; static volatile int sigcounter; +static struct tst_cg_group *test_cg; static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) { @@ -48,9 +46,10 @@ static void do_test(void) do_child(); while (sigcounter < 50000) { - if (access(SUBDIR, F_OK)) - SAFE_MKDIR(SUBDIR, 0644); - rmdir(SUBDIR); + test_cg = tst_cg_group_mk(tst_cg, "test"); + + if (test_cg) + test_cg = tst_cg_group_rm(test_cg); } SAFE_KILL(cpid, SIGKILL); @@ -61,32 +60,26 @@ static void do_test(void) static void setup(void) { - int ret; + struct tst_cg_opts opts; - SAFE_MKDIR(MNTPOINT, 0644); + memset(&opts, 0, sizeof(opts)); - ret = mount("memcg", MNTPOINT, "cgroup", 0, "memory"); - if (ret) { - if (errno == ENOENT) - tst_brk(TCONF | TERRNO, "memcg not supported"); - - tst_brk(TCONF | TERRNO, "mounting memcg failed"); - } - mount_flag = 1; + tst_cg_require("memory", &opts); + tst_cg_init(); + if (TST_CG_VER(tst_cg, "memory") != TST_CG_V1) + SAFE_CG_PRINT(tst_cg, "cgroup.subtree_control", "+memory"); } static void cleanup(void) { - if (!access(SUBDIR, F_OK)) - SAFE_RMDIR(SUBDIR); + if (test_cg) + test_cg = tst_cg_group_rm(test_cg); - if (mount_flag) - tst_umount(MNTPOINT); + tst_cg_cleanup(); } static struct tst_test test = { .needs_root = 1, - .needs_tmpdir = 1, .forks_child = 1, .min_kver = "2.6.24", .setup = setup, diff --git a/testcases/kernel/controllers/memcg/regression/memcg_test_4.c b/testcases/kernel/controllers/memcg/regression/memcg_test_4.c index d714561ed..743c84108 100644 --- a/testcases/kernel/controllers/memcg/regression/memcg_test_4.c +++ b/testcases/kernel/controllers/memcg/regression/memcg_test_4.c @@ -1,24 +1,6 @@ -/******************************************************************************/ -/* */ -/* Copyright (c) 2009 FUJITSU LIMITED */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ -/* the GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* */ -/* Author: Li Zefan */ -/* */ -/******************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright (c) 2009 FUJITSU LIMITED +// Author: Li Zefan #include #include diff --git a/testcases/kernel/controllers/memcg/regression/memcg_test_4.sh b/testcases/kernel/controllers/memcg/regression/memcg_test_4.sh index 620031366..8723abb2f 100755 --- a/testcases/kernel/controllers/memcg/regression/memcg_test_4.sh +++ b/testcases/kernel/controllers/memcg/regression/memcg_test_4.sh @@ -1,30 +1,21 @@ #! /bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2009 FUJITSU LIMITED +# Author: Li Zefan -################################################################################ -## ## -## Copyright (c) 2009 FUJITSU LIMITED ## -## ## -## This program is free software; you can redistribute it and#or modify ## -## it under the terms of the GNU General Public License as published by ## -## the Free Software Foundation; either version 2 of the License, or ## -## (at your option) any later version. ## -## ## -## This program is distributed in the hope that it will be useful, but ## -## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## -## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## -## for more details. ## -## ## -## You should have received a copy of the GNU General Public License ## -## along with this program; if not, write to the Free Software ## -## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## -## ## -## Author: Li Zefan ## -## ## -################################################################################ - -# attach current task to memcg/0/ -mkdir memcg/0 -echo $$ > memcg/0/tasks +cgroup_version="$1" +mount_point="$2" +test_path="$3" + +if [ "$cgroup_version" = "2" ]; then + task_list="cgroup.procs" + memory_limit="memory.max" +else + task_list="tasks" + memory_limit="memory.limit_in_bytes" +fi + +echo $$ > "$test_path/$task_list" ./memcg_test_4 & pid=$! @@ -35,14 +26,13 @@ sleep 1 sleep 1 # shrink memory, and then 80M will be swapped -echo 40M > memcg/0/memory.limit_in_bytes +echo 40M > "$test_path/$memory_limit" # turn off swap, and swapoff will be killed swapoff -a sleep 1 -echo $pid > memcg/tasks 2> /dev/null -echo $$ > memcg/tasks 2> /dev/null +echo $pid > "$mount_point/$task_list" 2> /dev/null +echo $$ > "$mount_point/$task_list" 2> /dev/null # now remove the cgroup -rmdir memcg/0 - +rmdir "$test_path" From patchwork Tue Jul 26 22:13:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Nowakowski-Krijger X-Patchwork-Id: 1661033 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=s5ZC6KKc; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lsrng06jYz9sFk for ; Wed, 27 Jul 2022 08:15:18 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1A2A03C53F1 for ; Wed, 27 Jul 2022 00:15:16 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 5F3903C4FC3 for ; Wed, 27 Jul 2022 00:14:17 +0200 (CEST) Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id CD603601222 for ; Wed, 27 Jul 2022 00:14:16 +0200 (CEST) Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 4C71C3F12F for ; Tue, 26 Jul 2022 22:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1658873656; bh=uGNa8QdHMz0k2ooFiK8T8MMz532JCzb7s2Y8B8pZR2s=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s5ZC6KKcXAJU+iqSCkOQUoiQi/wzxdr8dq5Yav3mjSKpOqe5NtVYtruGpSgr2SrpE 7uxYXm5xhWMLVi7d/2ZqxptNhNZbGHZi9NXzKGJf90BTpMpEiVwp1ikccfF/bD2rkU rUsuXdyxdvd+6KwMUxgqfeyknOlxVQEOB2yvAeC3FB/LEGoXSWRy3vCpePuV95Umy1 lQZDGkq4JQUNj5FJ1P61eE/8KRbOO5DB7vYYP7KuqpR+/cRNbjPfxoGPwpi8yI5NBC n8Q4XkMZIRgRYDmX4EflIISRLH/dbO/V6EPJj7/agoJpnIo69n1rASasmwZQxENS2x oVYL9TtbndVVw== Received: by mail-pj1-f69.google.com with SMTP id d21-20020a17090ae29500b001f2042edb63so6334595pjz.8 for ; Tue, 26 Jul 2022 15:14:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=uGNa8QdHMz0k2ooFiK8T8MMz532JCzb7s2Y8B8pZR2s=; b=So6jheHk2AVFDaFl7aXgf2dWjG5rm6sLxazXtPB0FrbRXLjH2rmJlxda7hg/9lGh+y fjCxwCACAeLVsoDz8Bj0fMEX+9U4vmL+z6LMWc2ZNVXryJu7hW+S88YkyXjwFMxMmyE1 TtEYlIK4ePQLXnN7mK/9R9bZN2IFLMu2N0QtqfjJRH4KiRi/9r5NR0Ubz+oIgrjPGspX IFjmzwFs/GtLjbtFwOHh2CpaPVOSfYRk1BpkveX4W676lCHeEi2SrfHkEclVWa75KgqZ SMIkQB1JKUkJbxDc7wGgPqa1DiyVQ1lZV3Qu+oY143R9A/Y/CrTtdbKJDdrU9Sv+rAjr dYhw== X-Gm-Message-State: AJIora+82LlJ9VnjjiewI7yKkc5rXaUrba3sdzRxXdemU3UqGZtxcan5 KpnkzZoTXsA99iK6RqtJAjw99yO/9CDhEKxxCXM/jfw/HXe8Eu9JZVUsUOGajg5fPk68VmiMDUD OSxeTqhQwkS1YecOVik6Jgxv15Jng X-Received: by 2002:a05:6a00:10cf:b0:528:48c3:79e0 with SMTP id d15-20020a056a0010cf00b0052848c379e0mr18713334pfu.18.1658873653536; Tue, 26 Jul 2022 15:14:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1teQkeMJzIHnNBKPwH/tUCuBK+rWQB7cb0Usy8KAiFrWnSVv/lQbEqzCkmH1rSYxgLjA85MbQ== X-Received: by 2002:a05:6a00:10cf:b0:528:48c3:79e0 with SMTP id d15-20020a056a0010cf00b0052848c379e0mr18713319pfu.18.1658873653177; Tue, 26 Jul 2022 15:14:13 -0700 (PDT) Received: from luke-ubuntu.buildd (cpe-75-80-146-43.san.res.rr.com. [75.80.146.43]) by smtp.gmail.com with ESMTPSA id a13-20020a1709027e4d00b0015e9f45c1f4sm12069308pln.186.2022.07.26.15.14.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 15:14:12 -0700 (PDT) From: Luke Nowakowski-Krijger To: ltp@lists.linux.it, rpalethorpe@suse.de, liwang@redhat.com, pvorel@suse.cz, chrubis@suse.cz Date: Tue, 26 Jul 2022 15:13:22 -0700 Message-Id: <4688f4cff888ae1131c5dbab7cb52a3ac93d8a6e.1658872195.git.luke.nowakowskikrijger@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v6 06/10] controllers: Update memcg_stress_test to use newer cgroup lib X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Update the test to use the newer cgroup lib which enables the testing of both v1 and v2 memory controllers and makes the setup and cleanup much simpler. Signed-off-by: Luke Nowakowski-Krijger --- v2->v6: None .../memcg/stress/memcg_stress_test.sh | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh index fa0df3196..d38c650ea 100755 --- a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh +++ b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh @@ -21,10 +21,16 @@ TST_TIMEOUT=2100 setup() { - if ! is_cgroup_subsystem_available_and_enabled "memory"; then - tst_brk TCONF "Either kernel does not support Memory Resource Controller or feature not enabled" + cgroup_require "memory" + cgroup_version=$(cgroup_get_version "memory") + test_path=$(cgroup_get_test_path "memory") + task_list=$(cgroup_get_task_list "memory") + if [ "$cgroup_version" = "2" ]; then + ROD echo "+memory" > "$test_path/cgroup.subtree_control" fi + tst_res TINFO "test starts with cgroup version $cgroup_version" + echo 3 > /proc/sys/vm/drop_caches sleep 2 local mem_free=`cat /proc/meminfo | grep MemFree | awk '{ print $2 }'` @@ -41,18 +47,7 @@ setup() cleanup() { - if [ -e /dev/memcg ]; then - EXPECT_PASS umount /dev/memcg - EXPECT_PASS rmdir /dev/memcg - fi -} - -do_mount() -{ - cleanup - - EXPECT_PASS mkdir /dev/memcg - EXPECT_PASS mount -t cgroup -omemory memcg /dev/memcg + cgroup_cleanup } # $1 Number of cgroups @@ -69,13 +64,11 @@ run_stress() tst_res TINFO "Testing $cgroups cgroups, using $mem_size MB, interval $interval" - do_mount - tst_res TINFO "Starting cgroups" for i in $(seq 0 $(($cgroups-1))); do - mkdir /dev/memcg/$i 2> /dev/null + ROD mkdir "$test_path/$i" memcg_process_stress $mem_size $interval & - echo $! > /dev/memcg/$i/tasks + ROD echo $! > "$test_path/$i/$task_list" pids="$pids $!" done @@ -91,12 +84,11 @@ run_stress() for pid in $pids; do kill -KILL $pid 2> /dev/null wait $pid 2> /dev/null - rmdir /dev/memcg/$i 2> /dev/null + ROD rmdir "$test_path/$i" i=$((i+1)) done tst_res TPASS "Test passed" - cleanup } test1() From patchwork Tue Jul 26 22:13:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Nowakowski-Krijger X-Patchwork-Id: 1661035 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=mIndPrZJ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lsrp502S6z9sFk for ; Wed, 27 Jul 2022 08:15:40 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C85733C305A for ; Wed, 27 Jul 2022 00:15:38 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id BDDCD3C278D for ; Wed, 27 Jul 2022 00:14:18 +0200 (CEST) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 511C6601091 for ; Wed, 27 Jul 2022 00:14:18 +0200 (CEST) Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id E4E653F143 for ; Tue, 26 Jul 2022 22:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1658873656; bh=jysWCjcxIAPk7IKTvtSbkugKMztdMLqt9NW8Rk4VPRU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mIndPrZJodsLJMwhHSn9lxp/L3FP7P69gdZCyVDmjzkgPNqEwcZhYvqR7+R14mNzy yO+3/LtcQAEu1s9Zae8p0eMAxOFuWIyXK+tE0gcG/9Hdi8GxO4cMUC/xY43UXZsNAg Kg4ebLTrH4Ytn6OngndDJgtq+64SscWBNlGvABOrjOdUH+xEe1Ipd2o41hRfJP4NEZ 91g9C8Ux28aWC6z/mq1GsBB2MrzbJkoriMMC8TNboKRqN73nsXGdjGv90TUejtfuQd 78uBgXHQAGHn5XloWgrVoQRothEGScbkTjvXZL07RaclWAT7nSn/hVp2d9Wz5SJaZ1 2UdOHhyIWg/mw== Received: by mail-pj1-f71.google.com with SMTP id o13-20020a17090ab88d00b001f1ef2109aaso131361pjr.2 for ; Tue, 26 Jul 2022 15:14:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=jysWCjcxIAPk7IKTvtSbkugKMztdMLqt9NW8Rk4VPRU=; b=p18QFqYa8KHZrabRlBPg5bWgG8I3RZmo2LaNeruo4OsPAhiooJCkAUxcBRYcVafH1d xvHCLBc8VCvS39pN6VNC+lu9aX8e6pnmyVNS3neg3/lp90PN6TBt/Ek+ZvEhXjyY6bnl z5mE1V3ix2ubgs0m7rGXVagIY18BrpSfDVris1W2v+Knu8OVcua8BjnaaSbCT/nm6qOL ORwYSSgM2nuIjKkhPptDBs9vs1nfoI5sLL/8PsogtVV+Q6Cvj1eFoqL9pzrUtXGFVrqX d7pOAiokeay/MO4nDHZ7CoYN7KyF2VSdHQv/k+1mq2T9pkG+/kHukJG1wtozJP26pfqR C+hA== X-Gm-Message-State: AJIora9XGw+Ztg1swDa4y2COl3+UoZbQUwFINmOX9j4uS33Fxxwv6yo3 Qzc5Wz5JNFl+yb9YTmFkj2wyQ3LLOABscUU0K5+O/EWZXGWvKL19eJNnZpqBE8LkkEGZsk2aCzk QqvosEwyxfLebi/VRtjdQ1oHAGN8f X-Received: by 2002:a05:6a00:24c6:b0:52b:ee89:eca9 with SMTP id d6-20020a056a0024c600b0052bee89eca9mr14798666pfv.78.1658873654979; Tue, 26 Jul 2022 15:14:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tbbG3NYV9vzD9AXXCnJ40rR5xdibJN0S2T5E1YIxpjkfS55jOiqjIKx6sOX9DQ4Ltiwc2e5g== X-Received: by 2002:a05:6a00:24c6:b0:52b:ee89:eca9 with SMTP id d6-20020a056a0024c600b0052bee89eca9mr14798650pfv.78.1658873654643; Tue, 26 Jul 2022 15:14:14 -0700 (PDT) Received: from luke-ubuntu.buildd (cpe-75-80-146-43.san.res.rr.com. [75.80.146.43]) by smtp.gmail.com with ESMTPSA id a13-20020a1709027e4d00b0015e9f45c1f4sm12069308pln.186.2022.07.26.15.14.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 15:14:13 -0700 (PDT) From: Luke Nowakowski-Krijger To: ltp@lists.linux.it, rpalethorpe@suse.de, liwang@redhat.com, pvorel@suse.cz, chrubis@suse.cz Date: Tue, 26 Jul 2022 15:13:23 -0700 Message-Id: <2c68a75ab8936690f007adbb398fd6d29f3cf529.1658872195.git.luke.nowakowskikrijger@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v6 07/10] controllers: update memcg/functional to use newer cgroup lib X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Update memcg_lib.sh to uses the newer cgroup lib to cleanup the mounting and checking of the memory controller. There are still some tests that make sense for v2 and should be modified in a future patch, but since most of the tests are testing specific v1 memory controller features lets just skip it for now if v2 is mounted. Signed-off-by: Luke Nowakowski-Krijger --- v2->v6: Fixed spelling mistakes reported by checkpatch .../memcg/functional/memcg_force_empty.sh | 2 +- .../controllers/memcg/functional/memcg_lib.sh | 54 ++++++++++--------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh b/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh index 23a4bd04d..580468784 100755 --- a/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh +++ b/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh @@ -50,7 +50,7 @@ test6() { # writing to non-empty top mem cgroup's force_empty # should return failure - EXPECT_FAIL echo 1 \> /dev/memcg/memory.force_empty + EXPECT_FAIL echo 1 \> "$mount_point/memory.force_empty" } . memcg_lib.sh diff --git a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh index 96d26ef2d..a89e24485 100755 --- a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh +++ b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh @@ -16,20 +16,20 @@ TST_TESTFUNC=memcg_testfunc memcg_require_memsw() { - if ! [ -e /dev/memcg/memory.limit_in_bytes ]; then - tst_brk TBROK "/dev/memcg must be mounted before calling memcg_require_memsw" + if ! [ -e "$mount_point/memory.limit_in_bytes" ]; then + tst_brk TBROK "$mount_point must be mounted before calling memcg_require_memsw" fi - if ! [ -e /dev/memcg/memory.memsw.limit_in_bytes ]; then + if ! [ -e "$mount_point/memory.memsw.limit_in_bytes" ]; then tst_brk TCONF "mem+swap is not enabled" fi } memcg_require_hierarchy_disabled() { - if [ ! -e "/dev/memcg/memory.use_hierarchy" ]; then - tst_brk TBROK "/dev/memcg must be mounted before calling memcg_require_hierarchy_disabled" + if [ ! -e "$mount_point/memory.use_hierarchy" ]; then + tst_brk TBROK "$mount_point must be mounted before calling memcg_require_hierarchy_disabled" fi - if [ $(cat /dev/memcg/memory.use_hierarchy) -eq 1 ]; then + if [ "$(cat "$mount_point/memory.use_hierarchy")" -eq 1 ]; then tst_brk TCONF "Test requires root cgroup memory.use_hierarchy=0" fi } @@ -71,12 +71,19 @@ memcg_adjust_limit_for_kmem() memcg_setup() { - if ! is_cgroup_subsystem_available_and_enabled "memory"; then - tst_brk TCONF "Either kernel does not support Memory Resource Controller or feature not enabled" + cgroup_require "memory" + cgroup_version=$(cgroup_get_version "memory") + + # Most of the tests here are testing specific parts of the cgroup v1 memory interface that is + # not present for cgroup2, so if it is already mounted on a cgroup v2 hierarchy we should skip + # the test. + # Some tests still make sense in v2 and should be modified in a future patch + if [ "$cgroup_version" = "2" ]; then + tst_brk TCONF "memory controller mounted on cgroup v2 hierarchy, skipping test." fi - ROD mkdir /dev/memcg - ROD mount -t cgroup -omemory memcg /dev/memcg + mount_point=$(cgroup_get_mountpoint "memory") + test_dir=$(cgroup_get_test_path "memory") # For kernels older than v5.11 the default value for # memory.use_hierarchy is 0 and some of tests (memcg_stat_test.sh and @@ -89,15 +96,15 @@ memcg_setup() # Starting with kernel v5.11, the non-hierarchical mode is not # available. See Linux kernel commit bef8620cd8e0 ("mm: memcg: # deprecate the non-hierarchical mode"). - orig_memory_use_hierarchy=$(cat /dev/memcg/memory.use_hierarchy) + orig_memory_use_hierarchy=$(cat "$mount_point/memory.use_hierarchy") if [ -z "$orig_memory_use_hierarchy" ];then - tst_res TINFO "cat /dev/memcg/ failed" + tst_res TINFO "cat $mount_point failed" elif [ "$orig_memory_use_hierarchy" = "0" ];then orig_memory_use_hierarchy="" else - echo 0 > /dev/memcg/memory.use_hierarchy 2>/dev/null + echo 0 > "$mount_point/memory.use_hierarchy" 2>/dev/null if [ $? -ne 0 ];then - tst_res TINFO "set /dev/memcg/memory.use_hierarchy to 0 failed" + tst_res TINFO "set $mount_point/memory.use_hierarchy to 0 failed" fi fi @@ -110,22 +117,19 @@ memcg_cleanup() cd $TST_TMPDIR # In order to remove all subgroups, we have to remove them recursively - if [ -e /dev/memcg/ltp_$$ ]; then - ROD find /dev/memcg/ltp_$$ -depth -type d -delete + if [ -e $test_dir ]; then + ROD find $test_dir -depth -type d -delete fi if [ -n "$orig_memory_use_hierarchy" ];then - echo $orig_memory_use_hierarchy > /dev/memcg/memory.use_hierarchy + echo $orig_memory_use_hierarchy > $mount_point/memory.use_hierarchy if [ $? -ne 0 ];then - tst_res TINFO "restore /dev/memcg/memory.use_hierarchy failed" + tst_res TINFO "restore $mount_point/memory.use_hierarchy failed" fi orig_memory_use_hierarchy="" fi - if [ -e "/dev/memcg" ]; then - umount /dev/memcg - rmdir /dev/memcg - fi + cgroup_cleanup [ "$MEMCG_SHMMAX" = "1" ] && shmmax_cleanup } @@ -369,8 +373,8 @@ test_limit_in_bytes() memcg_testfunc() { - ROD mkdir /dev/memcg/ltp_$$ - cd /dev/memcg/ltp_$$ + ROD mkdir $test_dir/ltp_$$ + cd $test_dir/ltp_$$ if type ${MEMCG_TESTFUNC}1 > /dev/null 2>&1; then ${MEMCG_TESTFUNC}$1 $1 "$2" @@ -379,7 +383,7 @@ memcg_testfunc() fi cd $TST_TMPDIR - ROD rmdir /dev/memcg/ltp_$$ + ROD rmdir $test_dir/ltp_$$ } memcg_no_testfunc() From patchwork Tue Jul 26 22:13:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Nowakowski-Krijger X-Patchwork-Id: 1661037 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=MntBY0kF; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LsrpZ53SFz9sFk for ; Wed, 27 Jul 2022 08:16:06 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 43FFD3C207C for ; Wed, 27 Jul 2022 00:16:03 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 96ADE3C217C for ; Wed, 27 Jul 2022 00:14:19 +0200 (CEST) Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 6450E1A006E2 for ; Wed, 27 Jul 2022 00:14:19 +0200 (CEST) Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 550EE3F128 for ; Tue, 26 Jul 2022 22:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1658873658; bh=4v/eFOHrPt89HxYp22St+Uc2UyWsceDb/1MpTSmsx3E=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MntBY0kFF9fRQNTYVmbxHs8FMc5N/L/3yiDfBY7IrWkzeAkCtoENIsieuG0dm2gDC gRiRfsJGe0/9Ovca/PAX9GxkYVy3zrirAFyxl0UQGFAToHb9mVH3OU21n0hxBC0sYA V/ZxpTKnOd5uEVCe9ZIGXIx+UpkdkwsU6xesv8BkLagkZv0TXCrT6KMkin/x8qceWv 7xJe+nH4aQ/ozsQtS/fMslVqyWErAgxVnDxbjdaOfQXTaOKzj8IldcEGPSI/nWVZho 0eNfM7UqXCEw/j9li13TvMpDF/I/kNeavXZSnAZqOjhpVjMlwHBm3BdnWWi6yZKVao 7m0nssC5pBfZQ== Received: by mail-pg1-f199.google.com with SMTP id n12-20020a634d4c000000b0041af8261e17so2985981pgl.20 for ; Tue, 26 Jul 2022 15:14:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=4v/eFOHrPt89HxYp22St+Uc2UyWsceDb/1MpTSmsx3E=; b=f1D1jcWDa8nJ1XzZAzDZ3Y1+1o4t4H1QDjv8vS+Hiyj4svUwQBRz/y/oY7ZuMnH1bu zLYmjDRXB5nF8RQhGWUrZQz7TOvDIgoAp1cLoOOw5x5kckovNtf94FMhSpX9CUlQjywX YT5EIhPpVo95AsjX+ZVWqt+JppQ1SFp8/CRUsANvzhwfzr3ptYIepK8nblkzNOV4nHcA qTrdJGoRTcOkkm5RcToV2SGzQmH3XfV7IZEEMirk03MP1UlJlDQhDO0PkyOEvCPJ6YhJ 7ZAA7QSt+ysHU36vH75YOcFVyugKwjLH9WLU1Hw8AAeCqija/yJK+tKx3a8ynXJwOSxu +fUg== X-Gm-Message-State: AJIora+5wKsdFTNUO8esJ688v3pxgq8XSRKflq+284ZSNDtgqKc6tl7k 9/IpZrEoahSZOsR9JDiRMLAk9zluVp4mNHPoISWH8jr5WeGNwuamn8uY3EmzW+shWDkQP2BiCkZ Blq5aK82HXKoIyb1FVp9eaS7KUJNo X-Received: by 2002:a05:6a00:21c5:b0:52b:fc9c:295b with SMTP id t5-20020a056a0021c500b0052bfc9c295bmr9911212pfj.56.1658873656425; Tue, 26 Jul 2022 15:14:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vaoY87vCZNlGZTv7zO09iyuJLzKVSbTc/+EmUPfQ2WSMLCnNJgkjfqIIhJAsq88oTVMCZnrQ== X-Received: by 2002:a05:6a00:21c5:b0:52b:fc9c:295b with SMTP id t5-20020a056a0021c500b0052bfc9c295bmr9911195pfj.56.1658873656144; Tue, 26 Jul 2022 15:14:16 -0700 (PDT) Received: from luke-ubuntu.buildd (cpe-75-80-146-43.san.res.rr.com. [75.80.146.43]) by smtp.gmail.com with ESMTPSA id a13-20020a1709027e4d00b0015e9f45c1f4sm12069308pln.186.2022.07.26.15.14.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 15:14:15 -0700 (PDT) From: Luke Nowakowski-Krijger To: ltp@lists.linux.it, rpalethorpe@suse.de, liwang@redhat.com, pvorel@suse.cz, chrubis@suse.cz Date: Tue, 26 Jul 2022 15:13:24 -0700 Message-Id: <1a99931abafc1b02f854d51c19b9d16a671b8018.1658872195.git.luke.nowakowskikrijger@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v6 08/10] controllers: Update pids.sh to use newer cgroup lib X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Updated to use the newer cgroup_lib to make mounting and cleanup nicer. Signed-off-by: Luke Nowakowski-Krijger --- v3->v6: None testcases/kernel/controllers/pids/pids.sh | 67 +++-------------------- 1 file changed, 9 insertions(+), 58 deletions(-) diff --git a/testcases/kernel/controllers/pids/pids.sh b/testcases/kernel/controllers/pids/pids.sh index e8bafc739..26a0c6a22 100755 --- a/testcases/kernel/controllers/pids/pids.sh +++ b/testcases/kernel/controllers/pids/pids.sh @@ -36,66 +36,17 @@ cleanup() { killall -9 pids_task2 >/dev/null 2>&1 - tst_res TINFO "removing created directories" - rmdir $testpath - if [ "$mounted" -ne "1" ]; then - tst_res TINFO "Umounting pids" - umount $mount_point - rmdir $mount_point - fi -} - -setup_cgroupv2() -{ - mount_point=$(grep -w cgroup2 /proc/mounts | cut -f 2 | cut -d " " -f2) - if ! grep -q pids "$mount_point"/cgroup.controllers; then - tst_res TINFO "pids not supported on cgroup v2." - return - fi - - testpath="$mount_point/ltp_pids_$caseno" - ROD mkdir -p "$testpath" - task_list="cgroup.procs" - cgroup_v="v2" -} - -setup_cgroupv1() -{ - exist=`grep -w pids /proc/cgroups | cut -f1`; - if [ "$exist" = "" ]; then - tst_brk TCONF NULL "pids not supported" - fi - - mount_point=`grep -w pids /proc/mounts | cut -f 2 | cut -d " " -f2` - - if [ "$mount_point" = "" ]; then - mounted=0 - mount_point=/dev/cgroup - fi - - testpath=$mount_point/ltp_pids_$caseno - - if [ "$mounted" -eq "0" ]; then - ROD mkdir -p $mount_point - ROD mount -t cgroup -o pids none $mount_point - fi - ROD mkdir -p $testpath - task_list="tasks" - cgroup_v="v1" + cgroup_cleanup } setup() { - # If cgroup2 is mounted already, then let's - # try to start with cgroup v2. - if grep -q cgroup2 /proc/mounts; then - setup_cgroupv2 - fi - if [ -z "$cgroup_v" ]; then - setup_cgroupv1 - fi + cgroup_require "pids" + cgroup_version=$(cgroup_get_version "pids") + testpath=$(cgroup_get_test_path "pids") + task_list=$(cgroup_get_task_list "pids") - tst_res TINFO "test starts with cgroup $cgroup_v" + tst_res TINFO "test starts with cgroup version $cgroup_version" } start_pids_tasks2() @@ -296,7 +247,7 @@ case8() { tst_res TINFO "set child cgroup limit smaller than its parent limit" ROD echo $max \> $testpath/pids.max - if [ "$cgroup_v" = "v2" ]; then + if [ "$cgroup_version" = "2" ]; then ROD echo +pids \> "$testpath"/cgroup.subtree_control fi mkdir $testpath/child @@ -326,7 +277,7 @@ case9() tst_res TINFO "migrate cgroup" lim=$((max - 1)) - if [ "$cgroup_v" = "v2" ]; then + if [ "$cgroup_version" = "2" ]; then ROD echo +pids \> "$testpath"/cgroup.subtree_control fi for i in 1 2; do @@ -391,5 +342,5 @@ do_test() case$caseno } -. tst_test.sh +. cgroup_lib.sh tst_run From patchwork Tue Jul 26 22:13:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Nowakowski-Krijger X-Patchwork-Id: 1661036 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=qGWLBlko; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LsrpM5GbXz9sFk for ; Wed, 27 Jul 2022 08:15:55 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8A1643C1D21 for ; Wed, 27 Jul 2022 00:15:52 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 6C7603C5A9F for ; Wed, 27 Jul 2022 00:14:20 +0200 (CEST) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id CA8552003AF for ; Wed, 27 Jul 2022 00:14:19 +0200 (CEST) Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 9ED123F139 for ; Tue, 26 Jul 2022 22:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1658873658; bh=ukl4OVDQE9opIMIGpob7jXAYmiX8p3TibjFoXsDBRsU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qGWLBlko83kgFiC4NQWnU/2w6h+GI6yQN0pulCnxplsJz943VKs2tM3C9rOOeNusJ 0jMIjpaTV8jvzkYmQ8TUqU8w5QBYBo6dqKhrq/nLmmgM7D78nKnkzHVFFEj3XedQBL H2Zc9A1U2iuoMgKSRGhiT4BYYz9U2cOjsTQSKdF5Sj6CQX9uQgj5YWzMKV6QMdWHPb OzrY947/DNtzU76xq48DJk9lXU5zo1lP6n3V/NXS95LPt0C7B1CCxYJJOZAjDIyS/o CIbykS6SA/rb4qMYqnlqUKa00O/jBE9e9Md2B3gSD0wWHXSGJTpC9Toe43wm2VSWcH 0Xa8+u2Fx6zqw== Received: by mail-pg1-f200.google.com with SMTP id i63-20020a638742000000b0041b082610f7so2593049pge.14 for ; Tue, 26 Jul 2022 15:14:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=ukl4OVDQE9opIMIGpob7jXAYmiX8p3TibjFoXsDBRsU=; b=Befx/Q1VNfErMgV4H9YxfdPrmhNSlp2A7CTiym7Zxf0PinWAhTwfChp45N6qK/AVrB gFLS84pmINP0bYrCTDuf1y0qR8si7wLPYJxiLLYsk+Gnk6hDIVnSH7uoFDNsJnBndZgB m62UxSTQlzlSDKNAx/K+yLXuMTo/fN6vcWVicR7cFJPVlQdpujw8ISTB6g4erEh7JH3w wVbYygNVPoz68YB+l2+iRI99aGmeRL1vsX6MismVUDwC6BJXla+tdNPRIPklZlOPRzXJ MgDm+1sGBWn5IzX1r45mUvsYFnapAkC2DEj537jGKHRdsCWGOa1cELZzqpTTXRzjLVNW 1DSg== X-Gm-Message-State: AJIora8uRXPp7rhaDT00eSHDaDXtEGVrCTmxspr/+qu/yGbfIRJEhE8r gNFTavbof5UxqlKajG8awkifJeU7AhmGDRWpjYrJtkJMj5mFnH8oAiEeUi4MRz5dgx9xnNNpHjH pdQjX8O1ry43hApGcvAGM2m8z0ebt X-Received: by 2002:a17:902:ead2:b0:16d:e8c:ddd5 with SMTP id p18-20020a170902ead200b0016d0e8cddd5mr18219684pld.99.1658873657904; Tue, 26 Jul 2022 15:14:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tn5zFYvK8AgfOX3gA5qr9ojqikfstUS/1oC+1f/KNPwB90NI70mrMuJCP6bPyOUVKygHFNRw== X-Received: by 2002:a17:902:ead2:b0:16d:e8c:ddd5 with SMTP id p18-20020a170902ead200b0016d0e8cddd5mr18219668pld.99.1658873657627; Tue, 26 Jul 2022 15:14:17 -0700 (PDT) Received: from luke-ubuntu.buildd (cpe-75-80-146-43.san.res.rr.com. [75.80.146.43]) by smtp.gmail.com with ESMTPSA id a13-20020a1709027e4d00b0015e9f45c1f4sm12069308pln.186.2022.07.26.15.14.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 15:14:16 -0700 (PDT) From: Luke Nowakowski-Krijger To: ltp@lists.linux.it, rpalethorpe@suse.de, liwang@redhat.com, pvorel@suse.cz, chrubis@suse.cz Date: Tue, 26 Jul 2022 15:13:25 -0700 Message-Id: <801f4e9b436ea97cb754630e7b6c12626829a8f3.1658872195.git.luke.nowakowskikrijger@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v6 09/10] controllers: update cpuset_regression_test.sh to use newer cgroup lib X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Update the test to use the newer cgroup lib which handles mounting for v1 and v2 controllers enabling them both to be tested and cleaning up the mounting and cleanup process. Signed-off-by: Luke Nowakowski-Krijger --- v3->v6: None .../cpuset/cpuset_regression_test.sh | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh b/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh index 68fcf2eec..8e87d20e4 100755 --- a/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh +++ b/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh @@ -122,18 +122,13 @@ cpuset_restore() setup() { - if ! is_cgroup_subsystem_available_and_enabled "cpuset"; then - tst_brk TCONF "Either kernel does not support cpuset controller or feature not enabled" - fi - - # We need to mount cpuset if it is not found. - root_cpuset_dir=$(get_cgroup_mountpoint cpuset) - if [ -z "$root_cpuset_dir" ]; then - root_cpuset_dir="$LOCAL_MOUNTPOINT" + cgroup_require "cpuset" + cgroup_version=$(cgroup_get_version "cpuset") + root_cpuset_dir=$(cgroup_get_mountpoint "cpuset") + testpath=$(cgroup_get_test_path "cpuset") + task_list=$(cgroup_get_task_list "cpuset") - ROD_SILENT mkdir -p ${root_cpuset_dir} - ROD_SILENT mount -t cpuset cpuset ${root_cpuset_dir} - fi + tst_res TINFO "test starts with cgroup version $cgroup_version" if ! [ -f ${root_cpuset_dir}/${cpu_exclusive} ]; then cpu_exclusive=cpu_exclusive @@ -180,14 +175,7 @@ cleanup() echo ${old_cpu_exclusive_value} > ${root_cpuset_dir}/${cpu_exclusive} fi - if [ -d "$LOCAL_MOUNTPOINT" ]; then - umount ${LOCAL_MOUNTPOINT} - if [ $? -ne 0 ]; then - tst_res TWARN "'umount ${LOCAL_MOUNTPOINT}' failed" - fi - - rmdir ${LOCAL_MOUNTPOINT} - fi + cgroup_cleanup } test() From patchwork Tue Jul 26 22:13:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Nowakowski-Krijger X-Patchwork-Id: 1661038 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=GDvBZtcr; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lsrpl5rC1z9sFk for ; Wed, 27 Jul 2022 08:16:15 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7B3A13C31DA for ; Wed, 27 Jul 2022 00:16:13 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id AFC483C2A24 for ; Wed, 27 Jul 2022 00:14:23 +0200 (CEST) Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 2955260087B for ; Wed, 27 Jul 2022 00:14:22 +0200 (CEST) Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 4BCB73F130 for ; Tue, 26 Jul 2022 22:14:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1658873662; bh=Vgl3NeWSSm6MUdSzmMkpfd0Wy0WkA4Rz98gnPodEW0I=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GDvBZtcrT+gcpOZja2mpgm/118IppKH6pXHhibpVu+4Xp8OL52UGXPd1rtWGlOfI7 yMVsuD6FVnjqsHdmv1e629fV8it6DcVS6Axqt4XwRBAfMrjq4fZKrt4mFswMyHsOCL GvdD/hPFk+acFl1vC8IBfsA7RWckjAdJ6k5yuymk3K4Haiv5vhjnfBHGzCM7isjuzP OPSnPR1sN4pUYH9SgHmEEjhaJy+6JfwS8YKOwrVC13tmBi+Biw5Bmqk9zOFPWM0kke B4qQFmGRzWxBVZe3NrlB84g2BukDNUJ1i897J6MGV9gtRE6hRjL+m+HhM5Tt/4vX5G I3r/muRlpr6oA== Received: by mail-pf1-f197.google.com with SMTP id d18-20020aa78692000000b0052abaa9a6bbso5108564pfo.2 for ; Tue, 26 Jul 2022 15:14:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=Vgl3NeWSSm6MUdSzmMkpfd0Wy0WkA4Rz98gnPodEW0I=; b=Al8uKHcVWZQORPtNgnqb2SGf8ABvV19fOChRNf3PamG258DVY3CFwBCsH7USMXcrE2 8fnqtLsSaioYkrk4LLvPmTb8tpjYKkiDKOAUipfPBwiNlD0MTCNXp+MRIX4kRUKazo96 bnqSVyBfUYPoOEAb2otaNeFMmDlTJihXHNIgmBAa1keeQAFjKylAx15yn3WwjCSsIfIM mTx2M1W/LFlboLSWn5Kgy1pwMkoP1fef0HEtTRI9fzSg3vG+T2W37v1V62DJA4fN5nX6 78RFfflqCfJbsKGPp9Beh3Vd59sSxf5XT3EMBQkkljLBB9JwcUlBuR7sf2JtHW2EU5aW PNZw== X-Gm-Message-State: AJIora8g3/Dovl49bmYkoSKIAHKro0YjYE+3uPE1IesUFTa5zmJaGByb 0LreqtSEzQadXcKgPqTRvNaHs6aLINjZL5gVE+rx/F6DXG7iqLOEK0CZzaovQ84nDTGHIhoME8T BZG91pqZQ9YSDynQIoNHYKJdW0yNa X-Received: by 2002:a17:90b:33cd:b0:1f0:3655:17a8 with SMTP id lk13-20020a17090b33cd00b001f0365517a8mr1125995pjb.33.1658873659242; Tue, 26 Jul 2022 15:14:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sUAmlBQKsXaj7SSUjadbiMy+FzHrCG+fvq/wSgN4y42U6Gry94rij80ms6TRFxItlshgO5Zw== X-Received: by 2002:a17:90b:33cd:b0:1f0:3655:17a8 with SMTP id lk13-20020a17090b33cd00b001f0365517a8mr1125977pjb.33.1658873658964; Tue, 26 Jul 2022 15:14:18 -0700 (PDT) Received: from luke-ubuntu.buildd (cpe-75-80-146-43.san.res.rr.com. [75.80.146.43]) by smtp.gmail.com with ESMTPSA id a13-20020a1709027e4d00b0015e9f45c1f4sm12069308pln.186.2022.07.26.15.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 15:14:18 -0700 (PDT) From: Luke Nowakowski-Krijger To: ltp@lists.linux.it, rpalethorpe@suse.de, liwang@redhat.com, pvorel@suse.cz, chrubis@suse.cz Date: Tue, 26 Jul 2022 15:13:26 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v6 10/10] controllers: update cgroup_regression_test to use newer cgroup lib X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" The older function in the cgroup lib 'get_cgroup_mountpoint' has been removed, so instead replace it with its old functionaility to get mountpoint. Also use the newer cgroup lib require operation to mount and cleanup a cpu controller. Signed-off-by: Luke Nowakowski-Krijger --- v3->v6: None .../cgroup/cgroup_regression_test.sh | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/testcases/kernel/controllers/cgroup/cgroup_regression_test.sh b/testcases/kernel/controllers/cgroup/cgroup_regression_test.sh index 69b51773c..bfa9097ec 100755 --- a/testcases/kernel/controllers/cgroup/cgroup_regression_test.sh +++ b/testcases/kernel/controllers/cgroup/cgroup_regression_test.sh @@ -168,17 +168,8 @@ test3() return fi - cpu_subsys_path=$(get_cgroup_mountpoint "cpu") - - # Run the test for 30 secs - if [ -z "$cpu_subsys_path" ]; then - mount -t cgroup -o cpu xxx cgroup/ - if [ $? -ne 0 ]; then - tst_res TFAIL "Failed to mount cpu subsys" - return - fi - cpu_subsys_path=cgroup - fi + cgroup_require "cpu" + cpu_subsys_path=$(cgroup_get_mountpoint "cpu") cgroup_regression_3_1.sh $cpu_subsys_path & pid1=$! @@ -191,7 +182,7 @@ test3() wait $pid2 2>/dev/null rmdir $cpu_subsys_path/0 2> /dev/null - tst_umount $PWD/cgroup + cgroup_cleanup check_kernel_bug } @@ -303,21 +294,15 @@ test6() test_7_1() { local subsys=$1 + local subsys_path # we should be careful to select a $subsys_path which is related to # cgroup only: if cgroup debugging is enabled a 'debug' $subsys # could be passed here as params and this will lead to ambiguity and # errors when grepping simply for 'debug' in /proc/mounts since we'll # find also /sys/kernel/debug. Helper takes care of this. - local subsys_path=$(get_cgroup_mountpoint $subsys) - - if [ -z "$subsys_path" ]; then - mount -t cgroup -o $subsys xxx cgroup/ - if [ $? -ne 0 ]; then - tst_res TFAIL "failed to mount $subsys" - return - fi - subsys_path=cgroup - fi + + cgroup_require "$subsys" + subsys_path=$(cgroup_get_mountpoint "$subsys") mkdir $subsys_path/0 sleep 100 < $subsys_path/0 & # add refcnt to this dir @@ -332,6 +317,8 @@ test_7_1() wait $! 2>/dev/null umount cgroup/ fi + + cgroup_cleanup } test_7_2()