VirtualBox

source: vbox/trunk/src/VBox/Additions/common/testcase/led-lights.sh@ 106945

Last change on this file since 106945 was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette