summaryrefslogtreecommitdiff
path: root/tests/etc/host-run-test-jar
blob: d3c0fd5edad535a88815737e530f217411a6eb97 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/sh
#
# Run the code in test.jar using the host-mode virtual machine. The jar should
# contain a top-level class named Main to run.
#
# Options:
#   --quiet       -- don't chatter
#   --fast        -- use the fast interpreter (the default)
#   --jit         -- use the jit
#   --portable    -- use the portable interpreter
#   --debug       -- wait for debugger to attach
#   --valgrind    -- use valgrind
#   --no-verify   -- turn off verification (on by default)
#   --no-optimize -- turn off optimization (on by default)

msg() {
    if [ "$QUIET" = "n" ]; then
        echo "$@"
    fi
}

INTERP=""
DEBUG="n"
GDB="n"
VERIFY="y"
OPTIMIZE="y"
VALGRIND="n"
DEV_MODE="n"
QUIET="n"
PRECISE="y"

while true; do
    if [ "x$1" = "x--quiet" ]; then
        QUIET="y"
        shift
    elif [ "x$1" = "x--jit" ]; then
        INTERP="jit"
        msg "Using jit"
        shift
    elif [ "x$1" = "x--fast" ]; then
        INTERP="fast"
        msg "Using fast interpreter"
        shift
    elif [ "x$1" = "x--portable" ]; then
        INTERP="portable"
        msg "Using portable interpreter"
        shift
    elif [ "x$1" = "x--debug" ]; then
        DEBUG="y"
        shift
    elif [ "x$1" = "x--gdb" ]; then
        GDB="y"
        shift
    elif [ "x$1" = "x--valgrind" ]; then
        VALGRIND="y"
        shift
    elif [ "x$1" = "x--dev" ]; then
        DEV_MODE="y"
        shift
    elif [ "x$1" = "x--no-verify" ]; then
        VERIFY="n"
        shift
    elif [ "x$1" = "x--no-optimize" ]; then
        OPTIMIZE="n"
        shift
    elif [ "x$1" = "x--no-precise" ]; then
        PRECISE="n"
        shift
    elif [ "x$1" = "x--" ]; then
        shift
        break
    elif expr "x$1" : "x--" >/dev/null 2>&1; then
        echo "unknown option: $1" 1>&2
        exit 1
    else
        break
    fi
done

if [ "x$INTERP" = "x" ]; then
    INTERP="fast"
    msg "Using fast interpreter by default"
fi

if [ "$OPTIMIZE" = "y" ]; then
    if [ "$VERIFY" = "y" ]; then
        DEX_OPTIMIZE="-Xdexopt:verified"
    else
        DEX_OPTIMIZE="-Xdexopt:all"
    fi
    msg "Performing optimizations"
else
    DEX_OPTIMIZE="-Xdexopt:none"
    msg "Skipping optimizations"
fi

if [ "$VERIFY" = "y" ]; then
    DEX_VERIFY=""
    msg "Performing verification"
else
    DEX_VERIFY="-Xverify:none"
    msg "Skipping verification"
fi

if [ "$VALGRIND" = "y" ]; then
    msg "Running with valgrind"
    valgrind_cmd="valgrind"
    #valgrind_cmd="valgrind --leak-check=full"
else
    valgrind_cmd=""
fi

if [ "$PRECISE" = "y" ]; then
    GC_OPTS="-Xgc:precise -Xgenregmap"
else
    GC_OPTS="-Xgc:noprecise"
fi

msg "------------------------------"

HOSTBASE="${ANDROID_BUILD_TOP}/out/host"
BASE="$OUT" # from build environment
DATA_DIR=/tmp
DEBUG_OPTS="-Xcheck:jni -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

if [ ! -d $DATA_DIR/dalvik-cache ]; then
    mkdir -p $DATA_DIR/dalvik-cache
    [[ $? -ne 0 ]] && exit
fi

export ANDROID_PRINTF_LOG=brief
if [ "$DEV_MODE" = "y" ]; then
    export ANDROID_LOG_TAGS='*:d'
else
    export ANDROID_LOG_TAGS='*:s'
fi
export ANDROID_DATA="$DATA_DIR"
export ANDROID_ROOT="${HOSTBASE}/linux-x86"
export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"

exe="${ANDROID_ROOT}/bin/dalvikvm"
framework="${BASE}/system/framework"
bpath="${framework}/core.jar:${framework}/ext.jar:${framework}/framework.jar"

if [ "$DEBUG" = "y" ]; then
    PORT=8000
    msg "Waiting for debugger to connect on localhost:$PORT"
    DEX_DEBUG="-agentlib:jdwp=transport=dt_socket,addres=$PORT,server=y,suspend=y"
fi

if [ "$GDB" = "y" ]; then
    gdb=gdb
    gdbargs="--args $exe"
fi

$valgrind_cmd $gdb $exe $gdbargs "-Xbootclasspath:${bpath}" \
    $DEX_VERIFY $DEX_OPTIMIZE $DEX_DEBUG $GC_OPTS "-Xint:${INTERP}" -ea \
    -cp test.jar Main "$@"