Simon Glass | b91126d | 2017-05-29 15:31:28 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 3 | # |
| 4 | # Copyright (c) 2011 The Chromium OS Authors. |
| 5 | # |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 6 | |
| 7 | import os |
| 8 | import tempfile |
| 9 | import unittest |
| 10 | |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 11 | from patman import checkpatch |
| 12 | from patman import gitutil |
| 13 | from patman import patchstream |
| 14 | from patman import series |
| 15 | from patman import commit |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 16 | |
| 17 | |
| 18 | class 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 | |
| 28 | From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001 |
| 29 | From: Simon Glass <sjg@chromium.org> |
| 30 | Date: Thu, 28 Apr 2011 09:58:51 -0700 |
| 31 | Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support |
| 32 | |
| 33 | This adds functions to enable/disable clocks and reset to on-chip peripherals. |
| 34 | |
Simon Glass | b91126d | 2017-05-29 15:31:28 -0600 | [diff] [blame] | 35 | cmd/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 Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 39 | BUG=chromium-os:13875 |
| 40 | TEST=build U-Boot for Seaboard, boot |
| 41 | |
| 42 | Change-Id: I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413 |
| 43 | |
| 44 | Review URL: http://codereview.chromium.org/6900006 |
| 45 | |
| 46 | Signed-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 | ''' |
Douglas Anderson | 52b5ee8 | 2019-09-27 09:23:56 -0700 | [diff] [blame] | 52 | expected='''Message-Id: <19991231235959.0.I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413@changeid> |
| 53 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 54 | |
| 55 | From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001 |
| 56 | From: Simon Glass <sjg@chromium.org> |
| 57 | Date: Thu, 28 Apr 2011 09:58:51 -0700 |
| 58 | Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support |
| 59 | |
| 60 | This adds functions to enable/disable clocks and reset to on-chip peripherals. |
| 61 | |
Simon Glass | b91126d | 2017-05-29 15:31:28 -0600 | [diff] [blame] | 62 | cmd/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 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 66 | Signed-off-by: Simon Glass <sjg@chromium.org> |
| 67 | --- |
Simon Glass | b0cd341 | 2014-08-28 09:43:35 -0600 | [diff] [blame] | 68 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 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() |
Simon Glass | f544a2d | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 75 | infd = os.fdopen(inhandle, 'w', encoding='utf-8') |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 76 | infd.write(data) |
| 77 | infd.close() |
| 78 | |
| 79 | exphandle, expname = tempfile.mkstemp() |
Simon Glass | f544a2d | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 80 | expfd = os.fdopen(exphandle, 'w', encoding='utf-8') |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 81 | expfd.write(expected) |
| 82 | expfd.close() |
| 83 | |
Douglas Anderson | 52b5ee8 | 2019-09-27 09:23:56 -0700 | [diff] [blame] | 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 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 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): |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 101 | data='''From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001 |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 102 | From: Simon Glass <sjg@chromium.org> |
| 103 | Date: Thu, 7 Apr 2011 10:14:41 -0700 |
| 104 | Subject: [PATCH 1/4] Add microsecond boot time measurement |
| 105 | |
| 106 | This defines the basics of a new boot time measurement feature. This allows |
| 107 | logging of very accurate time measurements as the boot proceeds, by using |
| 108 | an available microsecond counter. |
| 109 | |
| 110 | %s |
| 111 | --- |
| 112 | README | 11 ++++++++ |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 113 | MAINTAINERS | 3 ++ |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 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 | |
| 121 | diff --git a/README b/README |
| 122 | index 6f3748d..f9e4e65 100644 |
| 123 | --- a/README |
| 124 | +++ b/README |
| 125 | @@ -2026,6 +2026,17 @@ The following options need to be configured: |
Doug Anderson | 3781675 | 2012-11-26 15:21:39 +0000 | [diff] [blame] | 126 | example, some LED's) on your board. At the moment, |
| 127 | the following checkpoints are implemented: |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 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: |
Doug Anderson | 3781675 | 2012-11-26 15:21:39 +0000 | [diff] [blame] | 141 | CONFIG_STANDALONE_LOAD_ADDR |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 142 | |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 143 | diff --git a/MAINTAINERS b/MAINTAINERS |
| 144 | index 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 |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 156 | diff --git a/common/bootstage.c b/common/bootstage.c |
| 157 | new file mode 100644 |
| 158 | index 0000000..2234c87 |
| 159 | --- /dev/null |
| 160 | +++ b/common/bootstage.c |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 161 | @@ -0,0 +1,37 @@ |
Chris Packham | df0c6af | 2018-06-07 20:45:07 +1200 | [diff] [blame] | 162 | +%s |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 163 | +/* |
| 164 | + * Copyright (c) 2011, Google Inc. All rights reserved. |
| 165 | + * |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 166 | + */ |
| 167 | + |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 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 | + |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 176 | +struct bootstage_record { |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 177 | + u32 time_us; |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 178 | + const char *name; |
| 179 | +}; |
| 180 | + |
| 181 | +static struct bootstage_record record[BOOTSTAGE_COUNT]; |
| 182 | + |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 183 | +u32 bootstage_mark(enum bootstage_id id, const char *name) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 184 | +{ |
| 185 | + struct bootstage_record *rec = &record[id]; |
| 186 | + |
| 187 | + /* Only record the first event for each */ |
| 188 | +%sif (!rec->name) { |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 189 | + rec->time_us = (u32)timer_get_us(); |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 190 | + rec->name = name; |
| 191 | + } |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 192 | + if (!rec->name && |
| 193 | + %ssomething_else) { |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 194 | + rec->time_us = (u32)timer_get_us(); |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 195 | + rec->name = name; |
| 196 | + } |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 197 | +%sreturn rec->time_us; |
| 198 | +} |
| 199 | -- |
| 200 | 1.7.3.1 |
| 201 | ''' |
| 202 | signoff = 'Signed-off-by: Simon Glass <sjg@chromium.org>\n' |
Chris Packham | df0c6af | 2018-06-07 20:45:07 +1200 | [diff] [blame] | 203 | license = '// SPDX-License-Identifier: GPL-2.0+' |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 204 | tab = ' ' |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 205 | indent = ' ' |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 206 | if data_type == 'good': |
| 207 | pass |
| 208 | elif data_type == 'no-signoff': |
| 209 | signoff = '' |
Chris Packham | df0c6af | 2018-06-07 20:45:07 +1200 | [diff] [blame] | 210 | elif data_type == 'no-license': |
| 211 | license = '' |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 212 | elif data_type == 'spaces': |
| 213 | tab = ' ' |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 214 | elif data_type == 'indent': |
| 215 | indent = tab |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 216 | else: |
Paul Burton | c393134 | 2016-09-27 16:03:50 +0100 | [diff] [blame] | 217 | print('not implemented') |
Chris Packham | df0c6af | 2018-06-07 20:45:07 +1200 | [diff] [blame] | 218 | return data % (signoff, license, tab, indent, tab) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 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 | |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 228 | def testGood(self): |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 229 | """Test checkpatch operation""" |
| 230 | inf = self.SetupData('good') |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 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) |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 237 | self.assertEqual(result.lines, 62) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 238 | os.remove(inf) |
| 239 | |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 240 | def testNoSignoff(self): |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 241 | inf = self.SetupData('no-signoff') |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 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) |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 248 | self.assertEqual(result.lines, 62) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 249 | os.remove(inf) |
| 250 | |
Chris Packham | df0c6af | 2018-06-07 20:45:07 +1200 | [diff] [blame] | 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 | |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 262 | def testSpaces(self): |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 263 | inf = self.SetupData('spaces') |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 264 | result = checkpatch.CheckPatch(inf) |
| 265 | self.assertEqual(result.ok, False) |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 266 | self.assertEqual(len(result.problems), 3) |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 267 | self.assertEqual(result.errors, 0) |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 268 | self.assertEqual(result.warnings, 3) |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 269 | self.assertEqual(result.checks, 0) |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 270 | self.assertEqual(result.lines, 62) |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 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) |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 281 | self.assertEqual(result.lines, 62) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 282 | os.remove(inf) |
| 283 | |
| 284 | |
| 285 | if __name__ == "__main__": |
| 286 | unittest.main() |
| 287 | gitutil.RunTests() |