aboutsummaryrefslogtreecommitdiff
path: root/src/shell/lisa_shell
blob: 37cc0c3e08aa13022ceac34321778f1e39fc97cb (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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
#
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (C) 2015, ARM Limited and contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# LISA Shell: the Linux Integrated System Analysis Shell

# Setup colors
source src/shell/lisa_colors

# By default use internal libraries
DEVMODE=${DEVMODE:-1}

# Get base installation path of LISA
export LISA_HOME="$(pwd)"

# Run any android scripts before launching
android_pre=$LISA_HOME/src/shell/android-pre.sh
if [ -f $android_pre ]; then
	source $android_pre;
fi

export PYTHONPATH=''
export PYTHONPATH=$LISA_HOME/libs/utils:$PYTHONPATH
export PYTHONPATH=$LISA_HOME/libs/wlgen:$PYTHONPATH
export PYTHONPATH=$LISA_HOME:$PYTHONPATH

if [ "x$DEVMODE" == "x1" ]; then
	export PYTHONPATH=$LISA_HOME/libs/devlib:$PYTHONPATH
	export PYTHONPATH=$LISA_HOME/libs/trappy:$PYTHONPATH
	export PYTHONPATH=$LISA_HOME/libs/bart:$PYTHONPATH
fi

################################################################################
# Generic LISA Shell commands
################################################################################

# LISA Shell On-Line HELP
function lisa-help {
clear
echo -ne '\E[37;42m'
echo "                                                                               "
echo "                    .:: LISA Shell - HELP On-Line ::.                          "
echo "                                                                               "
echo -ne "$LISASHELL_RESET$LISASHELL_GREEN"
cat $LISA_HOME/LisaShell.txt
echo -ne "$LISASHELL_DEFAULT"
}

function lisa-version {
echo -ne "$LISASHELL_GREEN"
cat <<EOF

.:: LISA ($(git describe --all))

Submodules version:
$(git submodule status)


EOF
echo -ne "$LISASHELL_DEFAULT"
}

################################################################################
# LISA Update utility functions
################################################################################

function _lisa-update-usage {
    echo "Usage: lisa-update (CMD)"
	echo "  CMD: what to update (default: all)"
	echo "       all - update lisa and all the external dependencies"
	echo "       submodules - update external dependencies provided by submodules"
	echo
    echo "Update submodules (if DEVMODE enabled)"
}

function _lisa-update-submodules {
echo -ne "${LISASHELL_BLUE}"
if [ "x$DEVMODE" == "x1" ]; then
	# Force update existing modules
	echo
	echo 'Developer mode ENABLED, updating local libraries...'
	git submodule sync
	git submodule update --init
	echo 'DONE'
fi
echo -ne "$LISASHELL_DEFAULT"
}

function _lisa-update-all {
echo -ne "${LISASHELL_BLUE}"
echo -e "*** Update LISA installation"

git update-index -q --refresh
ret=$?
if [ $ret -ne 0 ]; then
    echo "LISA internal error: git update-index failed"
    echo "Please report it: https://github.com/ARM-software/lisa/issues"
    return $ret
fi

git diff-index --quiet --ignore-submodules HEAD
ret=$?
if [ $ret -ne 0 ]; then
    echo "There are outstanding uncommitted changes."
    echo "Please, commit your changes or stash them before you can update lisa"
    return $ret
fi

curr_commit=$(git rev-parse HEAD)
remote_name=$(git remote -v | grep -i ARM-software/lisa | grep -m 1 fetch | awk '{print $1}')
if [ -z "$remote_name" ]; then
    echo "Couldn't find ARM-Software upstream remote, can't automatically update"
    return 1
fi
git merge-base --is-ancestor $curr_commit $remote_name/master
ret=$?
if [ $ret -ne 0 ]; then
    echo "You have committed changes that are not part of $remote_name/master"
    echo "Please move to the master branch before running lisa-update"
    return $ret
fi

git pull --ff-only $remote_name master
ret=$?
if [ $ret -ne 0 ]; then
    # git pull should have printed some error.  Abort and propagate the error code.
    return $ret
fi

_lisa-update-submodules

echo -ne "$LISASHELL_DEFAULT"
}

function lisa-update {
CMD=${1:-all}
echo
case "x${CMD^^}" in
'xSUBMODULES')
	_lisa-update-submodules
	;;
'xALL')
	_lisa-update-all
	;;
