1 | #!/bin/bash
|
---|
2 | # $Id: led-lights.sh 87390 2021-01-22 23:46:52Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # VirtualBox guest LED demonstration test
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2021 Oracle Corporation
|
---|
9 | #
|
---|
10 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | # available from http://www.virtualbox.org. This file is free software;
|
---|
12 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | # General Public License (GPL) as published by the Free Software
|
---|
14 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | #
|
---|
18 |
|
---|
19 | #
|
---|
20 | # Usage:
|
---|
21 | # led-lights.sh [-a | -r]
|
---|
22 | #
|
---|
23 |
|
---|
24 | #
|
---|
25 | # Test script to twiddle the console LEDs of a VirtualBox VM.
|
---|
26 | #
|
---|
27 | # This is not an automated test, just something for humans to look
|
---|
28 | # at, to convince themselves that the VM console LEDs are working.
|
---|
29 | # By default it cycles through the LED types in a specific order.
|
---|
30 | #
|
---|
31 | # '-a' twiddles all possible LEDs at the same time
|
---|
32 | # '-r' reverses the default order
|
---|
33 | #
|
---|
34 | # For instance, run the script in 2 VMs at once, one with '-r'.
|
---|
35 | #
|
---|
36 | # LEDs are not expected to track perfectly, as other OS activities
|
---|
37 | # will light them (and buffer cache effects can delay things). Just
|
---|
38 | # make sure that all the tested ones (hard disk, optical, USB storage,
|
---|
39 | # floppy, shared folders, net) are working. Expected activity:
|
---|
40 | #
|
---|
41 | # - Disk & optical devices show solid 'read'
|
---|
42 | # - Virtual USB disk & optical devices show 'write' on the USB LED
|
---|
43 | # - Floppy devices and shared folders alternate 'read/write'
|
---|
44 | # - Net blinks 'write'
|
---|
45 | #
|
---|
46 | # Pre-VM setup:
|
---|
47 | #
|
---|
48 | # Download or locate a bootable Linux ISO able to be used 'live'.
|
---|
49 | # Make a tarball of this script + extra junk:
|
---|
50 | #
|
---|
51 | # $ dd if=/dev/zero of=junk bs=100k count=1
|
---|
52 | # $ tar cf floppy.img led-lights.sh junk
|
---|
53 | #
|
---|
54 | # NOTE: floppy.img must be >= 20KiB or you will get I/O errors!
|
---|
55 | #
|
---|
56 | # VM setup:
|
---|
57 | #
|
---|
58 | # New VM; type: Linux (subtype to match ISO); create default HD.
|
---|
59 | # VM Settings:
|
---|
60 | # System > raise base memory to 4GiB
|
---|
61 | # Storage > insert 'Live bootable' Linux ISO image;
|
---|
62 | # turn on 'Live CD/DVD'
|
---|
63 | # Storage > add floppy controller (i82078); insert floppy.img
|
---|
64 | # Storage > add USB controller; insert USB HD & USB CD
|
---|
65 | # System > move Optical before Floppy in boot order
|
---|
66 | # Shared Folders > set up one or more Shared Folders if desired
|
---|
67 | # (they should be permanent, auto-mount,
|
---|
68 | # writable, with at least 10MB free space)
|
---|
69 | #
|
---|
70 | # Boot the VM. Open a shell, become root, optionally install
|
---|
71 | # VirtualBox Guest Utilities to access Shared Folders, then extract
|
---|
72 | # and run this script:
|
---|
73 | #
|
---|
74 | # $ sudo bash
|
---|
75 | # # yum install virtualbox-guest-utils # for Shared Folders
|
---|
76 | # # tar xf /dev/fd0 led-lights.sh
|
---|
77 | # # ./led-lights.sh [-a | -r]
|
---|
78 |
|
---|
79 | if [ ! -w / ]; then
|
---|
80 | echo "Must be run as root!" 1>&2
|
---|
81 | exit 1
|
---|
82 | fi
|
---|
83 |
|
---|
84 | all_all=false
|
---|
85 | reverse=false
|
---|
86 |
|
---|
87 | if [ "x$1" = "x-a" ]; then
|
---|
88 | all_all=true
|
---|
89 | fi
|
---|
90 |
|
---|
91 | if [ "x$1" = "x-r" ]; then
|
---|
92 | reverse=true
|
---|
93 | fi
|
---|
94 |
|
---|
95 | # Copy binaries to RAM tmpfs to avoid CD I/O after cache purges
|
---|
96 | MYTMP=/tmp/led-lights.$$
|
---|
97 | mkdir $MYTMP
|
---|
98 | for bin in $(which dd sleep sync); do
|
---|
99 | case $bin in
|
---|
100 | /*)
|
---|
101 | cp -p $bin $MYTMP
|
---|
102 | ;;
|
---|
103 | esac
|
---|
104 | done
|
---|
105 | export MYTMP PATH=$MYTMP:$PATH
|
---|
106 |
|
---|
107 | set -o monitor
|
---|
108 |
|
---|
109 | # Make device reads keep hitting the 'hardware'
|
---|
110 | # even if the whole medium fits in cache...
|
---|
111 | drop_cache()
|
---|
112 | {
|
---|
113 | echo 1 >/proc/sys/vm/drop_caches
|
---|
114 | }
|
---|
115 |
|
---|
116 | activate()
|
---|
117 | {
|
---|
118 | kill -CONT -$1 2>/dev/null
|
---|
119 | }
|
---|
120 |
|
---|
121 | suppress()
|
---|
122 | {
|
---|
123 | $all_all || kill -STOP -$1 2>/dev/null
|
---|
124 | }
|
---|
125 |
|
---|
126 | declare -a pids pidnames
|
---|
127 | cpids=0
|
---|
128 |
|
---|
129 | twiddle()
|
---|
130 | {
|
---|
131 | let ++cpids
|
---|
132 | new_pid=$!
|
---|
133 | pidname=$1
|
---|
134 | pids[$cpids]=$new_pid
|
---|
135 | pidnames[$cpids]=$pidname
|
---|
136 | suppress $new_pid
|
---|
137 | }
|
---|
138 |
|
---|
139 | hide_stderr()
|
---|
140 | {
|
---|
141 | exec 3>&2 2>/dev/null
|
---|
142 | }
|
---|
143 |
|
---|
144 | show_stderr()
|
---|
145 | {
|
---|
146 | exec 2>&3 3>&-
|
---|
147 | }
|
---|
148 |
|
---|
149 | bail()
|
---|
150 | {
|
---|
151 | hide_stderr
|
---|
152 | for pid in ${pids[*]}; do
|
---|
153 | activate $pid
|
---|
154 | kill -TERM -$pid
|
---|
155 | kill -TERM $pid
|
---|
156 | done 2>/dev/null
|
---|
157 | rm -rf $MYTMP
|
---|
158 | kill $$
|
---|
159 | }
|
---|
160 |
|
---|
161 | trap "bail" INT
|
---|
162 |
|
---|
163 | drives()
|
---|
164 | {
|
---|
165 | echo $(
|
---|
166 | awk '$NF ~/^('$1')$/ { print $NF }' /proc/partitions
|
---|
167 | )
|
---|
168 | }
|
---|
169 |
|
---|
170 | # Prevent job control 'stopped' msgs during twiddler startup
|
---|
171 | hide_stderr
|
---|
172 |
|
---|
173 | # Hard disks
|
---|
174 | for hdd in $(drives '[sh]d.'); do
|
---|
175 | while :; do
|
---|
176 | dd if=/dev/$hdd of=/dev/null
|
---|
177 | drop_cache
|
---|
178 | done 2>/dev/null &
|
---|
179 | twiddle disk:$hdd
|
---|
180 | done
|
---|
181 |
|
---|
182 | # Optical drives
|
---|
183 | for odd in $(drives 'sr.|scd.'); do
|
---|
184 | while :; do
|
---|
185 | dd if=/dev/$odd of=/dev/null
|
---|
186 | drop_cache
|
---|
187 | done 2>/dev/null &
|
---|
188 | twiddle optical:$odd
|
---|
189 | done
|
---|
190 |
|
---|
191 | # Floppy drives
|
---|
192 | for fdd in $(drives 'fd.'); do
|
---|
193 | while :; do
|
---|
194 | dd if=/dev/$fdd of=$MYTMP/$fdd bs=1k count=20
|
---|
195 | dd of=/dev/$fdd if=$MYTMP/$fdd bs=1k count=20
|
---|
196 | done 2>/dev/null &
|
---|
197 | twiddle floppy:$fdd
|
---|
198 | done
|
---|
199 |
|
---|
200 | # Shared folders
|
---|
201 | if ! lsmod | grep -q vboxsf; then
|
---|
202 | echo
|
---|
203 | echo "Note: to test the Shared Folders LED, install this"
|
---|
204 | echo "distro's VirtualBox Guest Utilities package, e.g.:"
|
---|
205 | echo
|
---|
206 | echo " # yum install virtualbox-guest-utils (Red Hat family)"
|
---|
207 | echo " # apt install virtualbox-guest-utils (Debian family)"
|
---|
208 | echo
|
---|
209 | fi >&3 # original stderr
|
---|
210 | for shf in $(mount -t vboxsf | awk '{ print $3 }'); do
|
---|
211 | while :; do
|
---|
212 | dd if=/dev/urandom of=$shf/tmp.led-lights.$$ bs=100k count=100
|
---|
213 | for rep in $(seq 1 10); do
|
---|
214 | drop_cache
|
---|
215 | dd of=/dev/zero if=$shf/tmp.led-lights.$$ bs=100k count=100
|
---|
216 | done
|
---|
217 | sync
|
---|
218 | rm -f $shf/tmp.led-lights.$$
|
---|
219 | #find $shf -type f -print0 | xargs -0 wc -l
|
---|
220 | #drop_cache
|
---|
221 | done >/dev/null 2>&1 &
|
---|
222 | twiddle sharedfs:$shf
|
---|
223 | done
|
---|
224 |
|
---|
225 | # Network
|
---|
226 | ping -i.2 1.2.3.4 >/dev/null &
|
---|
227 | twiddle net
|
---|
228 |
|
---|
229 | # Untested LED: Graphics3D -- add some day?
|
---|
230 |
|
---|
231 | sleep 0.1
|
---|
232 | show_stderr
|
---|
233 |
|
---|
234 | if $reverse; then
|
---|
235 | seq=$(seq $cpids -1 1)
|
---|
236 | else
|
---|
237 | seq=$(seq 1 $cpids)
|
---|
238 | fi
|
---|
239 |
|
---|
240 | show_intr()
|
---|
241 | {
|
---|
242 | intr=$(stty -a | sed -n '/intr/ { s/.*intr *=* *//; s/[ ;].*//p }')
|
---|
243 | echo
|
---|
244 | echo "[ Hit $intr to stop ]"
|
---|
245 | echo
|
---|
246 | }
|
---|
247 |
|
---|
248 | if $all_all; then
|
---|
249 | printf "%s ...\n" ${pidnames[*]}
|
---|
250 | show_intr
|
---|
251 | wait
|
---|
252 | else
|
---|
253 | CEOL=$(tput el)
|
---|
254 | show_intr
|
---|
255 | while :; do
|
---|
256 | for pidx in $seq; do
|
---|
257 | pid=${pids[$pidx]}
|
---|
258 | pidname=${pidnames[$pidx]}
|
---|
259 | echo -e -n "$pidname$CEOL\r"
|
---|
260 | shift
|
---|
261 | activate $pid
|
---|
262 | sleep 2
|
---|
263 | suppress $pid
|
---|
264 | sync
|
---|
265 | sleep .5
|
---|
266 | done
|
---|
267 | done
|
---|
268 | fi
|
---|