From ee511175af6df7494ceeaedd47022f74e28440b6 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Mon, 20 Nov 2017 10:54:05 -0800 Subject: [PATCH] Overhauled output.py to make it read the log file only once --- appveyor.yml | 42 +++++----- test/functional/output.py | 158 ++++++++++++++------------------------ 2 files changed, 74 insertions(+), 126 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index fb17c7d6..8f4f0333 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,16 +27,6 @@ environment: PHP_SDK_DIR: c:\projects\php\x64 PHP_INSTALL_DIR: c:\projects\php\x64\bin platform: x64 - - BUILD_PLATFORM: x64 - TEST_PHP_SQL_SERVER: (local)\SQL2016 - SQL_INSTANCE: SQL2016 - PHP_VC: 14 - PHP_MAJOR_VER: 7.1 - PHP_MINOR_VER: latest - PHP_SDK_DIR: c:\projects\php\x64 - PHP_INSTALL_DIR: c:\projects\php\x64\bin - PHP_ZTS: --disable-zts - platform: x64 - BUILD_PLATFORM: x86 TEST_PHP_SQL_SERVER: (local)\SQL2014 SQL_INSTANCE: SQL2014 @@ -56,6 +46,16 @@ environment: PHP_INSTALL_DIR: c:\projects\php\x86\bin PHP_ZTS: --disable-zts platform: x86 + - BUILD_PLATFORM: x64 + TEST_PHP_SQL_SERVER: (local)\SQL2016 + SQL_INSTANCE: SQL2016 + PHP_VC: 14 + PHP_MAJOR_VER: 7.1 + PHP_MINOR_VER: latest + PHP_SDK_DIR: c:\projects\php\x64 + PHP_INSTALL_DIR: c:\projects\php\x64\bin + PHP_ZTS: --disable-zts + platform: x64 # PHP_MAJOR_VER is PHP major version to build (7.0, 7.1) # PHP_MINOR_VER is PHP point release number (or latest for latest release) @@ -182,14 +182,13 @@ test_script: OpenCppCoverage.exe --sources $ext_dir\pdo_sqlsrv --sources $ext_dir\sqlsrv --modules *sqlsrv*.dll --export_type=cobertura:.\coverage.xml --cover_children --quiet --continue_after_cpp_exception --optimized_build -- .\php.exe .\run-tests.php -P ${env:APPVEYOR_BUILD_FOLDER}\test\functional\ > ${env:APPVEYOR_BUILD_FOLDER}\test\functional\sqlsrvtests.log 2>&1 type ${env:APPVEYOR_BUILD_FOLDER}\test\functional\sqlsrvtests.log; ls *.xml - } Else { - "Running phpt tests the regular way..." - .\php.exe .\run-tests.php -P ${env:APPVEYOR_BUILD_FOLDER}\test\functional\sqlsrv\*.phpt > ${env:APPVEYOR_BUILD_FOLDER}\test\functional\sqlsrv.log 2>&1 - type ${env:APPVEYOR_BUILD_FOLDER}\test\functional\sqlsrv.log; - .\php.exe .\run-tests.php -P ${env:APPVEYOR_BUILD_FOLDER}\test\functional\pdo_sqlsrv\*.phpt > ${env:APPVEYOR_BUILD_FOLDER}\test\functional\pdo_sqlsrv.log 2>&1 - type ${env:APPVEYOR_BUILD_FOLDER}\test\functional\pdo_sqlsrv.log; - } + } + - php run-tests.php -p php.exe %APPVEYOR_BUILD_FOLDER%\test\functional\sqlsrv\*.phpt > %APPVEYOR_BUILD_FOLDER%\test\functional\sqlsrv.log 2>&1 + - type %APPVEYOR_BUILD_FOLDER%\test\functional\sqlsrv.log + - php run-tests.php -p php.exe %APPVEYOR_BUILD_FOLDER%\test\functional\pdo_sqlsrv\*.phpt > %APPVEYOR_BUILD_FOLDER%\test\functional\pdo_sqlsrv.log 2>&1 + - type %APPVEYOR_BUILD_FOLDER%\test\functional\pdo_sqlsrv.log - python %APPVEYOR_BUILD_FOLDER%\test\functional\setup\cleanup_dbs.py -dbname %SQLSRV_DBNAME% + - python %APPVEYOR_BUILD_FOLDER%\test\functional\setup\cleanup_dbs.py -dbname %PDOSQLSRV_DBNAME% - python %APPVEYOR_BUILD_FOLDER%\test\functional\setup\cleanup_dbs.py -dbname %SQLSRV_DBNAME% - python %APPVEYOR_BUILD_FOLDER%\test\functional\setup\cleanup_dbs.py -dbname %PDOSQLSRV_DBNAME% - cd %PHP_INSTALL_DIR% - ps: $fileExists = Test-Path "coverage.xml" @@ -213,14 +212,9 @@ after_test: - ps: $out2files = Get-ChildItem pdo_sqlsrv\*.out - ps: foreach($file in $diff2files){ls $file; more $file} - ps: foreach($file in $out2files){ls $file; more $file} - #- cd %APPVEYOR_BUILD_FOLDER%\test\functional\ - # there is only one xml file if running tests with coverage analysis + - cd %APPVEYOR_BUILD_FOLDER%\test\functional\ - ps: (new-object net.webclient).UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\nativeresult1.xml)) - - ps: $result2Exists = Test-Path "nativeresult2.xml" - - ps: >- - If ($result2Exists -eq $true) { - (new-object net.webclient).UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\nativeresult2.xml)); - } + - ps: (new-object net.webclient).UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\nativeresult2.xml)) - ps: >- If ($difffiles -ne $null -Or $diff2files -ne $null) { $host.SetShouldExit(1); diff --git a/test/functional/output.py b/test/functional/output.py index f030e7e7..94c3e5a8 100644 --- a/test/functional/output.py +++ b/test/functional/output.py @@ -2,139 +2,93 @@ ######################################################################################### # # Description: -# Requirement of python 3.4 to execute this script and required result log file are in the same location +# Requirement of python 3.4 to execute this script and required result log file(s) +# are in the same location # Run with command line without options required. Example: py output.py # This script parse output of PHP Native Test # -# ############################################################################################# import os import stat import re -# This module returns either the number of test or the number of failed test -# depending on the argument you requested. -# Input: var - a single variable containing either "FAIL" or "TOTAL" -# Output: Returns a number of test/s or failed test/s -def returnCount(var): - with open(os.path.dirname(os.path.realpath(__file__)) + os.sep + logfile) as f: - num = 0 - failnum = 0 - for line in f: - if "FAIL" in line or "PASS" in line: - if ".phpt" in line: - if "FAIL" in line: - failnum += 1 - num += 1 - if var == 'total': - return str(num) +# This module appends an entry to the tests list, may include the test title. +# Input: search_pattern - pattern to look for in the line of the log file +# line - current line of the log file +# index - the current index of tests +# tests_list - a list of xml entries +# get_title - boolean flag to get the test title or not +# Output: None +def get_test_entry(search_pattern, line, index, tests_list, get_title = False): + # find the full path to the test name, enclosed by square brackets + result = re.search(search_pattern, line) + pos1 = result.group(1).find('[') + pos2 = result.group(1).find(']') + test_line = str(result.group(1)) + + # get the test name by splitting this full path delimited by os.sep + substr = test_line[pos1+1:pos2] + tmp_array = substr.split(os.sep) + pos = len(tmp_array) - 1 + test_name = tmp_array[pos] + + # only upon a failure do we get the test title + if (get_title is True): + entry = '\t' + tests_list.append(entry) + test_title = test_line[0:pos1] + entry = '\t\t' + tests_list.append(entry) + tests_list.append('\t') else: - return str(failnum) + entry = '\t' + tests_list.append(entry) -# This module prints the line that matches the expression. -# Input: inputStr - String that matches -# file - file name -# path - path of the file. -# Output: null -def readAndPrint(inputStr, file, path): - print(path) - filn = open(path + os.sep + file).readlines() - for lines in filn: - if inputStr in lines: - print(lines) - -# This module returns the test file name. -# Input: line - current line of the log file -# Output: Returns the filename. -def TestFilename(line): - terminateChar = os.sep - currentPos = 0 - firstpos = len(line) * -1 - print(line) - print(firstpos) - while True: - currentPos = currentPos - 1 - # if passed the first pos, stop - if currentPos < firstpos: - break - line[currentPos] - if line[currentPos] == terminateChar: - break - file = line[currentPos+1:-1] - return file - -def genXML(logfile,number): - # Generating the nativeresult.xml file. - file = open('nativeresult' + str(number) + '.xml','w') - file.write('' + os.linesep) - file.write('' + os.linesep) - file.close() - - # Extract individual test results from the log file and - # enter it in the nativeresult.xml file. +# Extract individual test results from the log file and +# enter it in the nativeresult.xml file. +# Input: logfile - the log file +# number - the number for this xml file +def gen_XML(logfile, number): + print('================================================') + print("\n" + os.path.splitext(logfile)[0] + "\n" ) + tests_list = [] with open(os.path.dirname(os.path.realpath(__file__)) + os.sep + logfile) as f: num = 1 failnum = 0 for line in f: - file = open('nativeresult' + str(number) + '.xml','a') if "FAIL" in line or "PASS" in line: if ".phpt" in line: - - file.write('\t' + os.linesep) - stop_pos = result.group(1).find('[') - file.write('\t\t' + os.linesep) - file.write('\t' + os.linesep) + get_test_entry('FAIL(.*).', line, str(num), tests_list, True) else: - result = re.search('PASS(.*).', line) - file.write(TestFilename(str(result.group(1))) + '-' + str(num) + '"/>' + os.linesep) + get_test_entry('PASS(.*).', line, str(num), tests_list) num += 1 - file.close() + elif 'Number of tests :' in line or 'Tests skipped ' in line or 'Tests warned ' in line or'Tests failed ' in line or 'Expected fail ' in line or 'Tests passed ' in line: + print(line) + print('================================================') - file = open('nativeresult' + str(number) + '.xml','a') - file.write('' + os.linesep) - file.close() + # Generating the nativeresult.xml file. + file = open('nativeresult' + str(number) + '.xml', 'w') + file.write('' + os.linesep) + file.write('' + os.linesep) -def run(): - num = 1 - for f in os.listdir(os.path.dirname(os.path.realpath(__file__))): - if f.endswith("log"): - print('================================================') - print(os.path.splitext(f)[0]) - readAndPrint('Number of tests :', f, os.path.dirname(os.path.realpath(__file__))) - readAndPrint('Tests skipped ', f, os.path.dirname(os.path.realpath(__file__))) - readAndPrint('Tests warned ', f, os.path.dirname(os.path.realpath(__file__))) - readAndPrint('Tests failed ', f, os.path.dirname(os.path.realpath(__file__))) - readAndPrint('Expected fail ', f, os.path.dirname(os.path.realpath(__file__))) - readAndPrint('Tests passed ', f, os.path.dirname(os.path.realpath(__file__))) - print('================================================') - logfile = f - genXML(logfile,num) - num = num + 1 + index = 1 + for test in tests_list: + file.write(test + os.linesep) + file.write('' + os.linesep) + file.close() - -# ------------------------------------------------------- Main Function --------------------------------------------------- +# ----------------------- Main Function ----------------------- # Display results on screen from result log file. if __name__ == '__main__': num = 1 for f in os.listdir(os.path.dirname(os.path.realpath(__file__))): if f.endswith("log"): - print('================================================') - print("\n" + os.path.splitext(f)[0] + "\n") - readAndPrint('Number of tests :', f, os.path.dirname(os.path.realpath(__file__))) - readAndPrint('Tests skipped ', f, os.path.dirname(os.path.realpath(__file__))) - readAndPrint('Tests warned ', f, os.path.dirname(os.path.realpath(__file__))) - readAndPrint('Tests failed ', f, os.path.dirname(os.path.realpath(__file__))) - readAndPrint('Expected fail ', f, os.path.dirname(os.path.realpath(__file__))) - readAndPrint('Tests passed ', f, os.path.dirname(os.path.realpath(__file__))) - print('================================================') logfile = f - genXML(logfile,num) + gen_XML(logfile, num) num = num + 1