2017-05-30 05:31:28 +08:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2018-05-07 05:58:06 +08:00
|
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2012-01-14 23:12:45 +08:00
|
|
|
|
#
|
2020-06-15 00:54:04 +08:00
|
|
|
|
# Tests for U-Boot-specific checkpatch.pl features
|
|
|
|
|
#
|
2012-01-14 23:12:45 +08:00
|
|
|
|
# Copyright (c) 2011 The Chromium OS Authors.
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import tempfile
|
|
|
|
|
import unittest
|
|
|
|
|
|
2020-04-18 08:09:04 +08:00
|
|
|
|
from patman import checkpatch
|
|
|
|
|
from patman import gitutil
|
|
|
|
|
from patman import patchstream
|
|
|
|
|
from patman import series
|
|
|
|
|
from patman import commit
|
2012-01-14 23:12:45 +08:00
|
|
|
|
|
|
|
|
|
|
2020-06-15 00:54:05 +08:00
|
|
|
|
class Line:
|
|
|
|
|
def __init__(self, fname, text):
|
|
|
|
|
self.fname = fname
|
|
|
|
|
self.text = text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PatchMaker:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.lines = []
|
|
|
|
|
|
|
|
|
|
def add_line(self, fname, text):
|
|
|
|
|
self.lines.append(Line(fname, text))
|
|
|
|
|
|
|
|
|
|
def get_patch_text(self):
|
|
|
|
|
base = '''From 125b77450f4c66b8fd9654319520bbe795c9ef31 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Simon Glass <sjg@chromium.org>
|
|
|
|
|
Date: Sun, 14 Jun 2020 09:45:14 -0600
|
|
|
|
|
Subject: [PATCH] Test commit
|
|
|
|
|
|
|
|
|
|
This is a test commit.
|
|
|
|
|
|
|
|
|
|
Signed-off-by: Simon Glass <sjg@chromium.org>
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
lines = base.splitlines()
|
|
|
|
|
|
|
|
|
|
# Create the diffstat
|
|
|
|
|
change = 0
|
|
|
|
|
insert = 0
|
|
|
|
|
for line in self.lines:
|
|
|
|
|
lines.append(' %s | 1 +' % line.fname)
|
|
|
|
|
change += 1
|
|
|
|
|
insert += 1
|
|
|
|
|
lines.append(' %d files changed, %d insertions(+)' % (change, insert))
|
|
|
|
|
lines.append('')
|
|
|
|
|
|
|
|
|
|
# Create the patch info for each file
|
|
|
|
|
for line in self.lines:
|
|
|
|
|
lines.append('diff --git a/%s b/%s' % (line.fname, line.fname))
|
|
|
|
|
lines.append('index 7837d459f18..5ba7840f68e 100644')
|
|
|
|
|
lines.append('--- a/%s' % line.fname)
|
|
|
|
|
lines.append('+++ b/%s' % line.fname)
|
|
|
|
|
lines += ('''@@ -121,6 +121,7 @@ enum uclass_id {
|
|
|
|
|
UCLASS_W1, /* Dallas 1-Wire bus */
|
|
|
|
|
UCLASS_W1_EEPROM, /* one-wire EEPROMs */
|
|
|
|
|
UCLASS_WDT, /* Watchdog Timer driver */
|
|
|
|
|
+%s
|
|
|
|
|
|
|
|
|
|
UCLASS_COUNT,
|
|
|
|
|
UCLASS_INVALID = -1,
|
|
|
|
|
''' % line.text).splitlines()
|
|
|
|
|
lines.append('---')
|
|
|
|
|
lines.append('2.17.1')
|
|
|
|
|
|
|
|
|
|
return '\n'.join(lines)
|
|
|
|
|
|
|
|
|
|
def get_patch(self):
|
|
|
|
|
inhandle, inname = tempfile.mkstemp()
|
|
|
|
|
infd = os.fdopen(inhandle, 'w')
|
|
|
|
|
infd.write(self.get_patch_text())
|
|
|
|
|
infd.close()
|
|
|
|
|
return inname
|
|
|
|
|
|
|
|
|
|
def run_checkpatch(self):
|
2022-01-30 05:14:06 +08:00
|
|
|
|
return checkpatch.check_patch(self.get_patch(), show_types=True)
|
2020-06-15 00:54:05 +08:00
|
|
|
|
|
|
|
|
|
|
2012-01-14 23:12:45 +08:00
|
|
|
|
class TestPatch(unittest.TestCase):
|
2020-06-15 00:54:04 +08:00
|
|
|
|
"""Test the u_boot_line() function in checkpatch.pl"""
|
2012-01-14 23:12:45 +08:00
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_basic(self):
|
2012-01-14 23:12:45 +08:00
|
|
|
|
"""Test basic filter operation"""
|
|
|
|
|
data='''
|
|
|
|
|
|
|
|
|
|
From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Simon Glass <sjg@chromium.org>
|
|
|
|
|
Date: Thu, 28 Apr 2011 09:58:51 -0700
|
|
|
|
|
Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
|
|
|
|
|
|
|
|
|
|
This adds functions to enable/disable clocks and reset to on-chip peripherals.
|
|
|
|
|
|
2017-05-30 05:31:28 +08:00
|
|
|
|
cmd/pci.c:152:11: warning: format ‘%llx’ expects argument of type
|
|
|
|
|
‘long long unsigned int’, but argument 3 has type
|
|
|
|
|
‘u64 {aka long unsigned int}’ [-Wformat=]
|
|
|
|
|
|
2012-01-14 23:12:45 +08:00
|
|
|
|
BUG=chromium-os:13875
|
|
|
|
|
TEST=build U-Boot for Seaboard, boot
|
|
|
|
|
|
|
|
|
|
Change-Id: I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413
|
|
|
|
|
|
|
|
|
|
Review URL: http://codereview.chromium.org/6900006
|
|
|
|
|
|
|
|
|
|
Signed-off-by: Simon Glass <sjg@chromium.org>
|
|
|
|
|
---
|
|
|
|
|
arch/arm/cpu/armv7/tegra2/Makefile | 2 +-
|
|
|
|
|
arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++----
|
|
|
|
|
arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++
|
|
|
|
|
'''
|
2019-09-28 00:23:56 +08:00
|
|
|
|
expected='''Message-Id: <19991231235959.0.I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413@changeid>
|
|
|
|
|
|
2012-01-14 23:12:45 +08:00
|
|
|
|
|
|
|
|
|
From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Simon Glass <sjg@chromium.org>
|
|
|
|
|
Date: Thu, 28 Apr 2011 09:58:51 -0700
|
|
|
|
|
Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support
|
|
|
|
|
|
|
|
|
|
This adds functions to enable/disable clocks and reset to on-chip peripherals.
|
|
|
|
|
|
2017-05-30 05:31:28 +08:00
|
|
|
|
cmd/pci.c:152:11: warning: format ‘%llx’ expects argument of type
|
|
|
|
|
‘long long unsigned int’, but argument 3 has type
|
|
|
|
|
‘u64 {aka long unsigned int}’ [-Wformat=]
|
|
|
|
|
|
2012-01-14 23:12:45 +08:00
|
|
|
|
Signed-off-by: Simon Glass <sjg@chromium.org>
|
|
|
|
|
---
|
2014-08-28 23:43:35 +08:00
|
|
|
|
|
2012-01-14 23:12:45 +08:00
|
|
|
|
arch/arm/cpu/armv7/tegra2/Makefile | 2 +-
|
|
|
|
|
arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++----
|
|
|
|
|
arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++
|
|
|
|
|
'''
|
|
|
|
|
out = ''
|
|
|
|
|
inhandle, inname = tempfile.mkstemp()
|
2019-10-31 21:42:51 +08:00
|
|
|
|
infd = os.fdopen(inhandle, 'w', encoding='utf-8')
|
2012-01-14 23:12:45 +08:00
|
|
|
|
infd.write(data)
|
|
|
|
|
infd.close()
|
|
|
|
|
|
|
|
|
|
exphandle, expname = tempfile.mkstemp()
|
2019-10-31 21:42:51 +08:00
|
|
|
|
expfd = os.fdopen(exphandle, 'w', encoding='utf-8')
|
2012-01-14 23:12:45 +08:00
|
|
|
|
expfd.write(expected)
|
|
|
|
|
expfd.close()
|
|
|
|
|
|
2020-10-30 11:46:19 +08:00
|
|
|
|
# Normally by the time we call fix_patch we've already collected
|
2019-09-28 00:23:56 +08:00
|
|
|
|
# metadata. Here, we haven't, but at least fake up something.
|
2020-10-30 11:46:19 +08:00
|
|
|
|
# Set the "count" to -1 which tells fix_patch to use a bogus/fixed
|
2019-09-28 00:23:56 +08:00
|
|
|
|
# time for generating the Message-Id.
|
|
|
|
|
com = commit.Commit('')
|
|
|
|
|
com.change_id = 'I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413'
|
|
|
|
|
com.count = -1
|
|
|
|
|
|
2020-10-30 11:46:19 +08:00
|
|
|
|
patchstream.fix_patch(None, inname, series.Series(), com)
|
2019-09-28 00:23:56 +08:00
|
|
|
|
|
2012-01-14 23:12:45 +08:00
|
|
|
|
rc = os.system('diff -u %s %s' % (inname, expname))
|
|
|
|
|
self.assertEqual(rc, 0)
|
|
|
|
|
|
|
|
|
|
os.remove(inname)
|
|
|
|
|
os.remove(expname)
|
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def get_data(self, data_type):
|
2017-11-13 12:52:12 +08:00
|
|
|
|
data='''From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001
|
2012-01-14 23:12:45 +08:00
|
|
|
|
From: Simon Glass <sjg@chromium.org>
|
|
|
|
|
Date: Thu, 7 Apr 2011 10:14:41 -0700
|
|
|
|
|
Subject: [PATCH 1/4] Add microsecond boot time measurement
|
|
|
|
|
|
|
|
|
|
This defines the basics of a new boot time measurement feature. This allows
|
|
|
|
|
logging of very accurate time measurements as the boot proceeds, by using
|
|
|
|
|
an available microsecond counter.
|
|
|
|
|
|
|
|
|
|
%s
|
|
|
|
|
---
|
|
|
|
|
README | 11 ++++++++
|
2017-11-13 12:52:12 +08:00
|
|
|
|
MAINTAINERS | 3 ++
|
2012-01-14 23:12:45 +08:00
|
|
|
|
common/bootstage.c | 50 ++++++++++++++++++++++++++++++++++++
|
|
|
|
|
include/bootstage.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
include/common.h | 8 ++++++
|
|
|
|
|
5 files changed, 141 insertions(+), 0 deletions(-)
|
|
|
|
|
create mode 100644 common/bootstage.c
|
|
|
|
|
create mode 100644 include/bootstage.h
|
|
|
|
|
|
|
|
|
|
diff --git a/README b/README
|
|
|
|
|
index 6f3748d..f9e4e65 100644
|
|
|
|
|
--- a/README
|
|
|
|
|
+++ b/README
|
|
|
|
|
@@ -2026,6 +2026,17 @@ The following options need to be configured:
|
2012-11-26 23:21:39 +08:00
|
|
|
|
example, some LED's) on your board. At the moment,
|
|
|
|
|
the following checkpoints are implemented:
|
2012-01-14 23:12:45 +08:00
|
|
|
|
|
|
|
|
|
+- Time boot progress
|
|
|
|
|
+ CONFIG_BOOTSTAGE
|
|
|
|
|
+
|
|
|
|
|
+ Define this option to enable microsecond boot stage timing
|
|
|
|
|
+ on supported platforms. For this to work your platform
|
|
|
|
|
+ needs to define a function timer_get_us() which returns the
|
|
|
|
|
+ number of microseconds since reset. This would normally
|
|
|
|
|
+ be done in your SOC or board timer.c file.
|
|
|
|
|
+
|
|
|
|
|
+ You can add calls to bootstage_mark() to set time markers.
|
|
|
|
|
+
|
|
|
|
|
- Standalone program support:
|
2012-11-26 23:21:39 +08:00
|
|
|
|
CONFIG_STANDALONE_LOAD_ADDR
|
2012-01-14 23:12:45 +08:00
|
|
|
|
|
2017-11-13 12:52:12 +08:00
|
|
|
|
diff --git a/MAINTAINERS b/MAINTAINERS
|
|
|
|
|
index b167b028ec..beb7dc634f 100644
|
|
|
|
|
--- a/MAINTAINERS
|
|
|
|
|
+++ b/MAINTAINERS
|
|
|
|
|
@@ -474,3 +474,8 @@ S: Maintained
|
|
|
|
|
T: git git://git.denx.de/u-boot.git
|
|
|
|
|
F: *
|
|
|
|
|
F: */
|
|
|
|
|
+
|
|
|
|
|
+BOOTSTAGE
|
|
|
|
|
+M: Simon Glass <sjg@chromium.org>
|
|
|
|
|
+L: u-boot@lists.denx.de
|
|
|
|
|
+F: common/bootstage.c
|
2012-01-14 23:12:45 +08:00
|
|
|
|
diff --git a/common/bootstage.c b/common/bootstage.c
|
|
|
|
|
new file mode 100644
|
|
|
|
|
index 0000000..2234c87
|
|
|
|
|
--- /dev/null
|
|
|
|
|
+++ b/common/bootstage.c
|
2017-11-13 12:52:12 +08:00
|
|
|
|
@@ -0,0 +1,37 @@
|
2018-06-07 16:45:07 +08:00
|
|
|
|
+%s
|
2012-01-14 23:12:45 +08:00
|
|
|
|
+/*
|
|
|
|
|
+ * Copyright (c) 2011, Google Inc. All rights reserved.
|
|
|
|
|
+ *
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+/*
|
|
|
|
|
+ * This module records the progress of boot and arbitrary commands, and
|
|
|
|
|
+ * permits accurate timestamping of each. The records can optionally be
|
|
|
|
|
+ * passed to kernel in the ATAGs
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+#include <common.h>
|
|
|
|
|
+
|
|
|
|
|
+struct bootstage_record {
|
2017-11-13 12:52:12 +08:00
|
|
|
|
+ u32 time_us;
|
2012-01-14 23:12:45 +08:00
|
|
|
|
+ const char *name;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+static struct bootstage_record record[BOOTSTAGE_COUNT];
|
|
|
|
|
+
|
2017-11-13 12:52:12 +08:00
|
|
|
|
+u32 bootstage_mark(enum bootstage_id id, const char *name)
|
2012-01-14 23:12:45 +08:00
|
|
|
|
+{
|
|
|
|
|
+ struct bootstage_record *rec = &record[id];
|
|
|
|
|
+
|
|
|
|
|
+ /* Only record the first event for each */
|
|
|
|
|
+%sif (!rec->name) {
|
2017-11-13 12:52:12 +08:00
|
|
|
|
+ rec->time_us = (u32)timer_get_us();
|
2012-01-14 23:12:45 +08:00
|
|
|
|
+ rec->name = name;
|
|
|
|
|
+ }
|
2013-03-26 21:09:39 +08:00
|
|
|
|
+ if (!rec->name &&
|
|
|
|
|
+ %ssomething_else) {
|
2017-11-13 12:52:12 +08:00
|
|
|
|
+ rec->time_us = (u32)timer_get_us();
|
2013-03-26 21:09:39 +08:00
|
|
|
|
+ rec->name = name;
|
|
|
|
|
+ }
|
2012-01-14 23:12:45 +08:00
|
|
|
|
+%sreturn rec->time_us;
|
|
|
|
|
+}
|
|
|
|
|
--
|
|
|
|
|
1.7.3.1
|
|
|
|
|
'''
|
|
|
|
|
signoff = 'Signed-off-by: Simon Glass <sjg@chromium.org>\n'
|
2018-06-07 16:45:07 +08:00
|
|
|
|
license = '// SPDX-License-Identifier: GPL-2.0+'
|
2012-01-14 23:12:45 +08:00
|
|
|
|
tab = ' '
|
2013-03-26 21:09:39 +08:00
|
|
|
|
indent = ' '
|
2012-01-14 23:12:45 +08:00
|
|
|
|
if data_type == 'good':
|
|
|
|
|
pass
|
|
|
|
|
elif data_type == 'no-signoff':
|
|
|
|
|
signoff = ''
|
2018-06-07 16:45:07 +08:00
|
|
|
|
elif data_type == 'no-license':
|
|
|
|
|
license = ''
|
2012-01-14 23:12:45 +08:00
|
|
|
|
elif data_type == 'spaces':
|
|
|
|
|
tab = ' '
|
2013-03-26 21:09:39 +08:00
|
|
|
|
elif data_type == 'indent':
|
|
|
|
|
indent = tab
|
2012-01-14 23:12:45 +08:00
|
|
|
|
else:
|
2016-09-27 23:03:50 +08:00
|
|
|
|
print('not implemented')
|
2018-06-07 16:45:07 +08:00
|
|
|
|
return data % (signoff, license, tab, indent, tab)
|
2012-01-14 23:12:45 +08:00
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def setup_data(self, data_type):
|
2012-01-14 23:12:45 +08:00
|
|
|
|
inhandle, inname = tempfile.mkstemp()
|
|
|
|
|
infd = os.fdopen(inhandle, 'w')
|
2022-01-30 05:14:13 +08:00
|
|
|
|
data = self.get_data(data_type)
|
2012-01-14 23:12:45 +08:00
|
|
|
|
infd.write(data)
|
|
|
|
|
infd.close()
|
|
|
|
|
return inname
|
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_good(self):
|
2012-01-14 23:12:45 +08:00
|
|
|
|
"""Test checkpatch operation"""
|
2022-01-30 05:14:13 +08:00
|
|
|
|
inf = self.setup_data('good')
|
2022-01-30 05:14:06 +08:00
|
|
|
|
result = checkpatch.check_patch(inf)
|
2013-03-26 21:09:39 +08:00
|
|
|
|
self.assertEqual(result.ok, True)
|
|
|
|
|
self.assertEqual(result.problems, [])
|
|
|
|
|
self.assertEqual(result.errors, 0)
|
|
|
|
|
self.assertEqual(result.warnings, 0)
|
|
|
|
|
self.assertEqual(result.checks, 0)
|
2017-11-13 12:52:12 +08:00
|
|
|
|
self.assertEqual(result.lines, 62)
|
2012-01-14 23:12:45 +08:00
|
|
|
|
os.remove(inf)
|
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_no_signoff(self):
|
|
|
|
|
inf = self.setup_data('no-signoff')
|
2022-01-30 05:14:06 +08:00
|
|
|
|
result = checkpatch.check_patch(inf)
|
2013-03-26 21:09:39 +08:00
|
|
|
|
self.assertEqual(result.ok, False)
|
|
|
|
|
self.assertEqual(len(result.problems), 1)
|
|
|
|
|
self.assertEqual(result.errors, 1)
|
|
|
|
|
self.assertEqual(result.warnings, 0)
|
|
|
|
|
self.assertEqual(result.checks, 0)
|
2017-11-13 12:52:12 +08:00
|
|
|
|
self.assertEqual(result.lines, 62)
|
2012-01-14 23:12:45 +08:00
|
|
|
|
os.remove(inf)
|
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_no_license(self):
|
|
|
|
|
inf = self.setup_data('no-license')
|
2022-01-30 05:14:06 +08:00
|
|
|
|
result = checkpatch.check_patch(inf)
|
2018-06-07 16:45:07 +08:00
|
|
|
|
self.assertEqual(result.ok, False)
|
|
|
|
|
self.assertEqual(len(result.problems), 1)
|
|
|
|
|
self.assertEqual(result.errors, 0)
|
|
|
|
|
self.assertEqual(result.warnings, 1)
|
|
|
|
|
self.assertEqual(result.checks, 0)
|
|
|
|
|
self.assertEqual(result.lines, 62)
|
|
|
|
|
os.remove(inf)
|
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_spaces(self):
|
|
|
|
|
inf = self.setup_data('spaces')
|
2022-01-30 05:14:06 +08:00
|
|
|
|
result = checkpatch.check_patch(inf)
|
2013-03-26 21:09:39 +08:00
|
|
|
|
self.assertEqual(result.ok, False)
|
2017-11-13 12:52:12 +08:00
|
|
|
|
self.assertEqual(len(result.problems), 3)
|
2013-03-26 21:09:39 +08:00
|
|
|
|
self.assertEqual(result.errors, 0)
|
2017-11-13 12:52:12 +08:00
|
|
|
|
self.assertEqual(result.warnings, 3)
|
2013-03-26 21:09:39 +08:00
|
|
|
|
self.assertEqual(result.checks, 0)
|
2017-11-13 12:52:12 +08:00
|
|
|
|
self.assertEqual(result.lines, 62)
|
2013-03-26 21:09:39 +08:00
|
|
|
|
os.remove(inf)
|
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_indent(self):
|
|
|
|
|
inf = self.setup_data('indent')
|
2022-01-30 05:14:06 +08:00
|
|
|
|
result = checkpatch.check_patch(inf)
|
2013-03-26 21:09:39 +08:00
|
|
|
|
self.assertEqual(result.ok, False)
|
|
|
|
|
self.assertEqual(len(result.problems), 1)
|
|
|
|
|
self.assertEqual(result.errors, 0)
|
|
|
|
|
self.assertEqual(result.warnings, 0)
|
|
|
|
|
self.assertEqual(result.checks, 1)
|
2017-11-13 12:52:12 +08:00
|
|
|
|
self.assertEqual(result.lines, 62)
|
2012-01-14 23:12:45 +08:00
|
|
|
|
os.remove(inf)
|
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def check_single_message(self, pm, msg, pmtype = 'warning'):
|
2020-06-15 00:54:07 +08:00
|
|
|
|
"""Helper function to run checkpatch and check the result
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
pm: PatchMaker object to use
|
2021-03-11 13:15:45 +08:00
|
|
|
|
msg: Expected message (e.g. 'LIVETREE')
|
2020-06-15 00:54:07 +08:00
|
|
|
|
pmtype: Type of problem ('error', 'warning')
|
|
|
|
|
"""
|
|
|
|
|
result = pm.run_checkpatch()
|
|
|
|
|
if pmtype == 'warning':
|
|
|
|
|
self.assertEqual(result.warnings, 1)
|
|
|
|
|
elif pmtype == 'error':
|
|
|
|
|
self.assertEqual(result.errors, 1)
|
|
|
|
|
if len(result.problems) != 1:
|
|
|
|
|
print(result.problems)
|
|
|
|
|
self.assertEqual(len(result.problems), 1)
|
|
|
|
|
self.assertIn(msg, result.problems[0]['cptype'])
|
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_uclass(self):
|
2020-06-15 00:54:05 +08:00
|
|
|
|
"""Test for possible new uclass"""
|
|
|
|
|
pm = PatchMaker()
|
|
|
|
|
pm.add_line('include/dm/uclass-id.h', 'UCLASS_WIBBLE,')
|
2022-01-30 05:14:13 +08:00
|
|
|
|
self.check_single_message(pm, 'NEW_UCLASS')
|
2020-06-15 00:54:07 +08:00
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_livetree(self):
|
2020-07-20 00:16:00 +08:00
|
|
|
|
"""Test for using the livetree API"""
|
2020-06-15 00:54:07 +08:00
|
|
|
|
pm = PatchMaker()
|
|
|
|
|
pm.add_line('common/main.c', 'fdtdec_do_something()')
|
2022-01-30 05:14:13 +08:00
|
|
|
|
self.check_single_message(pm, 'LIVETREE')
|
2020-06-15 00:54:07 +08:00
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_new_command(self):
|
2020-07-20 00:16:00 +08:00
|
|
|
|
"""Test for adding a new command"""
|
2020-06-15 00:54:07 +08:00
|
|
|
|
pm = PatchMaker()
|
|
|
|
|
pm.add_line('common/main.c', 'do_wibble(struct cmd_tbl *cmd_tbl)')
|
2022-01-30 05:14:13 +08:00
|
|
|
|
self.check_single_message(pm, 'CMD_TEST')
|
2020-06-15 00:54:07 +08:00
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_prefer_if(self):
|
2020-07-20 00:16:00 +08:00
|
|
|
|
"""Test for using #ifdef"""
|
2020-06-15 00:54:07 +08:00
|
|
|
|
pm = PatchMaker()
|
|
|
|
|
pm.add_line('common/main.c', '#ifdef CONFIG_YELLOW')
|
2020-06-15 00:54:08 +08:00
|
|
|
|
pm.add_line('common/init.h', '#ifdef CONFIG_YELLOW')
|
|
|
|
|
pm.add_line('fred.dtsi', '#ifdef CONFIG_YELLOW')
|
2022-01-30 05:14:13 +08:00
|
|
|
|
self.check_single_message(pm, "PREFER_IF")
|
2020-06-15 00:54:07 +08:00
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_command_use_defconfig(self):
|
2020-07-20 00:16:00 +08:00
|
|
|
|
"""Test for enabling/disabling commands using preprocesor"""
|
2020-06-15 00:54:07 +08:00
|
|
|
|
pm = PatchMaker()
|
|
|
|
|
pm.add_line('common/main.c', '#undef CONFIG_CMD_WHICH')
|
2022-01-30 05:14:13 +08:00
|
|
|
|
self.check_single_message(pm, 'DEFINE_CONFIG_CMD', 'error')
|
2020-06-15 00:54:05 +08:00
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_barred_include_in_hdr(self):
|
2020-07-20 00:16:01 +08:00
|
|
|
|
"""Test for using a barred include in a header file"""
|
|
|
|
|
pm = PatchMaker()
|
|
|
|
|
#pm.add_line('include/myfile.h', '#include <common.h>')
|
|
|
|
|
pm.add_line('include/myfile.h', '#include <dm.h>')
|
2022-01-30 05:14:13 +08:00
|
|
|
|
self.check_single_message(pm, 'BARRED_INCLUDE_IN_HDR', 'error')
|
2020-07-20 00:16:01 +08:00
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_config_is_enabled_config(self):
|
2020-10-05 14:57:30 +08:00
|
|
|
|
"""Test for accidental CONFIG_IS_ENABLED(CONFIG_*) calls"""
|
|
|
|
|
pm = PatchMaker()
|
|
|
|
|
pm.add_line('common/main.c', 'if (CONFIG_IS_ENABLED(CONFIG_CLK))')
|
2022-01-30 05:14:13 +08:00
|
|
|
|
self.check_single_message(pm, 'CONFIG_IS_ENABLED_CONFIG', 'error')
|
2020-10-05 14:57:30 +08:00
|
|
|
|
|
2020-12-04 07:55:24 +08:00
|
|
|
|
def check_struct(self, auto, suffix, warning):
|
|
|
|
|
"""Check one of the warnings for struct naming
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
auto: Auto variable name, e.g. 'per_child_auto'
|
|
|
|
|
suffix: Suffix to expect on member, e.g. '_priv'
|
|
|
|
|
warning: Warning name, e.g. 'PRIV_AUTO'
|
|
|
|
|
"""
|
|
|
|
|
pm = PatchMaker()
|
|
|
|
|
pm.add_line('common/main.c', '.%s = sizeof(struct(fred)),' % auto)
|
|
|
|
|
pm.add_line('common/main.c', '.%s = sizeof(struct(mary%s)),' %
|
|
|
|
|
(auto, suffix))
|
2022-01-30 05:14:13 +08:00
|
|
|
|
self.check_single_message(
|
2020-12-04 07:55:24 +08:00
|
|
|
|
pm, warning, "struct 'fred' should have a %s suffix" % suffix)
|
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_dm_driver_auto(self):
|
2020-12-04 07:55:24 +08:00
|
|
|
|
"""Check for the correct suffix on 'struct driver' auto members"""
|
|
|
|
|
self.check_struct('priv_auto', '_priv', 'PRIV_AUTO')
|
|
|
|
|
self.check_struct('plat_auto', '_plat', 'PLAT_AUTO')
|
|
|
|
|
self.check_struct('per_child_auto', '_priv', 'CHILD_PRIV_AUTO')
|
|
|
|
|
self.check_struct('per_child_plat_auto', '_plat', 'CHILD_PLAT_AUTO')
|
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_dm_uclass_auto(self):
|
2020-12-04 07:55:24 +08:00
|
|
|
|
"""Check for the correct suffix on 'struct uclass' auto members"""
|
|
|
|
|
# Some of these are omitted since they match those from struct driver
|
|
|
|
|
self.check_struct('per_device_auto', '_priv', 'DEVICE_PRIV_AUTO')
|
|
|
|
|
self.check_struct('per_device_plat_auto', '_plat', 'DEVICE_PLAT_AUTO')
|
|
|
|
|
|
2021-03-11 13:15:45 +08:00
|
|
|
|
def check_strl(self, func):
|
|
|
|
|
"""Check one of the checks for strn(cpy|cat)"""
|
|
|
|
|
pm = PatchMaker()
|
|
|
|
|
pm.add_line('common/main.c', "strn%s(foo, bar, sizeof(foo));" % func)
|
2022-01-30 05:14:13 +08:00
|
|
|
|
self.check_single_message(pm, "STRL",
|
2021-03-11 13:15:45 +08:00
|
|
|
|
"strl%s is preferred over strn%s because it always produces a nul-terminated string\n"
|
|
|
|
|
% (func, func))
|
|
|
|
|
|
2022-01-30 05:14:13 +08:00
|
|
|
|
def test_strl(self):
|
2021-03-11 13:15:45 +08:00
|
|
|
|
"""Check for uses of strn(cat|cpy)"""
|
|
|
|
|
self.check_strl("cat");
|
|
|
|
|
self.check_strl("cpy");
|
2012-01-14 23:12:45 +08:00
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main()
|
|
|
|
|
gitutil.RunTests()
|