blob: e7f709e34c7fcefb62198e628c0a59a6de57c873 [file] [log] [blame]
Simon Glass2eb5fc12017-05-29 15:31:28 -06001# -*- coding: utf-8 -*-
Tom Rini83d290c2018-05-06 17:58:06 -04002# SPDX-License-Identifier: GPL-2.0+
Simon Glass0d24de92012-01-14 15:12:45 +00003#
4# Copyright (c) 2011 The Chromium OS Authors.
5#
Simon Glass0d24de92012-01-14 15:12:45 +00006
7import os
8import tempfile
9import unittest
10
Simon Glassbf776672020-04-17 18:09:04 -060011from patman import checkpatch
12from patman import gitutil
13from patman import patchstream
14from patman import series
15from patman import commit
Simon Glass0d24de92012-01-14 15:12:45 +000016
17
18class TestPatch(unittest.TestCase):
19 """Test this program
20
21 TODO: Write tests for the rest of the functionality
22 """
23
24 def testBasic(self):
25 """Test basic filter operation"""
26 data='''
27
28From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
29From: Simon Glass <sjg@chromium.org>
30Date: Thu, 28 Apr 2011 09:58:51 -0700
31Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
32
33This adds functions to enable/disable clocks and reset to on-chip peripherals.
34
Simon Glass2eb5fc12017-05-29 15:31:28 -060035cmd/pci.c:152:11: warning: format ‘%llx’ expects argument of type
36 ‘long long unsigned int’, but argument 3 has type
37 ‘u64 {aka long unsigned int}’ [-Wformat=]
38
Simon Glass0d24de92012-01-14 15:12:45 +000039BUG=chromium-os:13875
40TEST=build U-Boot for Seaboard, boot
41
42Change-Id: I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413
43
44Review URL: http://codereview.chromium.org/6900006
45
46Signed-off-by: Simon Glass <sjg@chromium.org>
47---
48 arch/arm/cpu/armv7/tegra2/Makefile | 2 +-
49 arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++----
50 arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++
51'''
Douglas Anderson833e4192019-09-27 09:23:56 -070052 expected='''Message-Id: <19991231235959.0.I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413@changeid>
53
Simon Glass0d24de92012-01-14 15:12:45 +000054
55From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
56From: Simon Glass <sjg@chromium.org>
57Date: Thu, 28 Apr 2011 09:58:51 -0700
58Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
59
60This adds functions to enable/disable clocks and reset to on-chip peripherals.
61
Simon Glass2eb5fc12017-05-29 15:31:28 -060062cmd/pci.c:152:11: warning: format ‘%llx’ expects argument of type
63 ‘long long unsigned int’, but argument 3 has type
64 ‘u64 {aka long unsigned int}’ [-Wformat=]
65
Simon Glass0d24de92012-01-14 15:12:45 +000066Signed-off-by: Simon Glass <sjg@chromium.org>
67---
Simon Glasse752edc2014-08-28 09:43:35 -060068
Simon Glass0d24de92012-01-14 15:12:45 +000069 arch/arm/cpu/armv7/tegra2/Makefile | 2 +-
70 arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++----
71 arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++
72'''
73 out = ''
74 inhandle, inname = tempfile.mkstemp()
Simon Glass272cd852019-10-31 07:42:51 -060075 infd = os.fdopen(inhandle, 'w', encoding='utf-8')
Simon Glass0d24de92012-01-14 15:12:45 +000076 infd.write(data)
77 infd.close()
78
79 exphandle, expname = tempfile.mkstemp()
Simon Glass272cd852019-10-31 07:42:51 -060080 expfd = os.fdopen(exphandle, 'w', encoding='utf-8')
Simon Glass0d24de92012-01-14 15:12:45 +000081 expfd.write(expected)
82 expfd.close()
83
Douglas Anderson833e4192019-09-27 09:23:56 -070084 # Normally by the time we call FixPatch we've already collected
85 # metadata. Here, we haven't, but at least fake up something.
86 # Set the "count" to -1 which tells FixPatch to use a bogus/fixed
87 # time for generating the Message-Id.
88 com = commit.Commit('')
89 com.change_id = 'I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413'
90 com.count = -1
91
92 patchstream.FixPatch(None, inname, series.Series(), com)
93
Simon Glass0d24de92012-01-14 15:12:45 +000094 rc = os.system('diff -u %s %s' % (inname, expname))
95 self.assertEqual(rc, 0)
96
97 os.remove(inname)
98 os.remove(expname)
99
100 def GetData(self, data_type):
Simon Glass6c328f22017-11-12 21:52:12 -0700101 data='''From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001
Simon Glass0d24de92012-01-14 15:12:45 +0000102From: Simon Glass <sjg@chromium.org>
103Date: Thu, 7 Apr 2011 10:14:41 -0700
104Subject: [PATCH 1/4] Add microsecond boot time measurement
105
106This defines the basics of a new boot time measurement feature. This allows
107logging of very accurate time measurements as the boot proceeds, by using
108an available microsecond counter.
109
110%s
111---
112 README | 11 ++++++++
Simon Glass6c328f22017-11-12 21:52:12 -0700113 MAINTAINERS | 3 ++
Simon Glass0d24de92012-01-14 15:12:45 +0000114 common/bootstage.c | 50 ++++++++++++++++++++++++++++++++++++
115 include/bootstage.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++
116 include/common.h | 8 ++++++
117 5 files changed, 141 insertions(+), 0 deletions(-)
118 create mode 100644 common/bootstage.c
119 create mode 100644 include/bootstage.h
120
121diff --git a/README b/README
122index 6f3748d..f9e4e65 100644
123--- a/README
124+++ b/README
125@@ -2026,6 +2026,17 @@ The following options need to be configured:
Doug Anderson05d52822012-11-26 15:21:39 +0000126 example, some LED's) on your board. At the moment,
127 the following checkpoints are implemented:
Simon Glass0d24de92012-01-14 15:12:45 +0000128
129+- Time boot progress
130+ CONFIG_BOOTSTAGE
131+
132+ Define this option to enable microsecond boot stage timing
133+ on supported platforms. For this to work your platform
134+ needs to define a function timer_get_us() which returns the
135+ number of microseconds since reset. This would normally
136+ be done in your SOC or board timer.c file.
137+
138+ You can add calls to bootstage_mark() to set time markers.
139+
140 - Standalone program support:
Doug Anderson05d52822012-11-26 15:21:39 +0000141 CONFIG_STANDALONE_LOAD_ADDR
Simon Glass0d24de92012-01-14 15:12:45 +0000142
Simon Glass6c328f22017-11-12 21:52:12 -0700143diff --git a/MAINTAINERS b/MAINTAINERS
144index b167b028ec..beb7dc634f 100644
145--- a/MAINTAINERS
146+++ b/MAINTAINERS
147@@ -474,3 +474,8 @@ S: Maintained
148 T: git git://git.denx.de/u-boot.git
149 F: *
150 F: */
151+
152+BOOTSTAGE
153+M: Simon Glass <sjg@chromium.org>
154+L: u-boot@lists.denx.de
155+F: common/bootstage.c
Simon Glass0d24de92012-01-14 15:12:45 +0000156diff --git a/common/bootstage.c b/common/bootstage.c
157new file mode 100644
158index 0000000..2234c87
159--- /dev/null
160+++ b/common/bootstage.c
Simon Glass6c328f22017-11-12 21:52:12 -0700161@@ -0,0 +1,37 @@
Chris Packhamfe6ef1e2018-06-07 20:45:07 +1200162+%s
Simon Glass0d24de92012-01-14 15:12:45 +0000163+/*
164+ * Copyright (c) 2011, Google Inc. All rights reserved.
165+ *
Simon Glass0d24de92012-01-14 15:12:45 +0000166+ */
167+
Simon Glass0d24de92012-01-14 15:12:45 +0000168+/*
169+ * This module records the progress of boot and arbitrary commands, and
170+ * permits accurate timestamping of each. The records can optionally be
171+ * passed to kernel in the ATAGs
172+ */
173+
174+#include <common.h>
175+
Simon Glass0d24de92012-01-14 15:12:45 +0000176+struct bootstage_record {
Simon Glass6c328f22017-11-12 21:52:12 -0700177+ u32 time_us;
Simon Glass0d24de92012-01-14 15:12:45 +0000178+ const char *name;
179+};
180+
181+static struct bootstage_record record[BOOTSTAGE_COUNT];
182+
Simon Glass6c328f22017-11-12 21:52:12 -0700183+u32 bootstage_mark(enum bootstage_id id, const char *name)
Simon Glass0d24de92012-01-14 15:12:45 +0000184+{
185+ struct bootstage_record *rec = &record[id];
186+
187+ /* Only record the first event for each */
188+%sif (!rec->name) {
Simon Glass6c328f22017-11-12 21:52:12 -0700189+ rec->time_us = (u32)timer_get_us();
Simon Glass0d24de92012-01-14 15:12:45 +0000190+ rec->name = name;
191+ }
Simon Glassd29fe6e2013-03-26 13:09:39 +0000192+ if (!rec->name &&
193+ %ssomething_else) {
Simon Glass6c328f22017-11-12 21:52:12 -0700194+ rec->time_us = (u32)timer_get_us();
Simon Glassd29fe6e2013-03-26 13:09:39 +0000195+ rec->name = name;
196+ }
Simon Glass0d24de92012-01-14 15:12:45 +0000197+%sreturn rec->time_us;
198+}
199--
2001.7.3.1
201'''
202 signoff = 'Signed-off-by: Simon Glass <sjg@chromium.org>\n'
Chris Packhamfe6ef1e2018-06-07 20:45:07 +1200203 license = '// SPDX-License-Identifier: GPL-2.0+'
Simon Glass0d24de92012-01-14 15:12:45 +0000204 tab = ' '
Simon Glassd29fe6e2013-03-26 13:09:39 +0000205 indent = ' '
Simon Glass0d24de92012-01-14 15:12:45 +0000206 if data_type == 'good':
207 pass
208 elif data_type == 'no-signoff':
209 signoff = ''
Chris Packhamfe6ef1e2018-06-07 20:45:07 +1200210 elif data_type == 'no-license':
211 license = ''
Simon Glass0d24de92012-01-14 15:12:45 +0000212 elif data_type == 'spaces':
213 tab = ' '
Simon Glassd29fe6e2013-03-26 13:09:39 +0000214 elif data_type == 'indent':
215 indent = tab
Simon Glass0d24de92012-01-14 15:12:45 +0000216 else:
Paul Burtona920a172016-09-27 16:03:50 +0100217 print('not implemented')
Chris Packhamfe6ef1e2018-06-07 20:45:07 +1200218 return data % (signoff, license, tab, indent, tab)
Simon Glass0d24de92012-01-14 15:12:45 +0000219
220 def SetupData(self, data_type):
221 inhandle, inname = tempfile.mkstemp()
222 infd = os.fdopen(inhandle, 'w')
223 data = self.GetData(data_type)
224 infd.write(data)
225 infd.close()
226 return inname
227
Simon Glassd29fe6e2013-03-26 13:09:39 +0000228 def testGood(self):
Simon Glass0d24de92012-01-14 15:12:45 +0000229 """Test checkpatch operation"""
230 inf = self.SetupData('good')
Simon Glassd29fe6e2013-03-26 13:09:39 +0000231 result = checkpatch.CheckPatch(inf)
232 self.assertEqual(result.ok, True)
233 self.assertEqual(result.problems, [])
234 self.assertEqual(result.errors, 0)
235 self.assertEqual(result.warnings, 0)
236 self.assertEqual(result.checks, 0)
Simon Glass6c328f22017-11-12 21:52:12 -0700237 self.assertEqual(result.lines, 62)
Simon Glass0d24de92012-01-14 15:12:45 +0000238 os.remove(inf)
239
Simon Glassd29fe6e2013-03-26 13:09:39 +0000240 def testNoSignoff(self):
Simon Glass0d24de92012-01-14 15:12:45 +0000241 inf = self.SetupData('no-signoff')
Simon Glassd29fe6e2013-03-26 13:09:39 +0000242 result = checkpatch.CheckPatch(inf)
243 self.assertEqual(result.ok, False)
244 self.assertEqual(len(result.problems), 1)
245 self.assertEqual(result.errors, 1)
246 self.assertEqual(result.warnings, 0)
247 self.assertEqual(result.checks, 0)
Simon Glass6c328f22017-11-12 21:52:12 -0700248 self.assertEqual(result.lines, 62)
Simon Glass0d24de92012-01-14 15:12:45 +0000249 os.remove(inf)
250
Chris Packhamfe6ef1e2018-06-07 20:45:07 +1200251 def testNoLicense(self):
252 inf = self.SetupData('no-license')
253 result = checkpatch.CheckPatch(inf)
254 self.assertEqual(result.ok, False)
255 self.assertEqual(len(result.problems), 1)
256 self.assertEqual(result.errors, 0)
257 self.assertEqual(result.warnings, 1)
258 self.assertEqual(result.checks, 0)
259 self.assertEqual(result.lines, 62)
260 os.remove(inf)
261
Simon Glassd29fe6e2013-03-26 13:09:39 +0000262 def testSpaces(self):
Simon Glass0d24de92012-01-14 15:12:45 +0000263 inf = self.SetupData('spaces')
Simon Glassd29fe6e2013-03-26 13:09:39 +0000264 result = checkpatch.CheckPatch(inf)
265 self.assertEqual(result.ok, False)
Simon Glass6c328f22017-11-12 21:52:12 -0700266 self.assertEqual(len(result.problems), 3)
Simon Glassd29fe6e2013-03-26 13:09:39 +0000267 self.assertEqual(result.errors, 0)
Simon Glass6c328f22017-11-12 21:52:12 -0700268 self.assertEqual(result.warnings, 3)
Simon Glassd29fe6e2013-03-26 13:09:39 +0000269 self.assertEqual(result.checks, 0)
Simon Glass6c328f22017-11-12 21:52:12 -0700270 self.assertEqual(result.lines, 62)
Simon Glassd29fe6e2013-03-26 13:09:39 +0000271 os.remove(inf)
272
273 def testIndent(self):
274 inf = self.SetupData('indent')
275 result = checkpatch.CheckPatch(inf)
276 self.assertEqual(result.ok, False)
277 self.assertEqual(len(result.problems), 1)
278 self.assertEqual(result.errors, 0)
279 self.assertEqual(result.warnings, 0)
280 self.assertEqual(result.checks, 1)
Simon Glass6c328f22017-11-12 21:52:12 -0700281 self.assertEqual(result.lines, 62)
Simon Glass0d24de92012-01-14 15:12:45 +0000282 os.remove(inf)
283
284
285if __name__ == "__main__":
286 unittest.main()
287 gitutil.RunTests()