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