basetest.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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="http://autobuild.buildroot.org/toolchains/tarballs/br-arm-full-2017.05-1078-g95b1dae.tar.bz2"
  13. BR2_TOOLCHAIN_EXTERNAL_GCC_4_9=y
  14. BR2_TOOLCHAIN_EXTERNAL_HEADERS_3_10=y
  15. BR2_TOOLCHAIN_EXTERNAL_LOCALE=y
  16. # BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set
  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. config = None
  28. br2_external = list()
  29. downloaddir = None
  30. outputdir = None
  31. logtofile = True
  32. keepbuilds = False
  33. jlevel = 0
  34. timeout_multiplier = 1
  35. def __init__(self, names):
  36. super(BRConfigTest, self).__init__(names)
  37. self.testname = self.__class__.__name__
  38. self.builddir = self.outputdir and os.path.join(self.outputdir, self.testname)
  39. self.config += '\nBR2_DL_DIR="{}"\n'.format(self.downloaddir)
  40. self.config += "\nBR2_JLEVEL={}\n".format(self.jlevel)
  41. def show_msg(self, msg):
  42. print("{} {:40s} {}".format(datetime.datetime.now().strftime("%H:%M:%S"),
  43. self.testname, msg))
  44. def setUp(self):
  45. self.show_msg("Starting")
  46. self.b = Builder(self.config, self.builddir, self.logtofile)
  47. if not self.keepbuilds:
  48. self.b.delete()
  49. if not self.b.is_finished():
  50. self.b.configure(make_extra_opts=["BR2_EXTERNAL={}".format(":".join(self.br2_external))])
  51. def tearDown(self):
  52. self.show_msg("Cleaning up")
  53. if self.b and not self.keepbuilds:
  54. self.b.delete()
  55. class BRTest(BRConfigTest):
  56. def __init__(self, names):
  57. super(BRTest, self).__init__(names)
  58. self.emulator = None
  59. def setUp(self):
  60. super(BRTest, self).setUp()
  61. if not self.b.is_finished():
  62. self.show_msg("Building")
  63. self.b.build()
  64. self.show_msg("Building done")
  65. self.emulator = Emulator(self.builddir, self.downloaddir,
  66. self.logtofile, self.timeout_multiplier)
  67. def tearDown(self):
  68. if self.emulator:
  69. self.emulator.stop()
  70. super(BRTest, self).tearDown()