From: Uladzimir Bely <ubely@ilbers.de>
To: isar-users@googlegroups.com
Subject: [PATCH 3/3] testsuite: Document custom testcase for downstreams
Date: Tue, 28 Feb 2023 08:47:38 +0100 [thread overview]
Message-ID: <20230228074738.16304-4-ubely@ilbers.de> (raw)
In-Reply-To: <20230228074738.16304-1-ubely@ilbers.de>
Provide a complete example of testsuite implementation on the
downstream side in their own testcase directory.
Mention `PYTHONPATH` that needs to be adjusted.
Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
testsuite/README.md | 101 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)
diff --git a/testsuite/README.md b/testsuite/README.md
index 476b8607..28036bcb 100644
--- a/testsuite/README.md
+++ b/testsuite/README.md
@@ -122,3 +122,104 @@ 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
+
+Let's assume the downstream builds `custom_image_name` image for `qemuarm64`
+target in order to running custom tests using qemu.
+
+Let's assume the [kas](https://github.com/siemens/kas) is used by
+the downstream with the following directory structure:
+
+```
+...
+├── build/
+├── isar/
+├── kas
+│ ├── qemuarm64.yml
+│ └── kas-container
+├── meta-custom-layer
+└── test
+ ├── run_test.sh
+ ├── scripts
+ │ └── sample_script.sh
+ └── sample.py
+```
+
+### test/sample.py:
+
+```
+#!/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='custom_image_name', \
+ script='sample_script.sh')
+```
+
+### test/run_test.sh:
+
+```
+#!/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/test/test.py -p test_script_dir=${tsd}
+```
+
+Running testcase using `kas shell` may be done as:
+
+```
+./kas/kas-container shell kas/qemuarm64.yml -c '/work/test/run_test.sh'
+```
--
2.20.1
next prev parent reply other threads:[~2023-02-28 7:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-28 7:47 [PATCH 0/3] Creating custom testcases based on Isar one Uladzimir Bely
2023-02-28 7:47 ` [PATCH 1/3] testsuite: Check availability of script to run over ssh Uladzimir Bely
2023-02-28 7:47 ` [PATCH 2/3] testsuite: Move test scripts to their own subdirectory Uladzimir Bely
2023-02-28 7:47 ` Uladzimir Bely [this message]
2023-02-28 10:16 ` [PATCH 3/3] testsuite: Document custom testcase for downstreams Henning Schild
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=20230228074738.16304-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