func_test.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright (c) 2014 Google, Inc
  3. #
  4. import os
  5. import shutil
  6. import sys
  7. import tempfile
  8. import unittest
  9. from buildman import board
  10. from buildman import bsettings
  11. from buildman import cmdline
  12. from buildman import control
  13. from buildman import toolchain
  14. from patman import command
  15. from patman import gitutil
  16. from patman import terminal
  17. from patman import test_util
  18. from patman import tools
  19. settings_data = '''
  20. # Buildman settings file
  21. [toolchain]
  22. [toolchain-alias]
  23. [make-flags]
  24. src=/home/sjg/c/src
  25. chroot=/home/sjg/c/chroot
  26. vboot=VBOOT_DEBUG=1 MAKEFLAGS_VBOOT=DEBUG=1 CFLAGS_EXTRA_VBOOT=-DUNROLL_LOOPS VBOOT_SOURCE=${src}/platform/vboot_reference
  27. chromeos_coreboot=VBOOT=${chroot}/build/link/usr ${vboot}
  28. chromeos_daisy=VBOOT=${chroot}/build/daisy/usr ${vboot}
  29. chromeos_peach=VBOOT=${chroot}/build/peach_pit/usr ${vboot}
  30. '''
  31. boards = [
  32. ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''],
  33. ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''],
  34. ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''],
  35. ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''],
  36. ]
  37. commit_shortlog = """4aca821 patman: Avoid changing the order of tags
  38. 39403bb patman: Use --no-pager' to stop git from forking a pager
  39. db6e6f2 patman: Remove the -a option
  40. f2ccf03 patman: Correct unit tests to run correctly
  41. 1d097f9 patman: Fix indentation in terminal.py
  42. d073747 patman: Support the 'reverse' option for 'git log
  43. """
  44. commit_log = ["""commit 7f6b8315d18f683c5181d0c3694818c1b2a20dcd
  45. Author: Masahiro Yamada <yamada.m@jp.panasonic.com>
  46. Date: Fri Aug 22 19:12:41 2014 +0900
  47. buildman: refactor help message
  48. "buildman [options]" is displayed by default.
  49. Append the rest of help messages to parser.usage
  50. instead of replacing it.
  51. Besides, "-b <branch>" is not mandatory since commit fea5858e.
  52. Drop it from the usage.
  53. Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
  54. """,
  55. """commit d0737479be6baf4db5e2cdbee123e96bc5ed0ba8
  56. Author: Simon Glass <sjg@chromium.org>
  57. Date: Thu Aug 14 16:48:25 2014 -0600
  58. patman: Support the 'reverse' option for 'git log'
  59. This option is currently not supported, but needs to be, for buildman to
  60. operate as expected.
  61. Series-changes: 7
  62. - Add new patch to fix the 'reverse' bug
  63. Series-version: 8
  64. Change-Id: I79078f792e8b390b8a1272a8023537821d45feda
  65. Reported-by: York Sun <yorksun@freescale.com>
  66. Signed-off-by: Simon Glass <sjg@chromium.org>
  67. """,
  68. """commit 1d097f9ab487c5019152fd47bda126839f3bf9fc
  69. Author: Simon Glass <sjg@chromium.org>
  70. Date: Sat Aug 9 11:44:32 2014 -0600
  71. patman: Fix indentation in terminal.py
  72. This code came from a different project with 2-character indentation. Fix
  73. it for U-Boot.
  74. Series-changes: 6
  75. - Add new patch to fix indentation in teminal.py
  76. Change-Id: I5a74d2ebbb3cc12a665f5c725064009ac96e8a34
  77. Signed-off-by: Simon Glass <sjg@chromium.org>
  78. """,
  79. """commit f2ccf03869d1e152c836515a3ceb83cdfe04a105
  80. Author: Simon Glass <sjg@chromium.org>
  81. Date: Sat Aug 9 11:08:24 2014 -0600
  82. patman: Correct unit tests to run correctly
  83. It seems that doctest behaves differently now, and some of the unit tests
  84. do not run. Adjust the tests to work correctly.
  85. ./tools/patman/patman --test
  86. <unittest.result.TestResult run=10 errors=0 failures=0>
  87. Series-changes: 6
  88. - Add new patch to fix patman unit tests
  89. Change-Id: I3d2ca588f4933e1f9d6b1665a00e4ae58269ff3b
  90. """,
  91. """commit db6e6f2f9331c5a37647d6668768d4a40b8b0d1c
  92. Author: Simon Glass <sjg@chromium.org>
  93. Date: Sat Aug 9 12:06:02 2014 -0600
  94. patman: Remove the -a option
  95. It seems that this is no longer needed, since checkpatch.pl will catch
  96. whitespace problems in patches. Also the option is not widely used, so
  97. it seems safe to just remove it.
  98. Series-changes: 6
  99. - Add new patch to remove patman's -a option
  100. Suggested-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
  101. Change-Id: I5821a1c75154e532c46513486ca40b808de7e2cc
  102. """,
  103. """commit 39403bb4f838153028a6f21ca30bf100f3791133
  104. Author: Simon Glass <sjg@chromium.org>
  105. Date: Thu Aug 14 21:50:52 2014 -0600
  106. patman: Use --no-pager' to stop git from forking a pager
  107. """,
  108. """commit 4aca821e27e97925c039e69fd37375b09c6f129c
  109. Author: Simon Glass <sjg@chromium.org>
  110. Date: Fri Aug 22 15:57:39 2014 -0600
  111. patman: Avoid changing the order of tags
  112. patman collects tags that it sees in the commit and places them nicely
  113. sorted at the end of the patch. However, this is not really necessary and
  114. in fact is apparently not desirable.
  115. Series-changes: 9
  116. - Add new patch to avoid changing the order of tags
  117. Series-version: 9
  118. Suggested-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
  119. Change-Id: Ib1518588c1a189ad5c3198aae76f8654aed8d0db
  120. """]
  121. TEST_BRANCH = '__testbranch'
  122. class TestFunctional(unittest.TestCase):
  123. """Functional test for buildman.
  124. This aims to test from just below the invocation of buildman (parsing
  125. of arguments) to 'make' and 'git' invocation. It is not a true
  126. emd-to-end test, as it mocks git, make and the tool chain. But this
  127. makes it easier to detect when the builder is doing the wrong thing,
  128. since in many cases this test code will fail. For example, only a
  129. very limited subset of 'git' arguments is supported - anything
  130. unexpected will fail.
  131. """
  132. def setUp(self):
  133. self._base_dir = tempfile.mkdtemp()
  134. self._output_dir = tempfile.mkdtemp()
  135. self._git_dir = os.path.join(self._base_dir, 'src')
  136. self._buildman_pathname = sys.argv[0]
  137. self._buildman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
  138. command.test_result = self._HandleCommand
  139. self.setupToolchains()
  140. self._toolchains.Add('arm-gcc', test=False)
  141. self._toolchains.Add('powerpc-gcc', test=False)
  142. bsettings.Setup(None)
  143. bsettings.AddFile(settings_data)
  144. self._boards = board.Boards()
  145. for brd in boards:
  146. self._boards.AddBoard(board.Board(*brd))
  147. # Directories where the source been cloned
  148. self._clone_dirs = []
  149. self._commits = len(commit_shortlog.splitlines()) + 1
  150. self._total_builds = self._commits * len(boards)
  151. # Number of calls to make
  152. self._make_calls = 0
  153. # Map of [board, commit] to error messages
  154. self._error = {}
  155. self._test_branch = TEST_BRANCH
  156. # Avoid sending any output and clear all terminal output
  157. terminal.SetPrintTestMode()
  158. terminal.GetPrintTestLines()
  159. def tearDown(self):
  160. shutil.rmtree(self._base_dir)
  161. #shutil.rmtree(self._output_dir)
  162. def setupToolchains(self):
  163. self._toolchains = toolchain.Toolchains()
  164. self._toolchains.Add('gcc', test=False)
  165. def _RunBuildman(self, *args):
  166. return command.RunPipe([[self._buildman_pathname] + list(args)],
  167. capture=True, capture_stderr=True)
  168. def _RunControl(self, *args, boards=None, clean_dir=False,
  169. test_thread_exceptions=False):
  170. """Run buildman
  171. Args:
  172. args: List of arguments to pass
  173. boards:
  174. clean_dir: Used for tests only, indicates that the existing output_dir
  175. should be removed before starting the build
  176. test_thread_exceptions: Uses for tests only, True to make the threads
  177. raise an exception instead of reporting their result. This simulates
  178. a failure in the code somewhere
  179. Returns:
  180. result code from buildman
  181. """
  182. sys.argv = [sys.argv[0]] + list(args)
  183. options, args = cmdline.ParseArgs()
  184. result = control.DoBuildman(options, args, toolchains=self._toolchains,
  185. make_func=self._HandleMake, boards=boards or self._boards,
  186. clean_dir=clean_dir,
  187. test_thread_exceptions=test_thread_exceptions)
  188. self._builder = control.builder
  189. return result
  190. def testFullHelp(self):
  191. command.test_result = None
  192. result = self._RunBuildman('-H')
  193. help_file = os.path.join(self._buildman_dir, 'README')
  194. # Remove possible extraneous strings
  195. extra = '::::::::::::::\n' + help_file + '\n::::::::::::::\n'
  196. gothelp = result.stdout.replace(extra, '')
  197. self.assertEqual(len(gothelp), os.path.getsize(help_file))
  198. self.assertEqual(0, len(result.stderr))
  199. self.assertEqual(0, result.return_code)
  200. def testHelp(self):
  201. command.test_result = None
  202. result = self._RunBuildman('-h')
  203. help_file = os.path.join(self._buildman_dir, 'README')
  204. self.assertTrue(len(result.stdout) > 1000)
  205. self.assertEqual(0, len(result.stderr))
  206. self.assertEqual(0, result.return_code)
  207. def testGitSetup(self):
  208. """Test gitutils.Setup(), from outside the module itself"""
  209. command.test_result = command.CommandResult(return_code=1)
  210. gitutil.Setup()
  211. self.assertEqual(gitutil.use_no_decorate, False)
  212. command.test_result = command.CommandResult(return_code=0)
  213. gitutil.Setup()
  214. self.assertEqual(gitutil.use_no_decorate, True)
  215. def _HandleCommandGitLog(self, args):
  216. if args[-1] == '--':
  217. args = args[:-1]
  218. if '-n0' in args:
  219. return command.CommandResult(return_code=0)
  220. elif args[-1] == 'upstream/master..%s' % self._test_branch:
  221. return command.CommandResult(return_code=0, stdout=commit_shortlog)
  222. elif args[:3] == ['--no-color', '--no-decorate', '--reverse']:
  223. if args[-1] == self._test_branch:
  224. count = int(args[3][2:])
  225. return command.CommandResult(return_code=0,
  226. stdout=''.join(commit_log[:count]))
  227. # Not handled, so abort
  228. print('git log', args)
  229. sys.exit(1)
  230. def _HandleCommandGitConfig(self, args):
  231. config = args[0]
  232. if config == 'sendemail.aliasesfile':
  233. return command.CommandResult(return_code=0)
  234. elif config.startswith('branch.badbranch'):
  235. return command.CommandResult(return_code=1)
  236. elif config == 'branch.%s.remote' % self._test_branch:
  237. return command.CommandResult(return_code=0, stdout='upstream\n')
  238. elif config == 'branch.%s.merge' % self._test_branch:
  239. return command.CommandResult(return_code=0,
  240. stdout='refs/heads/master\n')
  241. # Not handled, so abort
  242. print('git config', args)
  243. sys.exit(1)
  244. def _HandleCommandGit(self, in_args):
  245. """Handle execution of a git command
  246. This uses a hacked-up parser.
  247. Args:
  248. in_args: Arguments after 'git' from the command line
  249. """
  250. git_args = [] # Top-level arguments to git itself
  251. sub_cmd = None # Git sub-command selected
  252. args = [] # Arguments to the git sub-command
  253. for arg in in_args:
  254. if sub_cmd:
  255. args.append(arg)
  256. elif arg[0] == '-':
  257. git_args.append(arg)
  258. else:
  259. if git_args and git_args[-1] in ['--git-dir', '--work-tree']:
  260. git_args.append(arg)
  261. else:
  262. sub_cmd = arg
  263. if sub_cmd == 'config':
  264. return self._HandleCommandGitConfig(args)
  265. elif sub_cmd == 'log':
  266. return self._HandleCommandGitLog(args)
  267. elif sub_cmd == 'clone':
  268. return command.CommandResult(return_code=0)
  269. elif sub_cmd == 'checkout':
  270. return command.CommandResult(return_code=0)
  271. elif sub_cmd == 'worktree':
  272. return command.CommandResult(return_code=0)
  273. # Not handled, so abort
  274. print('git', git_args, sub_cmd, args)
  275. sys.exit(1)
  276. def _HandleCommandNm(self, args):
  277. return command.CommandResult(return_code=0)
  278. def _HandleCommandObjdump(self, args):
  279. return command.CommandResult(return_code=0)
  280. def _HandleCommandObjcopy(self, args):
  281. return command.CommandResult(return_code=0)
  282. def _HandleCommandSize(self, args):
  283. return command.CommandResult(return_code=0)
  284. def _HandleCommand(self, **kwargs):
  285. """Handle a command execution.
  286. The command is in kwargs['pipe-list'], as a list of pipes, each a
  287. list of commands. The command should be emulated as required for
  288. testing purposes.
  289. Returns:
  290. A CommandResult object
  291. """
  292. pipe_list = kwargs['pipe_list']
  293. wc = False
  294. if len(pipe_list) != 1:
  295. if pipe_list[1] == ['wc', '-l']:
  296. wc = True
  297. else:
  298. print('invalid pipe', kwargs)
  299. sys.exit(1)
  300. cmd = pipe_list[0][0]
  301. args = pipe_list[0][1:]
  302. result = None
  303. if cmd == 'git':
  304. result = self._HandleCommandGit(args)
  305. elif cmd == './scripts/show-gnu-make':
  306. return command.CommandResult(return_code=0, stdout='make')
  307. elif cmd.endswith('nm'):
  308. return self._HandleCommandNm(args)
  309. elif cmd.endswith('objdump'):
  310. return self._HandleCommandObjdump(args)
  311. elif cmd.endswith('objcopy'):
  312. return self._HandleCommandObjcopy(args)
  313. elif cmd.endswith( 'size'):
  314. return self._HandleCommandSize(args)
  315. if not result:
  316. # Not handled, so abort
  317. print('unknown command', kwargs)
  318. sys.exit(1)
  319. if wc:
  320. result.stdout = len(result.stdout.splitlines())
  321. return result
  322. def _HandleMake(self, commit, brd, stage, cwd, *args, **kwargs):
  323. """Handle execution of 'make'
  324. Args:
  325. commit: Commit object that is being built
  326. brd: Board object that is being built
  327. stage: Stage that we are at (mrproper, config, build)
  328. cwd: Directory where make should be run
  329. args: Arguments to pass to make
  330. kwargs: Arguments to pass to command.RunPipe()
  331. """
  332. self._make_calls += 1
  333. if stage == 'mrproper':
  334. return command.CommandResult(return_code=0)
  335. elif stage == 'config':
  336. return command.CommandResult(return_code=0,
  337. combined='Test configuration complete')
  338. elif stage == 'build':
  339. stderr = ''
  340. out_dir = ''
  341. for arg in args:
  342. if arg.startswith('O='):
  343. out_dir = arg[2:]
  344. fname = os.path.join(cwd or '', out_dir, 'u-boot')
  345. tools.WriteFile(fname, b'U-Boot')
  346. if type(commit) is not str:
  347. stderr = self._error.get((brd.target, commit.sequence))
  348. if stderr:
  349. return command.CommandResult(return_code=1, stderr=stderr)
  350. return command.CommandResult(return_code=0)
  351. # Not handled, so abort
  352. print('make', stage)
  353. sys.exit(1)
  354. # Example function to print output lines
  355. def print_lines(self, lines):
  356. print(len(lines))
  357. for line in lines:
  358. print(line)
  359. #self.print_lines(terminal.GetPrintTestLines())
  360. def testNoBoards(self):
  361. """Test that buildman aborts when there are no boards"""
  362. self._boards = board.Boards()
  363. with self.assertRaises(SystemExit):
  364. self._RunControl()
  365. def testCurrentSource(self):
  366. """Very simple test to invoke buildman on the current source"""
  367. self.setupToolchains();
  368. self._RunControl('-o', self._output_dir)
  369. lines = terminal.GetPrintTestLines()
  370. self.assertIn('Building current source for %d boards' % len(boards),
  371. lines[0].text)
  372. def testBadBranch(self):
  373. """Test that we can detect an invalid branch"""
  374. with self.assertRaises(ValueError):
  375. self._RunControl('-b', 'badbranch')
  376. def testBadToolchain(self):
  377. """Test that missing toolchains are detected"""
  378. self.setupToolchains();
  379. ret_code = self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir)
  380. lines = terminal.GetPrintTestLines()
  381. # Buildman always builds the upstream commit as well
  382. self.assertIn('Building %d commits for %d boards' %
  383. (self._commits, len(boards)), lines[0].text)
  384. self.assertEqual(self._builder.count, self._total_builds)
  385. # Only sandbox should succeed, the others don't have toolchains
  386. self.assertEqual(self._builder.fail,
  387. self._total_builds - self._commits)
  388. self.assertEqual(ret_code, 100)
  389. for commit in range(self._commits):
  390. for board in self._boards.GetList():
  391. if board.arch != 'sandbox':
  392. errfile = self._builder.GetErrFile(commit, board.target)
  393. fd = open(errfile)
  394. self.assertEqual(fd.readlines(),
  395. ['No tool chain for %s\n' % board.arch])
  396. fd.close()
  397. def testBranch(self):
  398. """Test building a branch with all toolchains present"""
  399. self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir)
  400. self.assertEqual(self._builder.count, self._total_builds)
  401. self.assertEqual(self._builder.fail, 0)
  402. def testCount(self):
  403. """Test building a specific number of commitst"""
  404. self._RunControl('-b', TEST_BRANCH, '-c2', '-o', self._output_dir)
  405. self.assertEqual(self._builder.count, 2 * len(boards))
  406. self.assertEqual(self._builder.fail, 0)
  407. # Each board has a config, and then one make per commit
  408. self.assertEqual(self._make_calls, len(boards) * (1 + 2))
  409. def testIncremental(self):
  410. """Test building a branch twice - the second time should do nothing"""
  411. self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir)
  412. # Each board has a mrproper, config, and then one make per commit
  413. self.assertEqual(self._make_calls, len(boards) * (self._commits + 1))
  414. self._make_calls = 0
  415. self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir, clean_dir=False)
  416. self.assertEqual(self._make_calls, 0)
  417. self.assertEqual(self._builder.count, self._total_builds)
  418. self.assertEqual(self._builder.fail, 0)
  419. def testForceBuild(self):
  420. """The -f flag should force a rebuild"""
  421. self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir)
  422. self._make_calls = 0
  423. self._RunControl('-b', TEST_BRANCH, '-f', '-o', self._output_dir, clean_dir=False)
  424. # Each board has a config and one make per commit
  425. self.assertEqual(self._make_calls, len(boards) * (self._commits + 1))
  426. def testForceReconfigure(self):
  427. """The -f flag should force a rebuild"""
  428. self._RunControl('-b', TEST_BRANCH, '-C', '-o', self._output_dir)
  429. # Each commit has a config and make
  430. self.assertEqual(self._make_calls, len(boards) * self._commits * 2)
  431. def testForceReconfigure(self):
  432. """The -f flag should force a rebuild"""
  433. self._RunControl('-b', TEST_BRANCH, '-C', '-o', self._output_dir)
  434. # Each commit has a config and make
  435. self.assertEqual(self._make_calls, len(boards) * self._commits * 2)
  436. def testMrproper(self):
  437. """The -f flag should force a rebuild"""
  438. self._RunControl('-b', TEST_BRANCH, '-m', '-o', self._output_dir)
  439. # Each board has a mkproper, config and then one make per commit
  440. self.assertEqual(self._make_calls, len(boards) * (self._commits + 2))
  441. def testErrors(self):
  442. """Test handling of build errors"""
  443. self._error['board2', 1] = 'fred\n'
  444. self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir)
  445. self.assertEqual(self._builder.count, self._total_builds)
  446. self.assertEqual(self._builder.fail, 1)
  447. # Remove the error. This should have no effect since the commit will
  448. # not be rebuilt
  449. del self._error['board2', 1]
  450. self._make_calls = 0
  451. self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir, clean_dir=False)
  452. self.assertEqual(self._builder.count, self._total_builds)
  453. self.assertEqual(self._make_calls, 0)
  454. self.assertEqual(self._builder.fail, 1)
  455. # Now use the -F flag to force rebuild of the bad commit
  456. self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir, '-F', clean_dir=False)
  457. self.assertEqual(self._builder.count, self._total_builds)
  458. self.assertEqual(self._builder.fail, 0)
  459. self.assertEqual(self._make_calls, 2)
  460. def testBranchWithSlash(self):
  461. """Test building a branch with a '/' in the name"""
  462. self._test_branch = '/__dev/__testbranch'
  463. self._RunControl('-b', self._test_branch, clean_dir=False)
  464. self.assertEqual(self._builder.count, self._total_builds)
  465. self.assertEqual(self._builder.fail, 0)
  466. def testEnvironment(self):
  467. """Test that the done and environment files are written to out-env"""
  468. self._RunControl('-o', self._output_dir)
  469. board0_dir = os.path.join(self._output_dir, 'current', 'board0')
  470. self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done')))
  471. self.assertTrue(os.path.exists(os.path.join(board0_dir, 'out-env')))
  472. def testEnvironmentUnicode(self):
  473. """Test there are no unicode errors when the env has non-ASCII chars"""
  474. try:
  475. varname = b'buildman_test_var'
  476. os.environb[varname] = b'strange\x80chars'
  477. self.assertEqual(0, self._RunControl('-o', self._output_dir))
  478. board0_dir = os.path.join(self._output_dir, 'current', 'board0')
  479. self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done')))
  480. self.assertTrue(os.path.exists(os.path.join(board0_dir, 'out-env')))
  481. finally:
  482. del os.environb[varname]
  483. def testWorkInOutput(self):
  484. """Test the -w option which should write directly to the output dir"""
  485. board_list = board.Boards()
  486. board_list.AddBoard(board.Board(*boards[0]))
  487. self._RunControl('-o', self._output_dir, '-w', clean_dir=False,
  488. boards=board_list)
  489. self.assertTrue(
  490. os.path.exists(os.path.join(self._output_dir, 'u-boot')))
  491. self.assertTrue(
  492. os.path.exists(os.path.join(self._output_dir, 'done')))
  493. self.assertTrue(
  494. os.path.exists(os.path.join(self._output_dir, 'out-env')))
  495. def testWorkInOutputFail(self):
  496. """Test the -w option failures"""
  497. with self.assertRaises(SystemExit) as e:
  498. self._RunControl('-o', self._output_dir, '-w', clean_dir=False)
  499. self.assertIn("single board", str(e.exception))
  500. self.assertFalse(
  501. os.path.exists(os.path.join(self._output_dir, 'u-boot')))
  502. board_list = board.Boards()
  503. board_list.AddBoard(board.Board(*boards[0]))
  504. with self.assertRaises(SystemExit) as e:
  505. self._RunControl('-b', self._test_branch, '-o', self._output_dir,
  506. '-w', clean_dir=False, boards=board_list)
  507. self.assertIn("single commit", str(e.exception))
  508. board_list = board.Boards()
  509. board_list.AddBoard(board.Board(*boards[0]))
  510. with self.assertRaises(SystemExit) as e:
  511. self._RunControl('-w', clean_dir=False)
  512. self.assertIn("specify -o", str(e.exception))
  513. def testThreadExceptions(self):
  514. """Test that exceptions in threads are reported"""
  515. with test_util.capture_sys_output() as (stdout, stderr):
  516. self.assertEqual(102, self._RunControl('-o', self._output_dir,
  517. test_thread_exceptions=True))
  518. self.assertIn('Thread exception: test exception', stdout.getvalue())