mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
Remove test 'args' file rewrapping infrastructure
All tests which use files with 'ldargs' and 'args' suffix as output now use the internal and better line splitting. Remove the test-wrap-argv.py script, the syntax check which used it and the helper rewrapping the output when regenerating test output. For any further use, we require code to use virCommand anyways and thus it has internal wrapping now. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
d146b193e2
commit
76d722d3d5
@ -1679,7 +1679,7 @@ sc_prohibit_path_max_allocation:
|
||||
$(_sc_search_regexp)
|
||||
|
||||
ifneq ($(_gl-Makefile),)
|
||||
syntax-check: sc_spacing-check sc_test-wrap-argv \
|
||||
syntax-check: sc_spacing-check \
|
||||
sc_prohibit-duplicate-header sc_mock-noinline sc_group-qemu-caps \
|
||||
sc_header-ifdef
|
||||
@if ! cppi --version >/dev/null 2>&1; then \
|
||||
@ -1712,11 +1712,6 @@ sc_header-ifdef:
|
||||
$(AM_V_GEN)$(VC_LIST) | $(GREP) '\.[h]$$' | $(RUNUTF8) xargs \
|
||||
$(PYTHON) $(top_srcdir)/scripts/header-ifdef.py
|
||||
|
||||
sc_test-wrap-argv:
|
||||
$(AM_V_GEN)$(VC_LIST) | $(GREP) -v -E 'qemuxml2argvdata|nwfilterxml2firewalldata|bhyvexml2argvdata' \
|
||||
|$(GREP) -E '\.(ldargs|args)' | $(RUNUTF8) xargs \
|
||||
$(PYTHON) $(top_srcdir)/scripts/test-wrap-argv.py --check
|
||||
|
||||
sc_group-qemu-caps:
|
||||
$(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(top_srcdir)/scripts/group-qemu-caps.py \
|
||||
--check --prefix $(top_srcdir)/
|
||||
|
@ -29,7 +29,6 @@ scripts = [
|
||||
'meson-timestamp.py',
|
||||
'mock-noinline.py',
|
||||
'prohibit-duplicate-header.py',
|
||||
'test-wrap-argv.py',
|
||||
]
|
||||
|
||||
foreach name : scripts
|
||||
|
@ -1,168 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (C) 2019 Red Hat, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# This script is intended to be passed a list of .args files, used
|
||||
# to store command line ARGV for the test suites. It will reformat
|
||||
# them such that there is at most one '-param value' on each line
|
||||
# of the file. Parameter values that are longer than 80 chars will
|
||||
# also be split.
|
||||
#
|
||||
# If --in-place is supplied as the first parameter of this script,
|
||||
# the files will be changed in place.
|
||||
# If --check is the first parameter, the script will return
|
||||
# a non-zero value if a file is not wrapped correctly.
|
||||
# Otherwise the rewrapped files are printed to the standard output.
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def rewrap_line(line):
|
||||
bits = line.split(" ")
|
||||
|
||||
# bits contains env vars, then the command line
|
||||
# and then the arguments
|
||||
env = []
|
||||
cmd = None
|
||||
args = []
|
||||
|
||||
if "=" not in bits[0]:
|
||||
cmd = bits[0]
|
||||
bits = bits[1:]
|
||||
|
||||
for bit in bits:
|
||||
# If no command is defined yet, we must still
|
||||
# have env vars
|
||||
if cmd is None:
|
||||
# Look for leading / to indicate command name
|
||||
if bit.startswith("/"):
|
||||
cmd = bit
|
||||
else:
|
||||
env.append(bit)
|
||||
else:
|
||||
# If there's a leading '-' then this is a new
|
||||
# parameter, otherwise its a value for the prev
|
||||
# parameter.
|
||||
if bit.startswith("-") or len(args) == 0:
|
||||
args.append(bit)
|
||||
else:
|
||||
args[-1] = args[-1] + " " + bit
|
||||
|
||||
# We might have to split line argument values...
|
||||
args = [rewrap_arg(arg) for arg in args]
|
||||
|
||||
# Print env + command first
|
||||
return " \\\n".join(env + [cmd] + args) + "\n"
|
||||
|
||||
|
||||
def rewrap_arg(arg):
|
||||
ret = []
|
||||
max_len = 78
|
||||
|
||||
while len(arg) > max_len:
|
||||
split = arg.rfind(",", 0, max_len + 1)
|
||||
if split == -1:
|
||||
split = arg.rfind(":", 0, max_len + 1)
|
||||
if split == -1:
|
||||
split = arg.rfind(" ", 0, max_len + 1)
|
||||
if split == -1:
|
||||
print("cannot find nice place to split '%s' below 80 chars" %
|
||||
arg, file=sys.stderr)
|
||||
split = max_len - 1
|
||||
|
||||
split = split + 1
|
||||
|
||||
ret.append(arg[0:split])
|
||||
arg = arg[split:]
|
||||
|
||||
ret.append(arg)
|
||||
return "\\\n".join(ret)
|
||||
|
||||
|
||||
def rewrap(filename, in_place, check):
|
||||
# Read the original file
|
||||
with open(filename, 'r') as fh:
|
||||
orig_lines = []
|
||||
for line in fh:
|
||||
orig_lines.append(line)
|
||||
|
||||
if len(orig_lines) == 0:
|
||||
return
|
||||
|
||||
lines = []
|
||||
for line in orig_lines:
|
||||
if line.endswith("\\\n"):
|
||||
line = line[:-2]
|
||||
lines.append(line)
|
||||
|
||||
# Kill the last new line in the file
|
||||
lines[-1] = lines[-1].rstrip("\n")
|
||||
|
||||
# Reconstruct the master data by joining all lines
|
||||
# and then split again based on the real desired
|
||||
# newlines
|
||||
lines = "".join(lines).split("\n")
|
||||
|
||||
# Now each 'lines' entry represents a single command, we
|
||||
# can process them
|
||||
new_lines = []
|
||||
for line in lines:
|
||||
new_lines.append(rewrap_line(line))
|
||||
|
||||
if in_place:
|
||||
with open(filename, "w") as fh:
|
||||
for line in new_lines:
|
||||
print(line, file=fh, end='')
|
||||
elif check:
|
||||
orig = "".join(orig_lines)
|
||||
new = "".join(new_lines)
|
||||
if new != orig:
|
||||
diff = subprocess.Popen(["diff", "-u", filename, "-"],
|
||||
stdin=subprocess.PIPE)
|
||||
diff.communicate(input=new.encode('utf-8'))
|
||||
|
||||
print("Incorrect line wrapping in '%s'" %
|
||||
filename, file=sys.stderr)
|
||||
print("Use test-wrap-argv.py to wrap test data files",
|
||||
file=sys.stderr)
|
||||
return False
|
||||
else:
|
||||
for line in new_lines:
|
||||
print(line, end='')
|
||||
|
||||
return True
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='Test arg line wrapper')
|
||||
parser.add_argument('--in-place', '-i', action="store_true",
|
||||
help='modify files in-place')
|
||||
parser.add_argument('--check', action="store_true",
|
||||
help='check existing files only')
|
||||
parser.add_argument('files', nargs="+",
|
||||
help="filenames to check")
|
||||
args = parser.parse_args()
|
||||
|
||||
errs = False
|
||||
for filename in args.files:
|
||||
if not rewrap(filename, args.in_place, args.check):
|
||||
errs = True
|
||||
|
||||
if errs:
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
@ -325,26 +325,6 @@ virTestLoadFileJSON(const char *p, ...)
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virTestRewrapFile(const char *filename)
|
||||
{
|
||||
g_autofree char *script = NULL;
|
||||
g_autoptr(virCommand) cmd = NULL;
|
||||
|
||||
if (!(virStringHasSuffix(filename, ".args") ||
|
||||
virStringHasSuffix(filename, ".argv") ||
|
||||
virStringHasSuffix(filename, ".ldargs")))
|
||||
return 0;
|
||||
|
||||
script = g_strdup_printf("%s/scripts/test-wrap-argv.py", abs_top_srcdir);
|
||||
|
||||
cmd = virCommandNewArgList(PYTHON3, script, "--in-place", filename, NULL);
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stream: output stream to write differences to
|
||||
* @param expect: expected output text
|
||||
@ -364,8 +344,7 @@ virTestDifferenceFullInternal(FILE *stream,
|
||||
const char *expectName,
|
||||
const char *actual,
|
||||
const char *actualName,
|
||||
bool regenerate,
|
||||
bool rewrap)
|
||||
bool regenerate)
|
||||
{
|
||||
const char *expectStart;
|
||||
const char *expectEnd;
|
||||
@ -387,12 +366,6 @@ virTestDifferenceFullInternal(FILE *stream,
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rewrap &&
|
||||
virTestRewrapFile(expectName) < 0) {
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!virTestGetDebug())
|
||||
@ -457,7 +430,7 @@ virTestDifferenceFull(FILE *stream,
|
||||
const char *actualName)
|
||||
{
|
||||
return virTestDifferenceFullInternal(stream, expect, expectName,
|
||||
actual, actualName, true, true);
|
||||
actual, actualName, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -480,7 +453,7 @@ virTestDifferenceFullNoRegenerate(FILE *stream,
|
||||
const char *actualName)
|
||||
{
|
||||
return virTestDifferenceFullInternal(stream, expect, expectName,
|
||||
actual, actualName, false, false);
|
||||
actual, actualName, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -607,7 +580,7 @@ virTestCompareToFileFull(const char *actual,
|
||||
|
||||
if (STRNEQ_NULLABLE(cmpcontent, filecontent)) {
|
||||
virTestDifferenceFullInternal(stderr, filecontent, filename,
|
||||
cmpcontent, NULL, true, unwrap);
|
||||
cmpcontent, NULL, true);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user