]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - tools/buildman/test.py
buildman: Introduce an 'and' operator for board selection
[karo-tx-uboot.git] / tools / buildman / test.py
1 #
2 # Copyright (c) 2012 The Chromium OS Authors.
3 #
4 # SPDX-License-Identifier:      GPL-2.0+
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 = [
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', ''],
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.BuildBoards(self.commits, board_selected, keep_outputs=False,
140                           verbose=False)
141         build.SetDisplayOptions(show_errors=True);
142         build.ShowSummary(self.commits, board_selected)
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     def testBoardSingle(self):
169         """Test single board selection"""
170         self.assertEqual(self.boards.SelectBoards(['sandbox']),
171                          {'all': 1, 'sandbox': 1})
172
173     def testBoardArch(self):
174         """Test single board selection"""
175         self.assertEqual(self.boards.SelectBoards(['arm']),
176                          {'all': 2, 'arm': 2})
177
178     def testBoardArchSingle(self):
179         """Test single board selection"""
180         self.assertEqual(self.boards.SelectBoards(['arm sandbox']),
181                          {'all': 3, 'arm': 2, 'sandbox' : 1})
182
183     def testBoardArchSingleMultiWord(self):
184         """Test single board selection"""
185         self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']),
186                          {'all': 3, 'arm': 2, 'sandbox' : 1})
187
188     def testBoardSingleAnd(self):
189         """Test single board selection"""
190         self.assertEqual(self.boards.SelectBoards(['Tester & arm']),
191                          {'all': 2, 'Tester&arm': 2})
192
193     def testBoardTwoAnd(self):
194         """Test single board selection"""
195         self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm',
196                                                    'Tester' '&', 'powerpc',
197                                                    'sandbox']),
198                          {'all': 5, 'Tester&powerpc': 2, 'Tester&arm': 2,
199                           'sandbox' : 1})
200
201     def testBoardAll(self):
202         """Test single board selection"""
203         self.assertEqual(self.boards.SelectBoards([]), {'all': 5})
204
205     def testBoardRegularExpression(self):
206         """Test single board selection"""
207         self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']),
208                          {'T.*r&^Po': 2, 'all': 2})
209
210     def testBoardDuplicate(self):
211         """Test single board selection"""
212         self.assertEqual(self.boards.SelectBoards(['sandbox sandbox',
213                                                    'sandbox']),
214                          {'all': 1, 'sandbox': 1})
215
216 if __name__ == "__main__":
217     unittest.main()