summarylogtreecommitdiffstats
path: root/test.sh
blob: 053484fda0e722c61d50b2007fedbb67afcdef7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash

java_=$(source PKGBUILD && echo $java_)

if ! tmpdir=$(mktemp --directory --tmpdir graalvm-test.XXXX); then
    exit
fi
cd -- "$tmpdir" || exit
function cleanup {
    cd / || exit
    rm -rf -- "$tmpdir"
}
trap cleanup EXIT
PATH=/usr/lib/jvm/java-${java_}-graalvm/bin/:$(systemd-path search-binaries-default)

printf '%s\n' 'Testing Node with polyglot R, Python, Ruby, JavaScript, and Java...'

jsThree=$(node --polyglot --jvm << 'EOF'
rPlus = Polyglot.eval('R', '(function(s1, s2) s1 + s2)');
pythonPlus = Polyglot.eval('python', 'lambda s1, s2: s1 + s2');
rubyOne = Polyglot.eval('ruby', '1')
pythonOne = Polyglot.eval('python', '1')
jsOne = 1
jvmPrint = Java.type('java.lang.System').out.println
jvmPrint(pythonPlus(rPlus(rubyOne, pythonOne), jsOne))
EOF
) || exit
if [[ $jsThree != 3 ]]; then
    printf 'expected 3, got %q\n' "$rThree"
    exit 1
fi

printf '%s\n' 'Testing native image...'

cat > Test.java << 'EOF'
public class Test {
    public static void main(String[] args) {
        System.out.println("Hello, world!");
    }
}
EOF
javac Test.java || exit
native-image Test > /dev/null || exit

helloWorld=$(./test) || exit
if [[ $helloWorld != 'Hello, world!' ]]; then
    printf 'expected "Hello, world!", got %q\n' "$helloWorld"
    exit 1
fi

printf '%s\n' 'Testing Espresso...'

# reusing the same Test.java / Test.class
helloWorld=$(java -truffle Test) || exit
if [[ $helloWorld != 'Hello, world!' ]]; then
    printf 'expected "Hello, world!", got %q\n' "$helloWorld"
    exit 1
fi

printf '%s\n' 'Testing GraalWASM...'

PATH=$PATH:/usr/lib/emscripten

cat > hello.c << 'EOF'
#include <stdio.h>

int main() {
  printf("Hello, WASM!\n");
  return 0;
}
EOF
nice -n19 emcc -o hello.wasm hello.c 2>/dev/null || exit

helloWorld=$(wasm --Builtins=wasi_snapshot_preview1 hello.wasm) || exit
if [[ $helloWorld != 'Hello, WASM!' ]]; then
    printf 'expected "Hello, WASM!", got %q\n' "$helloWorld"
    exit 1
fi

printf '%s\n' 'Done.'