test_dos2unix.py 1.6 KB

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