-
Notifications
You must be signed in to change notification settings - Fork 71
Implement virtio-gpu 2D and virtio-input devices #121
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
Draft
Mes0903
wants to merge
9
commits into
sysprog21:master
Choose a base branch
from
Mes0903:vgpu-2D-rework
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ffc5798
Add DirectFB2 cross-compilation support
Mes0903 9b1d92b
Implement virtio-gpu 2D device
Mes0903 4469b91
Implement virtio-input for keyboard and mouse
Mes0903 d4b318a
Add buildroot config
Mes0903 7de0866
Add linux configs
Mes0903 c385e02
Move SDL event loop to main-thread for macOS
Mes0903 d2da92d
Track primary and cursor plane ops independently
Mes0903 abf6e81
DO NOT MERGE: Add X11 package build support
Mes0903 f5478f4
DO NOT MERGE: Add Image for CI testing
Mes0903 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| . "${SCRIPT_DIR}/common.sh" | ||
|
|
||
| # Override timeout and sleep duration for macOS - emulation is significantly slower | ||
| case "${OS_TYPE}" in | ||
| Darwin) | ||
| TIMEOUT=10800 | ||
| DFB_SLEEP=180 | ||
| ;; | ||
| *) | ||
| DFB_SLEEP=5 | ||
| ;; | ||
| esac | ||
| export DFB_SLEEP | ||
|
|
||
| cleanup | ||
| trap cleanup EXIT | ||
|
|
||
| # Download pre-built ext4.img with DirectFB if not present | ||
| EXT4_URL="https://github.com/Mes0903/semu/raw/blob/ext4.img.bz2" | ||
|
Mes0903 marked this conversation as resolved.
Mes0903 marked this conversation as resolved.
|
||
| EXT4_SHA1="83ed49c16d341bdf3210141d5f6d5842b77a6adc" | ||
|
|
||
| if [ ! -f "ext4.img.bz2" ]; then | ||
|
Mes0903 marked this conversation as resolved.
Mes0903 marked this conversation as resolved.
|
||
| echo "Downloading ext4.img.bz2 for DirectFB testing..." | ||
| curl --progress-bar -O -L "${EXT4_URL}" | ||
| echo "${EXT4_SHA1} ext4.img.bz2" | shasum -a 1 -c - | ||
| fi | ||
|
|
||
| echo "Decompressing ext4.img.bz2 for DirectFB testing..." | ||
| rm -f ext4.img | ||
| bunzip2 -kf ext4.img.bz2 | ||
|
|
||
| # Force fresh download of Image and rootfs.cpio to avoid stale cache | ||
| rm -f Image rootfs.cpio | ||
| make Image rootfs.cpio | ||
|
|
||
| # NOTE: We want to capture the expect exit code and map | ||
| # it to our MESSAGES array for meaningful error output. | ||
| # Temporarily disable errexit for the expect call. | ||
| set +e | ||
| expect <<'DONE' | ||
| set timeout $env(TIMEOUT) | ||
| spawn make check | ||
|
|
||
| # Boot and login | ||
| expect "buildroot login:" { send "root\r" } timeout { exit 1 } | ||
| expect "# " { send "uname -a\r" } timeout { exit 2 } | ||
| expect "riscv32 GNU/Linux" {} | ||
|
|
||
| # ---------------- vgpu basic checks ---------------- | ||
| expect "# " { send "ls -la /dev/dri/ 2>/dev/null || true\r" } | ||
| expect "# " { send "test -c /dev/dri/card0 && echo __VGPU_DRM_OK__ || echo __VGPU_DRM_MISSING__\r" } timeout { exit 3 } | ||
| expect { | ||
| -re "\r?\n__VGPU_DRM_OK__" {} | ||
| -re "\r?\n__VGPU_DRM_MISSING__" { exit 3 } | ||
| timeout { exit 3 } | ||
| } | ||
|
|
||
| # virtio transport may be virtio-mmio, binding check should look at virtio_gpu driver directory | ||
| expect "# " { | ||
| send "sh -lc 'ls /sys/bus/virtio/drivers/virtio_gpu/virtio* >/dev/null 2>&1 && echo __VGPU_BIND_OK__ || echo __VGPU_BIND_BAD__'\r" | ||
| } timeout { exit 3 } | ||
| expect { | ||
| -re "\r?\n__VGPU_BIND_OK__" {} | ||
| -re "\r?\n__VGPU_BIND_BAD__" { | ||
| send "ls -l /sys/bus/virtio/drivers/virtio_gpu/ 2>/dev/null || true\r" | ||
| # emit literal $d via \u0024 to avoid Tcl variable substitution | ||
| send "sh -lc 'for d in /sys/bus/virtio/devices/virtio*; do echo \u0024d; ls -l \u0024d/driver 2>/dev/null || true; done'\r" | ||
| exit 3 | ||
| } | ||
| timeout { exit 3 } | ||
| } | ||
|
|
||
| # Useful logs (non-fatal) | ||
| expect "# " { send "dmesg | grep -Ei 'virtio.*gpu|drm.*virtio|scanout|number of scanouts' | tail -n 80 || true\r" } | ||
|
|
||
| # ---------------- DirectFB2 ---------------- | ||
| # Strategy: | ||
| # 1) Stop X11 if running (it holds the DRM device) | ||
| # 2) Check run.sh exists at /root/run.sh | ||
| # 3) cd to /root and source run.sh to set PATH/LD_LIBRARY_PATH | ||
| # 4) Verify df_drivertest is in PATH | ||
| # 5) Run df_drivertest and check for DirectFB init messages | ||
| # | ||
| # NOTE: df_drivertest may segfault when killed due to a race condition in DirectFB2's | ||
| # fusion module (libfusion) during signal handling. When SIGTERM is sent, the signal | ||
| # handler starts cleanup while the "Fusion Dispatch" thread may still be accessing | ||
| # shared state, leading to a use-after-free crash. The test passes if DirectFB init | ||
| # messages appear, even if the program crashes afterward during cleanup. | ||
|
|
||
| # Step 0: Stop X11 to release DRM device (it holds /dev/dri/card0) | ||
| # Use pidof with fallback to ps/grep if pidof unavailable | ||
| expect "# " { | ||
| send "sh -lc '\ | ||
| if command -v pidof >/dev/null 2>&1; then \ | ||
| pidof Xorg >/dev/null 2>&1 && kill \u0024(pidof Xorg) 2>/dev/null || true; \ | ||
| else \ | ||
| ps | grep Xorg | grep -v grep | awk \"{print \u00241}\" | xargs kill 2>/dev/null || true; \ | ||
| fi; \ | ||
| sleep 1; echo __X11_STOPPED__'\r" | ||
| } | ||
| expect "__X11_STOPPED__" {} | ||
|
|
||
| # Step 1: Check run.sh exists | ||
| expect "# " { send "test -f /root/run.sh && echo __RUNSH_OK__ || echo __DFB_RUNSH_MISSING__\r" } | ||
| expect { | ||
| -re "\r?\n__RUNSH_OK__" {} | ||
| -re "\r?\n__DFB_RUNSH_MISSING__" { exit 4 } | ||
| timeout { exit 4 } | ||
| } | ||
|
|
||
| # Step 2: cd to /root and source run.sh | ||
| expect "# " { send "cd /root && . ./run.sh >/dev/null 2>&1; echo __SRC_DONE__\r" } | ||
| expect "__SRC_DONE__" {} | ||
|
|
||
| # Step 3: Verify df_drivertest is available | ||
| expect "# " { send "command -v df_drivertest && echo __APP_OK__ || echo __APP_MISS__\r" } | ||
| expect { | ||
| -re "\r?\n__APP_OK__" {} | ||
| -re "\r?\n__APP_MISS__" { exit 4 } | ||
| timeout { exit 4 } | ||
| } | ||
|
|
||
| # Step 4: Run df_drivertest and check output (run in background, kill after delay) | ||
| expect "# " { send "df_drivertest >/tmp/dfb.log 2>&1 & sleep $env(DFB_SLEEP); kill \u0024! 2>/dev/null; head -30 /tmp/dfb.log\r" } | ||
| # Check for DRMKMS init message | ||
| expect "# " { send "grep -qi 'DRMKMS/System' /tmp/dfb.log && echo __DFB_OK__ || echo __DFB_FAIL__\r" } | ||
| expect { | ||
| -re "\r?\n__DFB_OK__" {} | ||
| -re "\r?\n__DFB_FAIL__" { exit 4 } | ||
| timeout { exit 4 } | ||
| } | ||
| DONE | ||
|
|
||
| ret="$?" | ||
| set -e # Re-enable errexit after capturing expect's return code | ||
|
|
||
| MESSAGES=( | ||
| "PASS: headless vgpu + DirectFB2 checks" | ||
| "FAIL: boot/login prompt not found" | ||
| "FAIL: shell prompt not found" | ||
| "FAIL: virtio-gpu basic checks failed (/dev/dri/card0 or virtio_gpu binding)" | ||
| "FAIL: DirectFB2 check failed (run.sh/df_drivertest missing or no DRMKMS init messages)" | ||
| ) | ||
|
|
||
| # Clean up pre-built ext4.img so other tests can use their own | ||
| if [ -f "ext4.img.bz2" ]; then | ||
| rm -f ext4.img | ||
| fi | ||
|
|
||
| if [[ "${ret}" -eq 0 ]]; then | ||
| print_success "${MESSAGES[0]}" | ||
| exit 0 | ||
| fi | ||
|
|
||
| print_error "${MESSAGES[${ret}]:-FAIL: unknown error (exit code ${ret})}" | ||
| exit "${ret}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| . "${SCRIPT_DIR}/common.sh" | ||
|
|
||
| # Override timeout for macOS - emulation is significantly slower | ||
| case "${OS_TYPE}" in | ||
| Darwin) | ||
| TIMEOUT=10800 | ||
| ;; | ||
| esac | ||
|
|
||
| cleanup | ||
| trap cleanup EXIT | ||
|
|
||
| # Force fresh download of Image and rootfs.cpio to avoid stale cache | ||
| rm -f Image rootfs.cpio | ||
| make Image rootfs.cpio | ||
|
|
||
| # NOTE: We want to capture the expect exit code and map | ||
| # it to our MESSAGES array for meaningful error output. | ||
| # Temporarily disable errexit for the expect call. | ||
| set +e | ||
| expect <<'DONE' | ||
| set timeout $env(TIMEOUT) | ||
| spawn make check | ||
|
|
||
| # Boot and login | ||
| expect "buildroot login:" { send "root\r" } timeout { exit 1 } | ||
| expect "# " { send "uname -a\r" } timeout { exit 2 } | ||
| expect "riscv32 GNU/Linux" {} | ||
|
|
||
| # ---------------- virtio-input ---------------- | ||
| # Require actual event* nodes, not just /dev/input directory existence | ||
| expect "# " { send "ls /dev/input/event* >/dev/null 2>&1 && echo __EVT_OK__ || echo __EVT_BAD__\r" } | ||
| expect { | ||
| -re "\r?\n__EVT_OK__" {} | ||
| -re "\r?\n__EVT_BAD__" { exit 3 } | ||
| timeout { exit 3 } | ||
| } | ||
|
|
||
| expect "# " { send "cat /proc/bus/input/devices | head -20\r" } | ||
| expect "# " { send "grep -qi virtio /proc/bus/input/devices && echo __VPROC_OK__ || echo __VPROC_WARN__\r" } | ||
| expect -re "__VPROC_(OK|WARN)__" {} timeout { exit 3 } | ||
|
Mes0903 marked this conversation as resolved.
|
||
| DONE | ||
|
|
||
| ret="$?" | ||
| set -e # Re-enable errexit after capturing expect's return code | ||
|
|
||
| MESSAGES=( | ||
| "PASS: headless virtio-input checks" | ||
| "FAIL: boot/login prompt not found" | ||
| "FAIL: shell prompt not found" | ||
| "FAIL: virtio-input basic checks failed (/dev/input/event* or /proc/bus/input/devices)" | ||
| "FAIL: virtio-input event stream did not produce bytes (needs host->virtio-input injection path)" | ||
| ) | ||
|
|
||
| if [[ "${ret}" -eq 0 ]]; then | ||
| print_success "${MESSAGES[0]}" | ||
| exit 0 | ||
| fi | ||
|
|
||
| print_error "${MESSAGES[${ret}]:-FAIL: unknown error (exit code ${ret})}" | ||
| exit "${ret}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.