2 # Copyright (c) 2014 Google, Inc
4 # SPDX-License-Identifier: GPL-2.0+
22 # Buildman settings file
30 chroot=/home/sjg/c/chroot
31 vboot=USE_STDINT=1 VBOOT_DEBUG=1 MAKEFLAGS_VBOOT=DEBUG=1 CFLAGS_EXTRA_VBOOT=-DUNROLL_LOOPS VBOOT_SOURCE=${src}/platform/vboot_reference
32 chromeos_coreboot=VBOOT=${chroot}/build/link/usr ${vboot}
33 chromeos_daisy=VBOOT=${chroot}/build/daisy/usr ${vboot}
34 chromeos_peach=VBOOT=${chroot}/build/peach_pit/usr ${vboot}
37 class TestFunctional(unittest.TestCase):
38 """Functional test for buildman.
40 This aims to test from just below the invocation of buildman (parsing
41 of arguments) to 'make' and 'git' invocation. It is not a true
42 emd-to-end test, as it mocks git, make and the tool chain. But this
43 makes it easier to detect when the builder is doing the wrong thing,
44 since in many cases this test code will fail. For example, only a
45 very limited subset of 'git' arguments is supported - anything
49 self._base_dir = tempfile.mkdtemp()
50 self._git_dir = os.path.join(self._base_dir, 'src')
51 self._buildman_pathname = sys.argv[0]
52 self._buildman_dir = os.path.dirname(sys.argv[0])
53 command.test_result = self._HandleCommand
54 self._toolchains = toolchain.Toolchains()
55 self._toolchains.Add('gcc', test=False)
57 bsettings.AddFile(settings_data)
60 shutil.rmtree(self._base_dir)
62 def _RunBuildman(self, *args):
63 return command.RunPipe([[self._buildman_pathname] + list(args)],
64 capture=True, capture_stderr=True)
66 def _RunControl(self, *args):
67 sys.argv = [sys.argv[0]] + list(args)
68 options, args = cmdline.ParseArgs()
69 return control.DoBuildman(options, args, toolchains=self._toolchains,
70 make_func=self._HandleMake)
72 def testFullHelp(self):
73 command.test_result = None
74 result = self._RunBuildman('-H')
75 help_file = os.path.join(self._buildman_dir, 'README')
76 self.assertEqual(len(result.stdout), os.path.getsize(help_file))
77 self.assertEqual(0, len(result.stderr))
78 self.assertEqual(0, result.return_code)
81 command.test_result = None
82 result = self._RunBuildman('-h')
83 help_file = os.path.join(self._buildman_dir, 'README')
84 self.assertTrue(len(result.stdout) > 1000)
85 self.assertEqual(0, len(result.stderr))
86 self.assertEqual(0, result.return_code)
88 def testGitSetup(self):
89 """Test gitutils.Setup(), from outside the module itself"""
90 command.test_result = command.CommandResult(return_code=1)
92 self.assertEqual(gitutil.use_no_decorate, False)
94 command.test_result = command.CommandResult(return_code=0)
96 self.assertEqual(gitutil.use_no_decorate, True)
98 def _HandleCommandGitLog(self, args):
100 return command.CommandResult(return_code=0)
102 # Not handled, so abort
103 print 'git log', args
106 def _HandleCommandGit(self, in_args):
107 """Handle execution of a git command
109 This uses a hacked-up parser.
112 in_args: Arguments after 'git' from the command line
114 git_args = [] # Top-level arguments to git itself
115 sub_cmd = None # Git sub-command selected
116 args = [] # Arguments to the git sub-command
124 if sub_cmd == 'config':
125 return command.CommandResult(return_code=0)
126 elif sub_cmd == 'log':
127 return self._HandleCommandGitLog(args)
129 # Not handled, so abort
130 print 'git', git_args, sub_cmd, args
133 def _HandleCommandNm(self, args):
134 return command.CommandResult(return_code=0)
136 def _HandleCommandObjdump(self, args):
137 return command.CommandResult(return_code=0)
139 def _HandleCommandSize(self, args):
140 return command.CommandResult(return_code=0)
142 def _HandleCommand(self, **kwargs):
143 """Handle a command execution.
145 The command is in kwargs['pipe-list'], as a list of pipes, each a
146 list of commands. The command should be emulated as required for
150 A CommandResult object
152 pipe_list = kwargs['pipe_list']
153 if len(pipe_list) != 1:
154 print 'invalid pipe', kwargs
156 cmd = pipe_list[0][0]
157 args = pipe_list[0][1:]
159 return self._HandleCommandGit(args)
160 elif cmd == './scripts/show-gnu-make':
161 return command.CommandResult(return_code=0, stdout='make')
163 return self._HandleCommandNm(args)
164 elif cmd == 'objdump':
165 return self._HandleCommandObjdump(args)
167 return self._HandleCommandSize(args)
169 # Not handled, so abort
170 print 'unknown command', kwargs
172 return command.CommandResult(return_code=0)
174 def _HandleMake(self, commit, brd, stage, cwd, *args, **kwargs):
175 """Handle execution of 'make'
178 commit: Commit object that is being built
179 brd: Board object that is being built
180 stage: Stage that we are at (mrproper, config, build)
181 cwd: Directory where make should be run
182 args: Arguments to pass to make
183 kwargs: Arguments to pass to command.RunPipe()
185 if stage == 'mrproper':
186 return command.CommandResult(return_code=0)
187 elif stage == 'config':
188 return command.CommandResult(return_code=0,
189 combined='Test configuration complete')
190 elif stage == 'build':
191 return command.CommandResult(return_code=0)
193 # Not handled, so abort
197 def testCurrentSource(self):
198 """Very simple test to invoke buildman on the current source"""
200 lines = terminal.GetPrintTestLines()
201 self.assertTrue(lines[0].text.startswith('Building current source'))