test.py 26 KB

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