Simon Glass | b91126d | 2017-05-29 15:31:28 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 2 | # |
| 3 | # Copyright (c) 2011 The Chromium OS Authors. |
| 4 | # |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 6 | # |
| 7 | |
| 8 | import os |
| 9 | import tempfile |
| 10 | import unittest |
| 11 | |
| 12 | import checkpatch |
| 13 | import gitutil |
| 14 | import patchstream |
| 15 | import series |
| 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 | ''' |
| 52 | expected=''' |
| 53 | |
| 54 | From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001 |
| 55 | From: Simon Glass <sjg@chromium.org> |
| 56 | Date: Thu, 28 Apr 2011 09:58:51 -0700 |
| 57 | Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support |
| 58 | |
| 59 | This adds functions to enable/disable clocks and reset to on-chip peripherals. |
| 60 | |
Simon Glass | b91126d | 2017-05-29 15:31:28 -0600 | [diff] [blame] | 61 | cmd/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 Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 65 | Signed-off-by: Simon Glass <sjg@chromium.org> |
| 66 | --- |
Simon Glass | b0cd341 | 2014-08-28 09:43:35 -0600 | [diff] [blame] | 67 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 68 | 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): |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 91 | data='''From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001 |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 92 | From: Simon Glass <sjg@chromium.org> |
| 93 | Date: Thu, 7 Apr 2011 10:14:41 -0700 |
| 94 | Subject: [PATCH 1/4] Add microsecond boot time measurement |
| 95 | |
| 96 | This defines the basics of a new boot time measurement feature. This allows |
| 97 | logging of very accurate time measurements as the boot proceeds, by using |
| 98 | an available microsecond counter. |
| 99 | |
| 100 | %s |
| 101 | --- |
| 102 | README | 11 ++++++++ |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 103 | MAINTAINERS | 3 ++ |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 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 | |
| 111 | diff --git a/README b/README |
| 112 | index 6f3748d..f9e4e65 100644 |
| 113 | --- a/README |
| 114 | +++ b/README |
| 115 | @@ -2026,6 +2026,17 @@ The following options need to be configured: |
Doug Anderson | 3781675 | 2012-11-26 15:21:39 +0000 | [diff] [blame] | 116 | example, some LED's) on your board. At the moment, |
| 117 | the following checkpoints are implemented: |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 118 | |
| 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 Anderson | 3781675 | 2012-11-26 15:21:39 +0000 | [diff] [blame] | 131 | CONFIG_STANDALONE_LOAD_ADDR |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 132 | |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 133 | diff --git a/MAINTAINERS b/MAINTAINERS |
| 134 | index b167b028ec..beb7dc634f 100644 |
| 135 | --- a/MAINTAINERS |
| 136 | +++ b/MAINTAINERS |
| 137 | @@ -474,3 +474,8 @@ S: Maintained |
| 138 | T: git git://git.denx.de/u-boot.git |
| 139 | F: * |
| 140 | F: */ |
| 141 | + |
| 142 | +BOOTSTAGE |
| 143 | +M: Simon Glass <sjg@chromium.org> |
| 144 | +L: u-boot@lists.denx.de |
| 145 | +F: common/bootstage.c |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 146 | diff --git a/common/bootstage.c b/common/bootstage.c |
| 147 | new file mode 100644 |
| 148 | index 0000000..2234c87 |
| 149 | --- /dev/null |
| 150 | +++ b/common/bootstage.c |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 151 | @@ -0,0 +1,37 @@ |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 152 | +/* |
| 153 | + * Copyright (c) 2011, Google Inc. All rights reserved. |
| 154 | + * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 155 | + * SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 156 | + */ |
| 157 | + |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 158 | +/* |
| 159 | + * This module records the progress of boot and arbitrary commands, and |
| 160 | + * permits accurate timestamping of each. The records can optionally be |
| 161 | + * passed to kernel in the ATAGs |
| 162 | + */ |
| 163 | + |
| 164 | +#include <common.h> |
| 165 | + |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 166 | +struct bootstage_record { |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 167 | + u32 time_us; |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 168 | + const char *name; |
| 169 | +}; |
| 170 | + |
| 171 | +static struct bootstage_record record[BOOTSTAGE_COUNT]; |
| 172 | + |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 173 | +u32 bootstage_mark(enum bootstage_id id, const char *name) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 174 | +{ |
| 175 | + struct bootstage_record *rec = &record[id]; |
| 176 | + |
| 177 | + /* Only record the first event for each */ |
| 178 | +%sif (!rec->name) { |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 179 | + rec->time_us = (u32)timer_get_us(); |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 180 | + rec->name = name; |
| 181 | + } |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 182 | + if (!rec->name && |
| 183 | + %ssomething_else) { |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 184 | + rec->time_us = (u32)timer_get_us(); |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 185 | + rec->name = name; |
| 186 | + } |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 187 | +%sreturn rec->time_us; |
| 188 | +} |
| 189 | -- |
| 190 | 1.7.3.1 |
| 191 | ''' |
| 192 | signoff = 'Signed-off-by: Simon Glass <sjg@chromium.org>\n' |
| 193 | tab = ' ' |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 194 | indent = ' ' |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 195 | if data_type == 'good': |
| 196 | pass |
| 197 | elif data_type == 'no-signoff': |
| 198 | signoff = '' |
| 199 | elif data_type == 'spaces': |
| 200 | tab = ' ' |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 201 | elif data_type == 'indent': |
| 202 | indent = tab |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 203 | else: |
Paul Burton | c393134 | 2016-09-27 16:03:50 +0100 | [diff] [blame] | 204 | print('not implemented') |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 205 | return data % (signoff, tab, indent, tab) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 206 | |
| 207 | def SetupData(self, data_type): |
| 208 | inhandle, inname = tempfile.mkstemp() |
| 209 | infd = os.fdopen(inhandle, 'w') |
| 210 | data = self.GetData(data_type) |
| 211 | infd.write(data) |
| 212 | infd.close() |
| 213 | return inname |
| 214 | |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 215 | def testGood(self): |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 216 | """Test checkpatch operation""" |
| 217 | inf = self.SetupData('good') |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 218 | result = checkpatch.CheckPatch(inf) |
| 219 | self.assertEqual(result.ok, True) |
| 220 | self.assertEqual(result.problems, []) |
| 221 | self.assertEqual(result.errors, 0) |
| 222 | self.assertEqual(result.warnings, 0) |
| 223 | self.assertEqual(result.checks, 0) |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 224 | self.assertEqual(result.lines, 62) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 225 | os.remove(inf) |
| 226 | |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 227 | def testNoSignoff(self): |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 228 | inf = self.SetupData('no-signoff') |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 229 | result = checkpatch.CheckPatch(inf) |
| 230 | self.assertEqual(result.ok, False) |
| 231 | self.assertEqual(len(result.problems), 1) |
| 232 | self.assertEqual(result.errors, 1) |
| 233 | self.assertEqual(result.warnings, 0) |
| 234 | self.assertEqual(result.checks, 0) |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 235 | self.assertEqual(result.lines, 62) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 236 | os.remove(inf) |
| 237 | |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 238 | def testSpaces(self): |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 239 | inf = self.SetupData('spaces') |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 240 | result = checkpatch.CheckPatch(inf) |
| 241 | self.assertEqual(result.ok, False) |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 242 | self.assertEqual(len(result.problems), 3) |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 243 | self.assertEqual(result.errors, 0) |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 244 | self.assertEqual(result.warnings, 3) |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 245 | self.assertEqual(result.checks, 0) |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 246 | self.assertEqual(result.lines, 62) |
Simon Glass | 0495abf | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 247 | os.remove(inf) |
| 248 | |
| 249 | def testIndent(self): |
| 250 | inf = self.SetupData('indent') |
| 251 | result = checkpatch.CheckPatch(inf) |
| 252 | self.assertEqual(result.ok, False) |
| 253 | self.assertEqual(len(result.problems), 1) |
| 254 | self.assertEqual(result.errors, 0) |
| 255 | self.assertEqual(result.warnings, 0) |
| 256 | self.assertEqual(result.checks, 1) |
Simon Glass | ab2dabc | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 257 | self.assertEqual(result.lines, 62) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 258 | os.remove(inf) |
| 259 | |
| 260 | |
| 261 | if __name__ == "__main__": |
| 262 | unittest.main() |
| 263 | gitutil.RunTests() |