basetest.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 BRTest(unittest.TestCase):
  27. config = None
  28. downloaddir = None
  29. outputdir = None
  30. logtofile = True
  31. keepbuilds = False
  32. jlevel = 0
  33. timeout_multiplier = 1
  34. def __init__(self, names):
  35. super(BRTest, self).__init__(names)
  36. self.testname = self.__class__.__name__
  37. self.builddir = self.outputdir and os.path.join(self.outputdir, self.testname)
  38. self.emulator = None
  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.show_msg("Building")
  51. self.b.configure()
  52. self.b.build()
  53. self.show_msg("Building done")
  54. self.emulator = Emulator(self.builddir, self.downloaddir,
  55. self.logtofile, self.timeout_multiplier)
  56. def tearDown(self):
  57. self.show_msg("Cleaning up")
  58. if self.emulator:
  59. self.emulator.stop()
  60. if self.b and not self.keepbuilds:
  61. self.b.delete()