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 19, 2024
2 parents ed1d937 + 3bfc360 commit d6b59a4
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
FROM ubuntu:23.10

LABEL name=mptcp-upstream-virtme-docker
Expand Down Expand Up @@ -98,6 +99,6 @@ ENV CCACHE_COMPRESS true
ENV KBUILD_BUILD_TIMESTAMP "0"
ENV GCC_COLORS error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01

COPY entrypoint.sh /
COPY entrypoint.sh tap2json.py /

ENTRYPOINT ["/entrypoint.sh"]
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
name: 'MPTCP Upstream Tests Action'
description: 'Tests Linux kernel MPTCP Upstream changes'
inputs:
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash -ex
# SPDX-License-Identifier: GPL-2.0
cd "$(dirname "$(realpath -P "${0}")")"
docker build -t "${DOCKER_VIRTME_NAME:-mptcp/mptcp-upstream-virtme-docker:latest}" -f Dockerfile .
18 changes: 14 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# The goal is to launch (MPTCP) kernel selftests and more.
# But also to provide a dev env for kernel developers or testers.
Expand Down Expand Up @@ -1327,6 +1328,18 @@ _get_failed_tests_status() { local t fails=()
echo "${#fails[@]} failed test(s): ${fails[*]}"
}

_gen_results_files() {
LANG=C tap2junit "${RESULTS_DIR}"/*.tap

# remove prefix id (unique test) and comments (status, time)
sed -i 's/\(<testcase name="\)[0-9]\+[ -]*/\1/g;/<testcase name=/s/\s\+#.*">/">/g' "${RESULTS_DIR}"/*.tap.xml

LANG=C /tap2json.py \
--output "${RESULTS_DIR}/results.json" \
--info "run_id:${GITHUB_RUN_ID:-"none"}" \
"${RESULTS_DIR}/*.tap"
}

# $1: mode, rest: args for kconfig
analyze() {
# reduce log that could be wrongly interpreted
Expand All @@ -1338,10 +1351,7 @@ analyze() {
printinfo "Analyze results"

if is_ci; then
LANG=C tap2junit "${RESULTS_DIR}"/*.tap

# remove prefix id (unique test) and comments (status, time)
sed -i 's/\(<testcase name="\)[0-9]\+[ -]*/\1/g;/<testcase name=/s/\s\+#.*">/">/g' "${RESULTS_DIR}"/*.tap.xml
_gen_results_files || true
fi

echo -ne "\n${COLOR_GREEN}"
Expand Down
1 change: 1 addition & 0 deletions pull.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
docker pull mptcp/mptcp-upstream-virtme-docker:latest
1 change: 1 addition & 0 deletions run-tests-dev.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash -ex
# SPDX-License-Identifier: GPL-2.0
DIR="$(dirname "$(realpath -P "${0}")")"
docker -v >/dev/null

Expand Down
1 change: 1 addition & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash -e
# SPDX-License-Identifier: GPL-2.0
DIR="$(dirname "$(realpath -P "${0}")")"
docker -v >/dev/null

Expand Down
1 change: 1 addition & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

VIRTME_INTERACTIVE=""
[ "${VIRTME_NO_INTERACTIVE}" != 1 ] && VIRTME_INTERACTIVE="-it"
Expand Down
140 changes: 140 additions & 0 deletions tap2json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#! /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

import argparse
import json
import os
import re
import sys


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

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

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

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

has_results = True

success = r[0] is None

if only_fails and success:
continue

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

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

results[r[1]] = result

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

return results


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

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

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

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]

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)

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

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

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

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

write_json(args.output, results)

0 comments on commit d6b59a4

Please sign in to comment.