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