blob: 8cd26471c3c9854e433e63ae18495d395d123e05 [file] [log] [blame]
Simon Glass26132882012-01-14 15:12:45 +00001#
2# Copyright (c) 2011 The Chromium OS Authors.
3#
4# See file CREDITS for list of people who contributed to this
5# project.
6#
7# This program is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License as
9# published by the Free Software Foundation; either version 2 of
10# the License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20# MA 02111-1307 USA
21#
22
23import os
24import tempfile
25import unittest
26
27import checkpatch
28import gitutil
29import patchstream
30import series
31
32
33class TestPatch(unittest.TestCase):
34 """Test this program
35
36 TODO: Write tests for the rest of the functionality
37 """
38
39 def testBasic(self):
40 """Test basic filter operation"""
41 data='''
42
43From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
44From: Simon Glass <sjg@chromium.org>
45Date: Thu, 28 Apr 2011 09:58:51 -0700
46Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
47
48This adds functions to enable/disable clocks and reset to on-chip peripherals.
49
50BUG=chromium-os:13875
51TEST=build U-Boot for Seaboard, boot
52
53Change-Id: I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413
54
55Review URL: http://codereview.chromium.org/6900006
56
57Signed-off-by: Simon Glass <sjg@chromium.org>
58---
59 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 expected='''
64
65From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
66From: Simon Glass <sjg@chromium.org>
67Date: Thu, 28 Apr 2011 09:58:51 -0700
68Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
69
70This adds functions to enable/disable clocks and reset to on-chip peripherals.
71
72Signed-off-by: Simon Glass <sjg@chromium.org>
73---
74 arch/arm/cpu/armv7/tegra2/Makefile | 2 +-
75 arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++----
76 arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++
77'''
78 out = ''
79 inhandle, inname = tempfile.mkstemp()
80 infd = os.fdopen(inhandle, 'w')
81 infd.write(data)
82 infd.close()
83
84 exphandle, expname = tempfile.mkstemp()
85 expfd = os.fdopen(exphandle, 'w')
86 expfd.write(expected)
87 expfd.close()
88
89 patchstream.FixPatch(None, inname, series.Series(), None)
90 rc = os.system('diff -u %s %s' % (inname, expname))
91 self.assertEqual(rc, 0)
92
93 os.remove(inname)
94 os.remove(expname)
95
96 def GetData(self, data_type):
97 data='''
98From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001
99From: Simon Glass <sjg@chromium.org>
100Date: Thu, 7 Apr 2011 10:14:41 -0700
101Subject: [PATCH 1/4] Add microsecond boot time measurement
102
103This defines the basics of a new boot time measurement feature. This allows
104logging of very accurate time measurements as the boot proceeds, by using
105an available microsecond counter.
106
107%s
108---
109 README | 11 ++++++++
110 common/bootstage.c | 50 ++++++++++++++++++++++++++++++++++++
111 include/bootstage.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++
112 include/common.h | 8 ++++++
113 5 files changed, 141 insertions(+), 0 deletions(-)
114 create mode 100644 common/bootstage.c
115 create mode 100644 include/bootstage.h
116
117diff --git a/README b/README
118index 6f3748d..f9e4e65 100644
119--- a/README
120+++ b/README
121@@ -2026,6 +2026,17 @@ The following options need to be configured:
Doug Anderson37816752012-11-26 15:21:39 +0000122 example, some LED's) on your board. At the moment,
123 the following checkpoints are implemented:
Simon Glass26132882012-01-14 15:12:45 +0000124
125+- Time boot progress
126+ CONFIG_BOOTSTAGE
127+
128+ Define this option to enable microsecond boot stage timing
129+ on supported platforms. For this to work your platform
130+ needs to define a function timer_get_us() which returns the
131+ number of microseconds since reset. This would normally
132+ be done in your SOC or board timer.c file.
133+
134+ You can add calls to bootstage_mark() to set time markers.
135+
136 - Standalone program support:
Doug Anderson37816752012-11-26 15:21:39 +0000137 CONFIG_STANDALONE_LOAD_ADDR
Simon Glass26132882012-01-14 15:12:45 +0000138
139diff --git a/common/bootstage.c b/common/bootstage.c
140new file mode 100644
141index 0000000..2234c87
142--- /dev/null
143+++ b/common/bootstage.c
144@@ -0,0 +1,50 @@
145+/*
146+ * Copyright (c) 2011, Google Inc. All rights reserved.
147+ *
148+ * See file CREDITS for list of people who contributed to this
149+ * project.
150+ *
151+ * This program is free software; you can redistribute it and/or
152+ * modify it under the terms of the GNU General Public License as
153+ * published by the Free Software Foundation; either version 2 of
154+ * the License, or (at your option) any later version.
155+ *
156+ * This program is distributed in the hope that it will be useful,
157+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
158+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
159+ * GNU General Public License for more details.
160+ *
161+ * You should have received a copy of the GNU General Public License
162+ * along with this program; if not, write to the Free Software
163+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
164+ * MA 02111-1307 USA
165+ */
166+
167+
168+/*
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+
176+
177+struct bootstage_record {
178+ uint32_t time_us;
179+ const char *name;
180+};
181+
182+static struct bootstage_record record[BOOTSTAGE_COUNT];
183+
184+uint32_t bootstage_mark(enum bootstage_id id, const char *name)
185+{
186+ struct bootstage_record *rec = &record[id];
187+
188+ /* Only record the first event for each */
189+%sif (!rec->name) {
190+ rec->time_us = (uint32_t)timer_get_us();
191+ rec->name = name;
192+ }
Simon Glass0495abf2013-03-26 13:09:39 +0000193+ if (!rec->name &&
194+ %ssomething_else) {
195+ rec->time_us = (uint32_t)timer_get_us();
196+ rec->name = name;
197+ }
Simon Glass26132882012-01-14 15:12:45 +0000198+%sreturn rec->time_us;
199+}
200--
2011.7.3.1
202'''
203 signoff = 'Signed-off-by: Simon Glass <sjg@chromium.org>\n'
204 tab = ' '
Simon Glass0495abf2013-03-26 13:09:39 +0000205 indent = ' '
Simon Glass26132882012-01-14 15:12:45 +0000206 if data_type == 'good':
207 pass
208 elif data_type == 'no-signoff':
209 signoff = ''
210 elif data_type == 'spaces':
211 tab = ' '
Simon Glass0495abf2013-03-26 13:09:39 +0000212 elif data_type == 'indent':
213 indent = tab
Simon Glass26132882012-01-14 15:12:45 +0000214 else:
215 print 'not implemented'
Simon Glass0495abf2013-03-26 13:09:39 +0000216 return data % (signoff, tab, indent, tab)
Simon Glass26132882012-01-14 15:12:45 +0000217
218 def SetupData(self, data_type):
219 inhandle, inname = tempfile.mkstemp()
220 infd = os.fdopen(inhandle, 'w')
221 data = self.GetData(data_type)
222 infd.write(data)
223 infd.close()
224 return inname
225
Simon Glass0495abf2013-03-26 13:09:39 +0000226 def testGood(self):
Simon Glass26132882012-01-14 15:12:45 +0000227 """Test checkpatch operation"""
228 inf = self.SetupData('good')
Simon Glass0495abf2013-03-26 13:09:39 +0000229 result = checkpatch.CheckPatch(inf)
230 self.assertEqual(result.ok, True)
231 self.assertEqual(result.problems, [])
232 self.assertEqual(result.errors, 0)
233 self.assertEqual(result.warnings, 0)
234 self.assertEqual(result.checks, 0)
235 self.assertEqual(result.lines, 67)
Simon Glass26132882012-01-14 15:12:45 +0000236 os.remove(inf)
237
Simon Glass0495abf2013-03-26 13:09:39 +0000238 def testNoSignoff(self):
Simon Glass26132882012-01-14 15:12:45 +0000239 inf = self.SetupData('no-signoff')
Simon Glass0495abf2013-03-26 13:09:39 +0000240 result = checkpatch.CheckPatch(inf)
241 self.assertEqual(result.ok, False)
242 self.assertEqual(len(result.problems), 1)
243 self.assertEqual(result.errors, 1)
244 self.assertEqual(result.warnings, 0)
245 self.assertEqual(result.checks, 0)
246 self.assertEqual(result.lines, 67)
Simon Glass26132882012-01-14 15:12:45 +0000247 os.remove(inf)
248
Simon Glass0495abf2013-03-26 13:09:39 +0000249 def testSpaces(self):
Simon Glass26132882012-01-14 15:12:45 +0000250 inf = self.SetupData('spaces')
Simon Glass0495abf2013-03-26 13:09:39 +0000251 result = checkpatch.CheckPatch(inf)
252 self.assertEqual(result.ok, False)
253 self.assertEqual(len(result.problems), 1)
254 self.assertEqual(result.errors, 0)
255 self.assertEqual(result.warnings, 1)
256 self.assertEqual(result.checks, 0)
257 self.assertEqual(result.lines, 67)
258 os.remove(inf)
259
260 def testIndent(self):
261 inf = self.SetupData('indent')
262 result = checkpatch.CheckPatch(inf)
263 self.assertEqual(result.ok, False)
264 self.assertEqual(len(result.problems), 1)
265 self.assertEqual(result.errors, 0)
266 self.assertEqual(result.warnings, 0)
267 self.assertEqual(result.checks, 1)
268 self.assertEqual(result.lines, 67)
Simon Glass26132882012-01-14 15:12:45 +0000269 os.remove(inf)
270
271
272if __name__ == "__main__":
273 unittest.main()
274 gitutil.RunTests()