From efaba7ef62f5b6976b9aef6a83c0812c9ddf1447 Mon Sep 17 00:00:00 2001 From: Petr Schindler Date: Dec 06 2018 06:29:43 +0000 Subject: Initial commit --- diff --git a/rhts-report-result b/rhts-report-result new file mode 100755 index 0000000..3a13303 --- /dev/null +++ b/rhts-report-result @@ -0,0 +1,29 @@ +#!/usr/bin/bash + +source variables.sh + +if [ ! -d $artifacts ]; then + mkdir $artifacts +fi + +if [ ! -f $result ]; then + echo "PASS" > $result +fi + +if [ $2 = "FAIL" ]; then + if [ ! -f $failed ]; then + touch $failed + fi + + echo $1 >> $failed + + mv $3 ${artifacts}/FAIL_$(basename $3) + + if [ $(cat $result) = "PASS" ]; then + echo "FAIL" > $result + fi +else + mv $3 $artifacts +fi + +exit 0 diff --git a/runtests.sh b/runtests.sh new file mode 100755 index 0000000..7bd5b5f --- /dev/null +++ b/runtests.sh @@ -0,0 +1,44 @@ +#!/usr/bin/bash + +source variables.sh + +pwd=$(pwd) +component=$1 +branch=$2 +tier=$1 + +testdir=$(mktemp -d /tmp/${component}-${branch}.XXX) + +git clone -b $branch https://pagure.io/desktop-qa/${component}.git $testdir +chmod +rx $testdir + +if [ ! -d "$artifacts" ]; then + mkdir -p $artifacts +else + rm -rf ${artifacts}/* +fi + +PATH=${PATH}:${pwd} + +cd $testdir + +tests = $(teststorun tiers.yaml $tier) + +testrunner $tests &> ${artifacts}/harness.log + +result=$(cat ${result}) +count=$(echo $tests | wc -w) + +if [ $result = "PASS" ]; then + echo "** ALL $count TESTS PASSED" + exit 0 +else + failedtests=$(cat $failed) + count_f=$(echo $failedtests | wc -w) + echo "* Results:" + echo "** $(($count - $count_f)) TESTS PASSED" + echo "** $count_f TESTS FAILED" + echo "** Failed tests:" + echo "$failedtests" + exit 1 +fi \ No newline at end of file diff --git a/testrunner b/testrunner new file mode 100755 index 0000000..85d4d9c --- /dev/null +++ b/testrunner @@ -0,0 +1,80 @@ +#!/usr/bin/python3 + +import yaml +import sys +import os +from shutil import rmtree +from subprocess import Popen, PIPE +from time import ctime + +def run(component, index, name, run="", dir=".", timeout="30m", **kwargs): + # known args: run, dir, timeout, arches-exclude + + arches_exclude = [] if "arches-exclude" not in kwargs else kwargs.pop("arches-exclude") + + print(f"{15*'='} {index}: {name} {(61-len(str(index))-len(name))*'='}") + print(f"* Time: {ctime()}") + + if kwargs: + print(f"Test '{name}' has unknown arguments: {kwargs}") + + arch = os.uname().machine + if arch in arches_exclude: + print(f"* Arch '{arch}' is excluded from this test.") + return "skipped" + + print(f"* Changing directory to: {dir}") + curdir = os.environ["PWD"] + os.chdir(dir) + + os.putenv("TEST", f"{component}_Test{index}_{name}") + if not run: + run = f"./runtest.sh {name}" + print(f"* Running command: {run}") + p = Popen(f"timeout {timeout} {run}", shell=True)# stdout=PIPE) + p.communicate() + # stdout, stderr = p.communicate() + # print(f"** Stdout:\n{'None' if stdout is None else stdout.decode('utf-8')}") + # print(f"** Stderr:\n{'None' if stderr is None else stderr.decode('utf-8')}") + if p.returncode == 124: + print(f"** Test timedout!!!") + retval = "timedout" + elif p.returncode == 0: + print(f"** Test PASSED!!!") + retval = "passed" + else: + print(f"** Test FAILED!!!") + retval = "failed" + + print("\n\n") + + os.chdir(curdir) + + return retval + +to_run = sys.argv[1:] + +with open("mapper.yaml", "r") as f: + mapper = yaml.safe_load(f) + +component = mapper["component"]["name"] + +results = dict(passed=[], failed=[], skipped=[], timedout=[]) + +for i, t in enumerate(mapper["testmapper"]): + if type(t) is str: + if (to_run == []) or (t in to_run): + results[run(component, i, t)].append(t) + elif type(t) is dict: + t = t.popitem() + if (to_run == []) or (t[0] in to_run): + results[run(component, i, t[0], **t[1])].append(t[0]) + else: + print(f"Test definition in unknown format:\n\ttest - {t}\n\ttype - {type(t)}") + results["skipped"].append(t) + +print(f"{15*'='} Results {(56)*'='}") +for r, ts in results.items(): + print(f"{r}: {ts}") + + diff --git a/teststorun b/teststorun new file mode 100755 index 0000000..7e8e5b2 --- /dev/null +++ b/teststorun @@ -0,0 +1,17 @@ +#!/usr/bin/python3 + +import sys +import yaml + +with open(sys.argv[1], "r") as f: + testlist = yaml.safe_load(f) + +tests = [] +tier = int(sys.argv[2]) +if len(testlist.keys()) < tier: + tier = len(testlist.keys()) + +for i in range(tier, 0, -1): + tests.extend(testlist[i]) + +print(" ".join(tests)) diff --git a/variables.sh b/variables.sh new file mode 100644 index 0000000..7275944 --- /dev/null +++ b/variables.sh @@ -0,0 +1,3 @@ +artifacts=/tmp/artifacts +result=${artifacts}/result +failed=${artifacts}/failed \ No newline at end of file