Skip to contentSkip to conversation

support/testing: add assertRunOk method to BRTest class

PATCH New Patrick Havelange 2 participants 4 messages Nov 20, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 support/testing: add assertRunOk method to BRTest class

This method asserts that the given command ran successfully. The goal is for it to be used by the different tests when needed.

---
Changes
v1 -> v2
[Thomas
- Moved this function to the BRTest class
- Removed unnecessary "sh -c"

---
 support/testing/infra/basetest.py | 6 ++++++
 1 file changed, 6 insertions(+)
support/testing/infra/basetest.py +6 -0
index a176bc328a..023039f6af 100644
@@ -84,3 +84,9 @@ class BRTest(BRConfigTest):
         if self.emulator:
             self.emulator.stop()
         super(BRTest, self).tearDown()
+
+    # Run the given 'cmd' with a 'timeout' on the target and 
+    # assert that the command succeeded
+    def assertRunOk(self, cmd, timeout=-1):
+        _, exit_code = self.emulator.run(cmd, timeout)
+        self.assertEqual(exit_code, 0)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 2/2 support/testing: add lxc test

The test starts a simple container with an iperf3 server. The container is using the tini init system, with a shared rootfs. An iperf3 client is started from the host to check that the container is really up and running.

---
Changes
v1 -> v2
[Thomas
- Moved the assertRunOk function to the BRTest class

---
 .gitlab-ci.yml                                |  1 +
 support/testing/tests/package/test_lxc.py     | 56 +++++++++++++++++++
 .../tests/package/test_lxc/kernel_config_frag | 20 +++++++
 .../test_lxc_rootfs_overlay/usr/bin/iperf3.sh |  2 +
 .../usr/share/lxc/config/minimal-iperf3.conf  |  4 ++
 .../usr/share/lxc/config/minimal.conf         |  6 ++
 6 files changed, 89 insertions(+)
 create mode 100644 support/testing/tests/package/test_lxc.py
 create mode 100644 support/testing/tests/package/test_lxc/kernel_config_frag
 create mode 100755 support/testing/tests/package/test_lxc/test_lxc_rootfs_overlay/usr/bin/iperf3.sh
 create mode 100644 support/testing/tests/package/test_lxc/test_lxc_rootfs_overlay/usr/share/lxc/config/minimal-iperf3.conf
 create mode 100644 support/testing/tests/package/test_lxc/test_lxc_rootfs_overlay/usr/share/lxc/config/minimal.conf
.gitlab-ci.yml +1 -0
index 1d71257a20..9ef93130a1 100644
@@ -410,6 +410,7 @@ tests.package.test_luasocket.TestLuajitLuaSocket: { extends: .runtime_test }
 tests.package.test_luasyslog.TestLuaLuasyslog: { extends: .runtime_test }
 tests.package.test_luasyslog.TestLuajitLuasyslog: { extends: .runtime_test }
 tests.package.test_luvi.TestLuvi: { extends: .runtime_test }
+tests.package.test_lxc.TestLxc: { extends: .runtime_test }
 tests.package.test_lzlib.TestLuaLzlib: { extends: .runtime_test }
 tests.package.test_openjdk.TestOpenJdk: { extends: .runtime_test }
 tests.package.test_perl.TestPerl: { extends: .runtime_test }
support/testing/tests/package/test_lxc.py new file +56 -0

56 lines not on this page · raw message

support/testing/tests/package/test_lxc/kernel_config_frag new file +20 -0
new file mode 100644
index 0000000000..32f8bdd65e
@@ -0,0 +1,20 @@
+CONFIG_FIX_EARLYCON_MEM=y
+CONFIG_BLK_CGROUP=y
+CONFIG_CGROUP_SCHED=y
+CONFIG_CGROUP_PIDS=y
+CONFIG_CGROUP_FREEZER=y
+CONFIG_CGROUP_DEVICE=y
+CONFIG_CGROUP_CPUACCT=y
+CONFIG_CGROUP_DEBUG=y
+CONFIG_NETFILTER_XT_MATCH_CGROUP=y
+CONFIG_SOCK_CGROUP_DATA=y
+CONFIG_CGROUP_NET_PRIO=y
+CONFIG_CGROUP_NET_CLASSID=y
+CONFIG_NAMESPACES=y
+CONFIG_IPC_NS=y
+CONFIG_PID_NS=y
+CONFIG_UTS_NS=y
+CONFIG_USER_NS=y
+CONFIG_NET_NS=y
+CONFIG_BRIDGE=y
+CONFIG_VETH=y
support/testing/tests/package/test_lxc/test_lxc_rootfs_overlay/usr/bin/iperf3.sh new file +2 -0
new file mode 100755
index 0000000000..7045ca4806
@@ -0,0 +1,2 @@
+#!/bin/sh
+iperf3 -s -1 > /tmp/iperf3.serv.log 2>&1
support/testing/tests/package/test_lxc/test_lxc_rootfs_overlay/usr/share/lxc/config/minimal-iperf3.conf new file +4 -0
new file mode 100644
index 0000000000..41cc5311d6
@@ -0,0 +1,4 @@
+lxc.include = /usr/share/lxc/config/minimal.conf
+lxc.hook.version = 1
+lxc.hook.start-host = ip a add 192.168.1.1/24 dev lxc0
+lxc.init.cmd = tini -g iperf3.sh
support/testing/tests/package/test_lxc/test_lxc_rootfs_overlay/usr/share/lxc/config/minimal.conf new file +6 -0
new file mode 100644
index 0000000000..7319821506
@@ -0,0 +1,6 @@
+lxc.autodev = 0
+lxc.net.0.type = veth
+lxc.net.0.veth.pair = lxc0
+lxc.net.0.name = eth0
+lxc.net.0.flags = up
+lxc.net.0.ipv4.address = 192.168.1.2/24
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 2/2 support/testing: add lxc test

Hello Patrick,

Quoted 6 lines · On Wed, 20 Nov 2019 14:39:52 +0100 Patrick Havelange…

The test starts a simple container with an iperf3 server. The container is using the tini init system, with a shared rootfs. An iperf3 client is started from the host to check that the container is really up and running.

I've applied to next, after doing some small changes. See below.

Quoted 7 lines
 .gitlab-ci.yml                                |  1 +
 support/testing/tests/package/test_lxc.py     | 56 +++++++++++++++++++
 .../tests/package/test_lxc/kernel_config_frag | 20 +++++++
 .../test_lxc_rootfs_overlay/usr/bin/iperf3.sh |  2 +
 .../usr/share/lxc/config/minimal-iperf3.conf  |  4 ++
 .../usr/share/lxc/config/minimal.conf         |  6 ++
 6 files changed, 89 insertions(+)

An entry in the DEVELOPERS file was missing, so I added it.

Quoted 1 line

+ infra.filepath("tests/package/test_lxc/kernel_config_frag"),

This file name was not really great. The other kernel config fragments in our tests were named like this:

./conf/minimal-x86-qemu-kernel.config
./conf/docker-compose-kernel.config
./conf/f2fs-kernel-fragment.config
./tests/core/squashfs-xattr-kernel.config

So I renamed your to:

./tests/package/test_lxc/lxc-kernel.config

Quoted 1 line

+ infra.filepath("tests/package/test_lxc/test_lxc_rootfs_overlay"))

Repeating the name of the test in the rootfs overlay subdirectory doesn't seem to be very useful. Also, the other overlays we have in the tests use rootfs-overlay, so I've switched to that as well.

Applied to next with those changes. Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw

PATCH v2 1/2 support/testing: add assertRunOk method to BRTest class

In reply to Patrick Havelange
Quoted 11 lines · On Wed, 20 Nov 2019 14:39:51 +0100 Patrick Havelange…

This method asserts that the given command ran successfully. The goal is for it to be used by the different tests when needed.

---
Changes
v1 -> v2
[Thomas
- Moved this function to the BRTest class
- Removed unnecessary "sh -c"

Quoted 3 lines
---
 support/testing/infra/basetest.py | 6 ++++++
 1 file changed, 6 insertions(+)

Applied to next, thanks.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com