2019-01-10 04:45:01 +00:00
|
|
|
#!/usr/bin/env python3
|
2012-06-08 09:49:29 +00:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import subprocess
|
2012-06-09 04:50:28 +00:00
|
|
|
import os
|
2012-06-08 09:49:29 +00:00
|
|
|
import os.path
|
|
|
|
|
2012-06-12 09:39:19 +00:00
|
|
|
if len(sys.argv) > 1:
|
|
|
|
pythonpath = sys.argv[1]
|
|
|
|
else:
|
|
|
|
pythonpath = sys.executable
|
2012-06-08 09:49:29 +00:00
|
|
|
homepath = os.path.realpath(os.path.dirname(sys.argv[0]))
|
|
|
|
ophispath = os.path.join(homepath, "..", "bin", "ophis")
|
|
|
|
|
|
|
|
failed = 0
|
|
|
|
|
2012-06-09 04:50:28 +00:00
|
|
|
# These are some simple routines for forwarding to Ophis. It relies
|
|
|
|
# on the standard input/output capabilities; we'll only go around it
|
|
|
|
# when explicitly testing the input/output file capabilities.
|
2012-06-08 09:49:29 +00:00
|
|
|
|
2012-06-09 04:50:28 +00:00
|
|
|
|
2012-06-12 09:39:19 +00:00
|
|
|
def assembled(raw):
|
2019-01-10 04:45:01 +00:00
|
|
|
return ' '.join(["%02X" % c for c in raw])
|
2012-06-12 09:39:19 +00:00
|
|
|
|
|
|
|
|
2012-06-09 04:50:28 +00:00
|
|
|
def assemble_raw(asm="", options=[]):
|
|
|
|
p = subprocess.Popen([pythonpath, ophispath] + options,
|
2012-06-08 09:49:29 +00:00
|
|
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE)
|
2019-01-10 04:45:01 +00:00
|
|
|
return p.communicate(asm.encode("UTF-8"))
|
2012-06-08 09:49:29 +00:00
|
|
|
|
|
|
|
|
2012-06-09 04:50:28 +00:00
|
|
|
def assemble_string(asm, options=[]):
|
2012-06-12 09:39:19 +00:00
|
|
|
return assemble_raw(asm, ["-qo", "-", "-"] + options)
|
2012-06-09 04:50:28 +00:00
|
|
|
|
|
|
|
|
2012-06-08 09:49:29 +00:00
|
|
|
def test_string(test_name, asm, expected, options=[]):
|
|
|
|
(out, err) = assemble_string(asm, options)
|
|
|
|
if out == expected:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("%s: SUCCESS" % test_name)
|
2012-06-08 09:49:29 +00:00
|
|
|
else:
|
|
|
|
global failed
|
|
|
|
failed += 1
|
2019-01-10 04:45:01 +00:00
|
|
|
print("%s: FAILED" % test_name)
|
|
|
|
print("Assembled code: ", assembled(out))
|
|
|
|
print("Expected code: ", assembled(expected))
|
2012-06-12 09:39:19 +00:00
|
|
|
if err != '':
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Error output:\n%s" % err.decode(sys.stderr.encoding))
|
2012-06-08 09:49:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2019-01-10 04:45:01 +00:00
|
|
|
expected = b''
|
2012-06-08 09:49:29 +00:00
|
|
|
test_string(test_name, asm, expected, options)
|
|
|
|
|
|
|
|
|
2012-06-09 04:50:28 +00:00
|
|
|
# And now, the actual test suites. First, the most basic techniques
|
|
|
|
# are tested - these are the ones the test harness *itself* depends
|
|
|
|
# on, then we start running through the features.
|
|
|
|
|
|
|
|
def test_basic():
|
2019-01-10 04:45:01 +00:00
|
|
|
print()
|
|
|
|
print("==== BASIC OPERATION ====")
|
2012-06-11 02:08:20 +00:00
|
|
|
test_string('Basic Ophis operation', '.byte "Hello, world!"',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'Hello, world!')
|
2012-06-11 02:08:20 +00:00
|
|
|
test_string('Newline/EOF passthrough', '.byte 10,26,13,4,0,"Hi",13,10',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'\n\x1a\r\x04\x00Hi\r\n')
|
2012-06-11 02:08:20 +00:00
|
|
|
# Normally these would go in Expressions but we need them to run the
|
|
|
|
# tests for relative instructions.
|
2019-01-10 04:45:01 +00:00
|
|
|
test_string('Program counter recognition', '.org $41\nlda #^\n', b'\xa9A')
|
|
|
|
test_string('Program counter math', '.org $41\nlda #^+3\n', b'\xa9D')
|
2012-06-08 09:49:29 +00:00
|
|
|
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'])
|
2014-02-07 16:21:42 +00:00
|
|
|
test_file('4502 extensions', 'test4502.oph', 'test4502.bin', ['-4'])
|
2012-06-09 04:50:28 +00:00
|
|
|
test_file('Wide instructions', 'testwide.oph', 'testwide.bin', ['-c'])
|
2012-06-08 09:49:29 +00:00
|
|
|
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'])
|
|
|
|
|
2012-06-09 04:50:28 +00:00
|
|
|
|
|
|
|
def test_outfile():
|
|
|
|
global failed
|
2019-01-10 04:45:01 +00:00
|
|
|
print("\n==== INPUT AND OUTPUT ====")
|
2012-06-09 04:50:28 +00:00
|
|
|
if os.path.exists("ophis.bin"):
|
2019-01-10 04:45:01 +00:00
|
|
|
print("TEST SUITE FAILED: unclean test environment (ophis.bin exists)")
|
2012-06-09 04:50:28 +00:00
|
|
|
failed += 1
|
|
|
|
return
|
|
|
|
elif os.path.exists("custom.bin"):
|
2019-01-10 04:45:01 +00:00
|
|
|
print("TEST SUITE FAILED: unclean test environment (custom.bin exists)")
|
2012-06-09 04:50:28 +00:00
|
|
|
failed += 1
|
|
|
|
return
|
|
|
|
|
|
|
|
# Test 1: Defaults
|
|
|
|
try:
|
|
|
|
assemble_raw('.byte "Hello, world!", 10', ['-'])
|
|
|
|
f = open('ophis.bin', 'rb')
|
2019-01-10 04:45:01 +00:00
|
|
|
if f.read() != b'Hello, world!\n':
|
|
|
|
print("Default output filename: FAILED (bad output)")
|
2012-06-09 04:50:28 +00:00
|
|
|
failed += 1
|
|
|
|
else:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Default output filename: SUCCESS")
|
2012-06-09 04:50:28 +00:00
|
|
|
f.close()
|
|
|
|
os.unlink('ophis.bin')
|
|
|
|
except:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Default output filename: FAILED (exception)")
|
2012-06-09 04:50:28 +00:00
|
|
|
failed += 1
|
2019-01-10 04:45:01 +00:00
|
|
|
raise
|
2012-06-09 04:50:28 +00:00
|
|
|
|
|
|
|
# Test 2: Command line override
|
|
|
|
try:
|
|
|
|
assemble_raw('.byte "Hello, world!", 10', ['-', '-o', 'custom.bin'])
|
|
|
|
f = open('custom.bin', 'rb')
|
2019-01-10 04:45:01 +00:00
|
|
|
if f.read() != b'Hello, world!\n':
|
|
|
|
print("Commandline output filename: FAILED (bad output)")
|
2012-06-09 04:50:28 +00:00
|
|
|
failed += 1
|
|
|
|
else:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Commandline output filename: SUCCESS")
|
2012-06-09 04:50:28 +00:00
|
|
|
f.close()
|
|
|
|
os.unlink('custom.bin')
|
|
|
|
except:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Commandline output filename: FAILED (exception)")
|
2012-06-09 04:50:28 +00:00
|
|
|
failed += 1
|
|
|
|
|
|
|
|
# Test 3: Pragma override
|
|
|
|
try:
|
|
|
|
assemble_raw('.outfile "custom.bin"\n.byte "Hello, world!", 10', ['-'])
|
|
|
|
f = open('custom.bin', 'rb')
|
2019-01-10 04:45:01 +00:00
|
|
|
if f.read() != b'Hello, world!\n':
|
|
|
|
print("Commandline output filename: FAILED (bad output)")
|
2012-06-09 04:50:28 +00:00
|
|
|
failed += 1
|
|
|
|
else:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Commandline output filename: SUCCESS")
|
2012-06-09 04:50:28 +00:00
|
|
|
f.close()
|
|
|
|
os.unlink('custom.bin')
|
|
|
|
except:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Commandline output filename: FAILED (exception)")
|
2012-06-09 04:50:28 +00:00
|
|
|
failed += 1
|
|
|
|
|
|
|
|
# Test 4: Command line override of .outfile
|
|
|
|
try:
|
|
|
|
assemble_raw('.outfile "custom2.bin"\n'
|
|
|
|
'.byte "Hello, world!", 10', ['-', '-o', 'custom.bin'])
|
|
|
|
f = open('custom.bin', 'rb')
|
2019-01-10 04:45:01 +00:00
|
|
|
if f.read() != b'Hello, world!\n':
|
|
|
|
print("Commandline override of pragma: FAILED (bad output)")
|
2012-06-09 04:50:28 +00:00
|
|
|
failed += 1
|
|
|
|
else:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Commandline override of pragma: SUCCESS")
|
2012-06-09 04:50:28 +00:00
|
|
|
f.close()
|
|
|
|
os.unlink('custom.bin')
|
|
|
|
except:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Commandline override of pragma: FAILED (exception)")
|
2012-06-09 04:50:28 +00:00
|
|
|
failed += 1
|
|
|
|
|
|
|
|
# Test 5: Pragma repetition priority
|
|
|
|
try:
|
|
|
|
assemble_raw('.outfile "custom.bin"\n'
|
|
|
|
'.outfile "custom2.bin"\n'
|
|
|
|
'.byte "Hello, world!", 10', ['-'])
|
|
|
|
f = open('custom.bin', 'rb')
|
2019-01-10 04:45:01 +00:00
|
|
|
if f.read() != b'Hello, world!\n':
|
|
|
|
print("Pragma repetition: FAILED (bad output)")
|
2012-06-09 04:50:28 +00:00
|
|
|
failed += 1
|
|
|
|
else:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Pragma repetition: SUCCESS")
|
2012-06-09 04:50:28 +00:00
|
|
|
f.close()
|
|
|
|
os.unlink('custom.bin')
|
|
|
|
except:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Pragma repetition: FAILED (exception)")
|
2012-06-09 04:50:28 +00:00
|
|
|
failed += 1
|
|
|
|
|
|
|
|
# Test 6: multiple input files
|
|
|
|
try:
|
|
|
|
out = assemble_raw('', ['-o', '-', '-u',
|
|
|
|
os.path.join(homepath, "testbase.oph"),
|
|
|
|
os.path.join(homepath, "test6510.oph")])[0]
|
|
|
|
f = open(os.path.join(homepath, "testbase.bin"), 'rb')
|
|
|
|
s = f.read()
|
|
|
|
f.close()
|
|
|
|
f = open(os.path.join(homepath, "test6510.bin"), 'rb')
|
|
|
|
s += f.read()
|
|
|
|
f.close()
|
|
|
|
if out != s:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Multiple input files: FAILED (bad output)")
|
2012-06-09 04:50:28 +00:00
|
|
|
failed += 1
|
|
|
|
else:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Multiple input files: SUCCESS")
|
2012-06-09 04:50:28 +00:00
|
|
|
except:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Multiple input files: FAILED (exception)")
|
2012-06-09 04:50:28 +00:00
|
|
|
failed += 1
|
|
|
|
|
|
|
|
|
|
|
|
def test_transforms():
|
2019-01-10 04:45:01 +00:00
|
|
|
print("\n==== BINARY TRANSFORM PASSES ====")
|
|
|
|
print("Simple zero page selection: SUCCESS (covered in basic tests)")
|
2012-06-09 04:50:28 +00:00
|
|
|
test_string('Chained collapse', '.org $fa \n lda + \n lda ^ \n * rts \n',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'\xa5\xfe\xa5\xfc\x60')
|
2012-06-09 04:50:28 +00:00
|
|
|
test_string('Reversible collapse', '.org $fb \n bne ^+200 \n lda ^ \n',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'\xf0\x03\x4c\xc5\x01\xad\x00\x01')
|
2012-06-09 04:50:28 +00:00
|
|
|
|
|
|
|
|
2012-06-11 02:08:20 +00:00
|
|
|
def test_expressions():
|
2019-01-10 04:45:01 +00:00
|
|
|
print("\n==== EXPRESSIONS AND LABELS ====")
|
|
|
|
test_string('Basic addition', '.byte 3+2', b'\x05')
|
|
|
|
test_string('Basic subtraction', '.byte 3-2', b'\x01')
|
|
|
|
test_string('Basic multiplication', '.byte 3*2', b'\x06')
|
|
|
|
test_string('Basic division', '.byte 6/2', b'\x03')
|
|
|
|
test_string('Basic bit-union', '.byte 5|9', b'\x0d')
|
|
|
|
test_string('Basic bit-intersection', '.byte 5&9', b'\x01')
|
|
|
|
test_string('Basic bit-toggle', '.byte 5^9', b'\x0c')
|
|
|
|
test_string('Division truncation', '.byte 5/2', b'\x02')
|
|
|
|
test_string('Overflow', '.byte $FF*$10', b'')
|
|
|
|
test_string('Multibyte overflow', '.word $FF*$10', b'\xf0\x0f')
|
|
|
|
test_string('Masked overflow', '.byte $FF*$10&$FF', b'\xf0')
|
|
|
|
test_string('Underflow', '.byte 2-3', b'')
|
|
|
|
test_string('Masked underflow', '.byte 2-3&$FF', b'\xff')
|
|
|
|
test_string('Arithmetic precedence', '.byte 2+3*4-6/2', b'\x0b')
|
|
|
|
test_string('Parentheses', '.byte [2+3]*[4-6/2]', b'\x05')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string('String escapes',
|
|
|
|
'.byte "The man said, \\"The \\\\ is Windowsy.\\""',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'The man said, "The \\ is Windowsy."')
|
2012-06-11 02:08:20 +00:00
|
|
|
test_string('Byte selector precedence',
|
|
|
|
'.byte >$d000+32,>[$d000+32],<[$D000-275]',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'\xf0\xd0\xed')
|
|
|
|
test_string('Named labels', '.org $6948\nl: .word l', b'Hi')
|
|
|
|
test_string('.alias directive (basic)', '.alias hi $6948\n.word hi', b'Hi')
|
2012-06-11 02:08:20 +00:00
|
|
|
test_string('.alias directive (derived)',
|
2019-01-10 04:45:01 +00:00
|
|
|
'.alias hi $6948\n.alias ho hi+$600\n.word hi,ho', b'HiHo')
|
2012-06-11 02:08:20 +00:00
|
|
|
test_string('.alias directive (circular)',
|
|
|
|
'.alias a c+1\n.alias b a+3\n.alias c b-4\n.word a, b, c',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string('.advance directive (basic)',
|
|
|
|
'lda #$05\n.advance $05\n.byte ^',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'\xa9\x05\x00\x00\x00\x05')
|
2012-06-11 02:08:20 +00:00
|
|
|
test_string('.advance directive (filler)',
|
|
|
|
'lda #$05\nf: .advance $05,f+3\n.byte ^',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'\xa9\x05\x05\x05\x05\x05')
|
2012-06-11 02:08:20 +00:00
|
|
|
test_string('.advance no-op', 'lda #$05\n.advance $02\n.byte ^',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'\xa9\x05\x02')
|
|
|
|
test_string('.advance failure', 'lda #$05\n.advance $01\n.byte ^', b'')
|
|
|
|
test_string('.checkpc, space > 0', 'lda #$05\n.checkpc $10', b'\xa9\x05')
|
|
|
|
test_string('.checkpc, space = 0', 'lda #$05\n.checkpc 2', b'\xa9\x05')
|
|
|
|
test_string('.checkpc, space < 0', 'lda $05\n.checkpc 1', b'')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string('A X Y usable as labels',
|
|
|
|
'.alias a 1\n.alias x 2\n.alias y 3\n'
|
|
|
|
'lda (a+x+y),y\nlda (x+y,x)',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'\xb1\x06\xa1\x05')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string('Opcodes usable as labels',
|
|
|
|
'ldy #$00\n dey: dey\n bne dey',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'\xa0\x00\x88\xd0\xfd')
|
2012-06-11 02:08:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_segments():
|
|
|
|
print("\n==== ASSEMBLY SEGMENTS ====")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string('Segments (basic)',
|
|
|
|
'.org $41\n'
|
|
|
|
'.data\n'
|
|
|
|
'.org $61\n'
|
|
|
|
'd:\n'
|
|
|
|
'.text\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
'l: .byte l, d', b'Aa')
|
|
|
|
test_string('Data cleanliness', '.byte 65\n.data\n.byte 65', b'')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string('.space directive',
|
|
|
|
'.data\n.org $41\n.space a 2\n.space b 1\n.space c 1\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
'.text\n.byte a, b, c\n', b'ACD')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string('Multiple named segments',
|
|
|
|
'.data\n.org $41\n.data a\n.org $61\n.data b\n.org $4a\n'
|
|
|
|
'.data\n.space q 1\n.data a\n.space r 1\n.data b\n.space s 1\n'
|
|
|
|
'.text\n.org $10\n.text a\n.org $20\n'
|
|
|
|
'.text\n.byte ^,q,r,s\n'
|
|
|
|
'.text a\n.byte ^,q,r,s\n',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'\x10AaJ\x20AaJ')
|
2012-06-11 02:08:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_scopes():
|
|
|
|
print("\n==== LABEL SCOPING ====")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string('Repeated labels, different scopes',
|
|
|
|
'.org $41\n'
|
|
|
|
'.scope\n'
|
|
|
|
'_l: .byte _l\n'
|
|
|
|
'.scend\n'
|
|
|
|
'.scope\n'
|
|
|
|
'_l: .byte _l\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
'.scend\n', b'AB')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string('Data hiding outside of scope',
|
|
|
|
'.org $41\n'
|
|
|
|
'.scope\n'
|
|
|
|
'_l: .byte _l\n'
|
|
|
|
'.scend\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
' .byte _l\n', b'')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string('Repeated labels, nested scopes',
|
|
|
|
'.org $41\n'
|
|
|
|
'.scope\n'
|
|
|
|
'_l: .byte _l\n'
|
|
|
|
'.scope\n'
|
|
|
|
'_l: .byte _l\n'
|
|
|
|
'.scend\n'
|
|
|
|
' .byte _l\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
'.scend\n', b'ABA')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string('Anonymous labels (basic)',
|
|
|
|
'.org $41\n'
|
|
|
|
'* .byte -, +\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
'* .byte -, --\n', b'ACCA')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string('Anonymous labels (across scopes)',
|
|
|
|
'.org $41\n'
|
|
|
|
'* .byte -, +\n'
|
|
|
|
'.scope\n'
|
|
|
|
'* .byte -, --\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
'.scend\n', b'ACCA')
|
2012-06-11 02:08:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_macros():
|
|
|
|
print("\n==== MACROS ====")
|
|
|
|
test_string('Basic macros',
|
|
|
|
'.macro greet\n'
|
|
|
|
' .byte "hi"\n'
|
|
|
|
'.macend\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
'`greet\n.invoke greet', b"hihi")
|
2012-06-11 02:08:20 +00:00
|
|
|
test_string('Macros with arguments',
|
|
|
|
'.macro greet\n'
|
|
|
|
' .byte "hi",_1\n'
|
|
|
|
'.macend\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
"`greet 'A\n.invoke greet 'B", b"hiAhiB")
|
2012-06-11 02:08:20 +00:00
|
|
|
test_string('Macros invoking macros',
|
|
|
|
'.macro inner\n'
|
|
|
|
' .byte " there"\n'
|
|
|
|
'.macend\n'
|
|
|
|
'.macro greet\n'
|
|
|
|
' .byte "hi"\n'
|
|
|
|
' `inner\n'
|
|
|
|
'.macend\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
"`greet", b"hi there")
|
2012-06-11 02:08:20 +00:00
|
|
|
test_string('Macros defining macros (illegal)',
|
|
|
|
'.macro greet\n'
|
|
|
|
'.macro inner\n'
|
|
|
|
' .byte " there"\n'
|
|
|
|
'.macend\n'
|
|
|
|
' .byte "hi"\n'
|
|
|
|
' `inner\n'
|
|
|
|
'.macend\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
"`greet", b"")
|
2012-06-11 02:08:20 +00:00
|
|
|
test_string('Fail on infinite recursion',
|
|
|
|
'.macro inner\n'
|
|
|
|
' .byte " there"\n'
|
|
|
|
' `greet\n'
|
|
|
|
'.macend\n'
|
|
|
|
'.macro greet\n'
|
|
|
|
' .byte "hi"\n'
|
|
|
|
' `inner\n'
|
|
|
|
'.macend\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
"`greet", b"")
|
2012-06-11 02:08:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_subfiles():
|
|
|
|
print("\n==== COMPILATION UNITS ====")
|
2019-01-10 04:45:01 +00:00
|
|
|
test_string(".include pragma", '.include "baseinc.oph"', b'BASIC\n')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".include repeated",
|
|
|
|
'.include "baseinc.oph"\n.include "baseinc.oph"',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'BASIC\nBASIC\n')
|
|
|
|
test_string(".require pragma", '.require "baseinc.oph"', b'BASIC\n')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".include before .require",
|
|
|
|
'.include "baseinc.oph"\n.require "baseinc.oph"',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'BASIC\n')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".require before .include",
|
|
|
|
'.require "baseinc.oph"\n.include "baseinc.oph"',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'BASIC\nBASIC\n')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".require same file twice with different paths",
|
|
|
|
'.include "baseinc.oph"\n.include "sub/baseinc.oph"',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'BASIC\nSUB 1 START\nSUB 1 END\n')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".require different files with identical paths",
|
|
|
|
'.include "sub/sub/sub.oph"',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'SUB 2 START\nSUB 1 START\nBASIC\nSUB 1 END\nSUB 2 END\n')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".charmap (basic)",
|
|
|
|
'.charmap \'A, "abcdefghijklmnopqrstuvwxyz"\n'
|
|
|
|
'.charmap \'a, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
'.byte "hELLO, wORLD!"', b"Hello, World!")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".charmap (reset)",
|
|
|
|
'.charmap \'A, "abcdefghijklmnopqrstuvwxyz"\n'
|
|
|
|
'.charmap \'a, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"\n'
|
|
|
|
'.byte "hELLO, wORLD!",10\n'
|
|
|
|
'.charmap\n'
|
|
|
|
'.byte "hELLO, wORLD!",10\n',
|
2019-01-10 04:45:01 +00:00
|
|
|
b"Hello, World!\nhELLO, wORLD!\n")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".charmap (out of range)",
|
|
|
|
'.charmap 250, "ABCDEFGHIJKLM"\n.byte 250,251',
|
2019-01-10 04:45:01 +00:00
|
|
|
b'')
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".charmapbin (basic)",
|
|
|
|
'.charmapbin "../examples/petscii.map"\n.byte "hELLO, wORLD!"',
|
2019-01-10 04:45:01 +00:00
|
|
|
b"Hello, World!")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".charmapbin (illegal)",
|
2019-01-10 04:45:01 +00:00
|
|
|
'.charmapbin "baseinc.bin"\n.byte "hELLO, wORLD!"', b'')
|
|
|
|
test_string(".incbin (basic)", '.incbin "baseinc.bin"', b"BASIC\n")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".incbin (hardcoded offset)",
|
2019-01-10 04:45:01 +00:00
|
|
|
'.incbin "baseinc.bin",3', b"IC\n")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".incbin (hardcoded offset and length)",
|
2019-01-10 04:45:01 +00:00
|
|
|
'.incbin "baseinc.bin",3,2', b"IC")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".incbin (softcoded offset and length)",
|
|
|
|
'.alias off len+1\n.alias len 2\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
'.incbin "baseinc.bin",off,len', b"IC")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".incbin (length too long)",
|
2019-01-10 04:45:01 +00:00
|
|
|
'.byte 65\n.incbin "baseinc.bin",3,4', b"")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".incbin (negative offset)",
|
2019-01-10 04:45:01 +00:00
|
|
|
'.byte 65\n.incbin "baseinc.bin",1-5,4', b"")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".incbin (offset = size)",
|
2019-01-10 04:45:01 +00:00
|
|
|
'.byte 65\n.incbin "baseinc.bin",6', b"A")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".incbin (offset > size)",
|
2019-01-10 04:45:01 +00:00
|
|
|
'.byte 65\n.incbin "baseinc.bin",7', b"")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".incbin (softcoded length too long)",
|
|
|
|
'.alias off len\n.alias len 4\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
'.byte 65\n.incbin "baseinc.bin",off,len', b"")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".incbin (softcoded negative offset)",
|
|
|
|
'.alias off 1-5\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
'.byte 65\n.incbin "baseinc.bin",off,4', b"")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".incbin (softcoded offset = size)",
|
|
|
|
'.alias off 6\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
'.byte 65\n.incbin "baseinc.bin",off', b"A")
|
2012-06-12 09:39:19 +00:00
|
|
|
test_string(".incbin (softcoded offset > size)",
|
|
|
|
'.alias off 7\n'
|
2019-01-10 04:45:01 +00:00
|
|
|
'.byte 65\n.incbin "baseinc.bin",off', b"")
|
2012-06-11 02:08:20 +00:00
|
|
|
|
|
|
|
|
2012-06-09 04:50:28 +00:00
|
|
|
def test_systematic():
|
|
|
|
test_outfile()
|
|
|
|
test_transforms()
|
2012-06-11 02:08:20 +00:00
|
|
|
test_expressions()
|
|
|
|
test_segments()
|
|
|
|
test_scopes()
|
|
|
|
test_macros()
|
|
|
|
test_subfiles()
|
2012-06-09 04:50:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-01-10 04:45:01 +00:00
|
|
|
print("Using Python interpreter:", pythonpath)
|
2012-06-09 04:50:28 +00:00
|
|
|
|
|
|
|
test_basic()
|
2012-06-12 09:39:19 +00:00
|
|
|
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
|
2012-06-09 04:50:28 +00:00
|
|
|
if failed == 0:
|
|
|
|
test_systematic()
|
|
|
|
else:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("\nBasic test cases failed, aborting test.")
|
2012-06-09 04:50:28 +00:00
|
|
|
|
2012-06-08 09:49:29 +00:00
|
|
|
if failed > 0:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("\nTotal test case failures: %d" % failed)
|
2014-05-17 06:16:24 +00:00
|
|
|
sys.exit(1)
|
2012-06-08 09:49:29 +00:00
|
|
|
else:
|
2019-01-10 04:45:01 +00:00
|
|
|
print("\nAll test cases succeeded")
|
2014-05-17 06:16:24 +00:00
|
|
|
sys.exit(0)
|