]> Git Repo - u-boot.git/blame - tools/patman/test.py
SPDX: Convert all of our single license tags to Linux Kernel style
[u-boot.git] / tools / patman / test.py
CommitLineData
2eb5fc13 1# -*- coding: utf-8 -*-
83d290c5 2# SPDX-License-Identifier: GPL-2.0+
0d24de9d
SG
3#
4# Copyright (c) 2011 The Chromium OS Authors.
5#
0d24de9d
SG
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 <[email protected]>
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
2eb5fc13
SG
34cmd/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
0d24de9d
SG
38BUG=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 <[email protected]>
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'''
51 expected='''
52
53From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
54From: Simon Glass <[email protected]>
55Date: Thu, 28 Apr 2011 09:58:51 -0700
56Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
57
58This adds functions to enable/disable clocks and reset to on-chip peripherals.
59
2eb5fc13
SG
60cmd/pci.c:152:11: warning: format ‘%llx’ expects argument of type
61 ‘long long unsigned int’, but argument 3 has type
62 ‘u64 {aka long unsigned int}’ [-Wformat=]
63
0d24de9d
SG
64Signed-off-by: Simon Glass <[email protected]>
65---
e752edcb 66
0d24de9d
SG
67 arch/arm/cpu/armv7/tegra2/Makefile | 2 +-
68 arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++----
69 arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++
70'''
71 out = ''
72 inhandle, inname = tempfile.mkstemp()
73 infd = os.fdopen(inhandle, 'w')
74 infd.write(data)
75 infd.close()
76
77 exphandle, expname = tempfile.mkstemp()
78 expfd = os.fdopen(exphandle, 'w')
79 expfd.write(expected)
80 expfd.close()
81
82 patchstream.FixPatch(None, inname, series.Series(), None)
83 rc = os.system('diff -u %s %s' % (inname, expname))
84 self.assertEqual(rc, 0)
85
86 os.remove(inname)
87 os.remove(expname)
88
89 def GetData(self, data_type):
6c328f29 90 data='''From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001
0d24de9d
SG
91From: Simon Glass <[email protected]>
92Date: Thu, 7 Apr 2011 10:14:41 -0700
93Subject: [PATCH 1/4] Add microsecond boot time measurement
94
95This defines the basics of a new boot time measurement feature. This allows
96logging of very accurate time measurements as the boot proceeds, by using
97an available microsecond counter.
98
99%s
100---
101 README | 11 ++++++++
6c328f29 102 MAINTAINERS | 3 ++
0d24de9d
SG
103 common/bootstage.c | 50 ++++++++++++++++++++++++++++++++++++
104 include/bootstage.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++
105 include/common.h | 8 ++++++
106 5 files changed, 141 insertions(+), 0 deletions(-)
107 create mode 100644 common/bootstage.c
108 create mode 100644 include/bootstage.h
109
110diff --git a/README b/README
111index 6f3748d..f9e4e65 100644
112--- a/README
113+++ b/README
114@@ -2026,6 +2026,17 @@ The following options need to be configured:
05d5282b
DA
115 example, some LED's) on your board. At the moment,
116 the following checkpoints are implemented:
0d24de9d
SG
117
118+- Time boot progress
119+ CONFIG_BOOTSTAGE
120+
121+ Define this option to enable microsecond boot stage timing
122+ on supported platforms. For this to work your platform
123+ needs to define a function timer_get_us() which returns the
124+ number of microseconds since reset. This would normally
125+ be done in your SOC or board timer.c file.
126+
127+ You can add calls to bootstage_mark() to set time markers.
128+
129 - Standalone program support:
05d5282b 130 CONFIG_STANDALONE_LOAD_ADDR
0d24de9d 131
6c328f29
SG
132diff --git a/MAINTAINERS b/MAINTAINERS
133index b167b028ec..beb7dc634f 100644
134--- a/MAINTAINERS
135+++ b/MAINTAINERS
136@@ -474,3 +474,8 @@ S: Maintained
137 T: git git://git.denx.de/u-boot.git
138 F: *
139 F: */
140+
141+BOOTSTAGE
142+M: Simon Glass <[email protected]>
143+L: [email protected]
144+F: common/bootstage.c
0d24de9d
SG
145diff --git a/common/bootstage.c b/common/bootstage.c
146new file mode 100644
147index 0000000..2234c87
148--- /dev/null
149+++ b/common/bootstage.c
6c328f29 150@@ -0,0 +1,37 @@
83d290c5 151+/* SPDX-License-Identifier: GPL-2.0+ */
0d24de9d
SG
152+/*
153+ * Copyright (c) 2011, Google Inc. All rights reserved.
154+ *
0d24de9d
SG
155+ */
156+
0d24de9d
SG
157+/*
158+ * This module records the progress of boot and arbitrary commands, and
159+ * permits accurate timestamping of each. The records can optionally be
160+ * passed to kernel in the ATAGs
161+ */
162+
163+#include <common.h>
164+
0d24de9d 165+struct bootstage_record {
6c328f29 166+ u32 time_us;
0d24de9d
SG
167+ const char *name;
168+};
169+
170+static struct bootstage_record record[BOOTSTAGE_COUNT];
171+
6c328f29 172+u32 bootstage_mark(enum bootstage_id id, const char *name)
0d24de9d
SG
173+{
174+ struct bootstage_record *rec = &record[id];
175+
176+ /* Only record the first event for each */
177+%sif (!rec->name) {
6c328f29 178+ rec->time_us = (u32)timer_get_us();
0d24de9d
SG
179+ rec->name = name;
180+ }
d29fe6e2
SG
181+ if (!rec->name &&
182+ %ssomething_else) {
6c328f29 183+ rec->time_us = (u32)timer_get_us();
d29fe6e2
SG
184+ rec->name = name;
185+ }
0d24de9d
SG
186+%sreturn rec->time_us;
187+}
188--
1891.7.3.1
190'''
191 signoff = 'Signed-off-by: Simon Glass <[email protected]>\n'
192 tab = ' '
d29fe6e2 193 indent = ' '
0d24de9d
SG
194 if data_type == 'good':
195 pass
196 elif data_type == 'no-signoff':
197 signoff = ''
198 elif data_type == 'spaces':
199 tab = ' '
d29fe6e2
SG
200 elif data_type == 'indent':
201 indent = tab
0d24de9d 202 else:
a920a17b 203 print('not implemented')
d29fe6e2 204 return data % (signoff, tab, indent, tab)
0d24de9d
SG
205
206 def SetupData(self, data_type):
207 inhandle, inname = tempfile.mkstemp()
208 infd = os.fdopen(inhandle, 'w')
209 data = self.GetData(data_type)
210 infd.write(data)
211 infd.close()
212 return inname
213
d29fe6e2 214 def testGood(self):
0d24de9d
SG
215 """Test checkpatch operation"""
216 inf = self.SetupData('good')
d29fe6e2
SG
217 result = checkpatch.CheckPatch(inf)
218 self.assertEqual(result.ok, True)
219 self.assertEqual(result.problems, [])
220 self.assertEqual(result.errors, 0)
221 self.assertEqual(result.warnings, 0)
222 self.assertEqual(result.checks, 0)
6c328f29 223 self.assertEqual(result.lines, 62)
0d24de9d
SG
224 os.remove(inf)
225
d29fe6e2 226 def testNoSignoff(self):
0d24de9d 227 inf = self.SetupData('no-signoff')
d29fe6e2
SG
228 result = checkpatch.CheckPatch(inf)
229 self.assertEqual(result.ok, False)
230 self.assertEqual(len(result.problems), 1)
231 self.assertEqual(result.errors, 1)
232 self.assertEqual(result.warnings, 0)
233 self.assertEqual(result.checks, 0)
6c328f29 234 self.assertEqual(result.lines, 62)
0d24de9d
SG
235 os.remove(inf)
236
d29fe6e2 237 def testSpaces(self):
0d24de9d 238 inf = self.SetupData('spaces')
d29fe6e2
SG
239 result = checkpatch.CheckPatch(inf)
240 self.assertEqual(result.ok, False)
6c328f29 241 self.assertEqual(len(result.problems), 3)
d29fe6e2 242 self.assertEqual(result.errors, 0)
6c328f29 243 self.assertEqual(result.warnings, 3)
d29fe6e2 244 self.assertEqual(result.checks, 0)
6c328f29 245 self.assertEqual(result.lines, 62)
d29fe6e2
SG
246 os.remove(inf)
247
248 def testIndent(self):
249 inf = self.SetupData('indent')
250 result = checkpatch.CheckPatch(inf)
251 self.assertEqual(result.ok, False)
252 self.assertEqual(len(result.problems), 1)
253 self.assertEqual(result.errors, 0)
254 self.assertEqual(result.warnings, 0)
255 self.assertEqual(result.checks, 1)
6c328f29 256 self.assertEqual(result.lines, 62)
0d24de9d
SG
257 os.remove(inf)
258
259
260if __name__ == "__main__":
261 unittest.main()
262 gitutil.RunTests()
This page took 0.288626 seconds and 4 git commands to generate.