blob: 03ff576c9e7a5c5f9b42358bd2d5946f5a960520 [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#
Simon Glass40d97342020-06-14 10:54:04 -06004# Tests for U-Boot-specific checkpatch.pl features
5#
Simon Glass0d24de92012-01-14 15:12:45 +00006# Copyright (c) 2011 The Chromium OS Authors.
7#
Simon Glass0d24de92012-01-14 15:12:45 +00008
9import os
10import tempfile
11import unittest
12
Simon Glassbf776672020-04-17 18:09:04 -060013from patman import checkpatch
14from patman import gitutil
15from patman import patchstream
16from patman import series
17from patman import commit
Simon Glass0d24de92012-01-14 15:12:45 +000018
19
20class TestPatch(unittest.TestCase):
Simon Glass40d97342020-06-14 10:54:04 -060021 """Test the u_boot_line() function in checkpatch.pl"""
Simon Glass0d24de92012-01-14 15:12:45 +000022
23 def testBasic(self):
24 """Test basic filter operation"""
25 data='''
26
27From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
28From: Simon Glass <sjg@chromium.org>
29Date: Thu, 28 Apr 2011 09:58:51 -0700
30Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
31
32This adds functions to enable/disable clocks and reset to on-chip peripherals.
33
Simon Glass2eb5fc12017-05-29 15:31:28 -060034cmd/pci.c:152:11: warning: format ‘%llx’ expects argument of type
35 ‘long long unsigned int’, but argument 3 has type
36 ‘u64 {aka long unsigned int}’ [-Wformat=]
37
Simon Glass0d24de92012-01-14 15:12:45 +000038BUG=chromium-os:13875
39TEST=build U-Boot for Seaboard, boot
40
41Change-Id: I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413
42
43Review URL: http://codereview.chromium.org/6900006
44
45Signed-off-by: Simon Glass <sjg@chromium.org>
46---
47 arch/arm/cpu/armv7/tegra2/Makefile | 2 +-
48 arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++----
49 arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++
50'''
Douglas Anderson833e4192019-09-27 09:23:56 -070051 expected='''Message-Id: <19991231235959.0.I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413@changeid>
52
Simon Glass0d24de92012-01-14 15:12:45 +000053
54From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
55From: Simon Glass <sjg@chromium.org>
56Date: Thu, 28 Apr 2011 09:58:51 -0700
57Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
58
59This adds functions to enable/disable clocks and reset to on-chip peripherals.
60
Simon Glass2eb5fc12017-05-29 15:31:28 -060061cmd/pci.c:152:11: warning: format ‘%llx’ expects argument of type
62 ‘long long unsigned int’, but argument 3 has type
63 ‘u64 {aka long unsigned int}’ [-Wformat=]
64
Simon Glass0d24de92012-01-14 15:12:45 +000065Signed-off-by: Simon Glass <sjg@chromium.org>
66---
Simon Glasse752edc2014-08-28 09:43:35 -060067
Simon Glass0d24de92012-01-14 15:12:45 +000068 arch/arm/cpu/armv7/tegra2/Makefile | 2 +-
69 arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++----
70 arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++
71'''
72 out = ''
73 inhandle, inname = tempfile.mkstemp()
Simon Glass272cd852019-10-31 07:42:51 -060074 infd = os.fdopen(inhandle, 'w', encoding='utf-8')
Simon Glass0d24de92012-01-14 15:12:45 +000075 infd.write(data)
76 infd.close()
77
78 exphandle, expname = tempfile.mkstemp()
Simon Glass272cd852019-10-31 07:42:51 -060079 expfd = os.fdopen(exphandle, 'w', encoding='utf-8')
Simon Glass0d24de92012-01-14 15:12:45 +000080 expfd.write(expected)
81 expfd.close()
82
Douglas Anderson833e4192019-09-27 09:23:56 -070083 # Normally by the time we call FixPatch we've already collected
84 # metadata. Here, we haven't, but at least fake up something.
85 # Set the "count" to -1 which tells FixPatch to use a bogus/fixed
86 # time for generating the Message-Id.
87 com = commit.Commit('')
88 com.change_id = 'I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413'
89 com.count = -1
90
91 patchstream.FixPatch(None, inname, series.Series(), com)
92
Simon Glass0d24de92012-01-14 15:12:45 +000093 rc = os.system('diff -u %s %s' % (inname, expname))
94 self.assertEqual(rc, 0)
95
96 os.remove(inname)
97 os.remove(expname)
98
99 def GetData(self, data_type):
Simon Glass6c328f22017-11-12 21:52:12 -0700100 data='''From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001
Simon Glass0d24de92012-01-14 15:12:45 +0000101From: Simon Glass <sjg@chromium.org>
102Date: Thu, 7 Apr 2011 10:14:41 -0700
103Subject: [PATCH 1/4] Add microsecond boot time measurement
104
105This defines the basics of a new boot time measurement feature. This allows
106logging of very accurate time measurements as the boot proceeds, by using
107an available microsecond counter.
108
109%s
110---
111 README | 11 ++++++++
Simon Glass6c328f22017-11-12 21:52:12 -0700112 MAINTAINERS | 3 ++
Simon Glass0d24de92012-01-14 15:12:45 +0000113 common/bootstage.c | 50 ++++++++++++++++++++++++++++++++++++
114 include/bootstage.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++
115 include/common.h | 8 ++++++
116 5 files changed, 141 insertions(+), 0 deletions(-)
117 create mode 100644 common/bootstage.c
118 create mode 100644 include/bootstage.h
119
120diff --git a/README b/README
121index 6f3748d..f9e4e65 100644
122--- a/README
123+++ b/README
124@@ -2026,6 +2026,17 @@ The following options need to be configured:
Doug Anderson05d52822012-11-26 15:21:39 +0000125 example, some LED's) on your board. At the moment,
126 the following checkpoints are implemented:
Simon Glass0d24de92012-01-14 15:12:45 +0000127
128+- Time boot progress
129+ CONFIG_BOOTSTAGE
130+
131+ Define this option to enable microsecond boot stage timing
132+ on supported platforms. For this to work your platform
133+ needs to define a function timer_get_us() which returns the
134+ number of microseconds since reset. This would normally
135+ be done in your SOC or board timer.c file.
136+
137+ You can add calls to bootstage_mark() to set time markers.
138+
139 - Standalone program support:
Doug Anderson05d52822012-11-26 15:21:39 +0000140 CONFIG_STANDALONE_LOAD_ADDR
Simon Glass0d24de92012-01-14 15:12:45 +0000141
Simon Glass6c328f22017-11-12 21:52:12 -0700142diff --git a/MAINTAINERS b/MAINTAINERS
143index b167b028ec..beb7dc634f 100644
144--- a/MAINTAINERS
145+++ b/MAINTAINERS
146@@ -474,3 +474,8 @@ S: Maintained
147 T: git git://git.denx.de/u-boot.git
148 F: *
149 F: */
150+
151+BOOTSTAGE
152+M: Simon Glass <sjg@chromium.org>
153+L: u-boot@lists.denx.de
154+F: common/bootstage.c
Simon Glass0d24de92012-01-14 15:12:45 +0000155diff --git a/common/bootstage.c b/common/bootstage.c
156new file mode 100644
157index 0000000..2234c87
158--- /dev/null
159+++ b/common/bootstage.c
Simon Glass6c328f22017-11-12 21:52:12 -0700160@@ -0,0 +1,37 @@
Chris Packhamfe6ef1e2018-06-07 20:45:07 +1200161+%s
Simon Glass0d24de92012-01-14 15:12:45 +0000162+/*
163+ * Copyright (c) 2011, Google Inc. All rights reserved.
164+ *
Simon Glass0d24de92012-01-14 15:12:45 +0000165+ */
166+
Simon Glass0d24de92012-01-14 15:12:45 +0000167+/*
168+ * This module records the progress of boot and arbitrary commands, and
169+ * permits accurate timestamping of each. The records can optionally be
170+ * passed to kernel in the ATAGs
171+ */
172+
173+#include <common.h>
174+
Simon Glass0d24de92012-01-14 15:12:45 +0000175+struct bootstage_record {
Simon Glass6c328f22017-11-12 21:52:12 -0700176+ u32 time_us;
Simon Glass0d24de92012-01-14 15:12:45 +0000177+ const char *name;
178+};
179+
180+static struct bootstage_record record[BOOTSTAGE_COUNT];
181+
Simon Glass6c328f22017-11-12 21:52:12 -0700182+u32 bootstage_mark(enum bootstage_id id, const char *name)
Simon Glass0d24de92012-01-14 15:12:45 +0000183+{
184+ struct bootstage_record *rec = &record[id];
185+
186+ /* Only record the first event for each */
187+%sif (!rec->name) {
Simon Glass6c328f22017-11-12 21:52:12 -0700188+ rec->time_us = (u32)timer_get_us();
Simon Glass0d24de92012-01-14 15:12:45 +0000189+ rec->name = name;
190+ }
Simon Glassd29fe6e2013-03-26 13:09:39 +0000191+ if (!rec->name &&
192+ %ssomething_else) {
Simon Glass6c328f22017-11-12 21:52:12 -0700193+ rec->time_us = (u32)timer_get_us();
Simon Glassd29fe6e2013-03-26 13:09:39 +0000194+ rec->name = name;
195+ }
Simon Glass0d24de92012-01-14 15:12:45 +0000196+%sreturn rec->time_us;
197+}
198--
1991.7.3.1
200'''
201 signoff = 'Signed-off-by: Simon Glass <sjg@chromium.org>\n'
Chris Packhamfe6ef1e2018-06-07 20:45:07 +1200202 license = '// SPDX-License-Identifier: GPL-2.0+'
Simon Glass0d24de92012-01-14 15:12:45 +0000203 tab = ' '
Simon Glassd29fe6e2013-03-26 13:09:39 +0000204 indent = ' '
Simon Glass0d24de92012-01-14 15:12:45 +0000205 if data_type == 'good':
206 pass
207 elif data_type == 'no-signoff':
208 signoff = ''
Chris Packhamfe6ef1e2018-06-07 20:45:07 +1200209 elif data_type == 'no-license':
210 license = ''
Simon Glass0d24de92012-01-14 15:12:45 +0000211 elif data_type == 'spaces':
212 tab = ' '
Simon Glassd29fe6e2013-03-26 13:09:39 +0000213 elif data_type == 'indent':
214 indent = tab
Simon Glass0d24de92012-01-14 15:12:45 +0000215 else:
Paul Burtona920a172016-09-27 16:03:50 +0100216 print('not implemented')
Chris Packhamfe6ef1e2018-06-07 20:45:07 +1200217 return data % (signoff, license, tab, indent, tab)
Simon Glass0d24de92012-01-14 15:12:45 +0000218
219 def SetupData(self, data_type):
220 inhandle, inname = tempfile.mkstemp()
221 infd = os.fdopen(inhandle, 'w')
222 data = self.GetData(data_type)
223 infd.write(data)
224 infd.close()
225 return inname
226
Simon Glassd29fe6e2013-03-26 13:09:39 +0000227 def testGood(self):
Simon Glass0d24de92012-01-14 15:12:45 +0000228 """Test checkpatch operation"""
229 inf = self.SetupData('good')
Simon Glassd29fe6e2013-03-26 13:09:39 +0000230 result = checkpatch.CheckPatch(inf)
231 self.assertEqual(result.ok, True)
232 self.assertEqual(result.problems, [])
233 self.assertEqual(result.errors, 0)
234 self.assertEqual(result.warnings, 0)
235 self.assertEqual(result.checks, 0)
Simon Glass6c328f22017-11-12 21:52:12 -0700236 self.assertEqual(result.lines, 62)
Simon Glass0d24de92012-01-14 15:12:45 +0000237 os.remove(inf)
238
Simon Glassd29fe6e2013-03-26 13:09:39 +0000239 def testNoSignoff(self):
Simon Glass0d24de92012-01-14 15:12:45 +0000240 inf = self.SetupData('no-signoff')
Simon Glassd29fe6e2013-03-26 13:09:39 +0000241 result = checkpatch.CheckPatch(inf)
242 self.assertEqual(result.ok, False)
243 self.assertEqual(len(result.problems), 1)
244 self.assertEqual(result.errors, 1)
245 self.assertEqual(result.warnings, 0)
246 self.assertEqual(result.checks, 0)
Simon Glass6c328f22017-11-12 21:52:12 -0700247 self.assertEqual(result.lines, 62)
Simon Glass0d24de92012-01-14 15:12:45 +0000248 os.remove(inf)
249
Chris Packhamfe6ef1e2018-06-07 20:45:07 +1200250 def testNoLicense(self):
251 inf = self.SetupData('no-license')
252 result = checkpatch.CheckPatch(inf)
253 self.assertEqual(result.ok, False)
254 self.assertEqual(len(result.problems), 1)
255 self.assertEqual(result.errors, 0)
256 self.assertEqual(result.warnings, 1)
257 self.assertEqual(result.checks, 0)
258 self.assertEqual(result.lines, 62)
259 os.remove(inf)
260
Simon Glassd29fe6e2013-03-26 13:09:39 +0000261 def testSpaces(self):
Simon Glass0d24de92012-01-14 15:12:45 +0000262 inf = self.SetupData('spaces')
Simon Glassd29fe6e2013-03-26 13:09:39 +0000263 result = checkpatch.CheckPatch(inf)
264 self.assertEqual(result.ok, False)
Simon Glass6c328f22017-11-12 21:52:12 -0700265 self.assertEqual(len(result.problems), 3)
Simon Glassd29fe6e2013-03-26 13:09:39 +0000266 self.assertEqual(result.errors, 0)
Simon Glass6c328f22017-11-12 21:52:12 -0700267 self.assertEqual(result.warnings, 3)
Simon Glassd29fe6e2013-03-26 13:09:39 +0000268 self.assertEqual(result.checks, 0)
Simon Glass6c328f22017-11-12 21:52:12 -0700269 self.assertEqual(result.lines, 62)
Simon Glassd29fe6e2013-03-26 13:09:39 +0000270 os.remove(inf)
271
272 def testIndent(self):
273 inf = self.SetupData('indent')
274 result = checkpatch.CheckPatch(inf)
275 self.assertEqual(result.ok, False)
276 self.assertEqual(len(result.problems), 1)
277 self.assertEqual(result.errors, 0)
278 self.assertEqual(result.warnings, 0)
279 self.assertEqual(result.checks, 1)
Simon Glass6c328f22017-11-12 21:52:12 -0700280 self.assertEqual(result.lines, 62)
Simon Glass0d24de92012-01-14 15:12:45 +0000281 os.remove(inf)
282
283
284if __name__ == "__main__":
285 unittest.main()
286 gitutil.RunTests()