1import os
2
3import infra.basetest
4
5
6class TestBash(infra.basetest.BRTest):
7    config = \
8        """
9        BR2_arm=y
10        BR2_TOOLCHAIN_EXTERNAL=y
11        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
12        BR2_ENABLE_LOCALE_WHITELIST=""
13        BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
14        BR2_PACKAGE_BASH=y
15        BR2_TARGET_ROOTFS_CPIO=y
16        # BR2_TARGET_ROOTFS_TAR is not set
17        """
18
19    def test_run(self):
20        cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
21        self.emulator.boot(arch="armv5",
22                           kernel="builtin",
23                           options=["-initrd", cpio_file])
24        self.emulator.login()
25
26        # Check that we are indeed not (yet) running bash
27        out, _ = self.emulator.run('echo "${BASH}"')
28        self.assertEqual(out[0], "", "Already running bash instead of busybox' sh")
29
30        self.assertRunOk("bash -il")
31        # Twist! The above command is still runing, it's just that
32        # bash did display the prompt we expect. Check we are indeed
33        # actually bash
34        out, _ = self.emulator.run('echo "${BASH}"')
35        self.assertEqual(out[0], "/bin/bash", "Not running bash")
36        # Exit bash, back to busybox' shell
37        self.emulator.run("exit 0")
38
39        # Check that we are indeed no longer running bash
40        out, _ = self.emulator.run('echo "${BASH}"')
41        self.assertEqual(out[0], "", "Still running bash instead of busybox' sh")
42
43        # Try to run with a non-available locale
44        self.assertRunOk("LC_ALL=en_US bash -il")
45        out, _ = self.emulator.run('echo "${BASH}"')
46        self.assertEqual(out[0], "/bin/bash", "Not running bash")
47        self.emulator.run("exit 0")
48