1#!/usr/bin/env python3 2 3# Test every patch from files folder and output error on failure 4# 5# Copyright (C) 2016 Intel Corporation 6# 7# SPDX-License-Identifier: GPL-2.0-only 8 9import os 10import subprocess 11import sys 12 13currentdir = os.path.dirname(os.path.abspath(__file__)) 14patchesdir = os.path.join(currentdir, 'files') 15topdir = os.path.dirname(currentdir) 16parentdir = os.path.dirname(topdir) 17 18# path to the repo root 19repodir = os.path.dirname(os.path.dirname(parentdir)) 20 21def print_results(passcount, failcount, skipcount, xpasscount, xfailcount, xskipcount, errorcount): 22 total = passcount + skipcount + failcount + xpasscount + xfailcount + xskipcount + errorcount 23 print("============================================================================") 24 print("Testsuite summary for %s" % os.path.basename(topdir)) 25 print("============================================================================") 26 print("# TOTAL: %s" % str(total)) 27 print("# XPASS: %s" % str(xpasscount)) 28 print("# XFAIL: %s" % str(xfailcount)) 29 print("# XSKIP: %s" % str(xskipcount)) 30 print("# PASS: %s" % str(passcount)) 31 print("# FAIL: %s" % str(failcount)) 32 print("# SKIP: %s" % str(skipcount)) 33 print("# ERROR: %s" % str(errorcount)) 34 print("============================================================================") 35 36# Once the tests are in oe-core, we can remove the testdir param and use os.path.dirname to get relative paths 37def test(root, patch): 38 res = True 39 patchpath = os.path.abspath(os.path.join(root, patch)) 40 41 cmd = 'patchtest --repodir %s --testdir %s/tests --patch %s' % (repodir, topdir, patchpath) 42 results = subprocess.check_output(cmd, stderr=subprocess.STDOUT, universal_newlines=True, shell=True) 43 44 return results 45 46if __name__ == '__main__': 47 passcount = 0 48 failcount = 0 49 skipcount = 0 50 xpasscount = 0 51 xfailcount = 0 52 xskipcount = 0 53 errorcount = 0 54 55 results = None 56 57 for root, dirs, patches in os.walk(patchesdir): 58 for patch in patches: 59 results = test(root, patch) 60 61 a = patch.split('.') 62 klass, testname = a[0], a[1] 63 expected_result = a[-1] 64 testid = ".%s.%s" % (klass,testname) 65 66 for resultline in results.splitlines(): 67 if testid in resultline: 68 result, _ = resultline.split(':', 1) 69 70 if expected_result.upper() == "FAIL" and result.upper() == "FAIL": 71 xfailcount = xfailcount + 1 72 print("XFAIL: %s (file: %s)" % (testid.strip("."), os.path.basename(patch))) 73 elif expected_result.upper() == "PASS" and result.upper() == "PASS": 74 xpasscount = xpasscount + 1 75 print("XPASS: %s (file: %s)" % (testid.strip("."), os.path.basename(patch))) 76 elif expected_result.upper() == "SKIP" and result.upper() == "SKIP": 77 xskipcount = xskipcount + 1 78 print("XSKIP: %s (file: %s)" % (testid.strip("."), os.path.basename(patch))) 79 else: 80 print("%s: %s (%s)" % (result.upper(), testid.strip("."), os.path.basename(patch))) 81 if result.upper() == "PASS": 82 passcount = passcount + 1 83 elif result.upper() == "FAIL": 84 failcount = failcount + 1 85 elif result.upper() == "SKIP": 86 skipcount = skipcount + 1 87 else: 88 print("Bad result on test %s against %s" % (testid.strip("."), os.path.basename(patch))) 89 errorcount = errorcount + 1 90 break 91 else: 92 print ("No test for=%s" % patch) 93 94 print_results(passcount, failcount, skipcount, xpasscount, xfailcount, xskipcount, errorcount) 95