Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions .github/workflows/test-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: Test and coverage

on: [push, pull_request]

permissions:
contents: read
actions: write

env:
CARGO_TERM_COLOR: always

jobs:
test-coverage:
runs-on: ubuntu-latest
container:
image: archlinux:latest
options: --cap-add=SYS_NICE

steps:
- name: Checkout
uses: actions/checkout@v7

- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview

- name: Build Cache
uses: Swatinem/rust-cache@v2

- name: Install wayland dependencies
run: |
pacman -Syu --noconfirm git egl-wayland egl-gbm wayland base-devel mesa pango cairo sway

- name: Install cargo-llvm-cov
uses: taiki-e/install-action@v2
with:
tool: cargo-llvm-cov

# Starts a real wlroots compositor using wlroots' headless backend,
# so tests that connect to a real Wayland server (registry/
# xdg_output round trips, freeze/screenshot capture) can run
# instead of being skipped.
# This job's container has no GPU, so:
# - WLR_BACKENDS=headless: no DRM/KMS, no libseat/seatd session needed
# - WLR_RENDERER=pixman: pure CPU rendering, sidesteps EGL/GBM/Mesa
# software-GL fallback entirely instead of hoping llvmpipe works
# - WLR_LIBINPUT_NO_DEVICES=1: don't fail just because the container
# has no /dev/input/event* nodes
# - WLR_HEADLESS_OUTPUTS=1: create one virtual output so
# the tests have something to enumerate/capture
# sway picks its own server socket name; WAYLAND_DISPLAY is
# discovered afterwards from XDG_RUNTIME_DIR and exported for
# later steps rather than assumed in advance.
- name: Start headless Wayland compositor
run: |
export XDG_RUNTIME_DIR=/tmp/xdg-runtime
mkdir -p "$XDG_RUNTIME_DIR"
chmod 0700 "$XDG_RUNTIME_DIR"
echo "XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR" >> "$GITHUB_ENV"

printf 'xwayland disable\n' > /tmp/ci-sway-config

XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" \
WLR_BACKENDS=headless \
WLR_RENDERER=pixman \
WLR_LIBINPUT_NO_DEVICES=1 \
WLR_HEADLESS_OUTPUTS=1 \
sway -c /tmp/ci-sway-config > /tmp/sway.log 2>&1 &
echo $! > /tmp/sway.pid

sock=""
for i in $(seq 1 60); do
sock=$(find "$XDG_RUNTIME_DIR" -maxdepth 1 -type s -name 'wayland-*' 2>/dev/null | head -n1)
if [ -n "$sock" ]; then
break
fi
if ! kill -0 "$(cat /tmp/sway.pid)" 2>/dev/null; then
echo "::error::sway process exited during startup"
cat /tmp/sway.log
exit 1
fi
if [ $((i % 10)) -eq 0 ]; then
echo "still waiting for compositor socket (${i}s elapsed, sway still running)"
fi
sleep 1
done

if [ -z "$sock" ]; then
echo "::error::compositor failed to start within timeout"
echo "sway (pid $(cat /tmp/sway.pid)) is still running - looks like a genuine hang, not a crash"
echo "--- full sway.log ---"
cat /tmp/sway.log
echo "--- contents of XDG_RUNTIME_DIR ---"
ls -la "$XDG_RUNTIME_DIR"
exit 1
fi

display_name=$(basename "$sock")
echo "compositor socket is up at $sock"
echo "WAYLAND_DISPLAY=$display_name" >> "$GITHUB_ENV"

- name: Run tests
run: cargo test --workspace --all-features --verbose

- name: Generate coverage report (libwaysip)
run: |
cargo llvm-cov --all-features -p libwaysip --lcov --output-path lcov-libwaysip.info

- name: Generate coverage report (waysip)
run: |
cargo llvm-cov --all-features -p waysip --lcov --output-path lcov-waysip.info

- name: Stop headless Wayland compositor
if: always()
run: |
if [ -f /tmp/sway.pid ]; then
kill "$(cat /tmp/sway.pid)" 2>/dev/null || true
fi
cat /tmp/sway.log || true

- name: Upload libwaysip coverage to Codecov
uses: codecov/codecov-action@v7
with:
files: ./lcov-libwaysip.info
flags: libwaysip
name: libwaysip
fail_ci_if_error: false
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Upload waysip coverage to Codecov
uses: codecov/codecov-action@v7
with:
files: ./lcov-waysip.info
flags: waysip
name: waysip
fail_ci_if_error: false
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions libwaysip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ pangocairo = "0.22"

memmap2 = "0.9"
thiserror = "2.0"

[dev-dependencies]
wayland-backend = "0.3"
2 changes: 2 additions & 0 deletions libwaysip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ mod render;

pub mod error;
pub mod state;
#[cfg(test)]
mod tests;
mod utils;
pub use utils::*;

Expand Down
2 changes: 1 addition & 1 deletion libwaysip/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub struct WaysipState {
pub(crate) effective_selection_type: Option<SelectionType>,
/// Time when mouse was pressed down
pub(crate) mouse_press_time: Option<std::time::Instant>,
redraw_all: bool,
pub(crate) redraw_all: bool,
/// Whether the "edit selection before confirming" feature is enabled
pub(crate) edit_enabled: bool,
/// Keycode (evdev) that confirms an edited selection
Expand Down
Loading