From patchwork Thu Jan 3 12:11:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 1020270 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43VmxY16cpz9s4s for ; Thu, 3 Jan 2019 23:12:00 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2FBD83E6AC0 for ; Thu, 3 Jan 2019 13:11:58 +0100 (CET) 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]) by picard.linux.it (Postfix) with ESMTP id AA2093E6A7A for ; Thu, 3 Jan 2019 13:11:56 +0100 (CET) Received: from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id AE7FA1400E42 for ; Thu, 3 Jan 2019 13:11:53 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3F6BDA78; Thu, 3 Jan 2019 04:11:52 -0800 (PST) Received: from e120937-lin.cambridge.arm.com (e120937-lin.cambridge.arm.com [10.1.197.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 73E3F3F5D4; Thu, 3 Jan 2019 04:11:51 -0800 (PST) From: Cristian Marussi To: ltp@lists.linux.it Date: Thu, 3 Jan 2019 12:11:28 +0000 Message-Id: <20190103121128.17395-2-cristian.marussi@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190103121128.17395-1-cristian.marussi@arm.com> References: <20190103121128.17395-1-cristian.marussi@arm.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v2] memcg_stress_test.sh: ported to newlib X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Ported to newlib framework and general cleanup. Moved an helper function out into cgroup_lib.sh. Signed-off-by: Cristian Marussi --- testcases/kernel/controllers/cgroup_lib.sh | 27 ++++ .../kernel/controllers/memcg/stress/Makefile | 21 +-- .../memcg/stress/memcg_process_stress.c | 34 ++--- .../memcg/stress/memcg_stress_test.sh | 135 ++++++++---------- 4 files changed, 103 insertions(+), 114 deletions(-) diff --git a/testcases/kernel/controllers/cgroup_lib.sh b/testcases/kernel/controllers/cgroup_lib.sh index 5cdf55363..74fb8f845 100644 --- a/testcases/kernel/controllers/cgroup_lib.sh +++ b/testcases/kernel/controllers/cgroup_lib.sh @@ -31,3 +31,30 @@ get_cgroup_mountpoint() return $ret } +# +# Helper to check /proc/cgroups to verify if the cgroup subsytem +# provided as param is supported and enabled in Kernel. +# +# It expects as single argument the cgroup subsytem for +# which to check in /proc/cgroups +# +# - returns true if subsystem is supported and enabled +# +is_cgroup_subsystem_available_and_enabled() +{ + local line + local val + local ret=1 + local subsystem=$1 + + # fail straight away with no args + [ $# -eq 0 ] && return $ret + + line=$(grep -w $subsystem /proc/cgroups) + if [ $? = 0 ];then + val=$(echo $line | awk '{print $4 }') + [ $val = 1 ] && ret=0 + fi + + return $ret +} diff --git a/testcases/kernel/controllers/memcg/stress/Makefile b/testcases/kernel/controllers/memcg/stress/Makefile index a0456ac5d..773363cfc 100644 --- a/testcases/kernel/controllers/memcg/stress/Makefile +++ b/testcases/kernel/controllers/memcg/stress/Makefile @@ -1,24 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2009, Cisco Systems Inc. +# Author: Ngie Cooper, September 2009 # # kernel/controllers/memcg/stress testcase suite Makefile. # -# Copyright (C) 2009, Cisco Systems Inc. -# -# 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. -# -# Ngie Cooper, September 2009 -# top_srcdir ?= ../../../../.. diff --git a/testcases/kernel/controllers/memcg/stress/memcg_process_stress.c b/testcases/kernel/controllers/memcg/stress/memcg_process_stress.c index 870575c26..6af550012 100644 --- a/testcases/kernel/controllers/memcg/stress/memcg_process_stress.c +++ b/testcases/kernel/controllers/memcg/stress/memcg_process_stress.c @@ -1,24 +1,9 @@ -/******************************************************************************/ -/* */ -/* 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 @@ -91,14 +76,15 @@ int main(int argc, char *argv[]) if (interval <= 0) interval = 1; - /* TODO (garrcoop): add error handling. */ memset(&sigint_action, 0, sizeof(sigint_action)); sigint_action.sa_handler = &sigint_handler; - sigaction(SIGINT, &sigint_action, NULL); + if (sigaction(SIGINT, &sigint_action, NULL)) + err(1, "sigaction(%s) failed", "SIGINT"); memset(&sigusr_action, 0, sizeof(sigusr_action)); sigusr_action.sa_handler = &sigusr_handler; - sigaction(SIGUSR1, &sigusr_action, NULL); + if (sigaction(SIGUSR1, &sigusr_action, NULL)) + err(1, "sigaction(%s) failed", "SIGUSR1"); while (!flag_exit) { sleep(interval); diff --git a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh index af1a708a8..652d99e55 100755 --- a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh +++ b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh @@ -1,56 +1,56 @@ -#! /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 ## -## Restructure for LTP: Shi Weihua ## -## Added memcg enable/disable functinality: Rishikesh K Rajak ## -## +# Restructure for LTP: Shi Weihua +# Added memcg enable/disable functionality: Rishikesh K Rajak /dev/null - rmdir /dev/memcg 2>/dev/null + if ! is_cgroup_subsystem_available_and_enabled "memory";then + tst_res TWARN "Either Kernel does not support MEMORY resource controller or feature not enabled" + tst_brk TCONF ignored "Skipping all memory cgroup testcases...." fi + + echo 3 > /proc/sys/vm/drop_caches + sleep 2 + local mem_free=`cat /proc/meminfo | grep MemFree | awk '{ print $2 }'` + local swap_free=`cat /proc/meminfo | grep SwapFree | awk '{ print $2 }'` + + MEM=$(( $mem_free + $swap_free / 2 )) + MEM=$(( $MEM / 1024 )) + RUN_TIME=$(( 15 * 60 )) + + tst_res TINFO "Calculated available memory $MEM MB" } +do_cleanup() +{ + if [ -e /dev/memcg ]; then + umount /dev/memcg 2> /dev/null + rmdir /dev/memcg 2> /dev/null + fi +} do_mount() { - cleanup; + do_cleanup mkdir /dev/memcg 2> /dev/null mount -t cgroup -omemory memcg /dev/memcg @@ -65,62 +65,53 @@ do_mount() # $4 - How long does this test run ? in second run_stress() { - do_mount; + local i + + do_mount for i in $(seq 0 $(($1-1))) do mkdir /dev/memcg/$i 2> /dev/null - ./memcg_process_stress $2 $3 & - eval pid$i=$! + memcg_process_stress $2 $3 & + eval local pid$i=$! eval echo \$pid$i > /dev/memcg/$i/tasks done for i in $(seq 0 $(($1-1))) do - eval /bin/kill -s SIGUSR1 \$pid$i 2> /dev/null + eval kill -USR1 \$pid$i 2> /dev/null done sleep $4 for i in $(seq 0 $(($1-1))) do - eval /bin/kill -s SIGKILL \$pid$i 2> /dev/null + eval kill -KILL \$pid$i 2> /dev/null eval wait \$pid$i rmdir /dev/memcg/$i 2> /dev/null done - cleanup; + do_cleanup } testcase_1() { - run_stress 150 $(( ($mem-150) / 150 )) 5 $RUN_TIME + tst_res TINFO "testcase 1 started...it will run for $RUN_TIME secs" + + run_stress 150 $(( ($MEM - 150) / 150 )) 5 $RUN_TIME - tst_resm TPASS "stress test 1 passed" + tst_res TPASS "stress test 1 passed" } testcase_2() { - run_stress 1 $mem 5 $RUN_TIME + tst_res TINFO "testcase 2 started...it will run for $RUN_TIME secs" - tst_resm TPASS "stress test 2 passed" -} - -echo 3 > /proc/sys/vm/drop_caches -sleep 2 -mem_free=`cat /proc/meminfo | grep MemFree | awk '{ print $2 }'` -swap_free=`cat /proc/meminfo | grep SwapFree | awk '{ print $2 }'` + run_stress 1 $MEM 5 $RUN_TIME -mem=$(( $mem_free + $swap_free / 2 )) -mem=$(( mem / 1024 )) - -date -export TST_COUNT=$(( $TST_COUNT + 1 )) -testcase_1 -export TST_COUNT=$(( $TST_COUNT + 1 )) -testcase_2 -date + tst_res TPASS "stress test 2 passed" +} -exit 0 +tst_run