blob: 6dcfef548e800e5b5bfe54a5535273be673a1392 (
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
#!/bin/bash
# Copyright (c) 2016, Intel Corporation.
# Author: Geoff Gustafson <geoff@linux.intel.com>
# trlite - a local version of the tests we run in Travis
# trlite [-v] [vmname] [testnum]
#
# -v turns on verbose output
# by default, runs all tests
# trlite 1 or trlite zephyr runs just VM #1 "zephyr" tests
# trlite 2 or trlite linux runs just VM #2 "linux" tests
# trlite 3 or trlite ashell runs just VM #3 "ashell" tests
# optional testnum is the first subtest to start with (default 1)
if [ ! -d "$ZJS_BASE" ]; then
>&2 echo "ZJS_BASE not defined. You need to source zjs-env.sh."
exit 1
fi
TRLDIR=$ZJS_BASE/.trlite
TMPFILE=/tmp/zjstest.js
if [ "$1" == "-h" -o "$1" == "-?" ]; then
echo usage: trlite [-h] [-v] [vmname] [testnum]
echo
echo positional arguments:
echo " vmname vm number 1/2/3 or name zephyr/linux/ashell (default: all)"
echo " testnum subtest to start with (default: 1)"
echo
echo optional arguments:
echo " -h, -? show this help message and exit"
echo " -v turn on verbose build output"
exit 1
fi
VERBOSE=
if [ "$1" == "-v" ]; then
VERBOSE=V=1
shift
fi
# flags for running tests from the different VMs
VM1=y
VM2=y
VM3=y
if [ "$1" == "1" -o "$1" == "zephyr" ]; then VM2=n; VM3=n; fi
if [ "$1" == "2" -o "$1" == "linux" ]; then VM1=n; VM3=n; fi
if [ "$1" == "3" -o "$1" == "ashell" ]; then VM1=n; VM2=n; fi
shift
START=1
if [[ "$1" =~ ^[0-9]+$ ]]; then
START=$1
shift
fi
rm -rf $TRLDIR
echo Building ZJS tree: "$ZJS_BASE"
echo Cloning git tree...
git clone -l $ZJS_BASE $TRLDIR > /dev/null 2>&1
echo Cloning git submodules...
cd $TRLDIR/deps
for i in */; do
git clone -l ../../deps/$i/.git $i > /dev/null 2>&1
# clone submodules of submodules
if [ -d $i/deps/ ]; then
cd $i/deps
for j in */; do
git clone -l ../../../../deps/$i/deps/$j/.git $j > /dev/null 2>&1
done
cd ../..
fi
done
echo Preserving uncommitted changes:
cd $ZJS_BASE
git --no-pager diff HEAD --stat
git diff HEAD > $TRLDIR/uncommitted.patch
cd $TRLDIR
patch -p1 < uncommitted.patch > /dev/null
# pause to allow consideration of diffs being applied
sleep 3
echo Updating submodules...
make update
echo
echo Running tests...
source zjs-env.sh
source deps/zephyr/zephyr-env.sh
# requires: first arg is a <=10-char label, second arg is command
# effects: runs banner with label, then runs the command; if it fails, prints
# label before exiting
function try_command()
{
TESTNUM=$((TESTNUM + 1))
if [ "$TESTNUM" -lt "$START" ]; then
echo "Skipping test #$TESTNUM"
return
fi
LABEL=$1
shift
banner "$LABEL"
# run the command
$*
CODE=$?
if [ $CODE -ne 0 ]; then
echo Error: Failed in $LABEL \(subtest \#$TESTNUM\) error $? $CODE!
exit $CODE
fi
echo Success: $LABEL
}
#
# Tests from VM #1
#
if [ "$VM1" == "y" ]; then
TESTNUM=0
# A101 build tests spanning all modules
try_command "helloworld" make $VERBOSE
# set this large enough to handle the biggest individual module (OCF now)
ROMSIZE=215
# individually test build modules with short names (ten chars or less)
SHORTMODULES=(aio ble dgram events gpio grove_lcd i2c k64f_pins ocf pwm \
uart)
for index in "${!SHORTMODULES[@]}"; do
MODULE=${SHORTMODULES[index]}
echo "var module = require('$MODULE');" > $TMPFILE
try_command "$MODULE" make $VERBOSE JS=$TMPFILE ROM=$ROMSIZE
done
# individually test build modules with long names, supplying short labels
LONGMODULES=(arduino101_pins performance)
LONGLABELS=(a101_pins perf)
for index in "${!LONGMODULES[@]}"; do
MODULE=${LONGMODULES[index]}
LABEL=${LONGLABELS[index]}
echo "var module = require('$MODULE');" > $TMPFILE
try_command "$LABEL" make $VERBOSE JS=$TMPFILE
done
# individually test A101 sensors
SENSORS=(Accelerometer Gyroscope AmbientLightSensor)
SENSORLABELS=(accelerom gyroscope ambient)
for index in "${!SENSORS[@]}"; do
MODULE=${SENSORS[index]}
LABEL=${SENSORLABELS[index]}
echo "var sensor = $MODULE({});" > $TMPFILE
try_command "$LABEL" make $VERBOSE JS=$TMPFILE
done
# individually test special modules
echo "var buf = new Buffer(10);" > $TMPFILE
try_command "buffer" make $VERBOSE JS=$TMPFILE
echo "console.log(3.14159);" > $TMPFILE
try_command "console" make $VERBOSE JS=$TMPFILE
try_command "floats" make $VERBOSE JS=$TMPFILE PRINT_FLOAT=on
echo "setTimeout(function() {}, 10);" > $TMPFILE
try_command "timers" make $VERBOSE JS=$TMPFILE
# test key sample code
try_command "btgrove" make $VERBOSE JS=samples/WebBluetoothGroveLcdDemo.js ROM=256
# test snapshot off
try_command "snapoff" make $VERBOSE SNAPSHOT=off
# test debug build
try_command "debug" make $VERBOSE VARIANT=debug
# test RAM size change
try_command "ram" make $VERBOSE RAM=70
# k64f build tests
git clean -dfx
try_command "k64f_hello" make $VERBOSE BOARD=frdm_k64f
fi
#
# Tests from VM #2
#
function check_jstring_util() {
CALLCOUNT=$(grep jerry_string_to_char_buffer src/zjs_util.c | wc -l)
# make sure there are exactly two calls to the function
if [ "$CALLCOUNT" != "2" ]; then
echo "Error: Expected two calls to jerry_string_to_char_buffer in zjs_util.c!"
echo "Use zjs_copy_jstring and zjs_alloc_from_jstring instead."
return 1;
fi
}
function check_jstring_others() {
SRCFILES=$(find src -name "*.[ch]" | grep -v zjs_util.c)
# make sure there are no other calls to the function
if grep jerry_string_to_char_buffer $SRCFILES; then
echo
echo "Error: Found calls to jerry_string_to_char_buffer outside zjs_util.c!"
echo "Use zjs_copy_jstring and zjs_alloc_from_jstring instead."
return 1;
fi
}
if [ "$VM2" == "y" ]; then
TESTNUM=0
# git check
try_command "git check" git --no-pager diff --check $(git rev-list HEAD | tail -1)
# ensure only two uses of jerry_string_to_char_buffer in zjs_util.c
try_command "jstring1" check_jstring_util
# ensure no other source file uses jerry-string_to_char_buffer
try_command "jstring2" check_jstring_others
# linux build tests
try_command "linux" make $VERBOSE BOARD=linux
# linux unit tests
try_command "unit tests" ./outdir/linux/release/jslinux --unittest
fi
#
# Tests from VM #3
#
if [ "$VM3" == "y" ]; then
TESTNUM=0
# ashell tests
git clean -dfx
try_command "ashell" make $VERBOSE DEV=ashell ROM=256
fi
# clean up on success
cd $ZJS_BASE
rm -rf $TRLDIR
|