diff --git a/crypto/func/auto-tests/run_tests.py b/crypto/func/auto-tests/run_tests.py new file mode 100644 index 00000000..ae9c990c --- /dev/null +++ b/crypto/func/auto-tests/run_tests.py @@ -0,0 +1,91 @@ +import os +import os.path +import subprocess +import sys +import tempfile + +def getenv(name, default=None): + if name in os.environ: + return os.environ[name] + if default is None: + print("Environment variable", name, "is not set", file=sys.stderr) + exit(1) + return default + +FUNC_EXECUTABLE = getenv("FUNC_EXECUTABLE", "func") +FIFT_EXECUTABLE = getenv("FIFT_EXECUTABLE", "fift") +#FUNC_STDLIB = getenv("FUNC_STDLIB") +FIFT_LIBS = getenv("FIFT_LIBS") +TMP_DIR = tempfile.mkdtemp() +COMPILED_FIF = os.path.join(TMP_DIR, "compiled.fif") +RUNNER_FIF = os.path.join(TMP_DIR, "runner.fif") + +if len(sys.argv) != 2: + print("Usage : run_tests.py tests_dir", file=sys.stderr) + exit(1) +TESTS_DIR = sys.argv[1] + +class ExecutionError(Exception): + pass + +def compile_func(f): + res = subprocess.run([FUNC_EXECUTABLE, "-o", COMPILED_FIF, "-SPA", f], capture_output=True, timeout=10) + if res.returncode != 0: + raise ExecutionError(str(res.stderr, "utf-8")) + +def run_runner(): + res = subprocess.run([FIFT_EXECUTABLE, "-I", FIFT_LIBS, RUNNER_FIF], capture_output=True, timeout=10) + if res.returncode != 0: + raise ExecutionError(str(res.stderr, "utf-8")) + s = str(res.stdout, "utf-8") + s = [x.strip() for x in s.split("\n")] + return [x for x in s if x != ""] + +tests = [s for s in os.listdir(TESTS_DIR) if s.endswith(".fc")] +tests.sort() +print("Found", len(tests), "tests", file=sys.stderr) +for ti, tf in enumerate(tests): + print("Running test %d/%d: %s" % (ti + 1, len(tests), tf), file=sys.stderr) + tf = os.path.join(TESTS_DIR, tf) + try: + compile_func(tf) + except ExecutionError as e: + print(file=sys.stderr) + print("Compilation error", file=sys.stderr) + print(e, file=sys.stderr) + exit(2) + with open(tf, "r") as fd: + lines = fd.readlines() + cases = [] + for s in lines: + s = [x.strip() for x in s.split("|")] + if len(s) == 4 and s[0].strip() == "TESTCASE": + cases.append(s[1:]) + if len(cases) == 0: + print(file=sys.stderr) + print("Error: no test cases", file=sys.stderr) + exit(2) + + with open(RUNNER_FIF, "w") as f: + print("\"%s\" include = %d);" % (var, self.n), file=f) + +def write_function(f, name, body, inline=False, inline_ref=False, method_id=None): + print("_ %s(int x)" % name, file=f, end="") + if inline: + print(" inline", file=f, end="") + if inline_ref: + print(" inline_ref", file=f, end="") + if method_id is not None: + print(" method_id(%d)" % method_id, file=f, end="") + print(" {", file=f) + for i in range(VAR_CNT): + print(" int v%d = 0;" % i, file=f) + body.write(f, 1); + print("}", file=f) + +def gen_code(xl, xr, with_return, loop_depth=0): + code = [] + for _ in range(random.randint(0, 2)): + if random.randint(0, 3) == 0 and loop_depth < 3: + c = gen_code(xl, xr, False, loop_depth + 1) + code.append(CodeRepeat(random.randint(0, 3), c, random.randint(0, 2))) + elif xr - xl > 1: + xmid = random.randrange(xl + 1, xr) + ret = random.choice((0, 0, 0, 0, 0, 1, 2)) + c1 = gen_code(xl, xmid, ret == 1, loop_depth) + if random.randrange(5) == 0: + c2 = CodeEmpty() + else: + c2 = gen_code(xmid, xr, ret == 2, loop_depth) + code.append(CodeIfRange(xl, xmid, c1, c2)) + if with_return: + if xr - xl == 1: + code.append(CodeReturn(random.randrange(10**9))) + else: + xmid = random.randrange(xl + 1, xr) + c1 = gen_code(xl, xmid, True, loop_depth) + c2 = gen_code(xmid, xr, True, loop_depth) + code.append(CodeIfRange(xl, xmid, c1, c2)) + for _ in range(random.randint(0, 3)): + pos = random.randint(0, len(code)) + code.insert(pos, CodeAdd(random.randrange(VAR_CNT), random.randint(0, 10**6))) + if len(code) == 0: + return CodeEmpty() + return CodeBlock(code) + +class ExecutionError(Exception): + pass + +def compile_func(fc, fif): + res = subprocess.run([FUNC_EXECUTABLE, "-o", fif, "-SPA", fc], capture_output=True) + if res.returncode != 0: + raise ExecutionError(str(res.stderr, "utf-8")) + +def runvm(compiled_fif, xl, xr): + runner = os.path.join(TMP_DIR, "runner.fif") + with open(runner, "w") as f: + print("\"%s\" include a) { + x -= 1; + z = 1; + } + return (y, z); +} + +{- + method_id | in | out +TESTCASE | 0 | 101 15 | 100 1 +TESTCASE | 0 | 101 14 | 100 1 +TESTCASE | 0 | 101 10 | 100 0 +TESTCASE | 0 | 100 10 | 100 0 +-} diff --git a/crypto/func/auto-tests/tests/a6.fc b/crypto/func/auto-tests/tests/a6.fc new file mode 100644 index 00000000..05a49fab --- /dev/null +++ b/crypto/func/auto-tests/tests/a6.fc @@ -0,0 +1,89 @@ +(int, int) f(int a, int b, int c, int d, int e, int f) { + ;; solve a 2x2 linear equation + int D = a * d - b * c; + int Dx = e * d - b * f; + int Dy = a * f - e * c; + return (Dx / D, Dy / D); +} + +int calc_phi() { + var n = 1; + repeat (70) { n *= 10; } + var p = var q = 1; + do { + (p, q) = (q, p + q); + } until (q > n); + return muldivr(p, n, q); +} + +int calc_sqrt2() { + var n = 1; + repeat (70) { n *= 10; } + var p = var q = 1; + do { + var t = p + q; + (p, q) = (q, t + q); + } until (q > n); + return muldivr(p, n, q); +} + +var calc_root(m) { + int base = 1; + repeat(70) { base *= 10; } + var (a, b, c) = (1, 0, - m); + var (p1, q1, p2, q2) = (1, 0, 0, 1); + do { + int k = -1; + var (a1, b1, c1) = (0, 0, 0); + do { + k += 1; + (a1, b1, c1) = (a, b, c); + c += b; + c += b += a; + } until (c > 0); + (a, b, c) = (- c1, - b1, - a1); + (p1, q1) = (k * p1 + q1, p1); + (p2, q2) = (k * p2 + q2, p2); + } until (p1 > base); + return (p1, q1, p2, q2); +} + +{- +operator _/%_ infix 20; + +(int, int) ((int x) /% (int y)) { + return (x / y, x % y); +} + +(int, int) _/%_ (int x, int y) { + return (x / y, x % y); +} +-} + +int ataninv(int base, int q) { ;; computes base*atan(1/q) + base ~/= q; + q *= - q; + int sum = 0; + int n = 1; + do { + sum += base ~/ n; + base ~/= q; + n += 2; + } until base == 0; + return sum; +} + +int calc_pi() { + int base = 64; + repeat (70) { base *= 10; } + return (ataninv(base << 2, 5) - ataninv(base, 239)) ~>> 4; +} + +int main() { + return calc_pi(); +} + +{- + method_id | in | out +TESTCASE | 0 | | 31415926535897932384626433832795028841971693993751058209749445923078164 +-} diff --git a/crypto/func/auto-tests/tests/a6_1.fc b/crypto/func/auto-tests/tests/a6_1.fc new file mode 100644 index 00000000..b6341df0 --- /dev/null +++ b/crypto/func/auto-tests/tests/a6_1.fc @@ -0,0 +1,16 @@ +(int, int) main(int a, int b, int c, int d, int e, int f) { + int D = a * d - b * c; + int Dx = e * d - b * f; + int Dy = a * f - e * c; + return (Dx / D, Dy / D); +} + +{- + method_id | in | out +TESTCASE | 0 | 1 1 1 -1 10 6 | 8 2 +TESTCASE | 0 | 817 -31 624 -241 132272 272276 | 132 -788 +TESTCASE | 0 | -886 562 498 -212 -36452 -68958 | -505 -861 +TESTCASE | 0 | 448 -433 -444 792 150012 -356232 | -218 -572 +TESTCASE | 0 | -40 -821 433 -734 -721629 -741724 | -206 889 +TESTCASE | 0 | -261 -98 -494 868 -166153 733738 | 263 995 +-} diff --git a/crypto/func/auto-tests/tests/a6_5.fc b/crypto/func/auto-tests/tests/a6_5.fc new file mode 100644 index 00000000..06b5cc9d --- /dev/null +++ b/crypto/func/auto-tests/tests/a6_5.fc @@ -0,0 +1,24 @@ +var twice(f, x) { + return f (f x); +} + +_ sqr(x) { + return x * x; +} + +var main(x) { + var f = sqr; + return twice(f, x) * f(x); +} + +var pow6(x) method_id(4) { + return twice(sqr, x) * sqr(x); +} + +{- + method_id | in | out +TESTCASE | 0 | 3 | 729 +TESTCASE | 0 | 10 | 1000000 +TESTCASE | 4 | 3 | 729 +TESTCASE | 4 | 10 | 1000000 +-} diff --git a/crypto/func/auto-tests/tests/a7.fc b/crypto/func/auto-tests/tests/a7.fc new file mode 100644 index 00000000..356759d4 --- /dev/null +++ b/crypto/func/auto-tests/tests/a7.fc @@ -0,0 +1,24 @@ +() main() { } +int steps(int x) method_id(1) { + var n = 0; + while (x > 1) { + n += 1; + if (x & 1) { + x = 3 * x + 1; + } else { + x >>= 1; + } + } + return n; +} + +{- + method_id | in | out +TESTCASE | 1 | 1 | 0 +TESTCASE | 1 | 2 | 1 +TESTCASE | 1 | 5 | 5 +TESTCASE | 1 | 19 | 20 +TESTCASE | 1 | 27 | 111 +TESTCASE | 1 | 100 | 25 +-} + diff --git a/crypto/func/auto-tests/tests/c2.fc b/crypto/func/auto-tests/tests/c2.fc new file mode 100644 index 00000000..27f8b88f --- /dev/null +++ b/crypto/func/auto-tests/tests/c2.fc @@ -0,0 +1,17 @@ +global ((int, int) -> int) op; + +int check_assoc(int a, int b, int c) { + return op(op(a, b), c) == op(a, op(b, c)); +} + +int main(int x, int y, int z) { + op = _+_; + return check_assoc(x, y, z); +} + +{- + method_id | in | out +TESTCASE | 0 | 2 3 9 | -1 +TESTCASE | 0 | 11 22 44 | -1 +TESTCASE | 0 | -1 -10 -20 | -1 +-} diff --git a/crypto/func/auto-tests/tests/c2_1.fc b/crypto/func/auto-tests/tests/c2_1.fc new file mode 100644 index 00000000..ef7183b6 --- /dev/null +++ b/crypto/func/auto-tests/tests/c2_1.fc @@ -0,0 +1,14 @@ +_ check_assoc(op, a, b, c) { + return op(op(a, b), c) == op(a, op(b, c)); +} + +int main(int x, int y, int z) { + return check_assoc(_+_, x, y, z); +} + +{- + method_id | in | out +TESTCASE | 0 | 2 3 9 | -1 +TESTCASE | 0 | 11 22 44 | -1 +TESTCASE | 0 | -1 -10 -20 | -1 +-} diff --git a/crypto/func/auto-tests/tests/co1.fc b/crypto/func/auto-tests/tests/co1.fc new file mode 100644 index 00000000..44067243 --- /dev/null +++ b/crypto/func/auto-tests/tests/co1.fc @@ -0,0 +1,60 @@ +const int1 = 1, int2 = 2; + +const int int101 = 101; +const int int111 = 111; + +const int1r = int1; + +const str1 = "const1", str2 = "aabbcc"s; + +const slice str2r = str2; + +const str1int = 0x636f6e737431; +const str2int = 0xAABBCC; + +const int nibbles = 4; + +int iget1() { return int1; } +int iget2() { return int2; } +int iget3() { return int1 + int2; } + +int iget1r() { return int1r; } + +slice sget1() { return str1; } +slice sget2() { return str2; } +slice sget2r() { return str2r; } + +const int int240 = ((int1 + int2) * 10) << 3; + +int iget240() { return int240; } + +builder newc() asm "NEWC"; +slice endcs(builder b) asm "ENDC" "CTOS"; +int sdeq (slice s1, slice s2) asm "SDEQ"; +builder stslicer(builder b, slice s) asm "STSLICER"; + +_ main() { + int i1 = iget1(); + int i2 = iget2(); + int i3 = iget3(); + + throw_unless(int101, i1 == 1); + throw_unless(102, i2 == 2); + throw_unless(103, i3 == 3); + + slice s1 = sget1(); + slice s2 = sget2(); + slice s3 = newc().stslicer(str1).stslicer(str2r).endcs(); + + throw_unless(int111, sdeq(s1, newc().store_uint(str1int, 12 * nibbles).endcs())); + throw_unless(112, sdeq(s2, newc().store_uint(str2int, 6 * nibbles).endcs())); + throw_unless(113, sdeq(s3, newc().store_uint(0x636f6e737431AABBCC, 18 * nibbles).endcs())); + + int i4 = iget240(); + throw_unless(104, i4 == 240); + return 0; +} + +{- +TESTCASE | 0 | | 0 +-} diff --git a/crypto/func/auto-tests/tests/code_after_ifelse.fc b/crypto/func/auto-tests/tests/code_after_ifelse.fc new file mode 100644 index 00000000..49e082c7 --- /dev/null +++ b/crypto/func/auto-tests/tests/code_after_ifelse.fc @@ -0,0 +1,19 @@ +int foo(int x) inline method_id(1) { + if (x == 1) { + return 111; + } else { + x *= 2; + } + return x + 1; +} +(int, int) main(int x) { + return (foo(x), 222); +} + +{- + method_id | in | out +TESTCASE | 1 | 1 | 111 +TESTCASE | 1 | 3 | 7 +TESTCASE | 0 | 1 | 111 222 +TESTCASE | 0 | 3 | 7 222 +-} diff --git a/crypto/func/auto-tests/tests/inline_big.fc b/crypto/func/auto-tests/tests/inline_big.fc new file mode 100644 index 00000000..61ad436e --- /dev/null +++ b/crypto/func/auto-tests/tests/inline_big.fc @@ -0,0 +1,61 @@ +int foo(int x) inline { + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + x = x * 10 + 1; + return x; +} + +(int) main(int x) { + return foo(x) * 10 + 5; +} +{- + method_id | in | out +TESTCASE | 0 | 9 | 9111111111111111111111111111111111111111111111111115 +-} diff --git a/crypto/func/auto-tests/tests/inline_if.fc b/crypto/func/auto-tests/tests/inline_if.fc new file mode 100644 index 00000000..390f0fd3 --- /dev/null +++ b/crypto/func/auto-tests/tests/inline_if.fc @@ -0,0 +1,26 @@ +int foo1(int x) { + if (x == 1) { + return 1; + } + return 2; +} +int foo2(int x) inline { + if (x == 1) { + return 11; + } + return 22; +} +int foo3(int x) inline_ref { + if (x == 1) { + return 111; + } + return 222; +} +(int, int, int) main(int x) { + return (foo1(x) + 1, foo2(x) + 1, foo3(x) + 1); +} +{- + method_id | in | out +TESTCASE | 0 | 1 | 2 12 112 +TESTCASE | 0 | 2 | 3 23 223 +-} diff --git a/crypto/func/auto-tests/tests/inline_loops.fc b/crypto/func/auto-tests/tests/inline_loops.fc new file mode 100644 index 00000000..9f1f45fc --- /dev/null +++ b/crypto/func/auto-tests/tests/inline_loops.fc @@ -0,0 +1,43 @@ +global int g; + +_ foo_repeat() impure inline { + g = 1; + repeat(5) { + g *= 2; + } +} + +int foo_until() impure inline { + g = 1; + int i = 0; + do { + g *= 2; + i += 1; + } until (i >= 8); + return i; +} + +int foo_while() impure inline { + g = 1; + int i = 0; + while (i < 10) { + g *= 2; + i += 1; + } + return i; +} + +_ main() { + foo_repeat(); + int x = g; + foo_until(); + int y = g; + foo_while(); + int z = g; + return (x, y, z); +} + +{- + method_id | in | out +TESTCASE | 0 | | 32 256 1024 +-} diff --git a/crypto/func/auto-tests/tests/method_id.fc b/crypto/func/auto-tests/tests/method_id.fc new file mode 100644 index 00000000..b4e0cd3b --- /dev/null +++ b/crypto/func/auto-tests/tests/method_id.fc @@ -0,0 +1,12 @@ +int foo1() method_id(1) { return 111; } +int foo2() method_id(3) { return 222; } +int foo3() method_id(10) { return 333; } +int main() { return 999; } + +{- + method_id | in | out +TESTCASE | 1 | | 111 +TESTCASE | 3 | | 222 +TESTCASE | 10 | | 333 +TESTCASE | 0 | | 999 +-} diff --git a/crypto/func/auto-tests/tests/s1.fc b/crypto/func/auto-tests/tests/s1.fc new file mode 100644 index 00000000..1541943d --- /dev/null +++ b/crypto/func/auto-tests/tests/s1.fc @@ -0,0 +1,54 @@ +slice ascii_slice() method_id { + return "string"; +} + +slice raw_slice() method_id { + return "abcdef"s; +} + +slice addr_slice() method_id { + return "Ef8zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzM0vF"a; +} + +int string_hex() method_id { + return "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"u; +} + +int string_minihash() method_id { + return "transfer(slice, int)"h; +} + +int string_maxihash() method_id { + return "transfer(slice, int)"H; +} + +int string_crc32() method_id { + return "transfer(slice, int)"c; +} + +builder newc() asm "NEWC"; +slice endcs(builder b) asm "ENDC" "CTOS"; +int sdeq (slice s1, slice s2) asm "SDEQ"; + +_ main() { + slice s_ascii = ascii_slice(); + slice s_raw = raw_slice(); + slice s_addr = addr_slice(); + int i_hex = string_hex(); + int i_mini = string_minihash(); + int i_maxi = string_maxihash(); + int i_crc = string_crc32(); + throw_unless(101, sdeq(s_ascii, newc().store_uint(0x737472696E67, 12 * 4).endcs())); + throw_unless(102, sdeq(s_raw, newc().store_uint(0xABCDEF, 6 * 4).endcs())); + throw_unless(103, sdeq(s_addr, newc().store_uint(4, 3).store_int(-1, 8) + .store_uint(0x3333333333333333333333333333333333333333333333333333333333333333, 256).endcs())); + throw_unless(104, i_hex == 0x4142434445464748494A4B4C4D4E4F505152535455565758595A303132333435); + throw_unless(105, i_mini == 0x7a62e8a8); + throw_unless(106, i_maxi == 0x7a62e8a8ebac41bd6de16c65e7be363bc2d2cbc6a0873778dead4795c13db979); + throw_unless(107, i_crc == 2235694568); + return 0; +} + +{- +TESTCASE | 0 | | 0 +-} diff --git a/crypto/func/auto-tests/tests/unbalanced_ret.fc b/crypto/func/auto-tests/tests/unbalanced_ret.fc new file mode 100644 index 00000000..0e4ef6ae --- /dev/null +++ b/crypto/func/auto-tests/tests/unbalanced_ret.fc @@ -0,0 +1,17 @@ +(int, int) main(int x) { + int y = 5; + if (x < 0) { + x *= 2; + y += 1; + if (x == -10) { + return (111, 0); + } + } + return (x + 1, y); +} +{- + method_id | in | out +TESTCASE | 0 | 10 | 11 5 +TESTCASE | 0 | -5 | 111 0 +TESTCASE | 0 | -4 | -7 6 +-} diff --git a/crypto/func/auto-tests/tests/unbalanced_ret_inline.fc b/crypto/func/auto-tests/tests/unbalanced_ret_inline.fc new file mode 100644 index 00000000..6d169345 --- /dev/null +++ b/crypto/func/auto-tests/tests/unbalanced_ret_inline.fc @@ -0,0 +1,18 @@ +int foo(int x) inline { + if (x < 0) { + x *= 2; + if (x == -10) { + return 111; + } + } + return x + 1; +} +int main(int x) { + return foo(x) * 10; +} +{- + method_id | in | out +TESTCASE | 0 | 10 | 110 +TESTCASE | 0 | -5 | 1110 +TESTCASE | 0 | -4 | -70 +-} diff --git a/crypto/func/auto-tests/tests/unbalanced_ret_loops.fc b/crypto/func/auto-tests/tests/unbalanced_ret_loops.fc new file mode 100644 index 00000000..104ec00d --- /dev/null +++ b/crypto/func/auto-tests/tests/unbalanced_ret_loops.fc @@ -0,0 +1,48 @@ +_ main() { } + +int foo_repeat(int x) method_id(1) { + repeat(10) { + x += 10; + if (x >= 100) { + return x; + } + } + return -1; +} + +int foo_while(int x) method_id(2) { + int i = 0; + while (i < 10) { + x += 10; + if (x >= 100) { + return x; + } + i += 1; + } + return -1; +} + +int foo_until(int x) method_id(3) { + int i = 0; + do { + x += 10; + if (x >= 100) { + return x; + } + i += 1; + } until (i >= 10); + return -1; +} + +{- + method_id | in | out +TESTCASE | 1 | 40 | 100 +TESTCASE | 1 | 33 | 103 +TESTCASE | 1 | -5 | -1 +TESTCASE | 2 | 40 | 100 +TESTCASE | 2 | 33 | 103 +TESTCASE | 2 | -5 | -1 +TESTCASE | 3 | 40 | 100 +TESTCASE | 3 | 33 | 103 +TESTCASE | 3 | -5 | -1 +-} diff --git a/crypto/func/auto-tests/tests/unbalanced_ret_nested.fc b/crypto/func/auto-tests/tests/unbalanced_ret_nested.fc new file mode 100644 index 00000000..7ab4bdf0 --- /dev/null +++ b/crypto/func/auto-tests/tests/unbalanced_ret_nested.fc @@ -0,0 +1,35 @@ +int foo(int y) { + if (y < 0) { + y *= 2; + if (y == -10) { + return 111; + } + } + return y + 1; +} +(int, int) bar(int x, int y) { + if (x < 0) { + y = foo(y); + x *= 2; + if (x == -10) { + return (111, y); + } + } + return (x + 1, y); +} +(int, int) main(int x, int y) { + (x, y) = bar(x, y); + return (x, y * 10); +} +{- + method_id | in | out +TESTCASE | 0 | 3 3 | 4 30 +TESTCASE | 0 | 3 -5 | 4 -50 +TESTCASE | 0 | 3 -4 | 4 -40 +TESTCASE | 0 | -5 3 | 111 40 +TESTCASE | 0 | -5 -5 | 111 1110 +TESTCASE | 0 | -5 -4 | 111 -70 +TESTCASE | 0 | -4 3 | -7 40 +TESTCASE | 0 | -4 -5 | -7 1110 +TESTCASE | 0 | -4 -4 | -7 -70 +-} diff --git a/crypto/func/auto-tests/tests/w1.fc b/crypto/func/auto-tests/tests/w1.fc new file mode 100644 index 00000000..3d6a8f69 --- /dev/null +++ b/crypto/func/auto-tests/tests/w1.fc @@ -0,0 +1,14 @@ +(int, int) main(int id) { + if (id > 0) { + if (id > 10) { + return (2 * id, 3 * id); + } + } + return (5, 6); +} +{- + method_id | in | out +TESTCASE | 0 | 0 | 5 6 +TESTCASE | 0 | 4 | 5 6 +TESTCASE | 0 | 11 | 22 33 +-} diff --git a/crypto/func/auto-tests/tests/w2.fc b/crypto/func/auto-tests/tests/w2.fc new file mode 100644 index 00000000..b9e5fb0e --- /dev/null +++ b/crypto/func/auto-tests/tests/w2.fc @@ -0,0 +1,18 @@ +_ f(cs) { + return (cs~load_uint(8), cs~load_uint(8), cs~load_uint(8), cs~load_uint(8), + cs~load_uint(8), cs~load_uint(8), cs~load_uint(8), cs~load_uint(8), + cs~load_uint(8), cs~load_uint(8), cs~load_uint(8), cs~load_uint(8), + cs~load_uint(8), cs~load_uint(8), cs~load_uint(8), cs~load_uint(8), + cs~load_uint(8), cs~load_uint(8), cs~load_uint(8), cs~load_uint(8)); +} + +_ main(cs) { + var (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, + x11, x12, x13, x14, x15, x16, x17, x18, x19) = f(cs); + return x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19; +} +{- + method_id | in | out +TESTCASE | 0 | x{000102030405060708090a0b0c0d0e0f10111213} | 190 +-} diff --git a/crypto/func/auto-tests/tests/w6.fc b/crypto/func/auto-tests/tests/w6.fc new file mode 100644 index 00000000..9b91cdf7 --- /dev/null +++ b/crypto/func/auto-tests/tests/w6.fc @@ -0,0 +1,17 @@ +int main(int x) { + int i = 0; + ;; int f = false; + do { + i = i + 1; + if (i > 5) { + return 1; + } + int f = (i * i == 64); + } until (f); + return -1; +} + +{- + method_id | in | out +TESTCASE | 0 | 0 | 1 +-} diff --git a/crypto/func/auto-tests/tests/w7.fc b/crypto/func/auto-tests/tests/w7.fc new file mode 100644 index 00000000..991b3e64 --- /dev/null +++ b/crypto/func/auto-tests/tests/w7.fc @@ -0,0 +1,24 @@ +int test(int y) method_id(1) { + int x = 1; + if (y > 0) { + return 1; + } + return x > 0; +} + +int f(int y) method_id(2) { + if (y > 0) { + return 1; + } + return 2; +} + +_ main() { } + +{- + method_id | in | out +TESTCASE | 1 | 10 | 1 +TESTCASE | 1 | -5 | -1 +TESTCASE | 2 | 10 | 1 +TESTCASE | 2 | -5 | 2 +-} diff --git a/crypto/func/auto-tests/tests/w9.fc b/crypto/func/auto-tests/tests/w9.fc new file mode 100644 index 00000000..f299dec1 --- /dev/null +++ b/crypto/func/auto-tests/tests/w9.fc @@ -0,0 +1,14 @@ +_ main(s) { + var (z, t) = (17, s); + while (z > 0) { + t = s; + z -= 1; + } + return ~ t; +} + +{- + method_id | in | out +TESTCASE | 0 | 1 | -2 +TESTCASE | 0 | 5 | -6 +-}