test.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #
  2. # Copyright (c) 2012 The Chromium OS Authors.
  3. #
  4. # See file CREDITS for list of people who contributed to this
  5. # project.
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License as
  9. # published by the Free Software Foundation; either version 2 of
  10. # the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. # MA 02111-1307 USA
  21. #
  22. import os
  23. import shutil
  24. import sys
  25. import tempfile
  26. import time
  27. import unittest
  28. # Bring in the patman libraries
  29. our_path = os.path.dirname(os.path.realpath(__file__))
  30. sys.path.append(os.path.join(our_path, '../patman'))
  31. import board
  32. import bsettings
  33. import builder
  34. import control
  35. import command
  36. import commit
  37. import toolchain
  38. errors = [
  39. '''main.c: In function 'main_loop':
  40. main.c:260:6: warning: unused variable 'joe' [-Wunused-variable]
  41. ''',
  42. '''main.c: In function 'main_loop':
  43. main.c:295:2: error: 'fred' undeclared (first use in this function)
  44. main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in
  45. make[1]: *** [main.o] Error 1
  46. make: *** [common/libcommon.o] Error 2
  47. Make failed
  48. ''',
  49. '''main.c: In function 'main_loop':
  50. main.c:280:6: warning: unused variable 'mary' [-Wunused-variable]
  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. ]
  62. # hash, subject, return code, list of errors/warnings
  63. commits = [
  64. ['1234', 'upstream/master, ok', 0, []],
  65. ['5678', 'Second commit, a warning', 0, errors[0:1]],
  66. ['9012', 'Third commit, error', 1, errors[0:2]],
  67. ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]],
  68. ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]],
  69. ['abcd', 'Sixth commit, fixes all errors', 0, []]
  70. ]
  71. boards = [
  72. ['board0', 'arm', 'armv7', 'ARM Board 1', 'Tester', '', ''],
  73. ['board1', 'arm', 'armv7', 'ARM Board 2', 'Tester', '', ''],
  74. ['board2', 'powerpc', 'powerpc', 'PowerPC board 1', 'Tester', '', ''],
  75. ['board3', 'powerpc', 'mpc5xx', 'PowerPC board 2', 'Tester', '', ''],
  76. ['board4', 'sandbox', 'sandbox', 'Sandbox board', 'Tester', '', '']
  77. ]
  78. class Options:
  79. """Class that holds build options"""
  80. pass
  81. class TestBuild(unittest.TestCase):
  82. """Test buildman
  83. TODO: Write tests for the rest of the functionality
  84. """
  85. def setUp(self):
  86. # Set up commits to build
  87. self.commits = []
  88. sequence = 0
  89. for commit_info in commits:
  90. comm = commit.Commit(commit_info[0])
  91. comm.subject = commit_info[1]
  92. comm.return_code = commit_info[2]
  93. comm.error_list = commit_info[3]
  94. comm.sequence = sequence
  95. sequence += 1
  96. self.commits.append(comm)
  97. # Set up boards to build
  98. self.boards = board.Boards()
  99. for brd in boards:
  100. self.boards.AddBoard(board.Board(*brd))
  101. self.boards.SelectBoards([])
  102. # Set up the toolchains
  103. bsettings.Setup()
  104. self.toolchains = toolchain.Toolchains()
  105. self.toolchains.Add('arm-linux-gcc', test=False)
  106. self.toolchains.Add('sparc-linux-gcc', test=False)
  107. self.toolchains.Add('powerpc-linux-gcc', test=False)
  108. self.toolchains.Add('gcc', test=False)
  109. def Make(self, commit, brd, stage, *args, **kwargs):
  110. result = command.CommandResult()
  111. boardnum = int(brd.target[-1])
  112. result.return_code = 0
  113. result.stderr = ''
  114. result.stdout = ('This is the test output for board %s, commit %s' %
  115. (brd.target, commit.hash))
  116. if boardnum >= 1 and boardnum >= commit.sequence:
  117. result.return_code = commit.return_code
  118. result.stderr = ''.join(commit.error_list)
  119. if stage == 'build':
  120. target_dir = None
  121. for arg in args:
  122. if arg.startswith('O='):
  123. target_dir = arg[2:]
  124. if not os.path.isdir(target_dir):
  125. os.mkdir(target_dir)
  126. #time.sleep(.2 + boardnum * .2)
  127. result.combined = result.stdout + result.stderr
  128. return result
  129. def testBasic(self):
  130. """Test basic builder operation"""
  131. output_dir = tempfile.mkdtemp()
  132. if not os.path.isdir(output_dir):
  133. os.mkdir(output_dir)
  134. build = builder.Builder(self.toolchains, output_dir, None, 1, 2,
  135. checkout=False, show_unknown=False)
  136. build.do_make = self.Make
  137. board_selected = self.boards.GetSelectedDict()
  138. #build.BuildCommits(self.commits, board_selected, False)
  139. build.BuildBoards(self.commits, board_selected, False, False)
  140. build.ShowSummary(self.commits, board_selected, True, False,
  141. False, False)
  142. def _testGit(self):
  143. """Test basic builder operation by building a branch"""
  144. base_dir = tempfile.mkdtemp()
  145. if not os.path.isdir(base_dir):
  146. os.mkdir(base_dir)
  147. options = Options()
  148. options.git = os.getcwd()
  149. options.summary = False
  150. options.jobs = None
  151. options.dry_run = False
  152. #options.git = os.path.join(base_dir, 'repo')
  153. options.branch = 'test-buildman'
  154. options.force_build = False
  155. options.list_tool_chains = False
  156. options.count = -1
  157. options.git_dir = None
  158. options.threads = None
  159. options.show_unknown = False
  160. options.quick = False
  161. options.show_errors = False
  162. options.keep_outputs = False
  163. args = ['tegra20']
  164. control.DoBuildman(options, args)
  165. if __name__ == "__main__":
  166. unittest.main()