test.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright (c) 2012 The Chromium OS Authors.
  3. #
  4. import os
  5. import shutil
  6. import sys
  7. import tempfile
  8. import time
  9. import unittest
  10. from buildman import board
  11. from buildman import bsettings
  12. from buildman import builder
  13. from buildman import control
  14. from buildman import toolchain
  15. from patman import commit
  16. from patman import command
  17. from patman import terminal
  18. from patman import test_util
  19. from patman import tools
  20. use_network = True
  21. settings_data = '''
  22. # Buildman settings file
  23. [toolchain]
  24. main: /usr/sbin
  25. [toolchain-alias]
  26. x86: i386 x86_64
  27. '''
  28. migration = '''===================== WARNING ======================
  29. This board does not use CONFIG_DM. CONFIG_DM will be
  30. compulsory starting with the v2020.01 release.
  31. Failure to update may result in board removal.
  32. See doc/driver-model/migration.rst for more info.
  33. ====================================================
  34. '''
  35. errors = [
  36. '''main.c: In function 'main_loop':
  37. main.c:260:6: warning: unused variable 'joe' [-Wunused-variable]
  38. ''',
  39. '''main.c: In function 'main_loop2':
  40. main.c:295:2: error: 'fred' undeclared (first use in this function)
  41. main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in
  42. make[1]: *** [main.o] Error 1
  43. make: *** [common/libcommon.o] Error 2
  44. Make failed
  45. ''',
  46. '''arch/arm/dts/socfpga_arria10_socdk_sdmmc.dtb: Warning \
  47. (avoid_unnecessary_addr_size): /clocks: unnecessary #address-cells/#size-cells \
  48. without "ranges" or child "reg" property
  49. ''',
  50. '''powerpc-linux-ld: warning: dot moved backwards before `.bss'
  51. powerpc-linux-ld: warning: dot moved backwards before `.bss'
  52. powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections
  53. powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections
  54. powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections
  55. powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections
  56. powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections
  57. powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections
  58. ''',
  59. '''In file included from %(basedir)sarch/sandbox/cpu/cpu.c:9:0:
  60. %(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
  61. %(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
  62. %(basedir)sarch/sandbox/cpu/cpu.c: In function 'do_reset':
  63. %(basedir)sarch/sandbox/cpu/cpu.c:27:1: error: unknown type name 'blah'
  64. %(basedir)sarch/sandbox/cpu/cpu.c:28:12: error: expected declaration specifiers or '...' before numeric constant
  65. make[2]: *** [arch/sandbox/cpu/cpu.o] Error 1
  66. make[1]: *** [arch/sandbox/cpu] Error 2
  67. make[1]: *** Waiting for unfinished jobs....
  68. In file included from %(basedir)scommon/board_f.c:55:0:
  69. %(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
  70. %(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
  71. make: *** [sub-make] Error 2
  72. '''
  73. ]
  74. # hash, subject, return code, list of errors/warnings
  75. commits = [
  76. ['1234', 'upstream/master, migration warning', 0, []],
  77. ['5678', 'Second commit, a warning', 0, errors[0:1]],
  78. ['9012', 'Third commit, error', 1, errors[0:2]],
  79. ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]],
  80. ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]],
  81. ['abcd', 'Sixth commit, fixes all errors', 0, []],
  82. ['ef01', 'Seventh commit, fix migration, check directory suppression', 1,
  83. [errors[4]]],
  84. ]
  85. boards = [
  86. ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''],
  87. ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''],
  88. ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''],
  89. ['Active', 'powerpc', 'mpc83xx', '', 'Tester', 'PowerPC board 2', 'board3', ''],
  90. ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''],
  91. ]
  92. BASE_DIR = 'base'
  93. OUTCOME_OK, OUTCOME_WARN, OUTCOME_ERR = range(3)
  94. class Options:
  95. """Class that holds build options"""
  96. pass
  97. class TestBuild(unittest.TestCase):
  98. """Test buildman
  99. TODO: Write tests for the rest of the functionality
  100. """
  101. def setUp(self):
  102. # Set up commits to build
  103. self.commits = []
  104. sequence = 0
  105. for commit_info in commits:
  106. comm = commit.Commit(commit_info[0])
  107. comm.subject = commit_info[1]
  108. comm.return_code = commit_info[2]
  109. comm.error_list = commit_info[3]
  110. if sequence < 6:
  111. comm.error_list += [migration]
  112. comm.sequence = sequence
  113. sequence += 1
  114. self.commits.append(comm)
  115. # Set up boards to build
  116. self.boards = board.Boards()
  117. for brd in boards:
  118. self.boards.AddBoard(board.Board(*brd))
  119. self.boards.SelectBoards([])
  120. # Add some test settings
  121. bsettings.Setup(None)
  122. bsettings.AddFile(settings_data)
  123. # Set up the toolchains
  124. self.toolchains = toolchain.Toolchains()
  125. self.toolchains.Add('arm-linux-gcc', test=False)
  126. self.toolchains.Add('sparc-linux-gcc', test=False)
  127. self.toolchains.Add('powerpc-linux-gcc', test=False)
  128. self.toolchains.Add('gcc', test=False)
  129. # Avoid sending any output
  130. terminal.SetPrintTestMode()
  131. self._col = terminal.Color()
  132. self.base_dir = tempfile.mkdtemp()
  133. if not os.path.isdir(self.base_dir):
  134. os.mkdir(self.base_dir)
  135. def tearDown(self):
  136. shutil.rmtree(self.base_dir)
  137. def Make(self, commit, brd, stage, *args, **kwargs):
  138. result = command.CommandResult()
  139. boardnum = int(brd.target[-1])
  140. result.return_code = 0
  141. result.stderr = ''
  142. result.stdout = ('This is the test output for board %s, commit %s' %
  143. (brd.target, commit.hash))
  144. if ((boardnum >= 1 and boardnum >= commit.sequence) or
  145. boardnum == 4 and commit.sequence == 6):
  146. result.return_code = commit.return_code
  147. result.stderr = (''.join(commit.error_list)
  148. % {'basedir' : self.base_dir + '/.bm-work/00/'})
  149. elif commit.sequence < 6:
  150. result.stderr = migration
  151. result.combined = result.stdout + result.stderr
  152. return result
  153. def assertSummary(self, text, arch, plus, boards, outcome=OUTCOME_ERR):
  154. col = self._col
  155. expected_colour = (col.GREEN if outcome == OUTCOME_OK else
  156. col.YELLOW if outcome == OUTCOME_WARN else col.RED)
  157. expect = '%10s: ' % arch
  158. # TODO(sjg@chromium.org): If plus is '', we shouldn't need this
  159. expect += ' ' + col.Color(expected_colour, plus)
  160. expect += ' '
  161. for board in boards:
  162. expect += col.Color(expected_colour, ' %s' % board)
  163. self.assertEqual(text, expect)
  164. def _SetupTest(self, echo_lines=False, threads=1, **kwdisplay_args):
  165. """Set up the test by running a build and summary
  166. Args:
  167. echo_lines: True to echo lines to the terminal to aid test
  168. development
  169. kwdisplay_args: Dict of arguemnts to pass to
  170. Builder.SetDisplayOptions()
  171. Returns:
  172. Iterator containing the output lines, each a PrintLine() object
  173. """
  174. build = builder.Builder(self.toolchains, self.base_dir, None, threads,
  175. 2, checkout=False, show_unknown=False)
  176. build.do_make = self.Make
  177. board_selected = self.boards.GetSelectedDict()
  178. # Build the boards for the pre-defined commits and warnings/errors
  179. # associated with each. This calls our Make() to inject the fake output.
  180. build.BuildBoards(self.commits, board_selected, keep_outputs=False,
  181. verbose=False)
  182. lines = terminal.GetPrintTestLines()
  183. count = 0
  184. for line in lines:
  185. if line.text.strip():
  186. count += 1
  187. # We should get two starting messages, an update for every commit built
  188. # and a summary message
  189. self.assertEqual(count, len(commits) * len(boards) + 3)
  190. build.SetDisplayOptions(**kwdisplay_args);
  191. build.ShowSummary(self.commits, board_selected)
  192. if echo_lines:
  193. terminal.EchoPrintTestLines()
  194. return iter(terminal.GetPrintTestLines())
  195. def _CheckOutput(self, lines, list_error_boards=False,
  196. filter_dtb_warnings=False,
  197. filter_migration_warnings=False):
  198. """Check for expected output from the build summary
  199. Args:
  200. lines: Iterator containing the lines returned from the summary
  201. list_error_boards: Adjust the check for output produced with the
  202. --list-error-boards flag
  203. filter_dtb_warnings: Adjust the check for output produced with the
  204. --filter-dtb-warnings flag
  205. """
  206. def add_line_prefix(prefix, boards, error_str, colour):
  207. """Add a prefix to each line of a string
  208. The training \n in error_str is removed before processing
  209. Args:
  210. prefix: String prefix to add
  211. error_str: Error string containing the lines
  212. colour: Expected colour for the line. Note that the board list,
  213. if present, always appears in magenta
  214. Returns:
  215. New string where each line has the prefix added
  216. """
  217. lines = error_str.strip().splitlines()
  218. new_lines = []
  219. for line in lines:
  220. if boards:
  221. expect = self._col.Color(colour, prefix + '(')
  222. expect += self._col.Color(self._col.MAGENTA, boards,
  223. bright=False)
  224. expect += self._col.Color(colour, ') %s' % line)
  225. else:
  226. expect = self._col.Color(colour, prefix + line)
  227. new_lines.append(expect)
  228. return '\n'.join(new_lines)
  229. col = terminal.Color()
  230. boards01234 = ('board0 board1 board2 board3 board4'
  231. if list_error_boards else '')
  232. boards1234 = 'board1 board2 board3 board4' if list_error_boards else ''
  233. boards234 = 'board2 board3 board4' if list_error_boards else ''
  234. boards34 = 'board3 board4' if list_error_boards else ''
  235. boards4 = 'board4' if list_error_boards else ''
  236. # Upstream commit: migration warnings only
  237. self.assertEqual(next(lines).text, '01: %s' % commits[0][1])
  238. if not filter_migration_warnings:
  239. self.assertSummary(next(lines).text, 'arm', 'w+',
  240. ['board0', 'board1'], outcome=OUTCOME_WARN)
  241. self.assertSummary(next(lines).text, 'powerpc', 'w+',
  242. ['board2', 'board3'], outcome=OUTCOME_WARN)
  243. self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
  244. outcome=OUTCOME_WARN)
  245. self.assertEqual(next(lines).text,
  246. add_line_prefix('+', boards01234, migration, col.RED))
  247. # Second commit: all archs should fail with warnings
  248. self.assertEqual(next(lines).text, '02: %s' % commits[1][1])
  249. if filter_migration_warnings:
  250. self.assertSummary(next(lines).text, 'arm', 'w+',
  251. ['board1'], outcome=OUTCOME_WARN)
  252. self.assertSummary(next(lines).text, 'powerpc', 'w+',
  253. ['board2', 'board3'], outcome=OUTCOME_WARN)
  254. self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
  255. outcome=OUTCOME_WARN)
  256. # Second commit: The warnings should be listed
  257. self.assertEqual(next(lines).text,
  258. add_line_prefix('w+', boards1234, errors[0], col.YELLOW))
  259. # Third commit: Still fails
  260. self.assertEqual(next(lines).text, '03: %s' % commits[2][1])
  261. if filter_migration_warnings:
  262. self.assertSummary(next(lines).text, 'arm', '',
  263. ['board1'], outcome=OUTCOME_OK)
  264. self.assertSummary(next(lines).text, 'powerpc', '+',
  265. ['board2', 'board3'])
  266. self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
  267. # Expect a compiler error
  268. self.assertEqual(next(lines).text,
  269. add_line_prefix('+', boards234, errors[1], col.RED))
  270. # Fourth commit: Compile errors are fixed, just have warning for board3
  271. self.assertEqual(next(lines).text, '04: %s' % commits[3][1])
  272. if filter_migration_warnings:
  273. expect = '%10s: ' % 'powerpc'
  274. expect += ' ' + col.Color(col.GREEN, '')
  275. expect += ' '
  276. expect += col.Color(col.GREEN, ' %s' % 'board2')
  277. expect += ' ' + col.Color(col.YELLOW, 'w+')
  278. expect += ' '
  279. expect += col.Color(col.YELLOW, ' %s' % 'board3')
  280. self.assertEqual(next(lines).text, expect)
  281. else:
  282. self.assertSummary(next(lines).text, 'powerpc', 'w+',
  283. ['board2', 'board3'], outcome=OUTCOME_WARN)
  284. self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
  285. outcome=OUTCOME_WARN)
  286. # Compile error fixed
  287. self.assertEqual(next(lines).text,
  288. add_line_prefix('-', boards234, errors[1], col.GREEN))
  289. if not filter_dtb_warnings:
  290. self.assertEqual(
  291. next(lines).text,
  292. add_line_prefix('w+', boards34, errors[2], col.YELLOW))
  293. # Fifth commit
  294. self.assertEqual(next(lines).text, '05: %s' % commits[4][1])
  295. if filter_migration_warnings:
  296. self.assertSummary(next(lines).text, 'powerpc', '', ['board3'],
  297. outcome=OUTCOME_OK)
  298. self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
  299. # The second line of errors[3] is a duplicate, so buildman will drop it
  300. expect = errors[3].rstrip().split('\n')
  301. expect = [expect[0]] + expect[2:]
  302. expect = '\n'.join(expect)
  303. self.assertEqual(next(lines).text,
  304. add_line_prefix('+', boards4, expect, col.RED))
  305. if not filter_dtb_warnings:
  306. self.assertEqual(
  307. next(lines).text,
  308. add_line_prefix('w-', boards34, errors[2], col.CYAN))
  309. # Sixth commit
  310. self.assertEqual(next(lines).text, '06: %s' % commits[5][1])
  311. if filter_migration_warnings:
  312. self.assertSummary(next(lines).text, 'sandbox', '', ['board4'],
  313. outcome=OUTCOME_OK)
  314. else:
  315. self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
  316. outcome=OUTCOME_WARN)
  317. # The second line of errors[3] is a duplicate, so buildman will drop it
  318. expect = errors[3].rstrip().split('\n')
  319. expect = [expect[0]] + expect[2:]
  320. expect = '\n'.join(expect)
  321. self.assertEqual(next(lines).text,
  322. add_line_prefix('-', boards4, expect, col.GREEN))
  323. self.assertEqual(next(lines).text,
  324. add_line_prefix('w-', boards4, errors[0], col.CYAN))
  325. # Seventh commit
  326. self.assertEqual(next(lines).text, '07: %s' % commits[6][1])
  327. if filter_migration_warnings:
  328. self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
  329. else:
  330. self.assertSummary(next(lines).text, 'arm', '', ['board0', 'board1'],
  331. outcome=OUTCOME_OK)
  332. self.assertSummary(next(lines).text, 'powerpc', '',
  333. ['board2', 'board3'], outcome=OUTCOME_OK)
  334. self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
  335. # Pick out the correct error lines
  336. expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n')
  337. expect = expect_str[3:8] + [expect_str[-1]]
  338. expect = '\n'.join(expect)
  339. if not filter_migration_warnings:
  340. self.assertEqual(
  341. next(lines).text,
  342. add_line_prefix('-', boards01234, migration, col.GREEN))
  343. self.assertEqual(next(lines).text,
  344. add_line_prefix('+', boards4, expect, col.RED))
  345. # Now the warnings lines
  346. expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]]
  347. expect = '\n'.join(expect)
  348. self.assertEqual(next(lines).text,
  349. add_line_prefix('w+', boards4, expect, col.YELLOW))
  350. def testOutput(self):
  351. """Test basic builder operation and output
  352. This does a line-by-line verification of the summary output.
  353. """
  354. lines = self._SetupTest(show_errors=True)
  355. self._CheckOutput(lines, list_error_boards=False,
  356. filter_dtb_warnings=False)
  357. def testErrorBoards(self):
  358. """Test output with --list-error-boards
  359. This does a line-by-line verification of the summary output.
  360. """
  361. lines = self._SetupTest(show_errors=True, list_error_boards=True)
  362. self._CheckOutput(lines, list_error_boards=True)
  363. def testFilterDtb(self):
  364. """Test output with --filter-dtb-warnings
  365. This does a line-by-line verification of the summary output.
  366. """
  367. lines = self._SetupTest(show_errors=True, filter_dtb_warnings=True)
  368. self._CheckOutput(lines, filter_dtb_warnings=True)
  369. def testFilterMigration(self):
  370. """Test output with --filter-migration-warnings
  371. This does a line-by-line verification of the summary output.
  372. """
  373. lines = self._SetupTest(show_errors=True,
  374. filter_migration_warnings=True)
  375. self._CheckOutput(lines, filter_migration_warnings=True)
  376. def testSingleThread(self):
  377. """Test operation without threading"""
  378. lines = self._SetupTest(show_errors=True, threads=0)
  379. self._CheckOutput(lines, list_error_boards=False,
  380. filter_dtb_warnings=False)
  381. def _testGit(self):
  382. """Test basic builder operation by building a branch"""
  383. options = Options()
  384. options.git = os.getcwd()
  385. options.summary = False
  386. options.jobs = None
  387. options.dry_run = False
  388. #options.git = os.path.join(self.base_dir, 'repo')
  389. options.branch = 'test-buildman'
  390. options.force_build = False
  391. options.list_tool_chains = False
  392. options.count = -1
  393. options.git_dir = None
  394. options.threads = None
  395. options.show_unknown = False
  396. options.quick = False
  397. options.show_errors = False
  398. options.keep_outputs = False
  399. args = ['tegra20']
  400. control.DoBuildman(options, args)
  401. def testBoardSingle(self):
  402. """Test single board selection"""
  403. self.assertEqual(self.boards.SelectBoards(['sandbox']),
  404. ({'all': ['board4'], 'sandbox': ['board4']}, []))
  405. def testBoardArch(self):
  406. """Test single board selection"""
  407. self.assertEqual(self.boards.SelectBoards(['arm']),
  408. ({'all': ['board0', 'board1'],
  409. 'arm': ['board0', 'board1']}, []))
  410. def testBoardArchSingle(self):
  411. """Test single board selection"""
  412. self.assertEqual(self.boards.SelectBoards(['arm sandbox']),
  413. ({'sandbox': ['board4'],
  414. 'all': ['board0', 'board1', 'board4'],
  415. 'arm': ['board0', 'board1']}, []))
  416. def testBoardArchSingleMultiWord(self):
  417. """Test single board selection"""
  418. self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']),
  419. ({'sandbox': ['board4'],
  420. 'all': ['board0', 'board1', 'board4'],
  421. 'arm': ['board0', 'board1']}, []))
  422. def testBoardSingleAnd(self):
  423. """Test single board selection"""
  424. self.assertEqual(self.boards.SelectBoards(['Tester & arm']),
  425. ({'Tester&arm': ['board0', 'board1'],
  426. 'all': ['board0', 'board1']}, []))
  427. def testBoardTwoAnd(self):
  428. """Test single board selection"""
  429. self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm',
  430. 'Tester' '&', 'powerpc',
  431. 'sandbox']),
  432. ({'sandbox': ['board4'],
  433. 'all': ['board0', 'board1', 'board2', 'board3',
  434. 'board4'],
  435. 'Tester&powerpc': ['board2', 'board3'],
  436. 'Tester&arm': ['board0', 'board1']}, []))
  437. def testBoardAll(self):
  438. """Test single board selection"""
  439. self.assertEqual(self.boards.SelectBoards([]),
  440. ({'all': ['board0', 'board1', 'board2', 'board3',
  441. 'board4']}, []))
  442. def testBoardRegularExpression(self):
  443. """Test single board selection"""
  444. self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']),
  445. ({'all': ['board2', 'board3'],
  446. 'T.*r&^Po': ['board2', 'board3']}, []))
  447. def testBoardDuplicate(self):
  448. """Test single board selection"""
  449. self.assertEqual(self.boards.SelectBoards(['sandbox sandbox',
  450. 'sandbox']),
  451. ({'all': ['board4'], 'sandbox': ['board4']}, []))
  452. def CheckDirs(self, build, dirname):
  453. self.assertEqual('base%s' % dirname, build._GetOutputDir(1))
  454. self.assertEqual('base%s/fred' % dirname,
  455. build.GetBuildDir(1, 'fred'))
  456. self.assertEqual('base%s/fred/done' % dirname,
  457. build.GetDoneFile(1, 'fred'))
  458. self.assertEqual('base%s/fred/u-boot.sizes' % dirname,
  459. build.GetFuncSizesFile(1, 'fred', 'u-boot'))
  460. self.assertEqual('base%s/fred/u-boot.objdump' % dirname,
  461. build.GetObjdumpFile(1, 'fred', 'u-boot'))
  462. self.assertEqual('base%s/fred/err' % dirname,
  463. build.GetErrFile(1, 'fred'))
  464. def testOutputDir(self):
  465. build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
  466. checkout=False, show_unknown=False)
  467. build.commits = self.commits
  468. build.commit_count = len(self.commits)
  469. subject = self.commits[1].subject.translate(builder.trans_valid_chars)
  470. dirname ='/%02d_g%s_%s' % (2, commits[1][0], subject[:20])
  471. self.CheckDirs(build, dirname)
  472. def testOutputDirCurrent(self):
  473. build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
  474. checkout=False, show_unknown=False)
  475. build.commits = None
  476. build.commit_count = 0
  477. self.CheckDirs(build, '/current')
  478. def testOutputDirNoSubdirs(self):
  479. build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
  480. checkout=False, show_unknown=False,
  481. no_subdirs=True)
  482. build.commits = None
  483. build.commit_count = 0
  484. self.CheckDirs(build, '')
  485. def testToolchainAliases(self):
  486. self.assertTrue(self.toolchains.Select('arm') != None)
  487. with self.assertRaises(ValueError):
  488. self.toolchains.Select('no-arch')
  489. with self.assertRaises(ValueError):
  490. self.toolchains.Select('x86')
  491. self.toolchains = toolchain.Toolchains()
  492. self.toolchains.Add('x86_64-linux-gcc', test=False)
  493. self.assertTrue(self.toolchains.Select('x86') != None)
  494. self.toolchains = toolchain.Toolchains()
  495. self.toolchains.Add('i386-linux-gcc', test=False)
  496. self.assertTrue(self.toolchains.Select('x86') != None)
  497. def testToolchainDownload(self):
  498. """Test that we can download toolchains"""
  499. if use_network:
  500. with test_util.capture_sys_output() as (stdout, stderr):
  501. url = self.toolchains.LocateArchUrl('arm')
  502. self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/'
  503. 'crosstool/files/bin/x86_64/.*/'
  504. 'x86_64-gcc-.*-nolibc[-_]arm-.*linux-gnueabi.tar.xz')
  505. def testGetEnvArgs(self):
  506. """Test the GetEnvArgs() function"""
  507. tc = self.toolchains.Select('arm')
  508. self.assertEqual('arm-linux-',
  509. tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE))
  510. self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_PATH))
  511. self.assertEqual('arm',
  512. tc.GetEnvArgs(toolchain.VAR_ARCH))
  513. self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS))
  514. self.toolchains.Add('/path/to/x86_64-linux-gcc', test=False)
  515. tc = self.toolchains.Select('x86')
  516. self.assertEqual('/path/to',
  517. tc.GetEnvArgs(toolchain.VAR_PATH))
  518. tc.override_toolchain = 'clang'
  519. self.assertEqual('HOSTCC=clang CC=clang',
  520. tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS))
  521. def testPrepareOutputSpace(self):
  522. def _Touch(fname):
  523. tools.WriteFile(os.path.join(base_dir, fname), b'')
  524. base_dir = tempfile.mkdtemp()
  525. # Add various files that we want removed and left alone
  526. to_remove = ['01_g0982734987_title', '102_g92bf_title',
  527. '01_g2938abd8_title']
  528. to_leave = ['something_else', '01-something.patch', '01_another']
  529. for name in to_remove + to_leave:
  530. _Touch(name)
  531. build = builder.Builder(self.toolchains, base_dir, None, 1, 2)
  532. build.commits = self.commits
  533. build.commit_count = len(commits)
  534. result = set(build._GetOutputSpaceRemovals())
  535. expected = set([os.path.join(base_dir, f) for f in to_remove])
  536. self.assertEqual(expected, result)
  537. if __name__ == "__main__":
  538. unittest.main()