1#!/usr/bin/ksh
2#
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright 2020 Oxide Computer Company
16#
17
18#
19# This is a stress test that tries to just generate a bunch of ksensor
20# activity. It will run launching a number of threads that do different
21# activities. The goal here is to try and have the following:
22#
23# o Things trying to modunload the ksensor_test and ksensor driver
24# o things trying to actually use the various sensors from the
25#   ksensor_test driver
26#
27# To make sure that everything cleans up when this exits, this script
28# wraps itself in a ctrun. The caller needs to ensure that the
29# ksensor_test driver is loaded to begin with. It may or may not be part
30# of the system when all is said and done.
31#
32
33sensor_base="/dev/sensors/test"
34
35#
36# The number of instances that we expect to exist.
37#
38sensor_inst=42
39sensor_count=4
40
41#
42# Tunnables
43#
44sensor_unloaders=50
45sensor_readers=500
46
47if [[ ${@:$#} != "elbereth" ]]; then
48	exec ctrun -o noorphan ksh $0 "elbereth"
49fi
50
51
52if [[ ! -L "$sensor_base/test.temp.0.1" ]]; then
53	printf "missing ksensor test data, ksensor_tstp driver loaded?\n" 2>&1
54	exit 1
55fi
56
57cat << EOL
58Beginning to run the ksensor stress test. This will launch processes
59which will:
60
61 o Attempt to modunload 'ksensor' driver ($sensor_unloaders procs)
62 o Attempt to modunload 'ksensor_test' driver ($sensor_unloaders procs)
63 o Attempt to read test sensors ($sensor_readers procs)
64
65To stop things, simply kill this process. All dependent processes will
66be cleaned up.
67EOL
68
69for ((i = 0; i < $sensor_unloaders; i++)); do
70	ksh ./ksensor_unload.ksh ksensor_test &
71	ksh ./ksensor_unload.ksh ksensor &
72done
73
74for ((i = 0; i < $sensor_readers; i++)); do
75	if [[ $(( $i % 2 )) -eq 0 ]]; then
76		./ksensor_sread.32 $sensor_inst $sensor_count &
77	else
78		./ksensor_sread.64 $sensor_inst $sensor_count &
79	fi
80done
81
82while :; do
83	wait
84done
85
86exit 0
87