Skip to contentSkip to conversation

test-runner: mount testhome rather than assume location

PATCH New James Prestwood 1 participant 5 messages May 25, 2022

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH 1/5 test-runner: mount testhome rather than assume location

Usually the test home directory is a git repo somewhere e.g. under /home. But if the home directory is located under /tmp this poses a problem since UML remounts /tmp. To handle both cases mount the home directory explicity.

---
 tools/runner.py | 6 ++++++
 1 file changed, 6 insertions(+)
tools/runner.py +6 -0
index 7c177f1f..5f837097 100644
@@ -451,6 +451,9 @@ class QemuRunner(RunnerAbstract):
 	def prepare_environment(self):
 		mounts = [ MountInfo('debugfs', 'debugfs', '/sys/kernel/debug', '', 0) ]
 
+		mounts.append(MountInfo('hostfs', 'hostfs', self.args.testhome,
+					self.args.testhome, 0))
+
 		if self.args.log:
 			mounts.append(MountInfo('9p', 'logdir', self.args.log,
 					'trans=virtio,version=9p2000.L,msize=10240', 0))
@@ -513,6 +516,9 @@ class UmlRunner(RunnerAbstract):
 			mounts.append(MountInfo('hostfs', 'hostfs', self.args.result_parent,
 						self.args.result_parent, 0))
 
+		mounts.append(MountInfo('hostfs', 'hostfs', self.args.testhome,
+					self.args.testhome, 0))
+
 		self._prepare_mounts(extra=mounts)
 
 		super().prepare_environment()
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 2/5 test-runner: disallow result/monitor/log directly under /tmp

Inside the virtual environments /tmp is mounted as its own FS and not taken from the host. This poses issues if any output files are directly under /tmp since test-runner tries to mount the parent directory (/tmp). The can be fixed by ensuring these output files are either not under /tmp or at least one folder down the tree (e.g. /tmp/outputs/outfile.txt).

Now this requirement is enforced and test-runner will not start if any output files parent directory is /tmp.

---
 tools/runner.py | 7 +++++++
 1 file changed, 7 insertions(+)
tools/runner.py +7 -0
index 5f837097..90818ef1 100644
@@ -311,6 +311,9 @@ class RunnerAbstract:
 		gid = int(os.environ.get('SUDO_GID', os.getgid()))
 
 		if self.args.log:
+			if self.args.log == '/tmp':
+				raise Exception('Log directly cannot be /tmp')
+
 			append_gid_uid = True
 
 			if not os.path.exists(self.args.log):
@@ -324,12 +327,16 @@ class RunnerAbstract:
 
 			self.args.monitor_parent = os.path.abspath(
 						os.path.join(self.args.monitor, os.pardir))
+			if self.args.monitor_parent == '/tmp':
+				raise Exception('--monitor cannot be directly under /tmp')
 
 		if self.args.result:
 			append_gid_uid = True
 
 			self.args.result_parent = os.path.abspath(
 						os.path.join(self.args.result, os.pardir))
+			if self.args.result_parent == '/tmp':
+				raise Exception('--result cannot be directly under /tmp')
 
 		if append_gid_uid:
 			self.args.SUDO_UID = uid
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 3/5 test-runner: skip mounting duplicate folders

In reply to James Prestwood

If the user specifies the same parent directory for several outfiles skip mounting since it already exists. For example:

--monitor /outfiles/monitor.txt --result /outfiles/result.txt

---
 tools/runner.py | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/runner.py +8 -0
index 90818ef1..bf28d9ad 100644
@@ -289,7 +289,13 @@ class RunnerAbstract:
 
 	# For QEMU/UML runners
 	def _prepare_mounts(self, extra=[]):
+		mounted = []
+
 		for entry in mounts_common + extra:
+			if entry.target in mounted:
+				print("%s already mounted, skipping" % entry.target)
+				continue
+
 			try:
 				os.lstat(entry.target)
 			except:
@@ -298,6 +304,8 @@ class RunnerAbstract:
 			mount(entry.source, entry.target, entry.fstype, entry.flags,
 				entry.options)
 
+			mounted.append(entry.target)
+
 		for entry in dev_table:
 			os.symlink(entry.target, entry.linkpath)
 
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH 4/5 auto-t: use copy_to_storage in address randomization test

In reply to James Prestwood

This test was just piping the PSK files into /tmp/iwd/ssidCCMP.psk which is a bit fragile if the storage dir was ever to change. Instead use copy_to_storage and the 'name' keyword to copy the file.

---
 autotests/testAddressRandomization/connection_test.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
autotests/testAddressRandomization/connection_test.py +3 -3
index 32163e0f..f9f62f7a 100644
@@ -46,7 +46,7 @@ class Test(unittest.TestCase):
         perm_addr = device.address
 
         # 1. Test per-network deterministic MAC generation
-        os.system('cat pernetwork.psk > /tmp/iwd/ssidCCMP.psk')
+        IWD.copy_to_storage('pernetwork.psk', name='ssidCCMP.psk')
         new_addr = self.try_connection(wd)
         self.assertNotEqual(perm_addr, new_addr)
         # try again to ensure the generation was deterministic
@@ -54,7 +54,7 @@ class Test(unittest.TestCase):
         self.assertEqual(new_addr, new_addr2)
 
         # 2. Test FullAddressRandomization
-        os.system('cat full_random.psk > /tmp/iwd/ssidCCMP.psk')
+        IWD.copy_to_storage('full_random.psk', name='ssidCCMP.psk')
         new_addr = self.try_connection(wd)
         self.assertNotEqual(perm_addr, new_addr)
         # try again to make sure the generation was random
@@ -62,7 +62,7 @@ class Test(unittest.TestCase):
         self.assertNotEqual(new_addr, new_addr2)
 
         # 3. Test AddressOverride
-        os.system('cat override.psk > /tmp/iwd/ssidCCMP.psk')
+        IWD.copy_to_storage('override.psk', name='ssidCCMP.psk')
         new_addr = self.try_connection(wd)
         self.assertEqual(new_addr, 'e6:f6:38:a9:02:02')
 
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH 5/5 auto-t: fix testRSSIAgent after signal agent changes

In reply to James Prestwood

The signal agent notifications were changed which breaks this test. Specifically commit ce227e7b94 sends a notification when connected which breaks the 'agent.calls' check. Since this check is done both after connecting and once already connected the initial value may be 1 or 0. Because of this that check was removed entirely.

---
 autotests/testRSSIAgent/connection_test.py | 1 -
 1 file changed, 1 deletion(-)
autotests/testRSSIAgent/connection_test.py +0 -1
index 160a17b3..4ffa3d2c 100644
@@ -56,7 +56,6 @@ class Test(unittest.TestCase):
             # at least) uses a moving-window average value over the last RSSI
             # measurements received from the driver and it changes gradually.
             # Normally 1 second is enough.
-            self.assertEqual(agent.calls, 0)
             for centre, level in rssi_pairs:
                 rule.signal = centre
                 agent.level = -1
Signature · 1 line
2.34.1