"xHELP"|*)
	_lisa-update-usage
	;;
esac
echo
echo
}

################################################################################
# LISA Notebooks utility functions
################################################################################

function _lisa-ipython-usage {
    echo "Usage: lisa-ipython CMD [NETIF [PORT]]"
	echo " CMD     - IPython Notebooks command (deafult: start)"
	echo "  start  start the ipython server"
	echo "   stop  stop the ipython server"
    echo " NETIF   - the network interface to start the server on (default: lo)"
    echo " PORT    - the tcp port for the server (default: 8888)"
}

function _lisa-ipython-start {
# Get IP address for the specified interface
IPADDR=$(/sbin/ifconfig $NETIF 2>/dev/null  | \
	awk '/inet / {print $2}' | \
	sed 's/addr://')
if [ "x$IPADDR" == "x" ]; then
    echo
    echo "$NETIF is not a valid network interface"
    echo
    echo "Usage: $0 <NETIF>"
    echo " NETIF - The network interface to start the server on"
    echo
    return 1
fi
# Setup paths
PYDIR="$LISA_HOME/ipynb"
LOGFILE="$PYDIR/server.log"
PIDFILE="$PYDIR/server.pid"
URLFILE="$PYDIR/server.url"

# Generate server URL
TOKEN=$(cat /dev/urandom | tr -dc 'a-fA-F0-9' | fold -w 48 | head -n 1)
URL="http://$IPADDR:$PORT/?token=$TOKEN"

# Check if an instance is already running
if [ -f "$PIDFILE" ] && pgrep -F $PIDFILE >/dev/null; then
	echo "Server already running:"
    echo "  " $(cat $URLFILE)
    xdg-open $(cat $URLFILE)
	return 1
fi

# Start the server bindeed to the specified interface
echo
echo 'Notebook server configuration:'
echo '  URL        : ' $URL
echo '  Folder     : ' $PYDIR
echo '  Logfile    : ' $LOGFILE
echo '  PYTHONPATH : '
echo -e "\t${PYTHONPATH//:/\\n\\t}"
cd $PYDIR
echo
echo -n 'Notebook server task: '
if which ipython >/dev/null; then
    local cmd=ipython
else
    local cmd=jupyter
fi
nohup $cmd notebook --ip=$IPADDR --port=$PORT \
                    --NotebookApp.token=$TOKEN \
                    >$LOGFILE 2>&1 &
echo $! >$PIDFILE
echo $URL >$URLFILE
cd - >/dev/null
}

function _lisa-ipython-stop {
PYDIR="$LISA_HOME/ipynb"
PIDFILE="$PYDIR/server.pid"
if [ -f "$PIDFILE" ] && pgrep -F $PIDFILE >/dev/null; then
	kill $(<$PIDFILE) 2>/dev/null
fi
rm -f $PIDFILE 2>/dev/null
}

function lisa-ipython {
CMD=${1:-start}

if [ "x$2" == "x" -a $USER == "vagrant" -a -e /vagrant/src/shell/lisa_shell ]; then
    # NETIF not set and we are in a vagrant environment.  Default to
    # eth0 as loopback won't let you connect from your host machine.
    NETIF="eth0"
else
    NETIF=${2:-lo}
fi

PORT=${3:-8888}
echo
case "x${CMD^^}" in
'xSTART')
	echo "Starting IPython Notebooks..."
	_lisa-ipython-start $NETIF $PORT
	;;
'xSTOP')
	echo "Stopping IPython Notebooks..."
	_lisa-ipython-stop
	;;
"xHELP"|*)
	_lisa-ipython-usage
	;;
esac
echo
echo
}

