test_lsof.py 1.3 KB

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