From patchwork Fri Jan 13 06:36:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 91264 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp50832qgi; Thu, 12 Jan 2017 22:37:41 -0800 (PST) X-Received: by 10.84.173.195 with SMTP id p61mr27444606plb.158.1484289461296; Thu, 12 Jan 2017 22:37:41 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s21si11748749pfi.53.2017.01.12.22.37.39; Thu, 12 Jan 2017 22:37:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751263AbdAMGh2 (ORCPT + 25 others); Fri, 13 Jan 2017 01:37:28 -0500 Received: from mail-pf0-f176.google.com ([209.85.192.176]:34045 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751236AbdAMGhZ (ORCPT ); Fri, 13 Jan 2017 01:37:25 -0500 Received: by mail-pf0-f176.google.com with SMTP id 127so26095910pfg.1 for ; Thu, 12 Jan 2017 22:37:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=h0Fm3mJRPlkQi0as19nIYstrmprFrEmTPgNH/51ndfA=; b=kw3eEjaQGa3awT1c6vyx7AJihQaPhdv0dDB0WTEyanhgec9/fDOaXXqyS7zxXE9SVW YJ0EprrwTDZTqUmlSDhEw3W5TqudCf9NV3o4MfscpZIDJCkOrcrZad/WGk64HsKUtEkB cVucS70dccLmEuXa6AD6Ugy72Ol79JAbj0ad4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=h0Fm3mJRPlkQi0as19nIYstrmprFrEmTPgNH/51ndfA=; b=nzzD01EzNJyoyqX1T02VO48Eoh1++cNh6fxNXeH14pg9nlpfbcuVneRdo/tD84X3bl BAc7IqgxwUXhVWvZ1jYJoc4ubcmdgS/DxlFMjDHyzUpBFqnJMPeK/JcYFAxAD5LH99Xm 0MDV9RC62daf6danximExlcSljUBT86zGsfhZ/ETaBQ7hpNB1yVK5piDEpkP3DChp5AE 6aWdxXWfjXHGZUiF58OIe70UbNnxr11bF8dp5MGa7tzayt6Qz5irgAOFHY1O+lM0JQ6j kCLJahQVJMFf5kme4Elajo64zZQZJqJpxUg6qNUaQTK0nUKVEQR1vabB1dd5Bhmxcgc/ yS7g== X-Gm-Message-State: AIkVDXLIw2WzE6CTWFcXmzh9f2xCciXUVrMexUHR95qk+VUOs14wXwr2k/qRNiqN49mu4mgr X-Received: by 10.84.167.2 with SMTP id c2mr26954605plb.56.1484289439405; Thu, 12 Jan 2017 22:37:19 -0800 (PST) Received: from localhost ([122.172.128.56]) by smtp.gmail.com with ESMTPSA id a68sm26199388pgc.31.2017.01.12.22.37.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jan 2017 22:37:18 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Shuah Khan Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , linux-kselftest@vger.kernel.org, Viresh Kumar Subject: [PATCH 4/4] selftest: cpufreq: Add special tests Date: Fri, 13 Jan 2017 12:06:48 +0530 Message-Id: <618cbb8e2bc2d17bacc3c1989823e6815888eafb.1484289212.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds support for special tests which were reported on the PM list over the years, which helped catching core bugs by several developers. Signed-off-by: Viresh Kumar --- tools/testing/selftests/cpufreq/Makefile | 2 +- tools/testing/selftests/cpufreq/governor.sh | 7 ++ tools/testing/selftests/cpufreq/main.sh | 25 ++++- tools/testing/selftests/cpufreq/special-tests.sh | 115 +++++++++++++++++++++++ 4 files changed, 146 insertions(+), 3 deletions(-) create mode 100755 tools/testing/selftests/cpufreq/special-tests.sh -- 2.7.1.410.g6faf27b diff --git a/tools/testing/selftests/cpufreq/Makefile b/tools/testing/selftests/cpufreq/Makefile index 80c8727dcec1..3955cd96f3a2 100644 --- a/tools/testing/selftests/cpufreq/Makefile +++ b/tools/testing/selftests/cpufreq/Makefile @@ -1,7 +1,7 @@ all: TEST_PROGS := main.sh -TEST_FILES := cpu.sh cpufreq.sh governor.sh module.sh +TEST_FILES := cpu.sh cpufreq.sh governor.sh module.sh special-tests.sh include ../lib.mk diff --git a/tools/testing/selftests/cpufreq/governor.sh b/tools/testing/selftests/cpufreq/governor.sh index 2e42432892ab..def645103555 100755 --- a/tools/testing/selftests/cpufreq/governor.sh +++ b/tools/testing/selftests/cpufreq/governor.sh @@ -71,6 +71,13 @@ __switch_governor() echo $2 > $CPUFREQROOT/$1/scaling_governor } +# param: +# $1: cpu, $2: governor +__switch_governor_for_cpu() +{ + echo $2 > $CPUROOT/$1/cpufreq/scaling_governor +} + # SWITCH GOVERNORS # $1: cpu, $2: governor diff --git a/tools/testing/selftests/cpufreq/main.sh b/tools/testing/selftests/cpufreq/main.sh index 2515867ac9de..01bac76ac0ec 100755 --- a/tools/testing/selftests/cpufreq/main.sh +++ b/tools/testing/selftests/cpufreq/main.sh @@ -4,6 +4,7 @@ source cpu.sh source cpufreq.sh source governor.sh source module.sh +source special-tests.sh FUNC=basic # do basic tests by default OUTFILE=cpufreq_selftest @@ -19,7 +20,11 @@ helpme() [-t ] + modtest: test driver or governor modules. Only to be used with -d or -g options, + sptest1: Simple governor switch to produce lockdep. + sptest2: Concurrent governor switch to produce lockdep. + sptest3: Governor races, shuffle between governors quickly. + sptest4: CPU hotplugs with updates to cpufreq files.>] [-d \"] [-g \"] \n" @@ -67,7 +72,7 @@ parse_arguments() helpme ;; - t) # --func_type (Function to perform: basic, suspend, hibernate, modtest (default: basic)) + t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic)) FUNC=$OPTARG ;; @@ -136,6 +141,22 @@ do_test() fi ;; + "sptest1") + simple_lockdep + ;; + + "sptest2") + concurrent_lockdep + ;; + + "sptest3") + governor_race + ;; + + "sptest4") + hotplug_with_updates + ;; + *) echo "Invalid [-f] function type" helpme diff --git a/tools/testing/selftests/cpufreq/special-tests.sh b/tools/testing/selftests/cpufreq/special-tests.sh new file mode 100755 index 000000000000..58b730f23ef7 --- /dev/null +++ b/tools/testing/selftests/cpufreq/special-tests.sh @@ -0,0 +1,115 @@ +#!/bin/bash +# +# Special test cases reported by people + +# Testcase 1: Reported here: http://marc.info/?l=linux-pm&m=140618592709858&w=2 + +# protect against multiple inclusion +if [ $FILE_SPECIAL ]; then + return 0 +else + FILE_SPECIAL=DONE +fi + +source cpu.sh +source cpufreq.sh +source governor.sh + +# Test 1 +# $1: policy +__simple_lockdep() +{ + # switch to ondemand + __switch_governor $1 "ondemand" + + # cat ondemand files + local ondir=$(find_gov_directory $1 "ondemand") + if [ -z $ondir ]; then + printf "${FUNCNAME[0]}Ondemand directory not created, quit" + return + fi + + cat $ondir/* + + # switch to conservative + __switch_governor $1 "conservative" +} + +simple_lockdep() +{ + printf "** Test: Running ${FUNCNAME[0]} **\n" + + for_each_policy __simple_lockdep +} + +# Test 2 +# $1: policy +__concurrent_lockdep() +{ + for i in `seq 0 100`; do + __simple_lockdep $1 + done +} + +concurrent_lockdep() +{ + printf "** Test: Running ${FUNCNAME[0]} **\n" + + for_each_policy_concurrent __concurrent_lockdep +} + +# Test 3 +quick_shuffle() +{ + # this is called concurrently from governor_race + for I in `seq 1000` + do + echo ondemand | sudo tee $CPUFREQROOT/policy*/scaling_governor & + echo userspace | sudo tee $CPUFREQROOT/policy*/scaling_governor & + done +} + +governor_race() +{ + printf "** Test: Running ${FUNCNAME[0]} **\n" + + # run 8 concurrent instances + for I in `seq 8` + do + quick_shuffle & + done +} + +# Test 4 +# $1: cpu +hotplug_with_updates_cpu() +{ + local filepath="$CPUROOT/$1/cpufreq" + + # switch to ondemand + __switch_governor_for_cpu $1 "ondemand" + + for i in `seq 1 5000` + do + reboot_cpu $1 + done & + + local freqs=$(cat $filepath/scaling_available_frequencies) + local oldfreq=$(cat $filepath/scaling_min_freq) + + for j in `seq 1 5000` + do + # Set all frequencies one-by-one + for freq in $freqs; do + echo $freq > $filepath/scaling_min_freq + done + done + + # restore old freq + echo $oldfreq > $filepath/scaling_min_freq +} + +hotplug_with_updates() +{ + for_each_non_boot_cpu hotplug_with_updates_cpu +}