Files
kotlin-fork/backend.native/tests/build.gradle
T
Svyatoslav Scherbina 8b83cb2adf backend: enable some tests
2017-01-11 19:32:25 +07:00

826 lines
20 KiB
Groovy

configurations {
cli_bc
}
dependencies {
cli_bc project(path: ':backend.native', configuration: 'cli_bc')
}
abstract class KonanTest extends DefaultTask {
protected String source
def backendNative = project.project(":backend.native")
def runtimeProject = project.project(":runtime")
def dist = project.parent.parent.file("dist")
def llvmLlc = llvmTool("llc")
def runtimeBc = new File("${dist.canonicalPath}/lib/runtime.bc").absolutePath
def launcherBc = new File("${dist.canonicalPath}/lib/launcher.bc").absolutePath
def startKtBc = new File("${dist.canonicalPath}/lib/start.kt.bc").absolutePath
def stdlibKtBc = new File("${dist.canonicalPath}/lib/stdlib.kt.bc").absolutePath
def mainC = 'main.c'
String goldValue = null
String testData = null
List<String> arguments = null
boolean enabled = true
public void setDisabled(boolean value) {
this.enabled = !value
}
public KonanTest(){
// TODO: that's a long reach up the project tree.
// May be we should reorganize a little.
dependsOn(project.parent.parent.tasks['dist'])
}
abstract void compileTest(String source, String exe)
protected void runCompiler(String source, String output, List<String> moreArgs) {
project.javaexec {
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
classpath = project.configurations.cli_bc
jvmArgs "-ea",
"-Dkonan.home=${dist.canonicalPath}",
"-Djava.library.path=${dist.canonicalPath}/konan/nativelib"
args("-output", output,
source,
*moreArgs,
*project.globalArgs)
}
}
@TaskAction
void executeTest() {
def sourceKt = project.file(source).absolutePath
def exe = sourceKt.replace(".kt", ".kt.exe")
compileTest(sourceKt, exe)
println "execution :$exe"
def out = null
project.exec {
commandLine exe
if (arguments != null) {
args arguments
}
if (testData != null) {
standardInput = new ByteArrayInputStream(testData.bytes)
}
if (goldValue != null) {
out = new ByteArrayOutputStream()
standardOutput = out
}
}
if (goldValue != null && goldValue != out.toString())
throw new RuntimeException("test failed")
}
private String llvmTool(String tool) {
return "${project.llvmDir}/bin/${tool}"
}
protected List<String> clangLinkArgs() {
return project.clangLinkArgs
}
}
class RunKonanTest extends KonanTest {
void compileTest(String source, String exe) {
runCompiler(source, exe, [])
}
}
class LinkKonanTest extends KonanTest {
protected String lib
void compileTest(String source, String exe) {
def libDir = project.file(lib).absolutePath
def libBc = "${libDir}.bc"
runCompiler(lib, libBc, ['-nolink', '-nostdlib'])
runCompiler(source, exe, ['-library', libBc])
}
}
task run() {
dependsOn(tasks.withType(KonanTest).matching { it.enabled })
}
task sum (type:RunKonanTest) {
source = "codegen/function/sum.kt"
}
task method_call(type: RunKonanTest) {
source = "codegen/object/method_call.kt"
}
task fields(type: RunKonanTest) {
source = "codegen/object/fields.kt"
}
task fields1(type: RunKonanTest) {
source = "codegen/object/fields1.kt"
}
task fields2(type: RunKonanTest) {
disabled = true
goldValue =
"Set global = 1\n" +
"Set member = 42\n" +
"Get member = 42\n" +
"Set global = 42\n" +
"Get global = 42\n" +
"Set member = 42\n"
source = "codegen/object/fields2.kt"
}
// This test checks object layout can't be done in
// RunKonanTest paradigm
//task constructor(type: UnitKonanTest) {
// source = "codegen/object/constructor.kt"
//}
task objectInitialization(type: RunKonanTest) {
source = "codegen/object/initialization.kt"
}
task check_type(type: RunKonanTest) {
goldValue = "true\nfalse\ntrue\ntrue\ntrue\ntrue\n"
source = "codegen/basics/check_type.kt"
}
task safe_cast(type: RunKonanTest) {
goldValue = "safe_cast_positive: true\n" +
"safe_cast_negative: true\n"
source = "codegen/basics/safe_cast.kt"
}
task aritmetic(type: RunKonanTest) {
source = "codegen/function/arithmetic.kt"
}
task sum1(type: RunKonanTest) {
source = "codegen/function/sum_foo_bar.kt"
}
task sum2(type: RunKonanTest) {
source = "codegen/function/sum_imm.kt"
}
task sum_3const(type: RunKonanTest) {
source = "codegen/function/sum_3const.kt"
}
task local_variable(type: RunKonanTest) {
source = "codegen/basics/local_variable.kt"
}
task canonical_name(type: RunKonanTest) {
goldValue = "A:foo\nA:qux\n"
source = "codegen/basics/canonical_name.kt"
}
task cast_simple(type: RunKonanTest) {
source = "codegen/basics/cast_simple.kt"
}
task null_check(type: RunKonanTest) {
source = "codegen/basics/null_check.kt"
}
task array_to_any(type: RunKonanTest) {
source = "codegen/basics/array_to_any.kt"
}
task hello0(type: RunKonanTest) {
goldValue = "Hello, world!\n"
source = "runtime/basic/hello0.kt"
}
task hello1(type: RunKonanTest) {
goldValue = "Hello World"
testData = "Hello World"
source = "runtime/basic/hello1.kt"
}
task hello2(type: RunKonanTest) {
goldValue = "you entered 'Hello World'"
testData = "Hello World"
source = "runtime/basic/hello2.kt"
}
task hello3(type: RunKonanTest) {
goldValue = "239\ntrue\n3.14159\nA\n"
source = "runtime/basic/hello3.kt"
}
task hello4(type: RunKonanTest) {
goldValue = "Hello\nПока\n"
source = "runtime/basic/hello4.kt"
}
task tostring0(type: RunKonanTest) {
goldValue = "127\n-1\n239\nA\n1122334455\n112233445566778899\n3.14159\n1E+27\n1E-300\ntrue\nfalse\n"
source = "runtime/basic/tostring0.kt"
}
task tostring1(type: RunKonanTest) {
goldValue = "ello\n"
source = "runtime/basic/tostring1.kt"
}
task tostring2(type: RunKonanTest) {
goldValue = "H e l l o \nHello\n"
source = "runtime/basic/tostring2.kt"
}
task tostring3(type: RunKonanTest) {
goldValue = "-128\n127\n-32768\n32767\n" +
"-2147483648\n2147483647\n-9223372036854775808\n9223372036854775807\n" +
"1.17549E-38\n3.40282E+38\n-INF\nINF\n" +
// Linux version prints -NAN.
// "NAN\n" +
"4.94066E-324\n1.79769E+308\n-INF\nINF\n"
// "NAN\n"
source = "runtime/basic/tostring3.kt"
}
task empty_substring(type: RunKonanTest) {
goldValue = "\n"
source = "runtime/basic/empty_substring.kt"
}
task array0(type: RunKonanTest) {
goldValue = "5\n6\n7\n8\n9\n10\n11\n12\n13\n"
source = "runtime/collections/array0.kt"
}
task array1(type: RunKonanTest) {
goldValue = "4 2\n1-1\n69\n38\n"
source = "runtime/collections/array1.kt"
}
task if_else(type: RunKonanTest) {
source = "codegen/branching/if_else.kt"
}
task when2(type: RunKonanTest) {
source = "codegen/branching/when2.kt"
}
task when5(type: RunKonanTest) {
source = "codegen/branching/when5.kt"
}
task when6(type: RunKonanTest) {
source = "codegen/branching/when6.kt"
}
task when7(type: RunKonanTest) {
source = "codegen/branching/when7.kt"
}
task when8(type: RunKonanTest) {
source = "codegen/branching/when8.kt"
goldValue = "true\n"
}
task when_through(type: RunKonanTest) {
source = "codegen/branching/when_through.kt"
}
task advanced_when2(type: RunKonanTest) {
source = "codegen/branching/advanced_when2.kt"
}
task advanced_when5(type: RunKonanTest) {
source = "codegen/branching/advanced_when5.kt"
}
task bool_yes(type: RunKonanTest) {
source = "codegen/function/boolean.kt"
}
task plus_eq(type: RunKonanTest) {
source = "codegen/function/plus_eq.kt"
}
task minus_eq(type: RunKonanTest) {
source = "codegen/function/minus_eq.kt"
}
task eqeq(type: RunKonanTest) {
source = "codegen/function/eqeq.kt"
}
task cycle(type: RunKonanTest) {
source = "codegen/cycles/cycle.kt"
}
task cycle_do(type: RunKonanTest) {
source = "codegen/cycles/cycle_do.kt"
}
task abstract_super(type: RunKonanTest) {
source = "datagen/rtti/abstract_super.kt"
}
task vtable1(type: RunKonanTest) {
source = "datagen/rtti/vtable1.kt"
}
task strdedup1(type: RunKonanTest) {
goldValue = "true\ntrue\n"
source = "datagen/literals/strdedup1.kt"
}
task strdedup2(type: RunKonanTest) {
// TODO: string deduplication across several components seems to require
// linking them as bitcode modules before translating to machine code.
disabled = true
goldValue = "true\ntrue\n"
source = "datagen/literals/strdedup2.kt"
}
task empty_string(type: RunKonanTest) {
goldValue = "\n"
source = "datagen/literals/empty_string.kt"
}
task intrinsic(type: RunKonanTest) {
source = "codegen/function/intrinsic.kt"
}
/*
Disabled until we extract the classes that should be
always present from stdlib.kt.bc into a separate binary.
task link(type: LinkKonanTest) {
goldValue = "0\n"
source = "link/src/bar.kt"
lib = "link/lib"
}
*/
task for0(type: RunKonanTest) {
goldValue = "2\n3\n4\n"
source = "runtime/basic/for0.kt"
}
task throw0(type: RunKonanTest) {
goldValue = "Done\n"
source = "runtime/basic/throw0.kt"
}
task statements0(type: RunKonanTest) {
goldValue = "239\n238\n30\n29\n"
source = "runtime/basic/statements0.kt"
}
task boxing0(type: RunKonanTest) {
goldValue = "17\n"
source = "codegen/boxing/boxing0.kt"
}
task boxing1(type: RunKonanTest) {
goldValue = "1\nfalse\nHello\n"
source = "codegen/boxing/boxing1.kt"
}
task boxing2(type: RunKonanTest) {
goldValue = "1\ntrue\nother\n"
source = "codegen/boxing/boxing2.kt"
}
task boxing3(type: RunKonanTest) {
goldValue = "42\n"
source = "codegen/boxing/boxing3.kt"
}
task boxing4(type: RunKonanTest) {
goldValue = "16\n"
source = "codegen/boxing/boxing4.kt"
}
task boxing5(type: RunKonanTest) {
goldValue = "16\n42\n"
source = "codegen/boxing/boxing5.kt"
}
task boxing6(type: RunKonanTest) {
goldValue = "42\n16\n"
source = "codegen/boxing/boxing6.kt"
}
task boxing7(type: RunKonanTest) {
goldValue = "1\n0\n"
source = "codegen/boxing/boxing7.kt"
}
task boxing8(type: RunKonanTest) {
goldValue = "1\n<null>\ntrue\nHello\n"
source = "codegen/boxing/boxing8.kt"
}
task boxing9(type: RunKonanTest) {
goldValue = "1\n<null>\ntrue\nHello\n2\n<null>\ntrue\nHello\n3\n"
source = "codegen/boxing/boxing9.kt"
}
task boxing10(type: RunKonanTest) {
goldValue = "Ok\n"
source = "codegen/boxing/boxing10.kt"
}
task boxing11(type: RunKonanTest) {
goldValue = "17\n42\n"
source = "codegen/boxing/boxing11.kt"
}
task boxing12(type: RunKonanTest) {
goldValue = "18\n"
source = "codegen/boxing/boxing12.kt"
}
task boxing13(type: RunKonanTest) {
goldValue = "false\nfalse\ntrue\ntrue\nfalse\nfalse\n"
source = "codegen/boxing/boxing13.kt"
}
task interface0(type: RunKonanTest) {
goldValue = "PASSED\n"
source = "runtime/basic/interface0.kt"
}
task hash0(type: RunKonanTest) {
goldValue = "239\n0\n97\n1065353216\n1072693248\n1\n0\ntrue\ntrue\n"
source = "runtime/basic/hash0.kt"
}
task array_list1(type: RunKonanTest) {
goldValue = "OK\n"
source = "runtime/collections/array_list1.kt"
}
task hash_map0(type: RunKonanTest) {
goldValue = "OK\n"
source = "runtime/collections/hash_map0.kt"
}
task hash_set0(type: RunKonanTest) {
goldValue = "OK\n"
source = "runtime/collections/hash_set0.kt"
}
task listof0(type: RunKonanTest) {
goldValue = "abc\n[a, b, c, d]\n[n, s, a]\n"
arguments = ["a"]
source = "runtime/collections/listof0.kt"
}
task listof1(type: RunKonanTest) {
goldValue = "true\n[a, b, c]\n"
source = "datagen/literals/listof1.kt"
}
task moderately_large_array(type: RunKonanTest) {
goldValue = "0\n"
source = "runtime/collections/moderately_large_array.kt"
}
task string_builder0(type: RunKonanTest) {
goldValue = "OK\n"
source = "runtime/text/string_builder0.kt"
}
task catch1(type: RunKonanTest) {
goldValue = "Before\nCaught Throwable\nDone\n"
source = "runtime/exceptions/catch1.kt"
}
task catch2(type: RunKonanTest) {
goldValue = "Before\nCaught Error\nDone\n"
source = "runtime/exceptions/catch2.kt"
}
task catch7(type: RunKonanTest) {
goldValue = "Error happens\n"
source = "runtime/exceptions/catch7.kt"
}
task catch3(type: RunKonanTest) {
goldValue = "Before\nCaught Throwable\nDone\n"
source = "codegen/try/catch3.kt"
}
task catch4(type: RunKonanTest) {
goldValue = "Before\nCaught Error\nDone\n"
source = "codegen/try/catch4.kt"
}
task catch5(type: RunKonanTest) {
goldValue = "Before\nCaught Error\nDone\n"
source = "codegen/try/catch5.kt"
}
task catch6(type: RunKonanTest) {
goldValue = "Before\nCaught Error\nDone\n"
source = "codegen/try/catch6.kt"
}
task catch8(type: RunKonanTest) {
goldValue = "Error happens\n"
source = "codegen/try/catch8.kt"
}
task finally1(type: RunKonanTest) {
goldValue = "Try\nFinally\nDone\n"
source = "codegen/try/finally1.kt"
}
task finally2(type: RunKonanTest) {
goldValue = "Try\nCaught Error\nFinally\nDone\n"
source = "codegen/try/finally2.kt"
}
task finally3(type: RunKonanTest) {
goldValue = "Try\nFinally\nCaught Error\nDone\n"
source = "codegen/try/finally3.kt"
}
task finally4(type: RunKonanTest) {
goldValue = "Try\nCatch\nFinally\nCaught Exception\nDone\n"
source = "codegen/try/finally4.kt"
}
task finally5(type: RunKonanTest) {
goldValue = "Done\nFinally\n0\n"
source = "codegen/try/finally5.kt"
}
task finally6(type: RunKonanTest) {
goldValue = "Done\nFinally\n1\n"
source = "codegen/try/finally6.kt"
}
task finally7(type: RunKonanTest) {
goldValue = "Done\nFinally\n1\n"
source = "codegen/try/finally7.kt"
}
task finally8(type: RunKonanTest) {
goldValue = "Finally 1\nFinally 2\n42\n"
source = "codegen/try/finally8.kt"
}
task finally9(type: RunKonanTest) {
goldValue = "Finally 1\nFinally 2\nAfter\n"
source = "codegen/try/finally9.kt"
}
task finally10(type: RunKonanTest) {
goldValue = "Finally\nAfter\n"
source = "codegen/try/finally10.kt"
}
task finally11(type: RunKonanTest) {
goldValue = "Finally\nCatch 2\nDone\n"
source = "codegen/try/finally11.kt"
}
task scope1(type: RunKonanTest) {
goldValue = "1\n"
source = "codegen/dataflow/scope1.kt"
}
task uninitialized_val(type: RunKonanTest) {
goldValue = "1\n2\n"
source = "codegen/dataflow/uninitialized_val.kt"
}
task try1(type: RunKonanTest) {
goldValue = "5\n"
source = "codegen/try/try1.kt"
}
task try2(type: RunKonanTest) {
goldValue = "6\n"
source = "codegen/try/try2.kt"
}
task try3(type: RunKonanTest) {
goldValue = "6\n"
source = "codegen/try/try3.kt"
}
task try4(type: RunKonanTest) {
goldValue = "Try\n5\n"
source = "codegen/try/try4.kt"
}
task unreachable1(type: RunKonanTest) {
goldValue = "1\n"
source = "codegen/controlflow/unreachable1.kt"
}
task break_continue(type: RunKonanTest) {
goldValue = "foo@l1\nfoo@l2\nfoo@l2\nfoo@l2\nbar@l1\nbar@l2\nbar@l2\nbar@l2\nqux@t1\nqux@l2\nqux@l2\nqux@l2\n"
source = "codegen/controlflow/break.kt"
}
task break1(type: RunKonanTest) {
goldValue = "Body\nDone\n"
source = "codegen/controlflow/break1.kt"
}
task range0(type: RunKonanTest) {
goldValue = "123\nabcd\n"
source = "runtime/collections/range0.kt"
}
task args0(type: RunKonanTest) {
arguments = ["AAA", "BB", "C"]
goldValue = "AAA\nBB\nC\n"
source = "runtime/basic/args0.kt"
}
task spread_operator_0(type: RunKonanTest) {
goldValue = "[K, o, t, l, i, n, , i, s, , c, o, o, l, , l, a, n, g, u, a, g, e]\n"
source = "codegen/basics/spread_operator_0.kt"
}
task main_exception(type: RunKonanTest) {
// TODO: cannot currently check the output because the exact stacktrace strings are unpredictable.
// goldValue = "Uncaught exception from Kotlin's main: Throwable\n"
source = "runtime/basic/main_exception.kt"
}
task initializers0(type: RunKonanTest) {
goldValue = "main\n" +
"B::constructor(1)\n" +
"A::companion\n" +
"A::companion::foo\n" +
"A::companion::foo\n" +
"B::constructor(0)\n" +
"B::constructor()\n" +
"A::Obj\n" +
"A::AObj::foo\n" +
"A::AObj::foo\n"
source = "runtime/basic/initializers0.kt"
}
task initializers1(type: RunKonanTest) {
goldValue = "Init Test\n" +
"Done\n"
disabled = true
source = "runtime/basic/initializers1.kt"
}
task concatenation(type: RunKonanTest) {
goldValue = "Hello world 1 2\nHello, a\nHello, b\n"
source = "codegen/basics/concatenation.kt"
}
task lambda1(type: RunKonanTest) {
goldValue = "lambda\n"
source = "codegen/lambda/lambda1.kt"
}
task lambda2(type: RunKonanTest) {
arguments = ["arg0"]
goldValue = "arg0\n"
source = "codegen/lambda/lambda2.kt"
}
task lambda3(type: RunKonanTest) {
goldValue = "lambda\n"
source = "codegen/lambda/lambda3.kt"
}
task lambda4(type: RunKonanTest) {
goldValue = "1\n2\n3\n3\n4\n"
source = "codegen/lambda/lambda4.kt"
}
task lambda5(type: RunKonanTest) {
goldValue = "42\n"
source = "codegen/lambda/lambda5.kt"
}
task lambda6(type: RunKonanTest) {
goldValue = "42\ncaptured\n"
source = "codegen/lambda/lambda6.kt"
}
task lambda7(type: RunKonanTest) {
goldValue = "43\n"
source = "codegen/lambda/lambda7.kt"
}
task lambda8(type: RunKonanTest) {
goldValue = "first\n0\nsecond\n0\nfirst\n1\nsecond\n1\n"
source = "codegen/lambda/lambda8.kt"
}
task lambda9(type: RunKonanTest) {
goldValue = "0\n0\n1\n0\n0\n1\n1\n1\n"
source = "codegen/lambda/lambda9.kt"
}
task lambda10(type: RunKonanTest) {
goldValue = "original\nchanged\n"
source = "codegen/lambda/lambda10.kt"
}
task lambda11(type: RunKonanTest) {
goldValue = "first\nsecond\n"
source = "codegen/lambda/lambda11.kt"
}
task lambda12(type: RunKonanTest) {
goldValue = "one\ntwo\n"
source = "codegen/lambda/lambda12.kt"
}
task lambda13(type: RunKonanTest) {
goldValue = "foo\n"
source = "codegen/lambda/lambda13.kt"
}
task initializers2(type: RunKonanTest) {
goldValue = "init globalValue2\n" +
"init globalValue3\n" +
"1\n" +
"globalValue2\n" +
"globalValue3\n"
source = "runtime/basic/initializers2.kt"
}
task initializers3(type: RunKonanTest) {
goldValue = "42\n"
source = "runtime/basic/initializers3.kt"
}
task initializers4(type: RunKonanTest) {
disabled = true
goldValue = "fixme\n"
source = "runtime/basic/initializers4.kt"
}
task expression_as_statement(type: RunKonanTest) {
goldValue = "Ok\n"
source = "codegen/basics/expression_as_statement.kt"
}
task memory_var1(type: RunKonanTest) {
source = "runtime/memory/var1.kt"
}
task memory_var2(type: RunKonanTest) {
source = "runtime/memory/var2.kt"
}
task memory_var3(type: RunKonanTest) {
source = "runtime/memory/var3.kt"
}
task memory_var4(type: RunKonanTest) {
source = "runtime/memory/var4.kt"
}
task memory_throw_cleanup(type: RunKonanTest) {
goldValue = "Ok\n"
source = "runtime/memory/throw_cleanup.kt"
}
task unit1(type: RunKonanTest) {
goldValue = "First\nkotlin.Unit\n"
source = "codegen/basics/unit1.kt"
}
task unit2(type: RunKonanTest) {
goldValue = "kotlin.Unit\n"
source = "codegen/basics/unit2.kt"
}
task unit3(type: RunKonanTest) {
goldValue = "kotlin.Unit\n"
source = "codegen/basics/unit3.kt"
}
task unit4(type: RunKonanTest) {
goldValue = "Done\n"
source = "codegen/basics/unit4.kt"
}