Skip to content

Commit

Permalink
Make sure tests pass both on ARTIQ Python and CPython.
Browse files Browse the repository at this point in the history
In some cases (the `is` operator and wraparound arithmetics)
the tests will only pass on ARTIQ Python. These are conditionally
commented out.
whitequark committed Jul 23, 2015
1 parent 65121b4 commit 20f5f82
Showing 16 changed files with 34 additions and 12 deletions.
4 changes: 3 additions & 1 deletion artiq/compiler/testbench/jit.py
Original file line number Diff line number Diff line change
@@ -18,7 +18,9 @@ def process_diagnostic(diag):
engine = diagnostic.Engine()
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()
llmachine = lltarget.create_target_machine()
3 changes: 2 additions & 1 deletion lit-test/compiler/integration/arithmetics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s

assert -(-1) == 1
assert -(-1.0) == 1.0
@@ -28,7 +29,7 @@
assert 1 << 1 == 2
assert 2 >> 1 == 1
assert -2 >> 1 == -1
assert 1 << 32 == 0
#ARTIQ#assert 1 << 32 == 0
assert -1 >> 32 == -1
assert 0x18 & 0x0f == 0x08
assert 0x18 | 0x0f == 0x1f
1 change: 1 addition & 0 deletions lit-test/compiler/integration/attribute.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s

r = range(10)
assert r.start == 0
1 change: 1 addition & 0 deletions lit-test/compiler/integration/bool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s

assert (not 0) == True
assert (not 1) == False
13 changes: 7 additions & 6 deletions lit-test/compiler/integration/builtin.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s

assert bool() is False
# bool(x) is tested in bool.py

assert int() is 0
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
assert float(1) is 1.0
#ARTIQ#assert float() is 0.0
#ARTIQ#assert float(1) is 1.0

x = list()
if False: x = [1]
assert x == []

assert range(10) is range(0, 10, 1)
assert range(1, 10) is range(1, 10, 1)
#ARTIQ#assert range(10) is range(0, 10, 1)
#ARTIQ#assert range(1, 10) is range(1, 10, 1)

assert len([1, 2, 3]) is 3
assert len(range(10)) is 10
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
3 changes: 2 additions & 1 deletion lit-test/compiler/integration/compare.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s

assert 1 < 2 and not (2 < 1)
assert 2 > 1 and not (1 > 2)
@@ -11,7 +12,7 @@

x, y = [1], [1]
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]
assert 1 in lst and 0 not in lst
1 change: 1 addition & 0 deletions lit-test/compiler/integration/for.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s

count = 0
for x in range(10):
1 change: 1 addition & 0 deletions lit-test/compiler/integration/function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s

def fib(x):
if x == 1:
1 change: 1 addition & 0 deletions lit-test/compiler/integration/if.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s

if True:
assert True
1 change: 1 addition & 0 deletions lit-test/compiler/integration/lambda.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s

assert (lambda: 1)() == 1
assert (lambda x: x)(1) == 1
1 change: 1 addition & 0 deletions lit-test/compiler/integration/list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s

[x, y] = [1, 2]
assert (x, y) == (1, 2)
1 change: 1 addition & 0 deletions lit-test/compiler/integration/locals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s

x = 1
assert x == 1
1 change: 1 addition & 0 deletions lit-test/compiler/integration/subscript.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s

lst = list(range(10))
assert lst[0] == 0
1 change: 1 addition & 0 deletions lit-test/compiler/integration/tuple.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s

x, y = 2, 1
x, y = y, x
1 change: 1 addition & 0 deletions lit-test/compiler/integration/while.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.jit %s
# RUN: %python %s

cond, count = True, 0
while cond:
12 changes: 9 additions & 3 deletions lit-test/harness.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
import sys, os, argparse, importlib

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')
parser.add_argument('args', type=str, nargs='+',
help='arguments passed to program in sys.argv[1:]')
@@ -21,5 +21,11 @@
artiq_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(1, artiq_path)

sys.argv[1:] = args.args
importlib.import_module(args.m).main()
if args.m:
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)

0 comments on commit 20f5f82

Please sign in to comment.