1import os 2 3import infra.basetest 4 5 6class TestLsof(infra.basetest.BRTest): 7 config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ 8 """ 9 BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y 10 BR2_PACKAGE_LSOF=y 11 BR2_TARGET_ROOTFS_CPIO=y 12 # BR2_TARGET_ROOTFS_TAR is not set 13 """ 14 15 def test_run(self): 16 cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio") 17 self.emulator.boot(arch="armv5", 18 kernel="builtin", 19 options=["-initrd", cpio_file]) 20 self.emulator.login() 21 22 test_file = "/tmp/this-is-a-test-file" 23 24 # Check the program can execute 25 self.assertRunOk("lsof -v") 26 27 # Check a normal program invocation 28 self.assertRunOk("lsof") 29 30 # Check lsof fails if requested file is not opened 31 _, exit_code = self.emulator.run("lsof {}".format(test_file)) 32 self.assertNotEqual(exit_code, 0) 33 34 # Open the test file from the shell on descriptor 10 35 self.assertRunOk("exec 10> {}".format(test_file)) 36 37 # Check that lsof now show the file 38 output, exit_code = self.emulator.run("lsof {}".format(test_file)) 39 self.assertEqual(exit_code, 0) 40 # output[0] is the lsof header line 41 self.assertIn(test_file, output[1]) 42