test_make.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import os
  2. import infra.basetest
  3. class TestMake(infra.basetest.BRTest):
  4. rootfs_overlay = \
  5. infra.filepath("tests/package/test_make/rootfs-overlay")
  6. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  7. f"""
  8. BR2_PACKAGE_MAKE=y
  9. BR2_ROOTFS_OVERLAY="{rootfs_overlay}"
  10. BR2_TARGET_ROOTFS_CPIO=y
  11. # BR2_TARGET_ROOTFS_TAR is not set
  12. """
  13. def gen_expected_str(self, count):
  14. """Return the expected string generated by the test Makefile"""
  15. return "".join(map(lambda x: str(x), range(1, count+1)))
  16. def test_run(self):
  17. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  18. self.emulator.boot(arch="armv5",
  19. kernel="builtin",
  20. options=["-initrd", cpio_file])
  21. self.emulator.login()
  22. # Check the program can execute.
  23. self.assertRunOk("make --version")
  24. # We touch the Makefile to set its modification time to the
  25. # current system time. This is to avoid warnings from Make
  26. # about having files with timestamps in the future. This is
  27. # because the minimal system running in the emulator might not
  28. # set the clock to the real time, and the Makefile has a
  29. # correct timestamp from the build host (which is likely at
  30. # the correct time).
  31. self.assertRunOk("touch Makefile")
  32. # We test the "message" target and check we get the expected
  33. # string.
  34. out, ret = self.emulator.run("make message")
  35. self.assertEqual(ret, 0)
  36. self.assertEqual(out[0], "Hello Buildroot!")
  37. # We redo the same test, this time by passing a new message
  38. # with a variable.
  39. msg = "This is Another Message..."
  40. out, ret = self.emulator.run(f"make message MESSAGE='{msg}'")
  41. self.assertEqual(ret, 0)
  42. self.assertEqual(out[0], msg)
  43. # We run a simple "make" invocation, using the defaults.
  44. self.assertRunOk("make")
  45. # We check the generated output contains the expected string.
  46. expected_str = self.gen_expected_str(10)
  47. out, ret = self.emulator.run("cat output.txt")
  48. self.assertEqual(ret, 0)
  49. self.assertEqual(out[0], expected_str)
  50. # Clean the previous invocation.
  51. self.assertRunOk("make clean")
  52. # We check a output generated file is no longer present.
  53. self.assertRunOk("test ! -e output.txt")
  54. # We run an invocation with a larger COUNT value. GNU Make
  55. # version 4.4 introduced the --shuffle option, which shuffle
  56. # rules. We use it with a constant seed, in order to have a
  57. # stable reshuffling in all test runs. We also include in this
  58. # execution a request for parallel jobs.
  59. count = 50
  60. seed = 123456
  61. self.assertRunOk(f"make -j10 --shuffle={seed} COUNT={count}")
  62. # Despite the pseudo-randomization in the previous invocation,
  63. # the expected output should be correctly ordered.
  64. expected_str = self.gen_expected_str(count)
  65. out, ret = self.emulator.run("cat output.txt")
  66. self.assertEqual(ret, 0)
  67. self.assertEqual(out[0], expected_str)