Simon Glass | 2eb5fc1 | 2017-05-29 15:31:28 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 3 | # |
| 4 | # Copyright (c) 2011 The Chromium OS Authors. |
| 5 | # |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 6 | |
| 7 | import os |
| 8 | import tempfile |
| 9 | import unittest |
| 10 | |
| 11 | import checkpatch |
| 12 | import gitutil |
| 13 | import patchstream |
| 14 | import series |
| 15 | |
| 16 | |
| 17 | class 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 | |
| 27 | From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001 |
| 28 | From: Simon Glass <sjg@chromium.org> |
| 29 | Date: Thu, 28 Apr 2011 09:58:51 -0700 |
| 30 | Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support |
| 31 | |
| 32 | This adds functions to enable/disable clocks and reset to on-chip peripherals. |
| 33 | |
Simon Glass | 2eb5fc1 | 2017-05-29 15:31:28 -0600 | [diff] [blame] | 34 | cmd/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 | |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 38 | BUG=chromium-os:13875 |
| 39 | TEST=build U-Boot for Seaboard, boot |
| 40 | |
| 41 | Change-Id: I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413 |
| 42 | |
| 43 | Review URL: http://codereview.chromium.org/6900006 |
| 44 | |
| 45 | Signed-off-by: Simon Glass <sjg@chromium.org> |
| 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 | |
| 53 | From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001 |
| 54 | From: Simon Glass <sjg@chromium.org> |
| 55 | Date: Thu, 28 Apr 2011 09:58:51 -0700 |
| 56 | Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support |
| 57 | |
| 58 | This adds functions to enable/disable clocks and reset to on-chip peripherals. |
| 59 | |
Simon Glass | 2eb5fc1 | 2017-05-29 15:31:28 -0600 | [diff] [blame] | 60 | cmd/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 | |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 64 | Signed-off-by: Simon Glass <sjg@chromium.org> |
| 65 | --- |
Simon Glass | e752edc | 2014-08-28 09:43:35 -0600 | [diff] [blame] | 66 | |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 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): |
Simon Glass | 6c328f2 | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 90 | data='''From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001 |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 91 | From: Simon Glass <sjg@chromium.org> |
| 92 | Date: Thu, 7 Apr 2011 10:14:41 -0700 |
| 93 | Subject: [PATCH 1/4] Add microsecond boot time measurement |
| 94 | |
| 95 | This defines the basics of a new boot time measurement feature. This allows |
| 96 | logging of very accurate time measurements as the boot proceeds, by using |
| 97 | an available microsecond counter. |
| 98 | |
| 99 | %s |
| 100 | --- |
| 101 | README | 11 ++++++++ |
Simon Glass | 6c328f2 | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 102 | MAINTAINERS | 3 ++ |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 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 | |
| 110 | diff --git a/README b/README |
| 111 | index 6f3748d..f9e4e65 100644 |
| 112 | --- a/README |
| 113 | +++ b/README |
| 114 | @@ -2026,6 +2026,17 @@ The following options need to be configured: |
Doug Anderson | 05d5282 | 2012-11-26 15:21:39 +0000 | [diff] [blame] | 115 | example, some LED's) on your board. At the moment, |
| 116 | the following checkpoints are implemented: |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 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: |
Doug Anderson | 05d5282 | 2012-11-26 15:21:39 +0000 | [diff] [blame] | 130 | CONFIG_STANDALONE_LOAD_ADDR |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 131 | |
Simon Glass | 6c328f2 | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 132 | diff --git a/MAINTAINERS b/MAINTAINERS |
| 133 | index 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 <sjg@chromium.org> |
| 143 | +L: u-boot@lists.denx.de |
| 144 | +F: common/bootstage.c |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 145 | diff --git a/common/bootstage.c b/common/bootstage.c |
| 146 | new file mode 100644 |
| 147 | index 0000000..2234c87 |
| 148 | --- /dev/null |
| 149 | +++ b/common/bootstage.c |
Simon Glass | 6c328f2 | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 150 | @@ -0,0 +1,37 @@ |
Chris Packham | fe6ef1e | 2018-06-07 20:45:07 +1200 | [diff] [blame] | 151 | +%s |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 152 | +/* |
| 153 | + * Copyright (c) 2011, Google Inc. All rights reserved. |
| 154 | + * |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 155 | + */ |
| 156 | + |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 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 | + |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 165 | +struct bootstage_record { |
Simon Glass | 6c328f2 | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 166 | + u32 time_us; |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 167 | + const char *name; |
| 168 | +}; |
| 169 | + |
| 170 | +static struct bootstage_record record[BOOTSTAGE_COUNT]; |
| 171 | + |
Simon Glass | 6c328f2 | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 172 | +u32 bootstage_mark(enum bootstage_id id, const char *name) |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 173 | +{ |
| 174 | + struct bootstage_record *rec = &record[id]; |
| 175 | + |
| 176 | + /* Only record the first event for each */ |
| 177 | +%sif (!rec->name) { |
Simon Glass | 6c328f2 | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 178 | + rec->time_us = (u32)timer_get_us(); |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 179 | + rec->name = name; |
| 180 | + } |
Simon Glass | d29fe6e | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 181 | + if (!rec->name && |
| 182 | + %ssomething_else) { |
Simon Glass | 6c328f2 | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 183 | + rec->time_us = (u32)timer_get_us(); |
Simon Glass | d29fe6e | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 184 | + rec->name = name; |
| 185 | + } |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 186 | +%sreturn rec->time_us; |
| 187 | +} |
| 188 | -- |
| 189 | 1.7.3.1 |
| 190 | ''' |
| 191 | signoff = 'Signed-off-by: Simon Glass <sjg@chromium.org>\n' |
Chris Packham | fe6ef1e | 2018-06-07 20:45:07 +1200 | [diff] [blame] | 192 | license = '// SPDX-License-Identifier: GPL-2.0+' |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 193 | tab = ' ' |
Simon Glass | d29fe6e | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 194 | indent = ' ' |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 195 | if data_type == 'good': |
| 196 | pass |
| 197 | elif data_type == 'no-signoff': |
| 198 | signoff = '' |
Chris Packham | fe6ef1e | 2018-06-07 20:45:07 +1200 | [diff] [blame] | 199 | elif data_type == 'no-license': |
| 200 | license = '' |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 201 | elif data_type == 'spaces': |
| 202 | tab = ' ' |
Simon Glass | d29fe6e | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 203 | elif data_type == 'indent': |
| 204 | indent = tab |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 205 | else: |
Paul Burton | a920a17 | 2016-09-27 16:03:50 +0100 | [diff] [blame] | 206 | print('not implemented') |
Chris Packham | fe6ef1e | 2018-06-07 20:45:07 +1200 | [diff] [blame] | 207 | return data % (signoff, license, tab, indent, tab) |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 208 | |
| 209 | def SetupData(self, data_type): |
| 210 | inhandle, inname = tempfile.mkstemp() |
| 211 | infd = os.fdopen(inhandle, 'w') |
| 212 | data = self.GetData(data_type) |
| 213 | infd.write(data) |
| 214 | infd.close() |
| 215 | return inname |
| 216 | |
Simon Glass | d29fe6e | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 217 | def testGood(self): |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 218 | """Test checkpatch operation""" |
| 219 | inf = self.SetupData('good') |
Simon Glass | d29fe6e | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 220 | result = checkpatch.CheckPatch(inf) |
| 221 | self.assertEqual(result.ok, True) |
| 222 | self.assertEqual(result.problems, []) |
| 223 | self.assertEqual(result.errors, 0) |
| 224 | self.assertEqual(result.warnings, 0) |
| 225 | self.assertEqual(result.checks, 0) |
Simon Glass | 6c328f2 | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 226 | self.assertEqual(result.lines, 62) |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 227 | os.remove(inf) |
| 228 | |
Simon Glass | d29fe6e | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 229 | def testNoSignoff(self): |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 230 | inf = self.SetupData('no-signoff') |
Simon Glass | d29fe6e | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 231 | result = checkpatch.CheckPatch(inf) |
| 232 | self.assertEqual(result.ok, False) |
| 233 | self.assertEqual(len(result.problems), 1) |
| 234 | self.assertEqual(result.errors, 1) |
| 235 | self.assertEqual(result.warnings, 0) |
| 236 | self.assertEqual(result.checks, 0) |
Simon Glass | 6c328f2 | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 237 | self.assertEqual(result.lines, 62) |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 238 | os.remove(inf) |
| 239 | |
Chris Packham | fe6ef1e | 2018-06-07 20:45:07 +1200 | [diff] [blame] | 240 | def testNoLicense(self): |
| 241 | inf = self.SetupData('no-license') |
| 242 | result = checkpatch.CheckPatch(inf) |
| 243 | self.assertEqual(result.ok, False) |
| 244 | self.assertEqual(len(result.problems), 1) |
| 245 | self.assertEqual(result.errors, 0) |
| 246 | self.assertEqual(result.warnings, 1) |
| 247 | self.assertEqual(result.checks, 0) |
| 248 | self.assertEqual(result.lines, 62) |
| 249 | os.remove(inf) |
| 250 | |
Simon Glass | d29fe6e | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 251 | def testSpaces(self): |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 252 | inf = self.SetupData('spaces') |
Simon Glass | d29fe6e | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 253 | result = checkpatch.CheckPatch(inf) |
| 254 | self.assertEqual(result.ok, False) |
Simon Glass | 6c328f2 | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 255 | self.assertEqual(len(result.problems), 3) |
Simon Glass | d29fe6e | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 256 | self.assertEqual(result.errors, 0) |
Simon Glass | 6c328f2 | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 257 | self.assertEqual(result.warnings, 3) |
Simon Glass | d29fe6e | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 258 | self.assertEqual(result.checks, 0) |
Simon Glass | 6c328f2 | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 259 | self.assertEqual(result.lines, 62) |
Simon Glass | d29fe6e | 2013-03-26 13:09:39 +0000 | [diff] [blame] | 260 | os.remove(inf) |
| 261 | |
| 262 | def testIndent(self): |
| 263 | inf = self.SetupData('indent') |
| 264 | result = checkpatch.CheckPatch(inf) |
| 265 | self.assertEqual(result.ok, False) |
| 266 | self.assertEqual(len(result.problems), 1) |
| 267 | self.assertEqual(result.errors, 0) |
| 268 | self.assertEqual(result.warnings, 0) |
| 269 | self.assertEqual(result.checks, 1) |
Simon Glass | 6c328f2 | 2017-11-12 21:52:12 -0700 | [diff] [blame] | 270 | self.assertEqual(result.lines, 62) |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 271 | os.remove(inf) |
| 272 | |
| 273 | |
| 274 | if __name__ == "__main__": |
| 275 | unittest.main() |
| 276 | gitutil.RunTests() |