blob: 068784a3041c03bac6370eb5621a3d8587389872 [file] [log] [blame]
Simon Glassc05694f2013-04-03 11:07:16 +00001#
2# Copyright (c) 2012 The Chromium OS Authors.
3#
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004# SPDX-License-Identifier: GPL-2.0+
Simon Glassc05694f2013-04-03 11:07:16 +00005#
6
7import os
8import shutil
9import sys
10import tempfile
11import time
12import unittest
13
14# Bring in the patman libraries
15our_path = os.path.dirname(os.path.realpath(__file__))
16sys.path.append(os.path.join(our_path, '../patman'))
17
18import board
19import bsettings
20import builder
21import control
22import command
23import commit
24import toolchain
25
26errors = [
27 '''main.c: In function 'main_loop':
28main.c:260:6: warning: unused variable 'joe' [-Wunused-variable]
29''',
30 '''main.c: In function 'main_loop':
31main.c:295:2: error: 'fred' undeclared (first use in this function)
32main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in
33make[1]: *** [main.o] Error 1
34make: *** [common/libcommon.o] Error 2
35Make failed
36''',
37 '''main.c: In function 'main_loop':
38main.c:280:6: warning: unused variable 'mary' [-Wunused-variable]
39''',
40 '''powerpc-linux-ld: warning: dot moved backwards before `.bss'
41powerpc-linux-ld: warning: dot moved backwards before `.bss'
42powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections
43powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections
44powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections
45powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections
46powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections
47powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections
48'''
49]
50
51
52# hash, subject, return code, list of errors/warnings
53commits = [
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
62boards = [
Simon Glass584cf862013-09-23 17:35:16 -060063 ['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 Glassc05694f2013-04-03 11:07:16 +000068]
69
70class Options:
71 """Class that holds build options"""
72 pass
73
74class 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
168if __name__ == "__main__":
169 unittest.main()