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