test.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #
  2. # Copyright (c) 2012 The Chromium OS Authors.
  3. #
  4. # SPDX-License-Identifier: GPL-2.0+
  5. #
  6. import os
  7. import shutil
  8. import sys
  9. import tempfile
  10. import time
  11. import unittest
  12. # Bring in the patman libraries
  13. our_path = os.path.dirname(os.path.realpath(__file__))
  14. sys.path.append(os.path.join(our_path, '../patman'))
  15. import board
  16. import bsettings
  17. import builder
  18. import control
  19. import command
  20. import commit
  21. import toolchain
  22. errors = [
  23. '''main.c: In function 'main_loop':
  24. main.c:260:6: warning: unused variable 'joe' [-Wunused-variable]
  25. ''',
  26. '''main.c: In function 'main_loop':
  27. main.c:295:2: error: 'fred' undeclared (first use in this function)
  28. main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in
  29. make[1]: *** [main.o] Error 1
  30. make: *** [common/libcommon.o] Error 2
  31. Make failed
  32. ''',
  33. '''main.c: In function 'main_loop':
  34. main.c:280:6: warning: unused variable 'mary' [-Wunused-variable]
  35. ''',
  36. '''powerpc-linux-ld: warning: dot moved backwards before `.bss'
  37. powerpc-linux-ld: warning: dot moved backwards before `.bss'
  38. powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections
  39. powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections
  40. powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections
  41. powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections
  42. powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections
  43. powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections
  44. '''
  45. ]
  46. # hash, subject, return code, list of errors/warnings
  47. commits = [
  48. ['1234', 'upstream/master, ok', 0, []],
  49. ['5678', 'Second commit, a warning', 0, errors[0:1]],
  50. ['9012', 'Third commit, error', 1, errors[0:2]],
  51. ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]],
  52. ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]],
  53. ['abcd', 'Sixth commit, fixes all errors', 0, []]
  54. ]
  55. boards = [
  56. ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''],
  57. ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''],
  58. ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''],
  59. ['Active', 'powerpc', 'mpc5xx', '', 'Tester', 'PowerPC board 2', 'board3', ''],
  60. ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''],
  61. ]
  62. class Options:
  63. """Class that holds build options"""
  64. pass
  65. class TestBuild(unittest.TestCase):
  66. """Test buildman
  67. TODO: Write tests for the rest of the functionality
  68. """
  69. def setUp(self):
  70. # Set up commits to build
  71. self.commits = []
  72. sequence = 0
  73. for commit_info in commits:
  74. comm = commit.Commit(commit_info[0])
  75. comm.subject = commit_info[1]
  76. comm.return_code = commit_info[2]
  77. comm.error_list = commit_info[3]
  78. comm.sequence = sequence
  79. sequence += 1
  80. self.commits.append(comm)
  81. # Set up boards to build
  82. self.boards = board.Boards()
  83. for brd in boards:
  84. self.boards.AddBoard(board.Board(*brd))
  85. self.boards.SelectBoards([])
  86. # Set up the toolchains
  87. bsettings.Setup()
  88. self.toolchains = toolchain.Toolchains()
  89. self.toolchains.Add('arm-linux-gcc', test=False)
  90. self.toolchains.Add('sparc-linux-gcc', test=False)
  91. self.toolchains.Add('powerpc-linux-gcc', test=False)
  92. self.toolchains.Add('gcc', test=False)
  93. def Make(self, commit, brd, stage, *args, **kwargs):
  94. result = command.CommandResult()
  95. boardnum = int(brd.target[-1])
  96. result.return_code = 0
  97. result.stderr = ''
  98. result.stdout = ('This is the test output for board %s, commit %s' %
  99. (brd.target, commit.hash))
  100. if boardnum >= 1 and boardnum >= commit.sequence:
  101. result.return_code = commit.return_code
  102. result.stderr = ''.join(commit.error_list)
  103. if stage == 'build':
  104. target_dir = None
  105. for arg in args:
  106. if arg.startswith('O='):
  107. target_dir = arg[2:]
  108. if not os.path.isdir(target_dir):
  109. os.mkdir(target_dir)
  110. #time.sleep(.2 + boardnum * .2)
  111. result.combined = result.stdout + result.stderr
  112. return result
  113. def testBasic(self):
  114. """Test basic builder operation"""
  115. output_dir = tempfile.mkdtemp()
  116. if not os.path.isdir(output_dir):
  117. os.mkdir(output_dir)
  118. build = builder.Builder(self.toolchains, output_dir, None, 1, 2,
  119. checkout=False, show_unknown=False)
  120. build.do_make = self.Make
  121. board_selected = self.boards.GetSelectedDict()
  122. #build.BuildCommits(self.commits, board_selected, False)
  123. build.BuildBoards(self.commits, board_selected, keep_outputs=False,
  124. verbose=False)
  125. build.SetDisplayOptions(show_errors=True);
  126. build.ShowSummary(self.commits, board_selected)
  127. def _testGit(self):
  128. """Test basic builder operation by building a branch"""
  129. base_dir = tempfile.mkdtemp()
  130. if not os.path.isdir(base_dir):
  131. os.mkdir(base_dir)
  132. options = Options()
  133. options.git = os.getcwd()
  134. options.summary = False
  135. options.jobs = None
  136. options.dry_run = False
  137. #options.git = os.path.join(base_dir, 'repo')
  138. options.branch = 'test-buildman'
  139. options.force_build = False
  140. options.list_tool_chains = False
  141. options.count = -1
  142. options.git_dir = None
  143. options.threads = None
  144. options.show_unknown = False
  145. options.quick = False
  146. options.show_errors = False
  147. options.keep_outputs = False
  148. args = ['tegra20']
  149. control.DoBuildman(options, args)
  150. if __name__ == "__main__":
  151. unittest.main()