• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2# SPDX-License-Identifier: GPL-2.0+
3#
4# Copyright (c) 2011 The Chromium OS Authors.
5#
6
7import os
8import tempfile
9import unittest
10
11import checkpatch
12import gitutil
13import patchstream
14import series
15import commit
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
35cmd/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
39BUG=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='''Message-Id: <19991231235959.0.I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413@changeid>
53
54
55From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
56From: Simon Glass <sjg@chromium.org>
57Date: Thu, 28 Apr 2011 09:58:51 -0700
58Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
59
60This adds functions to enable/disable clocks and reset to on-chip peripherals.
61
62cmd/pci.c:152:11: warning: format ‘%llx’ expects argument of type
63   ‘long long unsigned int’, but argument 3 has type
64   ‘u64 {aka long unsigned int}’ [-Wformat=]
65
66Signed-off-by: Simon Glass <sjg@chromium.org>
67---
68
69 arch/arm/cpu/armv7/tegra2/Makefile         |    2 +-
70 arch/arm/cpu/armv7/tegra2/ap20.c           |   57 ++----
71 arch/arm/cpu/armv7/tegra2/clock.c          |  163 +++++++++++++++++
72'''
73        out = ''
74        inhandle, inname = tempfile.mkstemp()
75        infd = os.fdopen(inhandle, 'w', encoding='utf-8')
76        infd.write(data)
77        infd.close()
78
79        exphandle, expname = tempfile.mkstemp()
80        expfd = os.fdopen(exphandle, 'w', encoding='utf-8')
81        expfd.write(expected)
82        expfd.close()
83
84        # Normally by the time we call FixPatch we've already collected
85        # metadata.  Here, we haven't, but at least fake up something.
86        # Set the "count" to -1 which tells FixPatch to use a bogus/fixed
87        # time for generating the Message-Id.
88        com = commit.Commit('')
89        com.change_id = 'I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413'
90        com.count = -1
91
92        patchstream.FixPatch(None, inname, series.Series(), com)
93
94        rc = os.system('diff -u %s %s' % (inname, expname))
95        self.assertEqual(rc, 0)
96
97        os.remove(inname)
98        os.remove(expname)
99
100    def GetData(self, data_type):
101        data='''From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001
102From: Simon Glass <sjg@chromium.org>
103Date: Thu, 7 Apr 2011 10:14:41 -0700
104Subject: [PATCH 1/4] Add microsecond boot time measurement
105
106This defines the basics of a new boot time measurement feature. This allows
107logging of very accurate time measurements as the boot proceeds, by using
108an available microsecond counter.
109
110%s
111---
112 README              |   11 ++++++++
113 MAINTAINERS         |    3 ++
114 common/bootstage.c  |   50 ++++++++++++++++++++++++++++++++++++
115 include/bootstage.h |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++
116 include/common.h    |    8 ++++++
117 5 files changed, 141 insertions(+), 0 deletions(-)
118 create mode 100644 common/bootstage.c
119 create mode 100644 include/bootstage.h
120
121diff --git a/README b/README
122index 6f3748d..f9e4e65 100644
123--- a/README
124+++ b/README
125@@ -2026,6 +2026,17 @@ The following options need to be configured:
126 		example, some LED's) on your board. At the moment,
127 		the following checkpoints are implemented:
128
129+- Time boot progress
130+		CONFIG_BOOTSTAGE
131+
132+		Define this option to enable microsecond boot stage timing
133+		on supported platforms. For this to work your platform
134+		needs to define a function timer_get_us() which returns the
135+		number of microseconds since reset. This would normally
136+		be done in your SOC or board timer.c file.
137+
138+		You can add calls to bootstage_mark() to set time markers.
139+
140 - Standalone program support:
141 		CONFIG_STANDALONE_LOAD_ADDR
142
143diff --git a/MAINTAINERS b/MAINTAINERS
144index b167b028ec..beb7dc634f 100644
145--- a/MAINTAINERS
146+++ b/MAINTAINERS
147@@ -474,3 +474,8 @@ S:	Maintained
148 T:	git git://git.denx.de/u-boot.git
149 F:	*
150 F:	*/
151+
152+BOOTSTAGE
153+M:	Simon Glass <sjg@chromium.org>
154+L:	u-boot@lists.denx.de
155+F:	common/bootstage.c
156diff --git a/common/bootstage.c b/common/bootstage.c
157new file mode 100644
158index 0000000..2234c87
159--- /dev/null
160+++ b/common/bootstage.c
161@@ -0,0 +1,37 @@
162+%s
163+/*
164+ * Copyright (c) 2011, Google Inc. All rights reserved.
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+struct bootstage_record {
177+	u32 time_us;
178+	const char *name;
179+};
180+
181+static struct bootstage_record record[BOOTSTAGE_COUNT];
182+
183+u32 bootstage_mark(enum bootstage_id id, const char *name)
184+{
185+	struct bootstage_record *rec = &record[id];
186+
187+	/* Only record the first event for each */
188+%sif (!rec->name) {
189+		rec->time_us = (u32)timer_get_us();
190+		rec->name = name;
191+	}
192+	if (!rec->name &&
193+	%ssomething_else) {
194+		rec->time_us = (u32)timer_get_us();
195+		rec->name = name;
196+	}
197+%sreturn rec->time_us;
198+}
199--
2001.7.3.1
201'''
202        signoff = 'Signed-off-by: Simon Glass <sjg@chromium.org>\n'
203        license = '// SPDX-License-Identifier: GPL-2.0+'
204        tab = '	'
205        indent = '    '
206        if data_type == 'good':
207            pass
208        elif data_type == 'no-signoff':
209            signoff = ''
210        elif data_type == 'no-license':
211            license = ''
212        elif data_type == 'spaces':
213            tab = '   '
214        elif data_type == 'indent':
215            indent = tab
216        else:
217            print('not implemented')
218        return data % (signoff, license, tab, indent, tab)
219
220    def SetupData(self, data_type):
221        inhandle, inname = tempfile.mkstemp()
222        infd = os.fdopen(inhandle, 'w')
223        data = self.GetData(data_type)
224        infd.write(data)
225        infd.close()
226        return inname
227
228    def testGood(self):
229        """Test checkpatch operation"""
230        inf = self.SetupData('good')
231        result = checkpatch.CheckPatch(inf)
232        self.assertEqual(result.ok, True)
233        self.assertEqual(result.problems, [])
234        self.assertEqual(result.errors, 0)
235        self.assertEqual(result.warnings, 0)
236        self.assertEqual(result.checks, 0)
237        self.assertEqual(result.lines, 62)
238        os.remove(inf)
239
240    def testNoSignoff(self):
241        inf = self.SetupData('no-signoff')
242        result = checkpatch.CheckPatch(inf)
243        self.assertEqual(result.ok, False)
244        self.assertEqual(len(result.problems), 1)
245        self.assertEqual(result.errors, 1)
246        self.assertEqual(result.warnings, 0)
247        self.assertEqual(result.checks, 0)
248        self.assertEqual(result.lines, 62)
249        os.remove(inf)
250
251    def testNoLicense(self):
252        inf = self.SetupData('no-license')
253        result = checkpatch.CheckPatch(inf)
254        self.assertEqual(result.ok, False)
255        self.assertEqual(len(result.problems), 1)
256        self.assertEqual(result.errors, 0)
257        self.assertEqual(result.warnings, 1)
258        self.assertEqual(result.checks, 0)
259        self.assertEqual(result.lines, 62)
260        os.remove(inf)
261
262    def testSpaces(self):
263        inf = self.SetupData('spaces')
264        result = checkpatch.CheckPatch(inf)
265        self.assertEqual(result.ok, False)
266        self.assertEqual(len(result.problems), 3)
267        self.assertEqual(result.errors, 0)
268        self.assertEqual(result.warnings, 3)
269        self.assertEqual(result.checks, 0)
270        self.assertEqual(result.lines, 62)
271        os.remove(inf)
272
273    def testIndent(self):
274        inf = self.SetupData('indent')
275        result = checkpatch.CheckPatch(inf)
276        self.assertEqual(result.ok, False)
277        self.assertEqual(len(result.problems), 1)
278        self.assertEqual(result.errors, 0)
279        self.assertEqual(result.warnings, 0)
280        self.assertEqual(result.checks, 1)
281        self.assertEqual(result.lines, 62)
282        os.remove(inf)
283
284
285if __name__ == "__main__":
286    unittest.main()
287    gitutil.RunTests()
288