The e2e test suite (tests/test_e2e.py) runs against a real LinuxCNC simulator
instance, validating that the gRPC server works correctly with actual LinuxCNC
state, commands, HAL data, and file management.
What E2E Tests Cover
The suite has about 70 tests organized into these areas:
- Status — version, joints, INI filename, positions, task state
- State transitions — estop/recovery, on/off, mode changes
- Commands — homing, MDI G-code, feedrate/spindle overrides
- WaitComplete — blocking until commands finish, timeout behavior, waiting on one command by its
linuxcnc_serial - G-code execution — upload/open/run, pause/resume, abort, single-step
- Jogging — incremental and continuous jog with stop, what
inposand velocity show during a jog, a joint jog refused in teleop - Errors — fan-out of one message to two streams,
status.errors, replay of buffered messages, a real MDI rejection - Errors on a machine without a GUI — 30 refused MDI lines (
M999) with noStreamErrorsclient, each of which must complete well within the 5 seconds LinuxCNC stalls for when nobody reads its full error queue, and must show up instatus.errors. It needs the server in its default mode on a configuration without a listed GUI (CI’sDISPLAY = headless), and is skipped whenGetServerInforeports any error-channel mode butalways - Machine configuration —
GetMachineConfigagainst the simulator’s INI file and status - Server information —
GetServerInforeports the package version, the connection and LinuxCNC’s version - Coolant — mist and flood on/off
- Rapid rate & max velocity — override scales
- Override config — feed/spindle override enable/disable
- Program options — optional stop, block delete
- Negative paths — empty MDI, wrong mode, invalid axis, path traversal, duplicate upload
- Streaming — StreamStatus, StreamErrors
- HAL — GetSystemStatus, QueryPins/Signals/Components/Params, GetValue, StreamStatus, SendCommand, WatchValues
- File management — upload/list/delete cycle, reading a file back whole and in chunks, resolving the loaded program
- A task that does not respond — the test freezes LinuxCNC’s task process (
milltask) withSIGSTOPfor about 5 seconds and always continues it afterwards. It checks that a command sent meanwhile returns withacknowledgedfalse after about 5 seconds, thatGetServerInfo,GetStatusand the health check, made at the same time while the command waits, all answer before it returns (each has a 3-second deadline), and that the command takes effect once the task runs again. It needs the tests to run on the same host and as the same user as LinuxCNC (as in CI), and is skipped otherwise. Against a server started with--in-process-commandsit fails, as it should - Stops first — with the task frozen (at a moment it holds none of LinuxCNC’s buffers), an E-stop is sent behind a blocked mode command, with a feed override sent behind that command. The E-stop is written next (its serial is the mode command’s plus one); the feed override is refused with
not_sent(overtaken or held by the stop) and never reaches LinuxCNC; the E-stop’s RPC answers after LinuxCNC’s waits (more than 5 s) withacknowledgedfalse; while the task stays frozenGetServerInfocounts the stop as not taken and a command is refused. After the task runs again the server is read until the count is 0, the blocked command has taken effect before the E-stop, and a command is accepted. The order inside the server is read from its answers, not inferred from the pauses between the sends: a round in which the E-stop arrived before the mode command had its turn (the mode command is then refused as overtaken) is run again, up to three rounds. Every round continues the task on every way out, reads the server until the E-stop has been taken, then puts the machine back on and fails if that fails. A second test has one client stream feed overrides while another sends 30 jog start and jog stop pairs: every command is either sent or refused withnot_sent, every accepted command is taken (the final echo reaches the highest accepted serial), most jogs are seen moving, the axis stops after every jog stop and after the final one, and an error in the streaming client fails the test. The first needs the same host and user as LinuxCNC, like the test above.
These tests catch issues that mock-based tests cannot:
- Real state machine transitions (estop, on/off, mode changes)
- Actual command execution (homing, MDI G-code, overrides)
- Real HAL pin/signal/component data from the motion controller
- File upload/list/delete against a real filesystem
- Streaming RPCs with live-updating data
- Thread safety under real concurrent access patterns
CI Workflow
The e2e tests run in .github/workflows/e2e.yml on every PR and push to main.
The workflow:
- Builds LinuxCNC from source in RIP (run-in-place) mode on Ubuntu 24.04
- Launches Xvfb (virtual framebuffer) for any X11 needs
- Creates a
headlessdisplay script (a no-op process that sleeps forever) — thelinuxcnclauncher waits for the DISPLAY program to exit and shuts everything down when it does, so a persistent headless script keeps components alive - Patches
sim/axis/axis.inito useDISPLAY = headlessinstead ofaxis - Starts LinuxCNC with the patched simulator config
- Waits for LinuxCNC readiness via
scripts/wait-for-linuxcnc.py - Starts the real gRPC server connected to the simulator
- Runs
pytest tests/test_e2e.py -m e2e
Running Locally
Prerequisites: LinuxCNC simulator installed (linuxcnc-uspace package on Debian/Ubuntu).
# 1. Start LinuxCNC with a sim config
linuxcnc /usr/share/linuxcnc/configs/sim/axis/axis.ini &
# 2. Wait for it to initialize
python3 scripts/wait-for-linuxcnc.py
# 3. Start the gRPC server
uv run python -m linuxcnc_grpc.server --nc-files /tmp/e2e-nc-files &
# 4. Run e2e tests
uv run pytest tests/test_e2e.py -v -m e2eNote: On a non-LinuxCNC machine, you need a virtual display:
Xvfb :99 -screen 0 1024x768x24 &
export DISPLAY=:99The server can be started before LinuxCNC (it waits), and
scripts/wait-for-linuxcnc.py can be started before LinuxCNC too. Its
--timeout covers the whole run, including the first check that the
linuxcnc module can be imported.
In Docker (macOS, Windows, or any machine without LinuxCNC)
Debian 13 packages the LinuxCNC simulator (linuxcnc-uspace, 2.9.4, also for
arm64), so the suite can run in a container. From the repository root:
# Dockerfile.sim
FROM debian:trixie
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
linuxcnc-uspace python3 python3-venv python3-pip xvfb netcat-openbsd procps sudo \
&& rm -rf /var/lib/apt/lists/*
RUN useradd -m cnc && echo 'cnc ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/cnc
USER cnc
RUN python3 -m venv --system-site-packages /home/cnc/venv \
&& /home/cnc/venv/bin/pip install grpcio grpcio-health-checking protobuf pytestdocker build -t linuxcnc-sim -f Dockerfile.sim .
docker run -d --init --name linuxcnc-sim \
--cap-add IPC_OWNER --cap-add SYS_NICE --cap-add IPC_LOCK \
-v "$PWD":/repo:ro linuxcnc-sim sleep infinityThen, inside the container (docker exec -it linuxcnc-sim bash), follow the
same steps as the CI workflow: copy the sim/axis sample configuration from
/usr/share/doc/linuxcnc/examples/sample-configs/sim/axis, create the
headless display script, set DISPLAY = headless in the copied axis.ini,
start Xvfb, start linuxcnc, and run the server and the tests with
PYTHONPATH=/repo/src:/repo/packages/python and the venv’s Python.
Three things the container needs:
--cap-add IPC_OWNER: LinuxCNC’s realtime helper (rtapi_app) runs as root and must open shared memory created by thecncuser. Docker drops that capability by default, and LinuxCNC then fails withrtapi_shmem_new failed due to shmget(...): Permission denied.--init: so that stopped LinuxCNC processes are reaped. Without it they stay as zombies, and anything that checks whether LinuxCNC is still running by looking for its processes is fooled.- A normal user rather than root, as on a real machine.
Adding New E2E Tests
- Add tests to
tests/test_e2e.py - Decorate with
@pytest.mark.e2e - Use the
linuxcnc_stuborhal_stubfixtures for gRPC access - Use
wait_for_condition()instead of fixedtime.sleep()to avoid flakiness - Use
ensure_machine_on()or themachine_onfixture to reset state between tests - Use
home_all(stub)to home joints before tests that require motion - Use
wait_complete(stub)instead of polling when waiting for a command to finish - Use
upload_test_file()/delete_test_file()for file management in tests - Always restore state (overrides, modes) at the end of tests to avoid affecting later tests
Mock Tests vs E2E Tests
| Aspect | Mock tests (test_integration.py) | E2E tests (test_e2e.py) |
|---|---|---|
| Server | tests/mock_server.py | Real linuxcnc_grpc.server |
| LinuxCNC | Not needed | Real simulator instance |
| Speed | Fast (~seconds) | Slower (~minutes) |
| Determinism | Fully deterministic | Timing-dependent |
| Coverage | API shape, serialization | Real behavior, state machines |