VirtualBox

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

Last change on this file since 87390 was 87390, checked in by vboxsync, 4 years ago

Add led-lights.sh: script to twiddle VM console LED lights. bugref:9892

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
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
79if [ ! -w / ]; then
80 echo "Must be run as root!" 1>&2
81 exit 1
82fi
83
84all_all=false
85reverse=false
86
87if [ "x$1" = "x-a" ]; then
88 all_all=true
89fi
90
91if [ "x$1" = "x-r" ]; then
92 reverse=true
93fi
94
95# Copy binaries to RAM tmpfs to avoid CD I/O after cache purges
96MYTMP=/tmp/led-lights.$$
97mkdir $MYTMP
98for bin in $(which dd sleep sync); do
99 case $bin in
100 /*)
101 cp -p $bin $MYTMP
102 ;;
103 esac
104done
105export MYTMP PATH=$MYTMP:$PATH
106
107set -o monitor
108
109# Make device reads keep hitting the 'hardware'
110# even if the whole medium fits in cache...
111drop_cache()
112{
113 echo 1 >/proc/sys/vm/drop_caches
114}
115
116activate()
117{
118 kill -CONT -$1 2>/dev/null
119}
120
121suppress()
122{
123 $all_all || kill -STOP -$1 2>/dev/null
124}
125
126declare -a pids pidnames
127cpids=0
128
129twiddle()
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
139hide_stderr()
140{
141 exec 3>&2 2>/dev/null
142}
143
144show_stderr()
145{
146 exec 2>&3 3>&-
147}
148
149bail()
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
161trap "bail" INT
162
163drives()
164{
165 echo $(
166 awk '$NF ~/^('$1')$/ { print $NF }' /proc/partitions
167 )
168}
169
170# Prevent job control 'stopped' msgs during twiddler startup
171hide_stderr
172
173# Hard disks
174for 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
180done
181
182# Optical drives
183for 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
189done
190
191# Floppy drives
192for 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
198done
199
200# Shared folders
201if ! 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
209fi >&3 # original stderr
210for 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
223done
224
225# Network
226ping -i.2 1.2.3.4 >/dev/null &
227twiddle net
228
229# Untested LED: Graphics3D -- add some day?
230
231sleep 0.1
232show_stderr
233
234if $reverse; then
235 seq=$(seq $cpids -1 1)
236else
237 seq=$(seq 1 $cpids)
238fi
239
240show_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
248if $all_all; then
249 printf "%s ...\n" ${pidnames[*]}
250 show_intr
251 wait
252else
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
268fi
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