Skip to content

Commit

Permalink
Merge branch 'latest' into net
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
  • Loading branch information
matttbe committed Mar 4, 2025
2 parents 92b80c9 + 882fe60 commit 1274620
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 108 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ RUN cd /opt && \
make install

# Virtme NG
ARG VIRTME_NG_VERSION="1.32"
ARG VIRTME_NG_VERSION="1.33"
RUN pip3 install --break-system-packages virtme-ng=="${VIRTME_NG_VERSION}"

# to quickly shutdown the VM and more
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ gen_kconfig() { local mode kconfig=() vck rc=0
fi

# KBUILD_OUTPUT is used by virtme
"${VIRTME_CONFIGKERNEL}" "${vck[@]}" "${MAKE_ARGS_O[@]}" || rc=${?}
"${VIRTME_CONFIGKERNEL}" "${vck[@]}" "${MAKE_ARGS_O[@]}" 2>/dev/null || rc=${?}

./scripts/config --file "${VIRTME_KCONFIG}" "${kconfig[@]}" || rc=${?}

Expand Down
223 changes: 117 additions & 106 deletions tap2json.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#! /usr/bin/python3
# SPDX-License-Identifier: GPL-2.0
#
# Very simple TAP to JSON parser
#
# JQ can be used to filter tests later, e.g.abs
# $ jq '.results.[] | select(.[].result == "fail")' results.json

"""
Very simple TAP to JSON parser
JQ can be used to filter tests later, e.g.abs
$ jq '.results.[] | select(.[].result == "fail")' results.json
"""

# pylint: disable=missing-function-docstring

import argparse
import json
Expand All @@ -14,138 +18,145 @@


def get_args_parser():
parser = argparse.ArgumentParser(
description="(Simple) TAP to JSON converter"
)

parser.add_argument(
"--output",
"-o",
action="store",
help="Output JSON file"
)

parser.add_argument(
"--info",
"-I",
action="append",
metavar="key:value",
help="Add extra info in the JSON, can be used multiple times"
)

parser.add_argument(
"--only-fails",
"-f",
action="store_true",
help="Only keep failed tests"
)

parser.add_argument(
"tapfiles",
metavar="tapfiles",
type=str,
nargs="*",
help="Input TAP file(s)"
)

return parser
parser = argparse.ArgumentParser(
description="(Simple) TAP to JSON converter"
)

parser.add_argument(
"--output",
"-o",
action="store",
help="Output JSON file"
)

parser.add_argument(
"--info",
"-I",
action="append",
metavar="key:value",
help="Add extra info in the JSON, can be used multiple times"
)

parser.add_argument(
"--only-fails",
"-f",
action="store_true",
help="Only keep failed tests"
)

parser.add_argument(
"tapfiles",
metavar="tapfiles",
type=str,
nargs="*",
help="Input TAP file(s)"
)

return parser


# Same as in NIPA
TAP_RE = re.compile(r"(not )?ok (\d+)( -)? ([^#]*[^ ])( +# +)?([^ ].*)?$")
TIME_RE = re.compile(r"time=([0-9.]+)ms")


def parse_tap(tap, name, only_fails):
results = {}
has_results = False
results = {}
has_results = False

for line in tap:
try:
r = TAP_RE.match(line.rstrip()).groups()
except AttributeError:
continue
for line in tap:
try:
r = TAP_RE.match(line.rstrip()).groups()
except AttributeError:
continue

has_results = True
has_results = True

success = r[0] is None
success = r[0] is None

result = {
'result': "pass" if success else "fail",
'name': r[3]
}
result = {
'result': "pass" if success else "fail",
'name': r[3]
}

if r[4] and r[5]:
result['comment'] = r[5]
if success:
if r[5].lower().startswith('skip'):
result['result'] = "skip"
elif r[5].lower().startswith('ignore flaky'):
result['result'] = "flaky"
if r[4] and r[5]:
result['comment'] = r[5]
if success:
if r[5].lower().startswith('skip'):
result['result'] = "skip"
elif r[5].lower().startswith('ignore flaky'):
result['result'] = "flaky"

t = TIME_RE.findall(r[5].lower())
if t:
result['time_ms'] = t[-1] # take the last one
result['comment'] = result['comment'].replace("time=" + result['time_ms'] + "ms", "").replace(" ", " ").strip()
if not result['comment']:
del result['comment']
t = TIME_RE.findall(r[5].lower())
if t:
result['time_ms'] = t[-1] # take the last one
result['comment'] = result['comment'] \
.replace("time=" + result['time_ms'] + "ms", "") \
.replace(" ", " ").strip()
if not result['comment']:
del result['comment']

if only_fails and result['result'] == "pass":
continue
if only_fails and result['result'] == "pass":
continue

results[r[1]] = result
results[r[1]] = result

# just in case, to catch errors
if not has_results:
results[0] = {'result': "fail", 'name': name}
# just in case, to catch errors
if not has_results:
results[0] = {'result': "fail", 'name': name}

return results
return results


def parse_all_tap(tap_files, only_fails):
results = {}
results = {}

for tap in tap_files:
name = os.path.splitext(os.path.basename(tap))[0]
with open(tap, "r", encoding="utf-8", errors='ignore') as fd:
result = parse_tap(fd.readlines(), name, only_fails)
if result:
results[name] = result

for tap in tap_files:
name = os.path.splitext(os.path.basename(tap))[0]
with open(tap, "r", encoding="utf-8") as fd:
result = parse_tap(fd.readlines(), name, only_fails)
if result:
results[name] = result
return results

return results

def add_info(results, infos):
results = {
"results": results
}
results = {
"results": results
}

for info in infos:
info = info.split(':', 1)
if len(info) != 2:
print("Skip info: " + info[0], file=sys.stderr)
continue
for info in infos:
info = info.split(':', 1)
if len(info) != 2:
print("Skip info: " + info[0], file=sys.stderr)
continue

results[info[0]] = info[1]
results[info[0]] = info[1]

return results

return results

def write_json(out_file, results):
out = json.dumps(results)
if out_file:
with open(out_file, "w") as fd:
fd.write(out)
else:
print(out)
out = json.dumps(results)
if out_file:
with open(out_file, "w", encoding="utf-8") as fd:
fd.write(out)
else:
print(out)


if __name__ == "__main__":
arg_parser = get_args_parser()
args = arg_parser.parse_args()
arg_parser = get_args_parser()
args = arg_parser.parse_args()

if not args.tapfiles:
arg_parser.print_usage()
sys.exit(1)
if not args.tapfiles:
arg_parser.print_usage()
sys.exit(1)

results = parse_all_tap(args.tapfiles, args.only_fails)
main_results = parse_all_tap(args.tapfiles, args.only_fails)

if args.info:
results = add_info(results, args.info)
if args.info:
main_results = add_info(main_results, args.info)

write_json(args.output, results)
write_json(args.output, main_results)

0 comments on commit 1274620

Please sign in to comment.