blob: e8f7472785fb5704fb5df8da85d3758163f9686c [file] [log] [blame]
Simon Glass0d24de92012-01-14 15:12:45 +00001#
2# Copyright (c) 2011 The Chromium OS Authors.
3#
Wolfgang Denk1a459662013-07-08 09:37:19 +02004# SPDX-License-Identifier: GPL-2.0+
Simon Glass0d24de92012-01-14 15:12:45 +00005#
6
7import os
8import tempfile
9import unittest
10
11import checkpatch
12import gitutil
13import patchstream
14import series
15
16
17class TestPatch(unittest.TestCase):
18 """Test this program
19
20 TODO: Write tests for the rest of the functionality
21 """
22
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
34BUG=chromium-os:13875
35TEST=build U-Boot for Seaboard, boot
36
37Change-Id: I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413
38
39Review URL: http://codereview.chromium.org/6900006
40
41Signed-off-by: Simon Glass <sjg@chromium.org>
42---
43 arch/arm/cpu/armv7/tegra2/Makefile | 2 +-
44 arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++----
45 arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++
46'''
47 expected='''
48
49From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
50From: Simon Glass <sjg@chromium.org>
51Date: Thu, 28 Apr 2011 09:58:51 -0700
52Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
53
54This adds functions to enable/disable clocks and reset to on-chip peripherals.
55
56Signed-off-by: Simon Glass <sjg@chromium.org>
57---
Simon Glasse752edc2014-08-28 09:43:35 -060058
Simon Glass0d24de92012-01-14 15:12:45 +000059 arch/arm/cpu/armv7/tegra2/Makefile | 2 +-
60 arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++----
61 arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++
62'''
63 out = ''
64 inhandle, inname = tempfile.mkstemp()
65 infd = os.fdopen(inhandle, 'w')
66 infd.write(data)
67 infd.close()
68
69 exphandle, expname = tempfile.mkstemp()
70 expfd = os.fdopen(exphandle, 'w')
71 expfd.write(expected)
72 expfd.close()
73
74 patchstream.FixPatch(None, inname, series.Series(), None)
75 rc = os.system('diff -u %s %s' % (inname, expname))
76 self.assertEqual(rc, 0)
77
78 os.remove(inname)
79 os.remove(expname)
80
81 def GetData(self, data_type):
82 data='''
83From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001
84From: Simon Glass <sjg@chromium.org>
85Date: Thu, 7 Apr 2011 10:14:41 -0700
86Subject: [PATCH 1/4] Add microsecond boot time measurement
87
88This defines the basics of a new boot time measurement feature. This allows
89logging of very accurate time measurements as the boot proceeds, by using
90an available microsecond counter.
91
92%s
93---
94 README | 11 ++++++++
95 common/bootstage.c | 50 ++++++++++++++++++++++++++++++++++++
96 include/bootstage.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++
97 include/common.h | 8 ++++++
98 5 files changed, 141 insertions(+), 0 deletions(-)
99 create mode 100644 common/bootstage.c
100 create mode 100644 include/bootstage.h
101
102diff --git a/README b/README
103index 6f3748d..f9e4e65 100644
104--- a/README
105+++ b/README
106@@ -2026,6 +2026,17 @@ The following options need to be configured:
Doug Anderson05d52822012-11-26 15:21:39 +0000107 example, some LED's) on your board. At the moment,
108 the following checkpoints are implemented:
Simon Glass0d24de92012-01-14 15:12:45 +0000109
110+- Time boot progress
111+ CONFIG_BOOTSTAGE
112+
113+ Define this option to enable microsecond boot stage timing
114+ on supported platforms. For this to work your platform
115+ needs to define a function timer_get_us() which returns the
116+ number of microseconds since reset. This would normally
117+ be done in your SOC or board timer.c file.
118+
119+ You can add calls to bootstage_mark() to set time markers.
120+
121 - Standalone program support:
Doug Anderson05d52822012-11-26 15:21:39 +0000122 CONFIG_STANDALONE_LOAD_ADDR
Simon Glass0d24de92012-01-14 15:12:45 +0000123
124diff --git a/common/bootstage.c b/common/bootstage.c
125new file mode 100644
126index 0000000..2234c87
127--- /dev/null
128+++ b/common/bootstage.c
Wolfgang Denk1a459662013-07-08 09:37:19 +0200129@@ -0,0 +1,39 @@
Simon Glass0d24de92012-01-14 15:12:45 +0000130+/*
131+ * Copyright (c) 2011, Google Inc. All rights reserved.
132+ *
Wolfgang Denk1a459662013-07-08 09:37:19 +0200133+ * SPDX-License-Identifier: GPL-2.0+
Simon Glass0d24de92012-01-14 15:12:45 +0000134+ */
135+
136+
137+/*
138+ * This module records the progress of boot and arbitrary commands, and
139+ * permits accurate timestamping of each. The records can optionally be
140+ * passed to kernel in the ATAGs
141+ */
142+
143+#include <common.h>
144+
145+
146+struct bootstage_record {
147+ uint32_t time_us;
148+ const char *name;
149+};
150+
151+static struct bootstage_record record[BOOTSTAGE_COUNT];
152+
153+uint32_t bootstage_mark(enum bootstage_id id, const char *name)
154+{
155+ struct bootstage_record *rec = &record[id];
156+
157+ /* Only record the first event for each */
158+%sif (!rec->name) {
159+ rec->time_us = (uint32_t)timer_get_us();
160+ rec->name = name;
161+ }
Simon Glassd29fe6e2013-03-26 13:09:39 +0000162+ if (!rec->name &&
163+ %ssomething_else) {
164+ rec->time_us = (uint32_t)timer_get_us();
165+ rec->name = name;
166+ }
Simon Glass0d24de92012-01-14 15:12:45 +0000167+%sreturn rec->time_us;
168+}
169--
1701.7.3.1
171'''
172 signoff = 'Signed-off-by: Simon Glass <sjg@chromium.org>\n'
173 tab = ' '
Simon Glassd29fe6e2013-03-26 13:09:39 +0000174 indent = ' '
Simon Glass0d24de92012-01-14 15:12:45 +0000175 if data_type == 'good':
176 pass
177 elif data_type == 'no-signoff':
178 signoff = ''
179 elif data_type == 'spaces':
180 tab = ' '
Simon Glassd29fe6e2013-03-26 13:09:39 +0000181 elif data_type == 'indent':
182 indent = tab
Simon Glass0d24de92012-01-14 15:12:45 +0000183 else:
184 print 'not implemented'
Simon Glassd29fe6e2013-03-26 13:09:39 +0000185 return data % (signoff, tab, indent, tab)
Simon Glass0d24de92012-01-14 15:12:45 +0000186
187 def SetupData(self, data_type):
188 inhandle, inname = tempfile.mkstemp()
189 infd = os.fdopen(inhandle, 'w')
190 data = self.GetData(data_type)
191 infd.write(data)
192 infd.close()
193 return inname
194
Simon Glassd29fe6e2013-03-26 13:09:39 +0000195 def testGood(self):
Simon Glass0d24de92012-01-14 15:12:45 +0000196 """Test checkpatch operation"""
197 inf = self.SetupData('good')
Simon Glassd29fe6e2013-03-26 13:09:39 +0000198 result = checkpatch.CheckPatch(inf)
199 self.assertEqual(result.ok, True)
200 self.assertEqual(result.problems, [])
201 self.assertEqual(result.errors, 0)
202 self.assertEqual(result.warnings, 0)
203 self.assertEqual(result.checks, 0)
Simon Glasse752edc2014-08-28 09:43:35 -0600204 self.assertEqual(result.lines, 56)
Simon Glass0d24de92012-01-14 15:12:45 +0000205 os.remove(inf)
206
Simon Glassd29fe6e2013-03-26 13:09:39 +0000207 def testNoSignoff(self):
Simon Glass0d24de92012-01-14 15:12:45 +0000208 inf = self.SetupData('no-signoff')
Simon Glassd29fe6e2013-03-26 13:09:39 +0000209 result = checkpatch.CheckPatch(inf)
210 self.assertEqual(result.ok, False)
211 self.assertEqual(len(result.problems), 1)
212 self.assertEqual(result.errors, 1)
213 self.assertEqual(result.warnings, 0)
214 self.assertEqual(result.checks, 0)
Simon Glasse752edc2014-08-28 09:43:35 -0600215 self.assertEqual(result.lines, 56)
Simon Glass0d24de92012-01-14 15:12:45 +0000216 os.remove(inf)
217
Simon Glassd29fe6e2013-03-26 13:09:39 +0000218 def testSpaces(self):
Simon Glass0d24de92012-01-14 15:12:45 +0000219 inf = self.SetupData('spaces')
Simon Glassd29fe6e2013-03-26 13:09:39 +0000220 result = checkpatch.CheckPatch(inf)
221 self.assertEqual(result.ok, False)
Simon Glasse752edc2014-08-28 09:43:35 -0600222 self.assertEqual(len(result.problems), 2)
Simon Glassd29fe6e2013-03-26 13:09:39 +0000223 self.assertEqual(result.errors, 0)
Simon Glasse752edc2014-08-28 09:43:35 -0600224 self.assertEqual(result.warnings, 2)
Simon Glassd29fe6e2013-03-26 13:09:39 +0000225 self.assertEqual(result.checks, 0)
Simon Glasse752edc2014-08-28 09:43:35 -0600226 self.assertEqual(result.lines, 56)
Simon Glassd29fe6e2013-03-26 13:09:39 +0000227 os.remove(inf)
228
229 def testIndent(self):
230 inf = self.SetupData('indent')
231 result = checkpatch.CheckPatch(inf)
232 self.assertEqual(result.ok, False)
233 self.assertEqual(len(result.problems), 1)
234 self.assertEqual(result.errors, 0)
235 self.assertEqual(result.warnings, 0)
236 self.assertEqual(result.checks, 1)
Simon Glasse752edc2014-08-28 09:43:35 -0600237 self.assertEqual(result.lines, 56)
Simon Glass0d24de92012-01-14 15:12:45 +0000238 os.remove(inf)
239
240
241if __name__ == "__main__":
242 unittest.main()
243 gitutil.RunTests()