diff mbox series

[v3,4/4] support/testing: add bats runtime test

Message ID 20240503020000.3168109-4-brandon.maier@collins.com
State Accepted
Headers show
Series [v3,1/4] package/bats-support: new package | expand

Commit Message

Brandon Maier May 3, 2024, 2 a.m. UTC
Tests the bats-core, bats-support, bats-assert, and bats-file packages.

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
---
 support/testing/tests/package/test_bats.py    | 33 +++++++++++++++++++
 .../rootfs-overlay/root/test-bats-assert.bats | 11 +++++++
 .../rootfs-overlay/root/test-bats-core.bats   | 11 +++++++
 .../rootfs-overlay/root/test-bats-file.bats   | 10 ++++++
 4 files changed, 65 insertions(+)
 create mode 100644 support/testing/tests/package/test_bats.py
 create mode 100755 support/testing/tests/package/test_bats/rootfs-overlay/root/test-bats-assert.bats
 create mode 100755 support/testing/tests/package/test_bats/rootfs-overlay/root/test-bats-core.bats
 create mode 100755 support/testing/tests/package/test_bats/rootfs-overlay/root/test-bats-file.bats
diff mbox series

Patch

diff --git a/support/testing/tests/package/test_bats.py b/support/testing/tests/package/test_bats.py
new file mode 100644
index 0000000000..c75a6df294
--- /dev/null
+++ b/support/testing/tests/package/test_bats.py
@@ -0,0 +1,33 @@ 
+import os
+
+import infra.basetest
+
+
+class TestBats(infra.basetest.BRTest):
+    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+        """
+        BR2_ENABLE_LOCALE_WHITELIST=""
+        BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
+        BR2_PACKAGE_BASH=y
+        BR2_PACKAGE_BATS_CORE=y
+        BR2_PACKAGE_BATS_ASSERT=y
+        BR2_PACKAGE_BATS_FILE=y
+        BR2_ROOTFS_OVERLAY="{}"
+        BR2_TARGET_ROOTFS_CPIO=y
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """.format(
+           # overlay to add a gnuradio python test script
+           infra.filepath("tests/package/test_bats/rootfs-overlay"))
+
+    def test_run(self):
+        cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
+        self.emulator.boot(arch="armv5",
+                           kernel="builtin",
+                           options=["-initrd", cpio_file])
+        self.emulator.login()
+
+        self.assertRunOk("bats --version")
+
+        self.assertRunOk("bats /root/test-bats-core.bats", timeout=5)
+        self.assertRunOk("bats /root/test-bats-assert.bats", timeout=5)
+        self.assertRunOk("bats /root/test-bats-file.bats", timeout=5)
diff --git a/support/testing/tests/package/test_bats/rootfs-overlay/root/test-bats-assert.bats b/support/testing/tests/package/test_bats/rootfs-overlay/root/test-bats-assert.bats
new file mode 100755
index 0000000000..cd0cb48290
--- /dev/null
+++ b/support/testing/tests/package/test_bats/rootfs-overlay/root/test-bats-assert.bats
@@ -0,0 +1,11 @@ 
+#!/usr/bin/env bats
+
+setup() {
+    bats_load_library bats-support
+    bats_load_library bats-assert
+}
+
+@test "bats-assert assert_output" {
+    run echo "Hello World"
+    assert_output "Hello World"
+}
diff --git a/support/testing/tests/package/test_bats/rootfs-overlay/root/test-bats-core.bats b/support/testing/tests/package/test_bats/rootfs-overlay/root/test-bats-core.bats
new file mode 100755
index 0000000000..54ec941e03
--- /dev/null
+++ b/support/testing/tests/package/test_bats/rootfs-overlay/root/test-bats-core.bats
@@ -0,0 +1,11 @@ 
+#!/usr/bin/env bats
+
+@test "bats-core true" {
+    true
+}
+
+@test "bats-core run" {
+    run echo "Hello World"
+    [ "$status" -eq 0 ]
+    [ "$output" = "Hello World" ]
+}
diff --git a/support/testing/tests/package/test_bats/rootfs-overlay/root/test-bats-file.bats b/support/testing/tests/package/test_bats/rootfs-overlay/root/test-bats-file.bats
new file mode 100755
index 0000000000..0ac2616b99
--- /dev/null
+++ b/support/testing/tests/package/test_bats/rootfs-overlay/root/test-bats-file.bats
@@ -0,0 +1,10 @@ 
+#!/usr/bin/env bats
+
+setup() {
+    bats_load_library bats-support
+    bats_load_library bats-file
+}
+
+@test "bats-file assert_exists" {
+    assert_exists /root/test-bats-file.bats
+}