2
1

basetest.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import unittest
  2. import os
  3. import datetime
  4. from infra.builder import Builder
  5. from infra.emulator import Emulator
  6. BASIC_TOOLCHAIN_CONFIG = \
  7. """
  8. BR2_arm=y
  9. BR2_TOOLCHAIN_EXTERNAL=y
  10. BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
  11. BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
  12. BR2_TOOLCHAIN_EXTERNAL_URL="https://toolchains.bootlin.com/downloads/releases/toolchains/armv5-eabi/tarballs/armv5-eabi--uclibc--bleeding-edge-2018.11-1.tar.bz2"
  13. BR2_TOOLCHAIN_EXTERNAL_GCC_8=y
  14. BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_14=y
  15. BR2_TOOLCHAIN_EXTERNAL_LOCALE=y
  16. BR2_TOOLCHAIN_HAS_THREADS_DEBUG=y
  17. BR2_TOOLCHAIN_EXTERNAL_CXX=y
  18. """
  19. MINIMAL_CONFIG = \
  20. """
  21. BR2_INIT_NONE=y
  22. BR2_SYSTEM_BIN_SH_NONE=y
  23. # BR2_PACKAGE_BUSYBOX is not set
  24. # BR2_TARGET_ROOTFS_TAR is not set
  25. """
  26. class BRConfigTest(unittest.TestCase):
  27. """Test up to the configure stage."""
  28. config = None
  29. br2_external = list()
  30. downloaddir = None
  31. outputdir = None
  32. logtofile = True
  33. keepbuilds = False
  34. jlevel = 0
  35. timeout_multiplier = 1
  36. def __init__(self, names):
  37. super(BRConfigTest, self).__init__(names)
  38. self.testname = self.__class__.__name__
  39. self.builddir = self.outputdir and os.path.join(self.outputdir, self.testname)
  40. self.config += '\nBR2_DL_DIR="{}"\n'.format(self.downloaddir)
  41. self.config += "\nBR2_JLEVEL={}\n".format(self.jlevel)
  42. def show_msg(self, msg):
  43. print("{} {:40s} {}".format(datetime.datetime.now().strftime("%H:%M:%S"),
  44. self.testname, msg))
  45. def setUp(self):
  46. self.show_msg("Starting")
  47. self.b = Builder(self.config, self.builddir, self.logtofile)
  48. if not self.keepbuilds:
  49. self.b.delete()
  50. if not self.b.is_finished():
  51. self.b.configure(make_extra_opts=["BR2_EXTERNAL={}".format(":".join(self.br2_external))])
  52. def tearDown(self):
  53. self.show_msg("Cleaning up")
  54. if self.b and not self.keepbuilds:
  55. self.b.delete()
  56. class BRTest(BRConfigTest):
  57. """Test up to the build stage and instantiate an emulator."""
  58. def __init__(self, names):
  59. super(BRTest, self).__init__(names)
  60. self.emulator = None
  61. def setUp(self):
  62. super(BRTest, self).setUp()
  63. if not self.b.is_finished():
  64. self.show_msg("Building")
  65. self.b.build()
  66. self.show_msg("Building done")
  67. self.emulator = Emulator(self.builddir, self.downloaddir,
  68. self.logtofile, self.timeout_multiplier)
  69. def tearDown(self):
  70. if self.emulator:
  71. self.emulator.stop()
  72. super(BRTest, self).tearDown()
  73. # Run the given 'cmd' with a 'timeout' on the target and
  74. # assert that the command succeeded; on error, print the
  75. # faulty command and its output
  76. def assertRunOk(self, cmd, timeout=-1):
  77. out, exit_code = self.emulator.run(cmd, timeout)
  78. self.assertEqual(
  79. exit_code,
  80. 0,
  81. "\nFailed to run: {}\noutput was:\n{}".format(cmd, ' '+'\n '.join(out))
  82. )