From b939c9e6c424b1020392afc86ad1c079ed609327 Mon Sep 17 00:00:00 2001 From: Corentin LABBE Date: Fri, 4 Jul 2025 08:35:33 +0000 Subject: [PATCH] Add a mini test framwork Signed-off-by: Corentin LABBE --- .github/workflows/basic.yml | 6 ++ tests.py | 63 ++++++++++++++++++++ tests/extra_hosts/boards-ci.yaml | 28 +++++++++ tests/tests.yaml | 23 +++++++ tests/worker/boards-worker.yml | 46 ++++++++++++++ tests/worker/worker/99-lavaworker-udev.rules | 1 + 6 files changed, 167 insertions(+) create mode 100755 tests.py create mode 100644 tests/extra_hosts/boards-ci.yaml create mode 100644 tests/tests.yaml create mode 100644 tests/worker/boards-worker.yml create mode 100644 tests/worker/worker/99-lavaworker-udev.rules diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index d792263..8004688 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -40,6 +40,12 @@ jobs: run: sh .github/docker-resolv.sh - name: Build lava-docker run: cd output/local && docker compose build + lava-docker-tests: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: run custom mini tests framwork + run: ./tests.py check-formats: runs-on: ubuntu-22.04 steps: diff --git a/tests.py b/tests.py new file mode 100755 index 0000000..41c4e3d --- /dev/null +++ b/tests.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 + +import yaml +import os +import subprocess +import shutil +import sys + +with open("tests/tests.yaml", "r") as f: + tests = yaml.safe_load(f) + +print(tests) + +for testname in tests["tests"]: + ltest = tests["tests"][testname] + print(ltest) + directory = ltest["directory"] + tpath = f"tests/{directory}" + output = f"{tpath}/output" + if os.path.exists(output): + print("Need clean") + shutil.rmtree(output) + boardyaml = ltest["boardyaml"] + cmd = ["./lavalab-gen.py", "-o", output, f"{tpath}/{boardyaml}"] + # TODO verify warnings + print(cmd) + ret = subprocess.run(cmd) + print(ret) + if ret.returncode != 0: + print("ERROR") + sys.exit(1) + # now test + if "tests" not in ltest: + ltest["tests"] = [] + if ltest["tests"] is None: + ltest["tests"] = [] + for itest in ltest["tests"]: + print(itest) + if "filecompare" in itest: + fpath = os.path.join(output, itest["filecompare"]) + print(f"DEBUG: tpath={tpath}") + fbase = os.path.join(tpath, itest["base"]) + print(f"DEBUG compare {fpath} and {fbase}") + cmd = ["diff", '-u', fbase, fpath] + ret = subprocess.run(cmd) + if ret.returncode != 0: + print("ERROR") + sys.exit(1) + if "directory" in itest: + fpath = os.path.join(output, itest["directory"]) + exists = itest["exists"] + if exists: + if os.path.exists(fpath): + print(f"DIR {fpath} OK") + else: + print(f"DIR {fpath} KO") + if "buildit" in ltest: + dockcomp = os.path.join(output, ltest["buildit"]) + cmd = ["docker", "compose", '-f', dockcomp, "build"] + ret = subprocess.run(cmd) + if ret.returncode != 0: + print("ERROR") + sys.exit(1) diff --git a/tests/extra_hosts/boards-ci.yaml b/tests/extra_hosts/boards-ci.yaml new file mode 100644 index 0000000..29f83ee --- /dev/null +++ b/tests/extra_hosts/boards-ci.yaml @@ -0,0 +1,28 @@ +--- +masters: + - name: masterci1 + host: local + write_dot_env: True + users: + - name: admin + token: tokenforci + password: passwordforci + superuser: true + staff: true + tokens: + - username: admin + token: dfjdfkfkdjfkdsjfslforci + description: no description +slaves: + - name: lab-ci-0 + host: local + remote_master: masterci1 + remote_user: admin + use_overlay_server: false + use_tftp: false + extra_hosts: + - "toto: 127.0.0.1" + +boards: + - name: qemu-01 + type: qemu diff --git a/tests/tests.yaml b/tests/tests.yaml new file mode 100644 index 0000000..7e8f9de --- /dev/null +++ b/tests/tests.yaml @@ -0,0 +1,23 @@ +tests: + worker: + comment: verify support of external worker + directory: worker + boardyaml: boards-worker.yml + buildit: local/docker-compose.yml + tests: + - directory: local + exists: True + - directory: local/worker-ser2net + exists: True + - directory: local/worker-ser2net/udev + exists: True + - directory: local/lab-ci-0/udev + exists: True + - filecompare: local/worker-ser2net/udev/99-lavaworker-udev.rules + base: worker/99-lavaworker-udev.rules + extra_hosts: + comment: verify extra_hosts + directory: extra_hosts + boardyaml: boards-ci.yaml + buildit: local/docker-compose.yml + tests: diff --git a/tests/worker/boards-worker.yml b/tests/worker/boards-worker.yml new file mode 100644 index 0000000..d9df5ce --- /dev/null +++ b/tests/worker/boards-worker.yml @@ -0,0 +1,46 @@ +masters: + - name: master + host: local + users: + - name: admin + token: tokenforci + password: passwordforci + superuser: true + staff: true + tokens: + - username: admin + token: dfjdfkfkdjfkdsjfslforci + description: no description + +slaves: + - name: lab-ci-0 + host: local + remote_master: master + remote_user: admin + +boards: + - name: qemu-03 + type: qemu + - name: minnowboard-turbot-E3826-01 + type: minnowboard-turbot-E3826 + pdu_generic: + hard_reset_command: power-sispmctl.sh reset 2 01:01:4f:ee:ae + power_off_command: power-sispmctl.sh off 2 01:01:4f:ee:ae + power_on_command: power-sispmctl.sh on 2 01:01:4f:ee:ae + uart: + idvendor: 0x0403 + idproduct: 0x6001 + serial: "AL00CN4X" + worker: worker-ser2net + custom_option: + - "set grub_autoboot_prompt = 'Press enter to boot the selected OS'" + - name: sun7i-a20-olinuxino-micro-01 + type: sun7i-a20-olinuxino-micro + pdu_generic: + hard_reset_command: /usr/local/bin/tinyci.sh tinyci5-jack1 reset 2 + power_off_command: /usr/local/bin/tinyci.sh tinyci5-jack1 off 2 + power_on_command: /usr/local/bin/tinyci.sh tinyci5-jack1 on 2 + uart: + idvendor: 0x0403 + idproduct: 0x6010 + serial: "D30HFJPD" diff --git a/tests/worker/worker/99-lavaworker-udev.rules b/tests/worker/worker/99-lavaworker-udev.rules new file mode 100644 index 0000000..4292214 --- /dev/null +++ b/tests/worker/worker/99-lavaworker-udev.rules @@ -0,0 +1 @@ +SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001",ATTRS{serial}=="AL00CN4X", MODE="0664", OWNER="uucp", SYMLINK+="minnowboard-turbot-E3826-01"