1import os 2 3import infra.basetest 4 5 6class TestDos2Unix(infra.basetest.BRTest): 7 config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ 8 """ 9 BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y 10 BR2_PACKAGE_DOS2UNIX=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 # Check the program can run. This test also checks that we're 23 # using the real "dos2unix" rather than the applet provided in 24 # BusyBox, since the "--version" option is recognized by the 25 # real dos2unix and return an error in BusyBox. 26 self.assertRunOk("dos2unix --version") 27 28 # Create a text file with UNIX new-lines 29 self.assertRunOk("echo -e 'Hello\\nBuildroot' > original.txt") 30 31 # Convert the original UNIX file to DOS 32 self.assertRunOk("unix2dos -n original.txt dos.txt") 33 34 # DOS file is expected to be different than the UNIX file 35 _, exit_code = self.emulator.run("cmp original.txt dos.txt") 36 self.assertNotEqual(exit_code, 0) 37 38 # The "cat -A" command should print '^M$' for CR-LF 39 self.assertRunOk("cat -A dos.txt | grep -Fq '^M$'") 40 41 # Convert back DOS file to UNIX 42 self.assertRunOk("dos2unix -n dos.txt unix.txt") 43 44 # "unix.txt" should be identical to "original.txt" 45 self.assertRunOk("cmp original.txt unix.txt") 46