From e44ad61af9a99ff1110b66ec112cdad80486677a Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Fri, 8 Jun 2012 02:49:29 -0700 Subject: [PATCH] Improved test script This script requires Python 2.4, for the subprocess module. --- tests/simpletest.sh | 19 ------------ tests/test_ophis.py | 70 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 19 deletions(-) delete mode 100755 tests/simpletest.sh create mode 100755 tests/test_ophis.py diff --git a/tests/simpletest.sh b/tests/simpletest.sh deleted file mode 100755 index 9277403..0000000 --- a/tests/simpletest.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -../bin/ophis -q --no-warn testbase.oph -diff -q testbase.bin ophis.bin -../bin/ophis -q --no-warn testdata.oph -diff -q testdata.bin ophis.bin -../bin/ophis -q --no-warn longbranch_ref.oph -o a_ref.bin -diff -q longbranch.bin a_ref.bin -../bin/ophis -q --no-warn longbranch.oph -diff -q longbranch.bin ophis.bin -../bin/ophis -cq --no-warn test65c02.oph -diff -q test65c02.bin ophis.bin -../bin/ophis -uq --no-warn test6510.oph -diff -q test6510.bin ophis.bin -../bin/ophis -cq --no-warn branch_c02_ref.oph -o a_ref.bin -diff -q branch_c02.bin a_ref.bin -../bin/ophis -cq --no-warn branch_c02.oph -diff -q branch_c02.bin ophis.bin -rm -f a_ref.bin ophis.bin diff --git a/tests/test_ophis.py b/tests/test_ophis.py new file mode 100755 index 0000000..e114237 --- /dev/null +++ b/tests/test_ophis.py @@ -0,0 +1,70 @@ +#!/usr/bin/python + +import sys +import subprocess +import os.path + +pythonpath = sys.executable +homepath = os.path.realpath(os.path.dirname(sys.argv[0])) +ophispath = os.path.join(homepath, "..", "bin", "ophis") + +failed = 0 + + +def assemble_string(asm, options=[]): + p = subprocess.Popen([pythonpath, ophispath, "-o", "-", "-"] + options, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + return p.communicate(asm) + + +def test_string(test_name, asm, expected, options=[]): + (out, err) = assemble_string(asm, options) + if out == expected: + print "%s: SUCCESS" % test_name + else: + global failed + failed += 1 + print "%s: FAILED\nError output:\n%s" % (test_name, err) + + +def test_file(test_name, fname, ename, options=[]): + f = open(os.path.join(homepath, fname), 'rt') + asm = f.read() + f.close() + if ename is not None: + f = open(os.path.join(homepath, ename), 'rb') + expected = f.read() + f.close() + else: # a test where we expect failure + expected = '' + test_string(test_name, asm, expected, options) + + +if __name__ == '__main__': + print "Using Python interpreter:", pythonpath + test_string('Basic Ophis operation', '.byte "Hello, world!", 10', + 'Hello, world!\n') + if failed == 0: + test_file('Basic instructions', 'testbase.oph', 'testbase.bin') + test_file('Basic data pragmas', 'testdata.oph', 'testdata.bin') + test_file('Undocumented instructions', 'test6510.oph', 'test6510.bin', + ['-u']) + test_file('65c02 extensions', 'test65c02.oph', 'test65c02.bin', ['-c']) + test_file('Branch restrictions (6502)', 'longbranch.oph', None, + ['--no-branch-extend']) + test_file('Branch restrictions (65c02)', 'branch_c02.oph', None, + ['-c', '--no-branch-extend']) + test_file('Branch extension, error-free (6502)', 'longbranch.oph', + 'longbranch.bin') + test_file('Branch extension, correct code (6502)', + 'longbranch_ref.oph', 'longbranch.bin') + test_file('Branch extension, error-free (65c02)', 'branch_c02.oph', + 'branch_c02.bin', ['-c']) + test_file('Branch extension, correct code (65c02)', + 'branch_c02_ref.oph', 'branch_c02.bin', ['-c']) + + if failed > 0: + print "Total test case failures: %d" % failed + else: + print "All test cases succeeded"