Make sure tests pass both on ARTIQ Python and CPython.

In some cases (the `is` operator and wraparound arithmetics)
the tests will only pass on ARTIQ Python. These are conditionally
commented out.
This commit is contained in:
whitequark 2015-07-23 08:09:25 +03:00
parent 65121b437f
commit 20f5f8217d
16 changed files with 34 additions and 12 deletions

View File

@ -18,7 +18,9 @@ def main():
engine = diagnostic.Engine() engine = diagnostic.Engine()
engine.process = process_diagnostic engine.process = process_diagnostic
llmod = Module.from_string("".join(fileinput.input()).expandtabs(), engine=engine).llvm_ir source = "".join(fileinput.input())
source = source.replace("#ARTIQ#", "")
llmod = Module.from_string(source.expandtabs(), engine=engine).llvm_ir
lltarget = llvm.Target.from_default_triple() lltarget = llvm.Target.from_default_triple()
llmachine = lltarget.create_target_machine() llmachine = lltarget.create_target_machine()

View File

@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s
assert -(-1) == 1 assert -(-1) == 1
assert -(-1.0) == 1.0 assert -(-1.0) == 1.0
@ -28,7 +29,7 @@ assert 9.0 ** 0.5 == 3.0
assert 1 << 1 == 2 assert 1 << 1 == 2
assert 2 >> 1 == 1 assert 2 >> 1 == 1
assert -2 >> 1 == -1 assert -2 >> 1 == -1
assert 1 << 32 == 0 #ARTIQ#assert 1 << 32 == 0
assert -1 >> 32 == -1 assert -1 >> 32 == -1
assert 0x18 & 0x0f == 0x08 assert 0x18 & 0x0f == 0x08
assert 0x18 | 0x0f == 0x1f assert 0x18 | 0x0f == 0x1f

View File

@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s
r = range(10) r = range(10)
assert r.start == 0 assert r.start == 0

View File

@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s
assert (not 0) == True assert (not 0) == True
assert (not 1) == False assert (not 1) == False

View File

@ -1,24 +1,25 @@
# RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s
assert bool() is False assert bool() is False
# bool(x) is tested in bool.py # bool(x) is tested in bool.py
assert int() is 0 assert int() is 0
assert int(1.0) is 1 assert int(1.0) is 1
assert int(1, width=64) << 40 is 1099511627776 #ARTIQ#assert int(1, width=64) << 40 is 1099511627776
assert float() is 0.0 #ARTIQ#assert float() is 0.0
assert float(1) is 1.0 #ARTIQ#assert float(1) is 1.0
x = list() x = list()
if False: x = [1] if False: x = [1]
assert x == [] assert x == []
assert range(10) is range(0, 10, 1) #ARTIQ#assert range(10) is range(0, 10, 1)
assert range(1, 10) is range(1, 10, 1) #ARTIQ#assert range(1, 10) is range(1, 10, 1)
assert len([1, 2, 3]) is 3 assert len([1, 2, 3]) is 3
assert len(range(10)) is 10 assert len(range(10)) is 10
assert len(range(0, 10, 2)) is 5 assert len(range(0, 10, 2)) is 5
assert round(1.4) is 1 and round(1.6) is 2 #ARTIQ#assert round(1.4) is 1 and round(1.6) is 2

View File

@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s
assert 1 < 2 and not (2 < 1) assert 1 < 2 and not (2 < 1)
assert 2 > 1 and not (1 > 2) assert 2 > 1 and not (1 > 2)
@ -11,7 +12,7 @@ assert 1 is not 2 and not (1 is not 1)
x, y = [1], [1] x, y = [1], [1]
assert x is x and x is not y assert x is x and x is not y
assert range(10) is range(10) and range(10) is not range(11) #ARTIQ#assert range(10) is range(10) and range(10) is not range(11)
lst = [1, 2, 3] lst = [1, 2, 3]
assert 1 in lst and 0 not in lst assert 1 in lst and 0 not in lst

View File

@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s
count = 0 count = 0
for x in range(10): for x in range(10):

View File

@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s
def fib(x): def fib(x):
if x == 1: if x == 1:

View File

@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s
if True: if True:
assert True assert True

View File

@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s
assert (lambda: 1)() == 1 assert (lambda: 1)() == 1
assert (lambda x: x)(1) == 1 assert (lambda x: x)(1) == 1

View File

@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s
[x, y] = [1, 2] [x, y] = [1, 2]
assert (x, y) == (1, 2) assert (x, y) == (1, 2)

View File

@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s
x = 1 x = 1
assert x == 1 assert x == 1

View File

@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s
lst = list(range(10)) lst = list(range(10))
assert lst[0] == 0 assert lst[0] == 0

View File

@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s
x, y = 2, 1 x, y = 2, 1
x, y = y, x x, y = y, x

View File

@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s # RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s
cond, count = True, 0 cond, count = True, 0
while cond: while cond:

View File

@ -12,7 +12,7 @@ emulate the same behavior when invoked under lit.
import sys, os, argparse, importlib import sys, os, argparse, importlib
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-m', metavar='mod', type=str, required=True, parser.add_argument('-m', metavar='mod', type=str,
help='run library module as a script') help='run library module as a script')
parser.add_argument('args', type=str, nargs='+', parser.add_argument('args', type=str, nargs='+',
help='arguments passed to program in sys.argv[1:]') help='arguments passed to program in sys.argv[1:]')
@ -21,5 +21,11 @@ args = parser.parse_args(sys.argv[1:])
artiq_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) artiq_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(1, artiq_path) sys.path.insert(1, artiq_path)
sys.argv[1:] = args.args if args.m:
importlib.import_module(args.m).main() sys.argv[1:] = args.args
importlib.import_module(args.m).main()
else:
sys.argv[1:] = args.args[1:]
with open(args.args[0]) as f:
code = compile(f.read(), args.args[0], 'exec')
exec(code)