2014-08-19 16:28:58 +02:00
|
|
|
# Copyright 2014 BitPay, Inc.
|
2014-12-13 05:09:33 +01:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
2014-08-19 16:28:58 +02:00
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2016-04-10 16:54:28 +02:00
|
|
|
from __future__ import division,print_function,unicode_literals
|
2014-08-19 16:28:58 +02:00
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
|
2014-09-30 22:05:27 +02:00
|
|
|
def bctest(testDir, testObj, exeext):
|
2014-08-19 05:14:29 +02:00
|
|
|
|
2014-09-30 22:05:27 +02:00
|
|
|
execprog = testObj['exec'] + exeext
|
|
|
|
execargs = testObj['args']
|
|
|
|
execrun = [execprog] + execargs
|
2014-08-19 05:14:29 +02:00
|
|
|
stdinCfg = None
|
|
|
|
inputData = None
|
|
|
|
if "input" in testObj:
|
|
|
|
filename = testDir + "/" + testObj['input']
|
|
|
|
inputData = open(filename).read()
|
|
|
|
stdinCfg = subprocess.PIPE
|
|
|
|
|
2014-08-20 05:15:58 +02:00
|
|
|
outputFn = None
|
|
|
|
outputData = None
|
|
|
|
if "output_cmp" in testObj:
|
|
|
|
outputFn = testObj['output_cmp']
|
|
|
|
outputData = open(testDir + "/" + outputFn).read()
|
2016-09-30 12:35:48 +02:00
|
|
|
if not outputData:
|
|
|
|
print("Output data missing for " + outputFn)
|
|
|
|
sys.exit(1)
|
2014-09-30 22:05:27 +02:00
|
|
|
proc = subprocess.Popen(execrun, stdin=stdinCfg, stdout=subprocess.PIPE, stderr=subprocess.PIPE,universal_newlines=True)
|
2014-08-19 16:28:58 +02:00
|
|
|
try:
|
2014-08-19 05:14:29 +02:00
|
|
|
outs = proc.communicate(input=inputData)
|
2014-08-19 16:28:58 +02:00
|
|
|
except OSError:
|
2014-09-30 22:05:27 +02:00
|
|
|
print("OSError, Failed to execute " + execprog)
|
2014-08-19 16:28:58 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2014-08-20 05:15:58 +02:00
|
|
|
if outputData and (outs[0] != outputData):
|
2014-08-19 16:28:58 +02:00
|
|
|
print("Output data mismatch for " + outputFn)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2014-08-20 05:15:58 +02:00
|
|
|
wantRC = 0
|
|
|
|
if "return_code" in testObj:
|
|
|
|
wantRC = testObj['return_code']
|
|
|
|
if proc.returncode != wantRC:
|
|
|
|
print("Return code mismatch for " + outputFn)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-10-08 21:22:19 +02:00
|
|
|
def bctester(testDir, input_basename, buildenv, verbose = False):
|
2014-08-19 16:28:58 +02:00
|
|
|
input_filename = testDir + "/" + input_basename
|
|
|
|
raw_data = open(input_filename).read()
|
|
|
|
input_data = json.loads(raw_data)
|
|
|
|
|
|
|
|
for testObj in input_data:
|
2016-10-08 21:22:19 +02:00
|
|
|
if verbose and "description" in testObj:
|
|
|
|
print ("Testing: " + testObj["description"])
|
2014-09-30 22:05:27 +02:00
|
|
|
bctest(testDir, testObj, buildenv.exeext)
|
2016-10-08 21:22:19 +02:00
|
|
|
if verbose and "description" in testObj:
|
|
|
|
print ("PASS")
|
2014-08-19 16:28:58 +02:00
|
|
|
|
|
|
|
sys.exit(0)
|
|
|
|
|