-
Notifications
You must be signed in to change notification settings - Fork 4
Add testing of synchronization script with virtual screen buffer #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
82a907e
e3b5a79
407e647
3bc61dd
e13ffa5
e06b7cd
ee55f2d
c11347e
2d567a0
74828e4
f9cddcd
2a9f662
62a4687
982af07
4a03fbe
592b3d1
76166fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,8 @@ jobs: | |
sudo apt-get update | ||
sudo apt-get install -y \ | ||
flawfinder squashfs-tools uuid-dev libuuid1 libffi-dev libssl-dev libssl1.1 \ | ||
libarchive-dev libgpgme11-dev libseccomp-dev wget gcc make pkg-config | ||
libarchive-dev libgpgme11-dev libseccomp-dev wget gcc make pkg-config \ | ||
xvfb xdotool ffmpeg | ||
|
||
- name: Build and install Singularity | ||
run: | | ||
|
@@ -83,3 +84,39 @@ jobs: | |
./test_reprostim_container.sh --version | ||
cd ../.. | ||
pwd | ||
|
||
- name: Test timesync-stimuli run | ||
run: | | ||
export FRAME_WIDTH=1920 | ||
export FRAME_HEIGHT=1080 | ||
export FRAME_RATE=60 | ||
export FRAME_BPP=24 | ||
export DISPLAY_PATH="/tmp/reprostim_last_display.txt" | ||
export XVFB_OPTS="-screen 0 ${FRAME_WIDTH}x${FRAME_HEIGHT}x${FRAME_BPP} -ac +extension GLX +render -noreset" | ||
export DISPLAY_START=25 | ||
export REPROSTIM_CMD="./run_reprostim_container.sh timesync-stimuli -m event --mute -d \$(cat /tmp/reprostim_last_display.txt)" | ||
cd tools/ci | ||
echo "Run Xvfb in background with REPROSTIM_CMD" | ||
xvfb-run -a -n $DISPLAY_START -s "$XVFB_OPTS" bash -c "echo \$DISPLAY > ${DISPLAY_PATH}; $REPROSTIM_CMD"& | ||
XVFB_RUN_PID=$! | ||
echo "Started xvfb-run with PID $XVFB_RUN_PID" | ||
echo "Wait for Xvfb to start" | ||
sleep 4 | ||
export DISPLAY=$(cat ${DISPLAY_PATH}) | ||
echo "Xvfb started on display: $DISPLAY" | ||
echo "Send test pulse events" | ||
./test_reprostim_events.sh 2 5 5 1.5 20 "${DISPLAY}" & | ||
echo "Record video for 45 seconds" | ||
ffmpeg -video_size "${FRAME_WIDTH}x${FRAME_HEIGHT}" -framerate "${FRAME_RATE}" -f x11grab -i "$DISPLAY" -t 45 -c:v libx264 -pix_fmt yuv420p "/tmp/reprostim_screenshot_$(date +%Y-%m-%d_%H-%M-%S).mp4" | ||
sleep 45 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may be move this entire block into |
||
ls -l /tmp/reprostim_* | ||
echo "Kill Xvfb at the end" | ||
sleep 1 | ||
kill $XVFB_RUN_PID 2>/dev/null || true | ||
wait $XVFB_RUN_PID 2>/dev/null || true | ||
|
||
- name: Upload screenshot video artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: reprostim-screenshot | ||
path: /tmp/reprostim_screenshot*.mp4 |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,103 @@ | ||||
# Virtual Screen Notes | ||||
|
||||
## Installation & Usage | ||||
|
||||
```shell | ||||
sudo apt update | ||||
sudo apt install xvfb | ||||
sudo apt install xdotool | ||||
|
||||
which xvfb-run | ||||
``` | ||||
|
||||
Run in background mode as FullHD: | ||||
```shell | ||||
# use FullHD resolution, disables access control, enables GLX and | ||||
# render extensions, no reset at last client exit | ||||
export XVFB_OPTS="-screen 0 1920x1080x24 -ac +extension GLX +render -noreset" | ||||
|
||||
# run on display :99 | ||||
Xvfb :99 -screen 0 1920x1080x24 & | ||||
export DISPLAY=:99 | ||||
|
||||
# or use automatic screen selection | ||||
Xvfb --auto-servernum --server-num=20 --auto-servernum --server-num=20 -s "$XVFB_OPTS" | ||||
|
||||
``` | ||||
Run say `xterm` in background: | ||||
```shell | ||||
xvfb-run xterm & | ||||
``` | ||||
|
||||
Make PNG screenshot: | ||||
```shell | ||||
import -display :99 -window root "screenshot_$(date +%Y-%m-%d_%H:%M:%S).png" | ||||
``` | ||||
|
||||
Kill Xvfb at the end: | ||||
```shell | ||||
killall Xvfb | ||||
``` | ||||
|
||||
## Script Example | ||||
|
||||
Now all together in a script: | ||||
```bash | ||||
# install Xvfb | ||||
sudo apt update | ||||
sudo apt install xvfb | ||||
sudo apt install xdotool | ||||
which xvfb-run | ||||
|
||||
# setup params | ||||
export FRAME_WIDTH=1920 | ||||
export FRAME_HEIGHT=1080 | ||||
export FRAME_RATE=60 | ||||
export FRAME_BPP=24 | ||||
export DISPLAY_PATH="/tmp/reprostim_last_display.txt" | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not hardcode paths under folders which are public, use |
||||
export XVFB_OPTS="-screen 0 ${FRAME_WIDTH}x${FRAME_HEIGHT}x${FRAME_BPP} -ac +extension GLX +render -noreset" | ||||
export DISPLAY_START=25 | ||||
# export REPROSTIM_CMD="hatch run reprostim timesync-stimuli -m event --mute -d $(cat /tmp/reprostim_last_display.txt)" | ||||
export REPROSTIM_CMD="./run_reprostim_container.sh timesync-stimuli -m event --mute -d $(cat /tmp/reprostim_last_display.txt)" | ||||
|
||||
cd tools/ci | ||||
|
||||
# run Xvfb in background with REPROSTIM_CMD | ||||
xvfb-run -a -n $DISPLAY_START -s "$XVFB_OPTS" \ | ||||
bash -c 'echo $DISPLAY > ${DISPLAY_PATH}; $REPROSTIM_CMD'& | ||||
|
||||
|
||||
XVFB_RUN_PID=$! | ||||
echo "Started xvfb-run with PID $XVFB_RUN_PID" | ||||
|
||||
# wait for Xvfb to start | ||||
sleep 2 | ||||
|
||||
export DISPLAY=$(cat ${DISPLAY_PATH}) | ||||
echo "Xvfb started on display: $DISPLAY" | ||||
|
||||
# wait some time to start command | ||||
# sleep 5 | ||||
|
||||
# make screenshot | ||||
# import -display $DISPLAY -window root "/tmp/reprostim_screenshot${DISPLAY}_$(date +%Y-%m-%d_%H:%M:%S).png" | ||||
|
||||
# send test pulse events | ||||
./test_reprostim_events.sh 2 5 5 1.5 20& | ||||
|
||||
# record video for 45 seconds | ||||
ffmpeg -video_size ${FRAME_WIDTH}x${FRAME_HEIGHT} -framerate ${FRAME_RATE} -f x11grab -i $DISPLAY \ | ||||
-t 45 -c:v libx264 -pix_fmt yuv420p /tmp/reprostim_screenshot${DISPLAY}_$(date +%Y-%m-%d_%H:%M:%S).mp4 | ||||
|
||||
sleep 45 | ||||
|
||||
# kill Xvfb at the end | ||||
sleep 1 | ||||
kill $XVFB_RUN_PID | ||||
wait $XVFB_RUN_PID 2>/dev/null | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when you move all those commands into a script, there would be no need for duplicating the commands here. |
||||
``` | ||||
|
||||
|
||||
|
||||
|
||||
|
||||
Comment on lines
+99
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ Miscellaneous Notes | |
containers | ||
audiocodes-notes | ||
disp_mon-notes | ||
xvfb-notes |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.. include:: ../../misc/xvfb-notes.md | ||
:parser: myst_parser.sphinx_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
|
||
# Script to simulate pulse events using xdotool | ||
# Usage: ./test_reprostim_events.sh NUM_SERIES SERIES_INTERVAL NUM_EVT EVT_INTERVAL [SLEEP_DELAY] [DISPLAY] | ||
# Make sure to set DISPLAY if using Xvfb | ||
|
||
NUM_SERIES="$1" | ||
SERIES_INTERVAL="$2" | ||
NUM_EVT="$3" | ||
EVT_INTERVAL="$4" | ||
SLEEP_DELAY="${5:-0}" | ||
DISPLAY_PARAM="$6" | ||
|
||
# Use passed-in DISPLAY if provided | ||
if [[ -n "$DISPLAY_PARAM" ]]; then | ||
export DISPLAY="$DISPLAY_PARAM" | ||
fi | ||
|
||
echo "DISPLAY is set to: $DISPLAY" | ||
|
||
sleep "$SLEEP_DELAY" | ||
|
||
# Validate inputs | ||
if [ -z "$NUM_SERIES" ] || [ -z "$SERIES_INTERVAL" ] || [ -z "$NUM_EVT" ] || [ -z "$EVT_INTERVAL" ]; then | ||
echo "Usage: $0 <number_of_series> <series_interval> <number_of_events> <events_interval> [<sleep_delay>] [<display>]" | ||
exit 1 | ||
fi | ||
|
||
start_time=$(date +%s) | ||
|
||
for (( series=1; series<=NUM_SERIES; series++ )); do | ||
echo "Starting series $series" | ||
for (( event=1; event<=NUM_EVT; event++ )); do | ||
echo "Sending pulse event $series.$event" | ||
xdotool key 5 | ||
sleep "$EVT_INTERVAL" | ||
done | ||
|
||
if [ "$series" -lt "$NUM_SERIES" ]; then | ||
echo "Waiting $SERIES_INTERVAL seconds before next series..." | ||
sleep "$SERIES_INTERVAL" | ||
fi | ||
done | ||
|
||
# Escape and quit the application | ||
echo "Finishing up and send ESC q ESC..." | ||
xdotool key Escape | ||
sleep 0.2 | ||
xdotool key q | ||
sleep 0.2 | ||
xdotool key Escape | ||
|
||
end_time=$(date +%s) | ||
dt=$(( end_time - start_time )) | ||
|
||
echo "Done. Execution time: $dt seconds" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally place this into a script which could even be used locally .
Do not rely on
/tmp
- use${TMPDIR:-/tmp}