blob: 63a7cae06a1fd7127820f66883f69a875e86ddca [file] [log] [blame]
Vishal Bhoj6448ec02024-09-12 16:08:00 +05301#!/bin/sh
2
3OUTPUT="$(pwd)/output"
4RESULT_FILE="${OUTPUT}/result.txt"
5mkdir $OUTPUT
6export RESULT_FILE
7
8# ----------------------
9# Peripheral Validation
10# ----------------------
11
12# Function to validate USB devices
13validate_usb_devices() {
14 echo "=== Validating USB Devices ==="
15 USB_PATH="/sys/bus/usb/devices/"
16 if [ -d "$USB_PATH" ]; then
17 echo "usb-sysfs-test pass" >> $RESULT_FILE
18 usb_devices=$(ls -1 $USB_PATH | grep -E '^[0-9]+-[0-9]+$')
19 if [ -z "$usb_devices" ]; then
20 echo "usb-device-test fail" >> $RESULT_FILE
21 echo "No USB devices found."
22 else
23 echo "usb-device-test pass" >> $RESULT_FILE
24 echo "USB devices found:"
25 echo "$usb_devices"
26 fi
27 else
28 echo "USB sysfs directory not found."
29 echo "usb-sysfs-test fail" >> $RESULT_FILE
30 fi
31 echo ""
32}
33
34# Function to validate network interfaces
35validate_network_interfaces() {
36 echo "=== Validating Network Interfaces ==="
37 NETWORK_PATH="/sys/class/net/"
38 if [ -d "$NETWORK_PATH" ]; then
39 echo "network-sysfs-test pass" >> $RESULT_FILE
40 interfaces=$(ls -1 $NETWORK_PATH)
41 if [ -z "$interfaces" ]; then
42 echo "network-interface-test fail" >> $RESULT_FILE
43 echo "No network interfaces found."
44 else
45 echo "network-interface-test pass" >> $RESULT_FILE
46 echo "Network interfaces found:"
47 echo "$interfaces"
48 fi
49 else
50 echo "network-sysfs-test fail" >> $RESULT_FILE
51 echo "Network interface sysfs directory not found."
52 fi
53 echo ""
54}
55
56# Function to validate block devices
57validate_block_devices() {
58 echo "=== Validating Block Devices (Storage) ==="
59 BLOCK_PATH="/sys/class/block/"
60 if [ -d "$BLOCK_PATH" ]; then
61 echo "block-sysfs-test pass" >> $RESULT_FILE
62 block_devices=$(ls -1 $BLOCK_PATH)
63 if [ -z "$block_devices" ]; then
64 echo "block-device-test fail" >> $RESULT_FILE
65 echo "No block devices found."
66 else
67 echo "block-device-test pass" >> $RESULT_FILE
68 echo "Block devices found:"
69 echo "$block_devices"
70 fi
71 else
72 echo "block-sysfs-test fail" >> $RESULT_FILE
73 echo "Block device sysfs directory not found."
74 fi
75 echo ""
76}
77
78# Function to validate Wi-Fi status
79validate_wifi() {
80 echo "=== Validating Wi-Fi Status ==="
81 WIFI_INTERFACE=$(ls /sys/class/net | grep -E 'wl.*[0-9]+')
82 if [ -n "$WIFI_INTERFACE" ]; then
83 echo "wifi-sysfs-test pass" >> $RESULT_FILE
84 echo "Wi-Fi interface detected: $WIFI_INTERFACE"
85 echo "Checking if Wi-Fi is up..."
86 state=$(cat /sys/class/net/$WIFI_INTERFACE/operstate)
87 if [ "$state" = "up" ]; then
88 echo "wifi-up-test pass" >> $RESULT_FILE
89 echo "Wi-Fi is up and running."
90 else
91 echo "wifi-up-test fail" >> $RESULT_FILE
92 echo "Wi-Fi is down."
93 fi
94 else
95 echo "wifi-sysfs-test fail" >> $RESULT_FILE
96 echo "No Wi-Fi interface found."
97 fi
98 echo ""
99}
100
101# Function to validate Bluetooth status
102validate_bluetooth() {
103 echo "=== Validating Bluetooth Status ==="
104 BT_PATH="/sys/class/bluetooth/"
105 if [ -d "$BT_PATH" ]; then
106 echo "bt-sysfs-test pass" >> $RESULT_FILE
107 bluetooth_devices=$(ls -1 $BT_PATH)
108 if [ -z "$bluetooth_devices" ]; then
109 echo "bt-device-test fail" >> $RESULT_FILE
110 echo "No Bluetooth devices found."
111 else
112 echo "Bluetooth devices found:"
113 echo "bt-device-test pass" >> $RESULT_FILE
114 echo "$bluetooth_devices"
115 hciconfig_output=$(hciconfig)
116 if [[ $hciconfig_output == *"UP RUNNING"* ]]; then
117 echo "Bluetooth is active."
118 else
119 echo "Bluetooth is not active."
120 fi
121 fi
122 else
123 echo "bt-sysfs-test fail" >> $RESULT_FILE
124 echo "Bluetooth sysfs directory not found."
125 fi
126 echo ""
127}
128
129# Function to validate sound devices
130validate_sound() {
131 echo "=== Validating Sound Devices ==="
132 SOUND_PATH="/sys/class/sound/"
133 if [ -d "$SOUND_PATH" ]; then
134 echo "snd-sysfs-test pass" >> $RESULT_FILE
135 sound_devices=$(ls -1 $SOUND_PATH)
136 if [ -z "$sound_devices" ]; then
137 echo "snd-device-test fail" >> $RESULT_FILE
138 echo "No sound devices found."
139 else
140 echo "snd-device-test pass" >> $RESULT_FILE
141 echo "Sound devices found:"
142 echo "$sound_devices"
143 fi
144 echo "Checking default audio output..."
145 default_audio=$(aplay -l | grep -i 'card' | head -n 1)
146 if [ -z "$default_audio" ]; then
147 echo "No sound card detected."
148 else
149 echo "Default audio output detected: $default_audio"
150 fi
151 else
152 echo "snd-sysfs-test fail" >> $RESULT_FILE
153 echo "Sound sysfs directory not found."
154 fi
155 echo ""
156}
157
158# Function to validate display devices
159validate_display() {
160 echo "=== Validating Display Devices ==="
161 DISPLAY_PATH="/sys/class/drm/"
162 if [ -d "$DISPLAY_PATH" ]; then
163 echo "drm-sysfs-test pass" >> $RESULT_FILE
164 display_devices=$(ls -1 $DISPLAY_PATH | grep -E 'card[0-9]-')
165 if [ -z "$display_devices" ]; then
166 echo "drm-interface-test fail" >> $RESULT_FILE
167 echo "No display devices found."
168 else
169 echo "drm-interface-test pass" >> $RESULT_FILE
170 echo "Display devices found:"
171 echo "$display_devices"
172 fi
173 echo "Checking connected displays..."
174 xrandr_output=$(xrandr --listmonitors | grep 'Monitors')
175 if [ -n "$xrandr_output" ]; then
176 echo "Connected displays:"
177 xrandr --listmonitors | grep -v 'Monitors'
178 else
179 echo "No displays connected."
180 fi
181 else
182 echo "drm-sysfs-test fail" >> $RESULT_FILE
183 echo "Display sysfs directory not found."
184 fi
185 echo ""
186}
187
188# Main test suite runner
189run_tests() {
190 echo "Starting Peripheral Validation Test Suite..."
191
192 validate_usb_devices
193 validate_network_interfaces
194 validate_block_devices
195 validate_wifi
196 validate_bluetooth
197 validate_sound
198 validate_display
199
200 echo "Peripheral validation test suite complete."
201}
202
203# Run the test suite
204run_tests