test_bash.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import os
  2. import infra.basetest
  3. class TestBash(infra.basetest.BRTest):
  4. config = \
  5. """
  6. BR2_arm=y
  7. BR2_TOOLCHAIN_EXTERNAL=y
  8. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
  9. BR2_ENABLE_LOCALE_WHITELIST=""
  10. BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
  11. BR2_PACKAGE_BASH=y
  12. BR2_TARGET_ROOTFS_CPIO=y
  13. # BR2_TARGET_ROOTFS_TAR is not set
  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. # Check that we are indeed not (yet) running bash
  22. out, _ = self.emulator.run('echo "${BASH}"')
  23. self.assertEqual(out[0], "", "Already running bash instead of busybox' sh")
  24. self.assertRunOk("bash -il")
  25. # Twist! The above command is still runing, it's just that
  26. # bash did display the prompt we expect. Check we are indeed
  27. # actually bash
  28. out, _ = self.emulator.run('echo "${BASH}"')
  29. self.assertEqual(out[0], "/bin/bash", "Not running bash")
  30. # Exit bash, back to busybox' shell
  31. self.emulator.run("exit 0")
  32. # Check that we are indeed no longer running bash
  33. out, _ = self.emulator.run('echo "${BASH}"')
  34. self.assertEqual(out[0], "", "Still running bash instead of busybox' sh")
  35. # Try to run with a non-available locale
  36. self.assertRunOk("LC_ALL=en_US bash -il")
  37. out, _ = self.emulator.run('echo "${BASH}"')
  38. self.assertEqual(out[0], "/bin/bash", "Not running bash")
  39. self.emulator.run("exit 0")