blob: 20dc9c1e0df15a725924192fafb4a4ebc768f7a5 [file] [log] [blame]
Simon Glassb91126d2017-05-29 15:31:28 -06001# -*- coding: utf-8 -*-
Simon Glass26132882012-01-14 15:12:45 +00002#
3# Copyright (c) 2011 The Chromium OS Authors.
4#
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005# SPDX-License-Identifier: GPL-2.0+
Simon Glass26132882012-01-14 15:12:45 +00006#
7
8import os
9import tempfile
10import unittest
11
12import checkpatch
13import gitutil
14import patchstream
15import series
16
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 Glassb91126d2017-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 Glass26132882012-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'''
52 expected='''
53
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 Glassb91126d2017-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 Glass26132882012-01-14 15:12:45 +000065Signed-off-by: Simon Glass <sjg@chromium.org>
66---
Simon Glassb0cd3412014-08-28 09:43:35 -060067
Simon Glass26132882012-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()
74 infd = os.fdopen(inhandle, 'w')
75 infd.write(data)
76 infd.close()
77
78 exphandle, expname = tempfile.mkstemp()
79 expfd = os.fdopen(exphandle, 'w')
80 expfd.write(expected)
81 expfd.close()
82
83 patchstream.FixPatch(None, inname, series.Series(), None)
84 rc = os.system('diff -u %s %s' % (inname, expname))
85 self.assertEqual(rc, 0)
86
87 os.remove(inname)
88 os.remove(expname)
89
90 def GetData(self, data_type):
91 data='''
92From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001
93From: Simon Glass <sjg@chromium.org>
94Date: Thu, 7 Apr 2011 10:14:41 -0700
95Subject: [PATCH 1/4] Add microsecond boot time measurement
96
97This defines the basics of a new boot time measurement feature. This allows
98logging of very accurate time measurements as the boot proceeds, by using
99an available microsecond counter.
100
101%s
102---
103 README | 11 ++++++++
104 common/bootstage.c | 50 ++++++++++++++++++++++++++++++++++++
105 include/bootstage.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++
106 include/common.h | 8 ++++++
107 5 files changed, 141 insertions(+), 0 deletions(-)
108 create mode 100644 common/bootstage.c
109 create mode 100644 include/bootstage.h
110
111diff --git a/README b/README
112index 6f3748d..f9e4e65 100644
113--- a/README
114+++ b/README
115@@ -2026,6 +2026,17 @@ The following options need to be configured:
Doug Anderson37816752012-11-26 15:21:39 +0000116 example, some LED's) on your board. At the moment,
117 the following checkpoints are implemented:
Simon Glass26132882012-01-14 15:12:45 +0000118
119+- Time boot progress
120+ CONFIG_BOOTSTAGE
121+
122+ Define this option to enable microsecond boot stage timing
123+ on supported platforms. For this to work your platform
124+ needs to define a function timer_get_us() which returns the
125+ number of microseconds since reset. This would normally
126+ be done in your SOC or board timer.c file.
127+
128+ You can add calls to bootstage_mark() to set time markers.
129+
130 - Standalone program support:
Doug Anderson37816752012-11-26 15:21:39 +0000131 CONFIG_STANDALONE_LOAD_ADDR
Simon Glass26132882012-01-14 15:12:45 +0000132
133diff --git a/common/bootstage.c b/common/bootstage.c
134new file mode 100644
135index 0000000..2234c87
136--- /dev/null
137+++ b/common/bootstage.c
Wolfgang Denkd79de1d2013-07-08 09:37:19 +0200138@@ -0,0 +1,39 @@
Simon Glass26132882012-01-14 15:12:45 +0000139+/*
140+ * Copyright (c) 2011, Google Inc. All rights reserved.
141+ *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +0200142+ * SPDX-License-Identifier: GPL-2.0+
Simon Glass26132882012-01-14 15:12:45 +0000143+ */
144+
145+
146+/*
147+ * This module records the progress of boot and arbitrary commands, and
148+ * permits accurate timestamping of each. The records can optionally be
149+ * passed to kernel in the ATAGs
150+ */
151+
152+#include <common.h>
153+
154+
155+struct bootstage_record {
156+ uint32_t time_us;
157+ const char *name;
158+};
159+
160+static struct bootstage_record record[BOOTSTAGE_COUNT];
161+
162+uint32_t bootstage_mark(enum bootstage_id id, const char *name)
163+{
164+ struct bootstage_record *rec = &record[id];
165+
166+ /* Only record the first event for each */
167+%sif (!rec->name) {
168+ rec->time_us = (uint32_t)timer_get_us();
169+ rec->name = name;
170+ }
Simon Glass0495abf2013-03-26 13:09:39 +0000171+ if (!rec->name &&
172+ %ssomething_else) {
173+ rec->time_us = (uint32_t)timer_get_us();
174+ rec->name = name;
175+ }
Simon Glass26132882012-01-14 15:12:45 +0000176+%sreturn rec->time_us;
177+}
178--
1791.7.3.1
180'''
181 signoff = 'Signed-off-by: Simon Glass <sjg@chromium.org>\n'
182 tab = ' '
Simon Glass0495abf2013-03-26 13:09:39 +0000183 indent = ' '
Simon Glass26132882012-01-14 15:12:45 +0000184 if data_type == 'good':
185 pass
186 elif data_type == 'no-signoff':
187 signoff = ''
188 elif data_type == 'spaces':
189 tab = ' '
Simon Glass0495abf2013-03-26 13:09:39 +0000190 elif data_type == 'indent':
191 indent = tab
Simon Glass26132882012-01-14 15:12:45 +0000192 else:
Paul Burtonc3931342016-09-27 16:03:50 +0100193 print('not implemented')
Simon Glass0495abf2013-03-26 13:09:39 +0000194 return data % (signoff, tab, indent, tab)
Simon Glass26132882012-01-14 15:12:45 +0000195
196 def SetupData(self, data_type):
197 inhandle, inname = tempfile.mkstemp()
198 infd = os.fdopen(inhandle, 'w')
199 data = self.GetData(data_type)
200 infd.write(data)
201 infd.close()
202 return inname
203
Simon Glass0495abf2013-03-26 13:09:39 +0000204 def testGood(self):
Simon Glass26132882012-01-14 15:12:45 +0000205 """Test checkpatch operation"""
206 inf = self.SetupData('good')
Simon Glass0495abf2013-03-26 13:09:39 +0000207 result = checkpatch.CheckPatch(inf)
208 self.assertEqual(result.ok, True)
209 self.assertEqual(result.problems, [])
210 self.assertEqual(result.errors, 0)
211 self.assertEqual(result.warnings, 0)
212 self.assertEqual(result.checks, 0)
Simon Glassb0cd3412014-08-28 09:43:35 -0600213 self.assertEqual(result.lines, 56)
Simon Glass26132882012-01-14 15:12:45 +0000214 os.remove(inf)
215
Simon Glass0495abf2013-03-26 13:09:39 +0000216 def testNoSignoff(self):
Simon Glass26132882012-01-14 15:12:45 +0000217 inf = self.SetupData('no-signoff')
Simon Glass0495abf2013-03-26 13:09:39 +0000218 result = checkpatch.CheckPatch(inf)
219 self.assertEqual(result.ok, False)
220 self.assertEqual(len(result.problems), 1)
221 self.assertEqual(result.errors, 1)
222 self.assertEqual(result.warnings, 0)
223 self.assertEqual(result.checks, 0)
Simon Glassb0cd3412014-08-28 09:43:35 -0600224 self.assertEqual(result.lines, 56)
Simon Glass26132882012-01-14 15:12:45 +0000225 os.remove(inf)
226
Simon Glass0495abf2013-03-26 13:09:39 +0000227 def testSpaces(self):
Simon Glass26132882012-01-14 15:12:45 +0000228 inf = self.SetupData('spaces')
Simon Glass0495abf2013-03-26 13:09:39 +0000229 result = checkpatch.CheckPatch(inf)
230 self.assertEqual(result.ok, False)
Simon Glassb0cd3412014-08-28 09:43:35 -0600231 self.assertEqual(len(result.problems), 2)
Simon Glass0495abf2013-03-26 13:09:39 +0000232 self.assertEqual(result.errors, 0)
Simon Glassb0cd3412014-08-28 09:43:35 -0600233 self.assertEqual(result.warnings, 2)
Simon Glass0495abf2013-03-26 13:09:39 +0000234 self.assertEqual(result.checks, 0)
Simon Glassb0cd3412014-08-28 09:43:35 -0600235 self.assertEqual(result.lines, 56)
Simon Glass0495abf2013-03-26 13:09:39 +0000236 os.remove(inf)
237
238 def testIndent(self):
239 inf = self.SetupData('indent')
240 result = checkpatch.CheckPatch(inf)
241 self.assertEqual(result.ok, False)
242 self.assertEqual(len(result.problems), 1)
243 self.assertEqual(result.errors, 0)
244 self.assertEqual(result.warnings, 0)
245 self.assertEqual(result.checks, 1)
Simon Glassb0cd3412014-08-28 09:43:35 -0600246 self.assertEqual(result.lines, 56)
Simon Glass26132882012-01-14 15:12:45 +0000247 os.remove(inf)
248
249
250if __name__ == "__main__":
251 unittest.main()
252 gitutil.RunTests()