3
# Script to perform CPU stress tests
5
# Copyright (c) 2016 Canonical Ltd.
8
# Rod Smith <rod.smith@canonical.com>
10
# This program is free software: you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License version 3,
12
# as published by the Free Software Foundation.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
# The purpose of this script is to run CPU stress tests using the
26
# cpu_stress [ --runtime <time-in-seconds> ]
28
# If --runtime is not specified, it defaults to 7200 (2 hours).
31
if [ "$#" = "2" ] && [ "$1" = "--runtime" ] && [ "$2" -eq "$2" ] ; then
33
elif [ "$#" != "0" ] ; then
35
echo " $0 [ --runtime <time-in-seconds> ]"
38
echo "Setting run time to $runtime seconds"
39
# Add 10% to runtime; will forcefully terminate if stress-ng
40
# fails to return in that time.
41
end_time=$((runtime*11/10))
44
# Options --af-alg 0 through --wcs 0 specify CPU stressors. As of stress-ng
45
# version 0.05.12, this is equivalent to --class cpu --all 0 --exclude numa,cpu_online.
46
# This script specifies stressors individually because the list of stressors keeps
47
# increasing, and we want consistency -- if the stress-ng version bumps up, we
48
# don't want new stressors being run. We're omitting numa because it's most
49
# useful on systems with massive numbers of CPUs, and cpu_online because it's
50
# failed on 4 of 8 test systems, so it seems too strict.
51
# Use "timeout" command to launch stress-ng, to catch it should it go into la-la land
52
timeout -s 9 $end_time stress-ng --aggressive --verify --timeout $runtime \
53
--metrics-brief --tz --times \
54
--af-alg 0 --bsearch 0 --context 0 --cpu 0 \
55
--crypt 0 --hsearch 0 --longjmp 0 --lsearch 0 \
56
--matrix 0 --qsort 0 --str 0 --stream 0 \
57
--tsearch 0 --vecmath 0 --wcs 0
60
echo "**********************************************************"
61
if [ $result = "0" ] ; then
62
echo "* stress-ng CPU test passed!"
64
if [ $result = "137" ] ; then
65
echo "* stress-ng CPU test timed out and was forcefully terminated!"
67
echo "* stress-ng CPU test failed with result $result"
69
echo "**********************************************************"