From 0e4365850672d95ced088966628ca848fb7f5110 Mon Sep 17 00:00:00 2001 From: reemo3dp <150130755+reemo3dp@users.noreply.github.com> Date: Thu, 29 Feb 2024 17:56:19 +0100 Subject: [PATCH] Add klipper-tests --- .github/workflows/test.yaml | 11 +++++- install-led_effect.sh | 14 ++++---- packages/klipper_tests/config/printer.cfg | 30 ++++++++++++++++ packages/klipper_tests/docker-compose.yml | 43 +++++++++++++++++++++++ packages/klipper_tests/run.sh | 31 ++++++++++++++++ packages/led_effect/src/__init__.py | 7 ++++ packages/led_effect/src/src | 1 + 7 files changed, 129 insertions(+), 8 deletions(-) create mode 100644 packages/klipper_tests/config/printer.cfg create mode 100644 packages/klipper_tests/docker-compose.yml create mode 100755 packages/klipper_tests/run.sh create mode 120000 packages/led_effect/src/src diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index a890193..aac8e72 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -21,4 +21,13 @@ jobs: run: poetry install - name: Run tests working-directory: ./packages/led_effect_tests - run: poetry run pytest -s -v \ No newline at end of file + run: poetry run pytest -s -v + + klipper-test: + name: Test klipper installation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Execute Klipper Test + working-directory: ./packages/klipper_tests + run: ./run.sh diff --git a/install-led_effect.sh b/install-led_effect.sh index 0774590..9defa08 100755 --- a/install-led_effect.sh +++ b/install-led_effect.sh @@ -56,7 +56,7 @@ check_folders() link_extension() { echo -n "Linking extension to Klipper... " - ln -sf "${SRCDIR}/packages/led_effect" "${KLIPPER_PATH}/klippy/extras/led_effect" + ln -sf "${SRCDIR}/packages/led_effect/src/" "${KLIPPER_PATH}/klippy/extras/led_effect" echo "[OK]" } @@ -131,15 +131,15 @@ verify_ready() } # Run steps -verify_ready -check_klipper -check_folders -stop_klipper +#verify_ready +#check_klipper +#check_folders +#stop_klipper if [ ! $UNINSTALL ]; then link_extension - add_updater +# add_updater else uninstall fi -start_klipper +#start_klipper diff --git a/packages/klipper_tests/config/printer.cfg b/packages/klipper_tests/config/printer.cfg new file mode 100644 index 0000000..5e5574b --- /dev/null +++ b/packages/klipper_tests/config/printer.cfg @@ -0,0 +1,30 @@ +[mcu] +serial: /opt/printer_data/run/klipper_host_mcu.tty + +[printer] +kinematics: none +max_velocity: 300 +max_accel: 3000 + +[gcode_macro] + +[led_effect sb_logo_busy] +autostart: false +frame_rate: 24 +leds: +layers: + breathing 3 1 top (1,0,0) + +[led_effect sb_logo_cleaning] +autostart: false +frame_rate: 24 +leds: +layers: + breathing 3 1 top (0.0, 0.02, 0.5) + +[led_effect sb_logo_calibrating_z] +autostart: false +frame_rate: 24 +leds: +layers: + breathing 3 1 top (0.0, 0.0, 0.35) \ No newline at end of file diff --git a/packages/klipper_tests/docker-compose.yml b/packages/klipper_tests/docker-compose.yml new file mode 100644 index 0000000..2a894d0 --- /dev/null +++ b/packages/klipper_tests/docker-compose.yml @@ -0,0 +1,43 @@ +services: + klipper: + image: mkuf/klipper:latest + privileged: true + entrypoint: + - tail + - -f + - /dev/null + volumes: + - /dev:/dev + - ../../:/app + - ./config:/opt/printer_data/config + - log:/opt/printer_data/logs + - run:/opt/printer_data/run + hostmcu: + image: mkuf/klipper:latest-hostmcu + privileged: true + volumes: + - /dev:/dev + - run:/opt/printer_data/run + log: + image: busybox + volumes: + - log:/opt/printer_data/logs + - run:/opt/printer_data/run + entrypoint: + - /bin/sh + - -c + - | + while true; do + tail -f /opt/printer_data/logs/klippy.log || true; + sleep 1; + done + +volumes: + run: + driver_opts: + type: tmpfs + device: tmpfs + log: + driver_opts: + type: tmpfs + device: tmpfs \ No newline at end of file diff --git a/packages/klipper_tests/run.sh b/packages/klipper_tests/run.sh new file mode 100755 index 0000000..93f2fa4 --- /dev/null +++ b/packages/klipper_tests/run.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -euxo pipefail + +trap destroy EXIT + +destroy() { + docker-compose down -t0 || true +} + +run() { + docker-compose up -d + docker-compose exec -T klipper bash -c ' + cd /app + ./install-led_effect.sh -k /opt/klipper/ + cd /opt + /opt/venv/bin/python klipper/klippy/klippy.py \ + -v \ + -I printer_data/run/klipper.tty \ + -a printer_data/run/klipper.sock \ + printer_data/config/printer.cfg \ + -l printer_data/logs/klippy.log +' & + sleep 5 + set +e + docker-compose logs log 2>&1 | tee /dev/stderr | grep "Config error" && exit 1 +} + + + +run \ No newline at end of file diff --git a/packages/led_effect/src/__init__.py b/packages/led_effect/src/__init__.py index e69de29..22224c5 100644 --- a/packages/led_effect/src/__init__.py +++ b/packages/led_effect/src/__init__.py @@ -0,0 +1,7 @@ +from . import led_effect + +def load_config(config): + return led_effect.load_config(config) + +def load_config_prefix(config): + return led_effect.load_config_prefix(config) diff --git a/packages/led_effect/src/src b/packages/led_effect/src/src new file mode 120000 index 0000000..2358c61 --- /dev/null +++ b/packages/led_effect/src/src @@ -0,0 +1 @@ +/app/packages/led_effect/src/ \ No newline at end of file