summaryrefslogtreecommitdiffstats
path: root/meta/lib/patchtest/selftest/selftest
blob: 6fad50ce616303931ec6411cd4094bee769ef891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3

# Test every patch from files folder and output error on failure
#
# Copyright (C) 2016 Intel Corporation
#
# SPDX-License-Identifier: GPL-2.0-only

import os
import subprocess
import sys

currentdir = os.path.dirname(os.path.abspath(__file__))
patchesdir = os.path.join(currentdir, 'files')
topdir     = os.path.dirname(currentdir)
parentdir  = os.path.dirname(topdir)

# path to the repo root
repodir = os.path.dirname(os.path.dirname(parentdir))

def print_results(passcount, failcount, skipcount, xpasscount, xfailcount, xskipcount, errorcount):
    total = passcount + skipcount + failcount + xpasscount + xfailcount + xskipcount + errorcount
    print("============================================================================")
    print("Testsuite summary for %s" % os.path.basename(topdir))
    print("============================================================================")
    print("# TOTAL: %s" % str(total))
    print("# XPASS: %s" % str(xpasscount))
    print("# XFAIL: %s" % str(xfailcount))
    print("# XSKIP: %s" % str(xskipcount))
    print("# PASS: %s" % str(passcount))
    print("# FAIL: %s" % str(failcount))
    print("# SKIP: %s" % str(skipcount))
    print("# ERROR: %s" % str(errorcount))
    print("============================================================================")

# Once the tests are in oe-core, we can remove the testdir param and use os.path.dirname to get relative paths
def test(root, patch):
    res = True
    patchpath = os.path.abspath(os.path.join(root, patch))
    
    cmd     = 'patchtest --repodir %s --testdir %s/tests --patch %s' % (repodir, topdir, patchpath)
    results = subprocess.check_output(cmd, stderr=subprocess.STDOUT, universal_newlines=True, shell=True)

    return results

if __name__ == '__main__':
    passcount = 0
    failcount = 0
    skipcount = 0
    xpasscount = 0
    xfailcount = 0
    xskipcount = 0
    errorcount = 0

    results = None
        
    for root, dirs, patches in os.walk(patchesdir):
        for patch in patches:
            results = test(root, patch)

            a = patch.split('.')
            klass, testname = a[0], a[1]
            expected_result = a[-1]
            testid          = ".%s.%s" % (klass,testname)

            for resultline in results.splitlines():
                if testid in resultline:
                    result, _ = resultline.split(':', 1)

                    if expected_result.upper() == "FAIL" and result.upper() == "FAIL":
                        xfailcount = xfailcount + 1
                        print("XFAIL: %s (file: %s)" % (testid.strip("."), os.path.basename(patch)))
                    elif expected_result.upper() == "PASS" and result.upper() == "PASS":
                        xpasscount = xpasscount + 1
                        print("XPASS: %s (file: %s)" % (testid.strip("."), os.path.basename(patch)))
                    elif expected_result.upper() == "SKIP" and result.upper() == "SKIP":
                        xskipcount = xskipcount + 1
                        print("XSKIP: %s (file: %s)" % (testid.strip("."), os.path.basename(patch)))
                    else:
                        print("%s: %s (%s)" % (result.upper(), testid.strip("."), os.path.basename(patch)))
                        if result.upper() == "PASS":
                            passcount = passcount + 1
                        elif result.upper() == "FAIL":
                            failcount = failcount + 1
                        elif result.upper() == "SKIP":
                            skipcount = skipcount + 1
                        else:
                            print("Bad result on test %s against %s" % (testid.strip("."), os.path.basename(patch)))
                            errorcount = errorcount + 1
                    break
            else:
                print ("No test for=%s" % patch)

    print_results(passcount, failcount, skipcount, xpasscount, xfailcount, xskipcount, errorcount)