function lisa-check-submods {
if [ ! -f ./libs/devlib/setup.py ] ||
   [ ! -f ./libs/bart/setup.py ] ||
   [ ! -f ./libs/trappy/setup.py ]; then
	echo "One or more submodules missing, updating";
	lisa-update submodules
fi
}

################################################################################
# LISA Tests utility functions
################################################################################

function _lisa-test-usage {
cat <<EOF
Usage: lisa-test [--iterations ITERATIONS] [args] FILE[:CLASS]
  Run automated tests. Tests can be found under the tests/ directory.

  --iterations (or -n) sets the number of iterations to use for
    each workload/target-conf, for tests that support this usage. 0 means use
    the test's default iteration count.

  This is a wrapper for the 'nosetests' utility, additional arguments are passed
  to that tool.

  Examples:
    Run all EAS Generic tests:

      lisa-test tests/eas/generic.py

    Run RampUp test from EAS Generic suite:

      lisa-test tests/eas/generic.py:RampUp

    Run RampUp test from EAS Generic suite, generating an XML test
    report via nose's XUnit plugin (see nosetests documentation):

      lisa-test --with-xunit --xunit-file=report.xml tests/eas/generic.py:RampUp

    Run RampUp test from EAS Generic suite, repeating the
    workload 10 times and reporting how many times the test run
    passed:

      lisa-test --iterations 10 tests/eas/generic.py:RampUp

    Run EAS Generic suite, repeating each workload 10 times:

      lisa-test --iterations 10 tests/eas/generic.py
EOF
}

function _lisa-test {
nosetests -v --nocapture --nologcapture \
          --logging-config=logging.conf \
          $*
}

function lisa-test {
local iterations=0 # Means use default - see libs/utils/test.py
local extra_args=""

echo
while [[ $# -gt 0 ]]; do
        case "$1" in
                help|-h|--help)
                        _lisa-test-usage
                        return 0
                        ;;
                -n|--iterations)
                        iterations="$2"
                        shift
                        ;;
                *)
                        # Unrecognised args are passed through to nosetests
                        extra_args="$extra_args $1"
                        ;;
        esac
        shift
done

if [ -z "$extra_args" ]; then
        # No arguments provided, default to "help"
        _lisa-test-usage
        return 1
fi

(export LISA_TEST_ITERATIONS=$iterations; _lisa-test $extra_args)
local retcode=$?
echo
echo
return $retcode
}

function lisa-report {
CMD=${1^^}
[ "x$CMD" != "xHELP" ] && CMD=report
echo
case "x${CMD^^}" in
'xREPORT')
	./tools/report.py $*
	;;
"xHELP"|*)
	./tools/report.py --help
	;;
esac
echo
echo
}


################################################################################
# LISA Shell MAIN
################################################################################

# Setup Shell variables
PS1="\[${LISASHELL_BLUE}\][LISAShell \[${LISASHELL_LCYAN}\]\W\[${LISASHELL_BLUE}\]] \> \[${LISASHELL_RESET}\]"

# Dump out a nice LISA Shell logo
clear

# Android post shell initialization script
android_post=$LISA_HOME/src/shell/android-post.sh
if [ -f $android_post ]; then
	source $android_post;
fi

echo -e '\E[37;44m'

echo "                                                                               "
echo "                        .:: LISA Shell ::.                                     "
echo "                                                                               "
echo -ne "$LISASHELL_RESET$LISASHELL_BLUE"
cat <<EOF

Welcome to the Linux Integrated System Analysis SHELL!

LISA_HOME  : $LISA_HOME
PYTHONPATH :
EOF
echo -e "\t${PYTHONPATH//:/\\n\\t}"

if [ "x$DEVMODE" == "x1" ]; then
lisa-check-submods
cat <<EOF
Submodules :
EOF
git submodule status
fi

cat <<EOF


Type "lisa-help" for on-line help on available commands

EOF

# Setup default SHELL text color
echo -e "$LISASHELL_DEFAULT"

# vim: set tabstop=4: