From: Uladzimir Bely <ubely@ilbers.de>
To: isar-users@googlegroups.com
Subject: [PATCH v2 3/3] testsuite: Exmaple of custom testcase for downstreams
Date: Fri, 24 Mar 2023 08:01:42 +0100 [thread overview]
Message-ID: <20230324070142.27122-4-ubely@ilbers.de> (raw)
In-Reply-To: <20230324070142.27122-1-ubely@ilbers.de>
Provide a complete example of testsuite implementation on the
downstream side in their own testcase directory.
Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
meta-isar/test/.gitignore | 2 ++
meta-isar/test/README.md | 16 ++++++++++
meta-isar/test/run_test.sh | 39 +++++++++++++++++++++++++
meta-isar/test/sample_kas_config.yml | 32 ++++++++++++++++++++
meta-isar/test/sample_test.py | 9 ++++++
meta-isar/test/scripts/sample_script.sh | 7 +++++
testsuite/README.md | 19 ++++++++++++
7 files changed, 124 insertions(+)
create mode 100644 meta-isar/test/.gitignore
create mode 100644 meta-isar/test/README.md
create mode 100755 meta-isar/test/run_test.sh
create mode 100644 meta-isar/test/sample_kas_config.yml
create mode 100644 meta-isar/test/sample_test.py
create mode 100755 meta-isar/test/scripts/sample_script.sh
diff --git a/meta-isar/test/.gitignore b/meta-isar/test/.gitignore
new file mode 100644
index 00000000..fd87a392
--- /dev/null
+++ b/meta-isar/test/.gitignore
@@ -0,0 +1,2 @@
+build/
+isar/
diff --git a/meta-isar/test/README.md b/meta-isar/test/README.md
new file mode 100644
index 00000000..f8c6338c
--- /dev/null
+++ b/meta-isar/test/README.md
@@ -0,0 +1,16 @@
+# Example of the downstream testcase
+
+Use `meta-isar/test/` as working directory. Make sure `kas-container` is
+available in $PATH (look at https://github.com/siemens/kas for it).
+
+Build an image:
+
+```
+kas-container build sample_kas_config.yml
+```
+
+Run testcase:
+
+```
+kas-container shell sample_kas_config.yml -c '/work/run_test.sh'
+```
diff --git a/meta-isar/test/run_test.sh b/meta-isar/test/run_test.sh
new file mode 100755
index 00000000..c4a7d4ac
--- /dev/null
+++ b/meta-isar/test/run_test.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+
+# Make Isar testsuite accessable
+export PYTHONPATH=${PYTHONPATH}:${TESTSUITEDIR}
+
+# install avocado in virtualenv in case it is not there already
+if ! command -v avocado > /dev/null; then
+ sudo apt-get -y update
+ sudo apt-get -y install virtualenv
+ rm -rf /tmp/avocado_venv
+ virtualenv --python python3 /tmp/avocado_venv
+ source /tmp/avocado_venv/bin/activate
+ pip install avocado-framework==100.1
+fi
+
+# Install qemu
+if ! command -v qemu-system-aarch64 > /dev/null; then
+ sudo apt-get -y update
+ sudo apt-get -y install --no-install-recommends qemu-system-aarch64 ipxe-qemu
+fi
+
+# Start tests in this dir
+BASE_DIR="/build/avocado"
+
+# Provide working path
+mkdir -p .config/avocado
+cat <<EOF > .config/avocado/avocado.conf
+[datadir.paths]
+base_dir = ${BASE_DIR}/
+data_dir = ${BASE_DIR}/data
+logs_dir = ${BASE_DIR}/logs
+test_dir = ${BASE_DIR}/test
+EOF
+export VIRTUAL_ENV="./"
+
+tsd=$(dirname $(realpath $0))/scripts
+
+# Run SSH tests
+avocado run --max-parallel-tasks=1 /work/sample_test.py -p test_script_dir=${tsd}
diff --git a/meta-isar/test/sample_kas_config.yml b/meta-isar/test/sample_kas_config.yml
new file mode 100644
index 00000000..e7635af8
--- /dev/null
+++ b/meta-isar/test/sample_kas_config.yml
@@ -0,0 +1,32 @@
+header:
+ version: 11
+
+build_system: isar
+
+distro: debian-bullseye
+machine: qemuarm64
+target: mc:qemuarm64-bullseye:isar-image-ci
+repos:
+ isar:
+ url: "https://github.com/ilbers/isar.git"
+ refspec: next
+ layers:
+ meta:
+ meta-isar:
+
+bblayers_conf_header:
+ standard: |
+ BBPATH = "${TOPDIR}"
+ BBFILES ?= ""
+
+local_conf_header:
+ standard: |
+ DISTRO_ARCH ??= "arm64"
+ PATCHRESOLVE = "noop"
+
+ USERS += "root"
+ USER_root[password] ??= "$6$rounds=10000$RXeWrnFmkY$DtuS/OmsAS2cCEDo0BF5qQsizIrq6jPgXnwv3PHqREJeKd1sXdHX/ayQtuQWVDHe0KIO0/sVH8dvQm1KthF0d/"
+ crossbuild: |
+ ISAR_CROSS_COMPILE = "1"
+ ccache: |
+ USE_CCACHE = "1"
diff --git a/meta-isar/test/sample_test.py b/meta-isar/test/sample_test.py
new file mode 100644
index 00000000..7020c6ff
--- /dev/null
+++ b/meta-isar/test/sample_test.py
@@ -0,0 +1,9 @@
+#!/usr/bin/env python3
+
+from cibase import CIBaseTest
+
+class SampleTest(CIBaseTest):
+ def test_sample_script(self):
+ self.init("/build")
+ self.vm_start('arm64','bullseye', image='isar-image-ci', \
+ script='sample_script.sh')
diff --git a/meta-isar/test/scripts/sample_script.sh b/meta-isar/test/scripts/sample_script.sh
new file mode 100755
index 00000000..38c0fc1e
--- /dev/null
+++ b/meta-isar/test/scripts/sample_script.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+set -e
+
+sleep 10
+
+systemctl is-active getty.target
diff --git a/testsuite/README.md b/testsuite/README.md
index cf2fdc10..b58a1013 100644
--- a/testsuite/README.md
+++ b/testsuite/README.md
@@ -121,3 +121,22 @@ And to execute this example:
```
$ avocado run sample.py:SampleTest.test_sample
```
+
+## Using a different directory for custom testcases
+
+Downstreams may want to keep their testcases in a different directory
+(e.g. `./test/sample.py` as top-level with test description) but reuse
+classes implemented in Isar testsuite (e.g. `./isar/testsuite/*.py`). This is
+a common case for downstream that use `kas` to handle layers they use.
+
+In this case it's important to adjust `PYTHONPATH` variable before running
+avocado so that isar testsuite files could be found:
+
+```
+# TESTSUITEDIR="/work/isar/testsuite"
+export PYTHONPATH=${PYTHONPATH}:${TESTSUITEDIR}
+```
+
+# Example of the downstream testcase
+
+See `meta-isar/test` for an example of the testcase for kas-based downstream.
--
2.20.1
next prev parent reply other threads:[~2023-03-24 7:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-24 7:01 [PATCH v2 0/3] Creating custom testcases based on Isar one Uladzimir Bely
2023-03-24 7:01 ` [PATCH v2 1/3] testsuite: Check availability of script to run over ssh Uladzimir Bely
2023-03-24 7:01 ` [PATCH v2 2/3] testsuite: Move test scripts to their own subdirectory Uladzimir Bely
2023-03-24 7:01 ` Uladzimir Bely [this message]
2023-03-26 17:30 ` [PATCH v2 3/3] testsuite: Exmaple of custom testcase for downstreams Uladzimir Bely
2023-03-31 6:48 ` [PATCH v2 0/3] Creating custom testcases based on Isar one Uladzimir Bely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230324070142.27122-4-ubely@ilbers.de \
--to=ubely@ilbers.de \
--cc=isar-users@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox