test_patch.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import os
  2. import infra.basetest
  3. class TestPatch(infra.basetest.BRTest):
  4. rootfs_overlay = \
  5. infra.filepath("tests/package/test_patch/rootfs-overlay")
  6. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  7. f"""
  8. BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
  9. BR2_PACKAGE_PATCH=y
  10. BR2_ROOTFS_OVERLAY="{rootfs_overlay}"
  11. BR2_TARGET_ROOTFS_CPIO=y
  12. # BR2_TARGET_ROOTFS_TAR is not set
  13. """
  14. def test_run(self):
  15. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  16. self.emulator.boot(arch="armv5",
  17. kernel="builtin",
  18. options=["-initrd", cpio_file])
  19. self.emulator.login()
  20. # Check the program can execute. This also checks that we are
  21. # not using the patch applet from BusyBox (as it does not
  22. # recognize the --version option).
  23. self.assertRunOk("patch --version")
  24. # We check the test file contains our expected string before
  25. # the patch.
  26. sed_cmd = "sed -n '2p' file.txt"
  27. out, ret = self.emulator.run(sed_cmd)
  28. self.assertEqual(ret, 0)
  29. self.assertEqual(out[0], "Hello World!")
  30. # We apply our test patch...
  31. self.assertRunOk("patch -p1 < file.diff")
  32. # We check the test file contains our expected string after
  33. # applying the patch.
  34. out, ret = self.emulator.run(sed_cmd)
  35. self.assertEqual(ret, 0)
  36. self.assertEqual(out[0], "Hello Buildroot!")