patman: Remove the test suite

These tests cover the patch-management functionality, which is being
removed from the tree in favour of the standalone patch-manager package.
Drop the tests and their data files.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2026-07-06 08:28:51 -06:00
committed by Tom Rini
parent f2cf431533
commit f7a4848a9c
10 changed files with 0 additions and 6106 deletions
File diff suppressed because it is too large Load Diff
-2
View File
@@ -1,2 +0,0 @@
[pytest]
addopts = --doctest-modules
-23
View File
@@ -1,23 +0,0 @@
From 5ab48490f03051875ab13d288a4bf32b507d76fd Mon Sep 17 00:00:00 2001
From: Simon Glass <sjg@chromium.org>
Date: Sat, 27 May 2017 20:52:11 -0600
Subject: [RFC 0/2] *** SUBJECT HERE ***
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
*** BLURB HERE ***
Simon Glass (2):
pci: Correct cast for sandbox
fdt: Correct cast for sandbox in fdtdec_setup_mem_size_base()
cmd/pci.c | 3 ++-
fs/fat/fat.c | 1 +
lib/efi_loader/efi_memory.c | 1 +
lib/fdtdec.c | 3 ++-
4 files changed, 6 insertions(+), 2 deletions(-)
--
2.7.4
@@ -1,51 +0,0 @@
From b9da5f937bd5ea4931ea17459bf79b2905d9594d Mon Sep 17 00:00:00 2001
From: Simon Glass <sjg@chromium.org>
Date: Sat, 15 Apr 2017 15:39:08 -0600
Subject: [RFC 1/2] pci: Correct cast for sandbox
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This gives a warning with some native compilers:
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=]
Fix it with a cast.
Signed-off-by: Simon Glass <sjg@chromium.org>
Commit-changes: 2
- Changes only for this commit
Series-notes:
some notes
about some things
from the first commit
END
Commit-notes:
Some notes about
the first commit
END
---
cmd/pci.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/cmd/pci.c b/cmd/pci.c
index 41b4fff..fe27b4f 100644
--- a/cmd/pci.c
+++ b/cmd/pci.c
@@ -150,7 +150,8 @@ int pci_bar_show(struct udevice *dev)
if ((!is_64 && size_low) || (is_64 && size)) {
size = ~size + 1;
printf(" %d %#016llx %#016llx %d %s %s\n",
- bar_id, base, size, is_64 ? 64 : 32,
+ bar_id, (unsigned long long)base,
+ (unsigned long long)size, is_64 ? 64 : 32,
is_io ? "I/O" : "MEM",
prefetchable ? "Prefetchable" : "");
}
--
2.7.4
@@ -1,85 +0,0 @@
From 5ab48490f03051875ab13d288a4bf32b507d76fd Mon Sep 17 00:00:00 2001
From: Simon Glass <sjg@chromium.org>
Date: Sat, 15 Apr 2017 15:39:08 -0600
Subject: [RFC 2/2] fdt: Correct cast for sandbox in fdtdec_setup_mem_size_base()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This gives a warning with some native compilers:
lib/fdtdec.c:1203:8: warning: format %llx expects argument of type
long long unsigned int, but argument 3 has type
long unsigned int [-Wformat=]
Fix it with a cast.
Signed-off-by: Simon Glass <sjg@chromium.org>
Series-to: u-boot
Series-prefix: RFC
Series-cc: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Cover-letter-cc: Lord Mëlchett <clergy@palace.gov>
Series-version: 3
Patch-cc: fred
Commit-cc: joe
Series-process-log: sort, uniq
Commit-added-in: 4
Series-changes: 4
- Some changes
- Multi
line
change
Commit-changes: 2
- Changes only for this commit
Cover-changes: 4
- Some notes for the cover letter
Cover-letter:
test: A test patch series
This is a test of how the cover
letter
works
END
---
fs/fat/fat.c | 1 +
lib/efi_loader/efi_memory.c | 1 +
lib/fdtdec.c | 3 ++-
3 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index a71bad1..ba169dc 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -1,3 +1,4 @@
+
/*
* fat.c
*
diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index db2ae19..05f75d1 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -1,3 +1,4 @@
+
/*
* EFI application memory management
*
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index c072e54..942244f 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1200,7 +1200,8 @@ int fdtdec_setup_mem_size_base(void)
}
gd->ram_size = (phys_size_t)(res.end - res.start + 1);
- debug("%s: Initial DRAM size %llx\n", __func__, (u64)gd->ram_size);
+ debug("%s: Initial DRAM size %llx\n", __func__,
+ (unsigned long long)gd->ram_size);
return 0;
}
--
2.7.4
-72
View File
@@ -1,72 +0,0 @@
commit b9da5f937bd5ea4931ea17459bf79b2905d9594d
Author: Simon Glass <sjg@chromium.org>
Date: Sat Apr 15 15:39:08 2017 -0600
pci: Correct cast for sandbox
This gives a warning with some native compilers:
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=]
Fix it with a cast.
Signed-off-by: Simon Glass <sjg@chromium.org>
Commit-changes: 2
- second revision change
Series-notes:
some notes
about some things
from the first commit
END
Commit-notes:
Some notes about
the first commit
END
commit 5ab48490f03051875ab13d288a4bf32b507d76fd
Author: Simon Glass <sjg@chromium.org>
Date: Sat Apr 15 15:39:08 2017 -0600
fdt: Correct cast for sandbox in fdtdec_setup_mem_size_base()
This gives a warning with some native compilers:
lib/fdtdec.c:1203:8: warning: format %llx expects argument of type
long long unsigned int, but argument 3 has type
long unsigned int [-Wformat=]
Fix it with a cast.
Signed-off-by: Simon Glass <sjg@chromium.org>
Series-to: u-boot
Series-prefix: RFC
Series-postfix: some-branch
Series-cc: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Cover-letter-cc: Lord Mëlchett <clergy@palace.gov>
Series-version: 3
Patch-cc: fred
Commit-cc: joe
Series-process-log: sort, uniq
Commit-added-in: 4
Series-changes: 4
- Some changes
- Multi
line
change
Commit-changes: 2
- Changes only for this commit
Cover-changes: 4
- Some notes for the cover letter
Cover-letter:
test: A test patch series
This is a test of how the cover
letter
works
END
-526
View File
@@ -1,526 +0,0 @@
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: GPL-2.0+
#
# Tests for U-Boot-specific checkpatch.pl features
#
# Copyright (c) 2011 The Chromium OS Authors.
#
import os
import tempfile
import unittest
from patman import checkpatch
from patman import patchstream
from patman import series
from patman import commit
from u_boot_pylib import gitutil
class Line:
"""Single changed line in one file in a patch
Args:
fname (str): Filename containing the added line
text (str): Text of the added line
"""
def __init__(self, fname, text):
self.fname = fname
self.text = text
class PatchMaker:
"""Makes a patch for checking with checkpatch.pl
The idea here is to create a patch which adds one line in one file,
intended to provoke a checkpatch error or warning. The base patch is empty
(i.e. invalid), so you should call add_line() to add at least one line.
"""
def __init__(self):
"""Set up the PatchMaker object
Properties:
lines (list of Line): List of lines to add to the patch. Note that
each line has both a file and some text associated with it,
since for simplicity we just add a single line for each file
"""
self.lines = []
def add_line(self, fname, text):
"""Add to the list of filename/line pairs"""
self.lines.append(Line(fname, text))
def get_patch_text(self):
"""Build the patch text
Takes a base patch and adds a diffstat and patch for each filename/line
pair in the list.
Returns:
str: Patch text ready for submission to checkpatch
"""
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):
"""Get the patch text and write it into a temporary file
Returns:
str: Filename containing the patch
"""
inhandle, inname = tempfile.mkstemp()
infd = os.fdopen(inhandle, 'w')
infd.write(self.get_patch_text())
infd.close()
return inname
def run_checkpatch(self):
"""Run checkpatch on the patch file
Returns:
namedtuple containing:
ok: False=failure, True=ok
problems: List of problems, each a dict:
'type'; error or warning
'msg': text message
'file' : filename
'line': line number
errors: Number of errors
warnings: Number of warnings
checks: Number of checks
lines: Number of lines
stdout: Full output of checkpatch
"""
return checkpatch.check_patch(self.get_patch(), show_types=True)
class TestPatch(unittest.TestCase):
"""Test the u_boot_line() function in checkpatch.pl"""
def test_filter(self):
"""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.
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=]
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 +++++++++++++++++
'''
expected='''Message-Id: <19991231235959.0.I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413@changeid>
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.
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=]
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 +++++++++++++++++
'''
out = ''
inhandle, inname = tempfile.mkstemp()
infd = os.fdopen(inhandle, 'w', encoding='utf-8')
infd.write(data)
infd.close()
exphandle, expname = tempfile.mkstemp()
expfd = os.fdopen(exphandle, 'w', encoding='utf-8')
expfd.write(expected)
expfd.close()
# Normally by the time we call fix_patch we've already collected
# metadata. Here, we haven't, but at least fake up something.
# Set the "count" to -1 which tells fix_patch to use a bogus/fixed
# time for generating the Message-Id.
com = commit.Commit('')
com.change_id = 'I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413'
com.count = -1
patchstream.fix_patch(None, inname, series.Series(), com)
rc = os.system('diff -u %s %s' % (inname, expname))
self.assertEqual(rc, 0)
os.remove(inname)
# Test whether the keep_change_id settings works.
inhandle, inname = tempfile.mkstemp()
infd = os.fdopen(inhandle, 'w', encoding='utf-8')
infd.write(data)
infd.close()
patchstream.fix_patch(None, inname, series.Series(), com,
keep_change_id=True)
with open(inname, 'r') as f:
content = f.read()
self.assertIn(
'Change-Id: I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413',
content)
os.remove(inname)
os.remove(expname)
def get_data(self, data_type):
data='''From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001
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 ++++++++
MAINTAINERS | 3 ++
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:
example, some LED's) on your board. At the moment,
the following checkpoints are implemented:
+- 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:
CONFIG_STANDALONE_LOAD_ADDR
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
diff --git a/common/bootstage.c b/common/bootstage.c
new file mode 100644
index 0000000..2234c87
--- /dev/null
+++ b/common/bootstage.c
@@ -0,0 +1,37 @@
+%s
+/*
+ * 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 <config.h>
+
+struct bootstage_record {
+ u32 time_us;
+ const char *name;
+};
+
+static struct bootstage_record record[BOOTSTAGE_COUNT];
+
+u32 bootstage_mark(enum bootstage_id id, const char *name)
+{
+ struct bootstage_record *rec = &record[id];
+
+ /* Only record the first event for each */
+%sif (!rec->name) {
+ rec->time_us = (u32)timer_get_us();
+ rec->name = name;
+ }
+ if (!rec->name &&
+ %ssomething_else) {
+ rec->time_us = (u32)timer_get_us();
+ rec->name = name;
+ }
+%sreturn rec->time_us;
+}
--
1.7.3.1
'''
signoff = 'Signed-off-by: Simon Glass <sjg@chromium.org>\n'
license = '// SPDX-License-Identifier: GPL-2.0+'
tab = ' '
indent = ' '
if data_type == 'good':
pass
elif data_type == 'no-signoff':
signoff = ''
elif data_type == 'no-license':
license = ''
elif data_type == 'spaces':
tab = ' '
elif data_type == 'indent':
indent = tab
else:
print('not implemented')
return data % (signoff, license, tab, indent, tab)
def setup_data(self, data_type):
inhandle, inname = tempfile.mkstemp()
infd = os.fdopen(inhandle, 'w')
data = self.get_data(data_type)
infd.write(data)
infd.close()
return inname
def test_good(self):
"""Test checkpatch operation"""
inf = self.setup_data('good')
result = checkpatch.check_patch(inf)
self.assertEqual(result.ok, True)
self.assertEqual(result.problems, [])
self.assertEqual(result.errors, 0)
self.assertEqual(result.warnings, 0)
self.assertEqual(result.checks, 0)
self.assertEqual(result.lines, 62)
os.remove(inf)
def test_no_signoff(self):
inf = self.setup_data('no-signoff')
result = checkpatch.check_patch(inf)
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)
self.assertEqual(result.lines, 62)
os.remove(inf)
def test_no_license(self):
inf = self.setup_data('no-license')
result = checkpatch.check_patch(inf)
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)
def test_spaces(self):
inf = self.setup_data('spaces')
result = checkpatch.check_patch(inf)
self.assertEqual(result.ok, False)
self.assertEqual(len(result.problems), 3)
self.assertEqual(result.errors, 0)
self.assertEqual(result.warnings, 3)
self.assertEqual(result.checks, 0)
self.assertEqual(result.lines, 62)
os.remove(inf)
def test_indent(self):
inf = self.setup_data('indent')
result = checkpatch.check_patch(inf)
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)
self.assertEqual(result.lines, 62)
os.remove(inf)
def check_single_message(self, pm, msg, pmtype = 'warning'):
"""Helper function to run checkpatch and check the result
Args:
pm: PatchMaker object to use
msg: Expected message (e.g. 'LIVETREE')
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'])
def test_uclass(self):
"""Test for possible new uclass"""
pm = PatchMaker()
pm.add_line('include/dm/uclass-id.h', 'UCLASS_WIBBLE,')
self.check_single_message(pm, 'NEW_UCLASS')
def test_livetree(self):
"""Test for using the livetree API"""
pm = PatchMaker()
pm.add_line('common/main.c', 'fdtdec_do_something()')
self.check_single_message(pm, 'LIVETREE')
def test_new_command(self):
"""Test for adding a new command"""
pm = PatchMaker()
pm.add_line('common/main.c', 'do_wibble(struct cmd_tbl *cmd_tbl)')
self.check_single_message(pm, 'CMD_TEST')
def test_prefer_if(self):
"""Test for using #ifdef"""
pm = PatchMaker()
pm.add_line('common/main.c', '#ifdef CONFIG_YELLOW')
pm.add_line('common/init.h', '#ifdef CONFIG_YELLOW')
pm.add_line('fred.dtsi', '#ifdef CONFIG_YELLOW')
self.check_single_message(pm, "PREFER_IF")
def test_command_use_defconfig(self):
"""Test for enabling/disabling commands using preprocesor"""
pm = PatchMaker()
pm.add_line('common/main.c', '#undef CONFIG_CMD_WHICH')
self.check_single_message(pm, 'DEFINE_CONFIG_SYM', 'error')
def test_barred_include_in_hdr(self):
"""Test for using a barred include in a header file"""
pm = PatchMaker()
pm.add_line('include/myfile.h', '#include <dm.h>')
self.check_single_message(pm, 'BARRED_INCLUDE_IN_HDR', 'error')
def test_barred_include_common_h(self):
"""Test for adding common.h to a file"""
pm = PatchMaker()
pm.add_line('include/myfile.h', '#include <common.h>')
self.check_single_message(pm, 'BARRED_INCLUDE_COMMON_H', 'error')
def test_config_is_enabled_config(self):
"""Test for accidental CONFIG_IS_ENABLED(CONFIG_*) calls"""
pm = PatchMaker()
pm.add_line('common/main.c', 'if (CONFIG_IS_ENABLED(CONFIG_CLK))')
self.check_single_message(pm, 'CONFIG_IS_ENABLED_CONFIG', 'error')
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))
self.check_single_message(
pm, warning, "struct 'fred' should have a %s suffix" % suffix)
def test_dm_driver_auto(self):
"""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')
def test_dm_uclass_auto(self):
"""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')
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)
self.check_single_message(pm, "STRL",
"strl%s is preferred over strn%s because it always produces a nul-terminated string\n"
% (func, func))
def test_strl(self):
"""Check for uses of strn(cat|cpy)"""
self.check_strl("cat");
self.check_strl("cpy");
if __name__ == "__main__":
unittest.main()
-254
View File
@@ -1,254 +0,0 @@
# SPDX-License-Identifier: GPL-2.0+
#
# Copyright 2025 Simon Glass <sjg@chromium.org>
#
"""Functional tests for checking that patman behaves correctly"""
import os
import shutil
import tempfile
import pygit2
from u_boot_pylib import gitutil
from u_boot_pylib import terminal
from u_boot_pylib import tools
from u_boot_pylib import tout
class TestCommon:
"""Contains common test functions"""
leb = (b'Lord Edmund Blackadd\xc3\xabr <weasel@blackadder.org>'.
decode('utf-8'))
# Fake patchwork project ID for U-Boot
PROJ_ID = 6
PROJ_LINK_NAME = 'uboot'
SERIES_ID_FIRST_V3 = 31
SERIES_ID_SECOND_V1 = 456
SERIES_ID_SECOND_V2 = 457
TITLE_SECOND = 'Series for my board'
verbosity = False
preserve_outdirs = False
@classmethod
def setup_test_args(cls, preserve_indir=False, preserve_outdirs=False,
toolpath=None, verbosity=None, no_capture=False):
"""Accept arguments controlling test execution
Args:
preserve_indir (bool): not used by patman
preserve_outdirs (bool): Preserve the output directories used by
tests. Each test has its own, so this is normally only useful
when running a single test.
toolpath (str): not used by patman
verbosity (int): verbosity to use (0 means tout.INIT, 1 means means
tout.DEBUG)
no_capture (bool): True to output all captured text after capturing
completes
"""
del preserve_indir
cls.preserve_outdirs = preserve_outdirs
cls.toolpath = toolpath
cls.verbosity = verbosity
cls.no_capture = no_capture
def __init__(self):
super().__init__()
self.repo = None
self.tmpdir = None
self.gitdir = None
def setUp(self):
"""Set up the test temporary dir and git dir"""
self.tmpdir = tempfile.mkdtemp(prefix='patman.')
self.gitdir = os.path.join(self.tmpdir, '.git')
tout.init(tout.DEBUG if self.verbosity else tout.INFO,
allow_colour=False)
def tearDown(self):
"""Delete the temporary dir"""
if self.preserve_outdirs:
print(f'Output dir: {self.tmpdir}')
else:
shutil.rmtree(self.tmpdir)
terminal.set_print_test_mode(False)
def make_commit_with_file(self, subject, body, fname, text):
"""Create a file and add it to the git repo with a new commit
Args:
subject (str): Subject for the commit
body (str): Body text of the commit
fname (str): Filename of file to create
text (str): Text to put into the file
"""
path = os.path.join(self.tmpdir, fname)
tools.write_file(path, text, binary=False)
index = self.repo.index
index.add(fname)
# pylint doesn't seem to find this
# pylint: disable=E1101
author = pygit2.Signature('Test user', 'test@email.com')
committer = author
tree = index.write_tree()
message = subject + '\n' + body
self.repo.create_commit('HEAD', author, committer, message, tree,
[self.repo.head.target])
def make_git_tree(self):
"""Make a simple git tree suitable for testing
It has four branches:
'base' has two commits: PCI, main
'first' has base as upstream and two more commits: I2C, SPI
'second' has base as upstream and three more: video, serial, bootm
'third4' has second as upstream and four more: usb, main, test, lib
Returns:
pygit2.Repository: repository
"""
os.environ['GIT_CONFIG_GLOBAL'] = '/dev/null'
os.environ['GIT_CONFIG_SYSTEM'] = '/dev/null'
repo = pygit2.init_repository(self.gitdir)
self.repo = repo
new_tree = repo.TreeBuilder().write()
common = ['git', f'--git-dir={self.gitdir}', 'config']
tools.run(*(common + ['user.name', 'Dummy']), cwd=self.gitdir)
tools.run(*(common + ['user.email', 'dumdum@dummy.com']),
cwd=self.gitdir)
# pylint doesn't seem to find this
# pylint: disable=E1101
author = pygit2.Signature('Test user', 'test@email.com')
committer = author
_ = repo.create_commit('HEAD', author, committer, 'Created master',
new_tree, [])
self.make_commit_with_file('Initial commit', '''
Add a README
''', 'README', '''This is the README file
describing this project
in very little detail''')
self.make_commit_with_file('pci: PCI implementation', '''
Here is a basic PCI implementation
''', 'pci.c', '''This is a file
it has some contents
and some more things''')
self.make_commit_with_file('main: Main program', '''
Hello here is the second commit.
''', 'main.c', '''This is the main file
there is very little here
but we can always add more later
if we want to
Series-to: u-boot
Series-cc: Barry Crump <bcrump@whataroa.nz>
''')
base_target = repo.revparse_single('HEAD')
self.make_commit_with_file('i2c: I2C things', '''
This has some stuff to do with I2C
''', 'i2c.c', '''And this is the file contents
with some I2C-related things in it''')
self.make_commit_with_file('spi: SPI fixes', f'''
SPI needs some fixes
and here they are
Signed-off-by: {self.leb}
Series-to: u-boot
Commit-notes:
title of the series
This is the cover letter for the series
with various details
END
''', 'spi.c', '''Some fixes for SPI in this
file to make SPI work
better than before''')
first_target = repo.revparse_single('HEAD')
target = repo.revparse_single('HEAD~2')
# pylint doesn't seem to find this
# pylint: disable=E1101
repo.reset(target.oid, pygit2.enums.ResetMode.HARD)
self.make_commit_with_file('video: Some video improvements', '''
Fix up the video so that
it looks more purple. Purple is
a very nice colour.
''', 'video.c', '''More purple here
Purple and purple
Even more purple
Could not be any more purple''')
self.make_commit_with_file('serial: Add a serial driver', f'''
Here is the serial driver
for my chip.
Cover-letter:
{self.TITLE_SECOND}
This series implements support
for my glorious board.
END
Series-to: u-boot
Series-links: {self.SERIES_ID_SECOND_V1}
''', 'serial.c', '''The code for the
serial driver is here''')
self.make_commit_with_file('bootm: Make it boot', '''
This makes my board boot
with a fix to the bootm
command
''', 'bootm.c', '''Fix up the bootm
command to make the code as
complicated as possible''')
second_target = repo.revparse_single('HEAD')
self.make_commit_with_file('usb: Try out the new DMA feature', '''
This is just a fix that
ensures that DMA is enabled
''', 'usb-uclass.c', '''Here is the USB
implementation and as you can see it
it very nice''')
self.make_commit_with_file('main: Change to the main program', '''
Here we adjust the main
program just a little bit
''', 'main.c', '''This is the text of the main program''')
self.make_commit_with_file('test: Check that everything works', '''
This checks that all the
various things we've been
adding actually work.
''', 'test.c', '''Here is the test code and it seems OK''')
self.make_commit_with_file('lib: Sort out the extra library', '''
The extra library is currently
broken. Fix it so that we can
use it in various place.
''', 'lib.c', '''Some library code is here
and a little more''')
third_target = repo.revparse_single('HEAD')
repo.branches.local.create('first', first_target)
repo.config.set_multivar('branch.first.remote', '', '.')
repo.config.set_multivar('branch.first.merge', '', 'refs/heads/base')
repo.branches.local.create('second', second_target)
repo.config.set_multivar('branch.second.remote', '', '.')
repo.config.set_multivar('branch.second.merge', '', 'refs/heads/base')
repo.branches.local.create('base', base_target)
repo.branches.local.create('third4', third_target)
repo.config.set_multivar('branch.third4.remote', '', '.')
repo.config.set_multivar('branch.third4.merge', '',
'refs/heads/second')
target = repo.lookup_reference('refs/heads/first')
repo.checkout(target, strategy=pygit2.GIT_CHECKOUT_FORCE)
target = repo.revparse_single('HEAD')
repo.reset(target.oid, pygit2.enums.ResetMode.HARD)
self.assertFalse(gitutil.check_dirty(self.gitdir, self.tmpdir))
return repo
File diff suppressed because it is too large Load Diff
-67
View File
@@ -1,67 +0,0 @@
# SPDX-License-Identifier: GPL-2.0+
#
# Copyright (c) 2022 Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com>
#
import argparse
import contextlib
import os
import sys
import tempfile
from patman import settings
from u_boot_pylib import tools
@contextlib.contextmanager
def empty_git_repository():
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
tools.run('git', 'init', raise_on_error=True)
yield tmpdir
@contextlib.contextmanager
def cleared_command_line_args():
old_value = sys.argv[:]
sys.argv = [sys.argv[0]]
try:
yield
finally:
sys.argv = old_value
def test_git_local_config():
# Clearing the command line arguments is required, otherwise
# arguments passed to the test running such as in 'pytest -k
# filter' would be processed by _UpdateDefaults and fail.
with cleared_command_line_args():
with empty_git_repository():
with tempfile.NamedTemporaryFile() as global_config:
global_config.write(b'[settings]\n'
b'project=u-boot\n')
global_config.flush()
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--project', default='unknown')
subparsers = parser.add_subparsers(dest='cmd')
send = subparsers.add_parser('send')
send.add_argument('--no-check', action='store_false',
dest='check_patch', default=True)
# Test "global" config is used.
settings.Setup(parser, 'unknown', None, global_config.name)
args, _ = parser.parse_known_args([])
assert args.project == 'u-boot'
send_args, _ = send.parse_known_args([])
assert send_args.check_patch
# Test local config can shadow it.
with open('.patman', 'w', buffering=1) as f:
f.write('[settings]\n'
'project: guix-patches\n'
'check_patch: False\n')
settings.Setup(parser, 'unknown', global_config.name)
args, _ = parser.parse_known_args([])
assert args.project == 'guix-patches'
send_args, _ = send.parse_known_args([])
assert not send_args.check_patch