1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
|
#!/bin/sh
# shellcheck disable=SC2039
set -e
# Instructions for generating mouse movement steps for testing keyboard interface clicks:
# 1) start X server, using Xephyr, and a specific screen size:
# Xephyr -screen 480x800 :11&
# 2) start osk-sdl on the X server:
# DISPLAY=:11 ./bin/osk-sdl -n a -d a -c osk.conf -v -t
# 3) mouse over desired keys, use xdotool to read cursor coordinates at each position:
# DISPLAY=:11 xdotool getmouselocation
if [ -n "${TEST_DEBUG-}" ]; then
set -x
pause="sleep 1"
else
pause="sleep 0.012"
fi
recorder_pid=
if [ -n "${TEST_RECORD-}" ]; then
rm -f "$TEST_RECORD"
ffmpeg \
-nostats \
-f x11grab \
-i "$DISPLAY" \
-c:v av1 \
-f webm \
"$TEST_RECORD" &
recorder_pid="$!"
cleanup_recorder () {
kill -INT "$recorder_pid"
# We expect it to have nonzero exit status
wait "$recorder_pid" || :
}
trap cleanup_recorder EXIT INT TERM HUP
fi
# Clicks out the string 'qwerty' with the mouse and then clicks 'enter'.
# *** NOTE: Depends on screen size being 480x800 !
mouse_click_qwerty() {
# q
xdotool mousemove 21 575 mousedown 1 $pause mouseup 1 $pause
# w
xdotool mousemove 70 575 mousedown 1 $pause mouseup 1 $pause
# e
xdotool mousemove 130 575 mousedown 1 $pause mouseup 1 $pause
# r
xdotool mousemove 185 575 mousedown 1 $pause mouseup 1 $pause
# t
xdotool mousemove 225 575 mousedown 1 $pause mouseup 1 $pause
# y
xdotool mousemove 270 575 mousedown 1 $pause mouseup 1 $pause
# take screenshot before pressing enter
import -window root "test_mouse_click_qwerty_screenshot.png"
# enter
xdotool mousemove 430 775 mousedown 1 $pause mouseup 1 $pause
}
# Clicks the 'osk' toggle button.
# *** NOTE: Depends on screen size being 480x800 !
mouse_click_osk_toggle() {
xdotool mousemove 460 775 click 1
}
# Clicks out the string '@#π48' with the mouse and then clicks 'enter'.
# *** NOTE: Depends on screen size being 480x800 !
mouse_click_symbols() {
# 123 key
xdotool mousemove 56 771 $pause mouseup 1 $pause
# @ key
xdotool mousemove 21 651 $pause mouseup 1 $pause
# # key
xdotool mousemove 92 647 $pause mouseup 1 $pause
# =\< key
xdotool mousemove 50 690 $pause mouseup 1 $pause
# pi key
xdotool mousemove 243 591 $pause mouseup 1 $pause
# =\< key
xdotool mousemove 50 691 $pause mouseup 1 $pause
# 4 key (symbol layout)
xdotool mousemove 184 576 $pause mouseup 1 $pause
# abc key
xdotool mousemove 69 745 $pause mouseup 1 $pause
# 8 key (abc layout, 5 row)
xdotool mousemove 369 557 $pause mouseup 1 $pause
# take screenshot before pressing enter
import -window root "test_mouse_click_symbols_screenshot.png"
# enter
xdotool mousemove 463 766 $pause mouseup 1 $pause
}
# $1: set to true to run with sudo, else false
# $2: output file for stdout/stderr
# $3: additional opts for osk_sdl
# returns: PID
run_osk_sdl() {
local use_sudo="$1"
local out_file="$2"
local opts="$3 -c $OSK_SDL_CONF_PATH -t -v"
if [ "$use_sudo" = true ]; then
# shellcheck disable=SC2086
sudo "$OSK_SDL_EXE_PATH" $opts >"$out_file" &
echo $!
else
# shellcheck disable=SC2086
"$OSK_SDL_EXE_PATH" $opts >"$out_file" &
echo $!
fi
}
# $1: result file to read from
# $2: expected contents of result file
# returns: 0 on match, 1 on mismatch
check_result() {
local result_file="$1"
local expected="$2"
local retval
# check result
result="$(cat "$result_file")"
rm "$result_file"
if [ "$result" != "$expected" ]; then
printf "ERROR: Unexpected result!\n"
printf "\t%-15s %s\n" "got:" "$result"
printf "\t%-15s %s\n" "expected:" "$expected"
retval=1
else
echo "Success!"
retval=0
fi
return $retval
}
#############################################################
# Test key script (-k) with 'mouse' key input (letter layer)
#############################################################
test_keyscript_mouse_letters() {
echo "** Testing key script with 'mouse' key input (letter layer)"
local expected="qwerty"
local result_file="/tmp/osk_sdl_test_keyscript_mouse_letters_$DISPLAY"
local osk_pid
osk_pid="$(run_osk_sdl false "$result_file" "-k -n test_disk -d test/luks.disk -s")"
sleep 3
# run test
mouse_click_qwerty
sleep 3
kill -9 "$osk_pid" 2>/dev/null || true
# check result
check_result "$result_file" "$expected"
}
##############################################################
# Test key script (-k) with 'mouse' key input (symbol layers)
##############################################################
test_keyscript_mouse_symbols() {
echo "** Testing key script with 'mouse' key input (symbol layers)"
local expected="@#π48"
local result_file="/tmp/osk_sdl_test_keyscript_mouse_symbols_$DISPLAY"
local osk_pid
osk_pid="$(run_osk_sdl false "$result_file" "-k -n test_disk -d test/luks.disk -s")"
sleep 3
# run test
mouse_click_symbols
sleep 3
kill -9 "$osk_pid" 2>/dev/null || true
# check result
check_result "$result_file" "$expected"
}
##################################################
# Test key script (-k) with 'physical' key input
##################################################
test_keyscript_phys() {
echo "** Testing key script with 'physical' key input"
local result_file="/tmp/osk_sdl_test_keyscript_phys_$DISPLAY"
local expected="postmarketOS"
local osk_pid
osk_pid="$(run_osk_sdl false "$result_file" "-k -n test_disk -d test/luks.disk")"
sleep 3
# run test
xdotool type --delay 300 "$expected"
xdotool key Return
sleep 3
kill -9 "$osk_pid" 2>/dev/null || true
# check result
check_result "$result_file" "$expected"
}
########################################################
# Test key script (-k) with 'physical' key input, and -x
########################################################
test_keyscript_no_keyboard_phys() {
echo "** Testing key script with 'physical' key input"
local result_file="/tmp/osk_sdl_test_keyscript_no_keyboard_phys_$DISPLAY"
local expected="postmarketOS"
local osk_pid
osk_pid="$(run_osk_sdl false "$result_file" "-k -n test_disk -d test/luks.disk -x")"
sleep 3
# run test
xdotool type --delay 300 "$expected"
xdotool key Return
sleep 3
kill -9 "$osk_pid" 2>/dev/null || true
# check result
check_result "$result_file" "$expected"
}
########################################################
# Test key script (-k) with 'physical' key input, and -x
########################################################
test_keyscript_mouse_toggle_osk() {
echo "** Testing osk toggle button and 'mouse' key input"
local expected="qwerty"
local result_file="/tmp/osk_sdl_test_keyscript_mouse_toggle_osk_$DISPLAY"
local osk_pid
osk_pid="$(run_osk_sdl false "$result_file" "-k -n test_disk -d test/luks.disk -x")"
sleep 3
# run test
mouse_click_osk_toggle
sleep 1
mouse_click_qwerty
sleep 3
kill -9 "$osk_pid" 2>/dev/null || true
# check result
check_result "$result_file" "$expected"
}
##################################################
# Test luks unlocking
##################################################
test_luks_phys() {
# This test requires a privileged user (root, for devicemapper)
if [ "$(whoami)" != "root" ]; then
echo "This test requires elevated privileges, skipping."
exit 77
# CI_JOB_ID is set by gitlab CI
elif [ "$CI_JOB_ID" ]; then
echo "This test does not work in the gitlab CI, skipping."
exit 77
fi
echo "** Testing luks unlocking with 'physical' key input"
local test_disk="test/luks.disk"
local passphrase="postmarketOS"
local result_file="/tmp/osk_sdl_test_phys_luks_$DISPLAY"
local osk_pid
local retval=0
# create test luks disk
qemu-img create -f raw "$test_disk" 20M 1>/dev/null
echo "$passphrase" | sudo cryptsetup --iter-time=1 luksFormat "$test_disk"
# run osk-sdl
osk_pid="$(run_osk_sdl true "$result_file" "-n osk-sdl-test -d $test_disk")"
sleep 3
# run test
xdotool type --delay 300 "$passphrase"
xdotool key Return
sleep 3
kill -9 "$osk_pid" 2>/dev/null || true
# check result
if [ ! -b /dev/mapper/osk-sdl-test ]; then
echo "ERROR: Decrypted test device not created!"
retval=1
else
echo "Success!"
fi
# clean up
sudo cryptsetup close osk-sdl-test || true
rm $test_disk || true
return $retval
}
if [ -z "$OSK_SDL_EXE_PATH" ]; then
echo "\$OSK_SDL_EXE_PATH must be set to the path of the osk-sdl binary to test"
exit 1
fi
if [ -z "$OSK_SDL_CONF_PATH" ]; then
echo "\$OSK_SDL_CONF_PATH must be set to the path of the osk.conf to use in testing"
exit 1
fi
# make sure osk-sdl uses X and not some other video backend for testing
export SDL_VIDEODRIVER=x11
case "$1" in
test_keyscript_phys)
test_keyscript_phys
;;
test_keyscript_no_keyboard_phys)
test_keyscript_no_keyboard_phys
;;
test_keyscript_mouse_letters)
test_keyscript_mouse_letters
;;
test_keyscript_mouse_symbols)
test_keyscript_mouse_symbols
;;
test_luks_phys)
test_luks_phys
;;
test_keyscript_mouse_toggle_osk)
test_keyscript_mouse_toggle_osk
;;
*)
test_keyscript_phys
test_keyscript_no_keyboard_phys
test_keyscript_mouse_letters
test_keyscript_mouse_symbols
test_keyscript_mouse_toggle_osk
test_luks_phys
;;
esac
|