1# 2# SPDX-License-Identifier: Apache-2.0 3# 4# Copyright (C) 2015, ARM Limited and contributors. 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); you may 7# not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19# LISA Shell: the Linux Integrated System Analysis Shell 20 21# Setup colors 22source src/shell/lisa_colors 23 24# By default use internal libraries 25DEVMODE=${DEVMODE:-1} 26 27# Get base installation path of LISA 28export LISA_HOME="$(pwd)" 29 30# Run any android scripts before launching 31android_pre=$LISA_HOME/src/shell/android-pre.sh 32if [ -f $android_pre ]; then 33 source $android_pre; 34fi 35 36export PYTHONPATH='' 37export PYTHONPATH=$LISA_HOME/libs/utils:$PYTHONPATH 38export PYTHONPATH=$LISA_HOME/libs/wlgen:$PYTHONPATH 39export PYTHONPATH=$LISA_HOME:$PYTHONPATH 40 41if [ "x$DEVMODE" == "x1" ]; then 42 export PYTHONPATH=$LISA_HOME/libs/devlib:$PYTHONPATH 43 export PYTHONPATH=$LISA_HOME/libs/trappy:$PYTHONPATH 44 export PYTHONPATH=$LISA_HOME/libs/bart:$PYTHONPATH 45fi 46 47################################################################################ 48# Generic LISA Shell commands 49################################################################################ 50 51# LISA Shell On-Line HELP 52function lisa-help { 53clear 54echo -ne '\E[37;42m' 55echo " " 56echo " .:: LISA Shell - HELP On-Line ::. " 57echo " " 58echo -ne "$LISASHELL_RESET$LISASHELL_GREEN" 59cat $LISA_HOME/LisaShell.txt 60echo -ne "$LISASHELL_DEFAULT" 61} 62 63function lisa-version { 64echo -ne "$LISASHELL_GREEN" 65cat <<EOF 66 67.:: LISA ($(git describe --all)) 68 69Submodules version: 70$(git submodule status) 71 72 73EOF 74echo -ne "$LISASHELL_DEFAULT" 75} 76 77################################################################################ 78# LISA Update utility functions 79################################################################################ 80 81function _lisa-update-usage { 82 echo "Usage: lisa-update (CMD)" 83 echo " CMD: what to update (default: all)" 84 echo " all - update lisa and all the external dependencies" 85 echo " submodules - update external dependencies provided by submodules" 86 echo 87 echo "Update submodules (if DEVMODE enabled)" 88} 89 90function _lisa-update-submodules { 91echo -ne "${LISASHELL_BLUE}" 92if [ "x$DEVMODE" == "x1" ]; then 93 # Force update existing modules 94 echo 95 echo 'Developer mode ENABLED, updating local libraries...' 96 git submodule sync 97 git submodule update --init 98 echo 'DONE' 99fi 100echo -ne "$LISASHELL_DEFAULT" 101} 102 103function _lisa-update-all { 104echo -ne "${LISASHELL_BLUE}" 105echo -e "*** Update LISA installation" 106 107git update-index -q --refresh 108ret=$? 109if [ $ret -ne 0 ]; then 110 echo "LISA internal error: git update-index failed" 111 echo "Please report it: https://github.com/ARM-software/lisa/issues" 112 return $ret 113fi 114 115git diff-index --quiet --ignore-submodules HEAD 116ret=$? 117if [ $ret -ne 0 ]; then 118 echo "There are outstanding uncommitted changes." 119 echo "Please, commit your changes or stash them before you can update lisa" 120 return $ret 121fi 122 123curr_commit=$(git rev-parse HEAD) 124remote_name=$(git remote -v | grep ARM-software/lisa | grep -m 1 fetch | awk '{print $1}') 125git merge-base --is-ancestor $curr_commit $remote_name/master 126ret=$? 127if [ $ret -ne 0 ]; then 128 echo "You have committed changes that are not part of $remote_name/master" 129 echo "Please move to the master branch before running lisa-update" 130 return $ret 131fi 132 133git pull --ff-only $remote_name master 134ret=$? 135if [ $ret -ne 0 ]; then 136 # git pull should have printed some error. Abort and propagate the error code. 137 return $ret 138fi 139 140_lisa-update-submodules 141 142echo -ne "$LISASHELL_DEFAULT" 143} 144 145function lisa-update { 146CMD=${1:-all} 147echo 148case "x${CMD^^}" in 149'xSUBMODULES') 150 _lisa-update-submodules 151 ;; 152'xALL') 153 _lisa-update-all 154 ;; 155"xHELP"|*) 156 _lisa-update-usage 157 ;; 158esac 159echo 160echo 161} 162 163################################################################################ 164# LISA Notebooks utility functions 165################################################################################ 166 167function _lisa-ipython-usage { 168 echo "Usage: lisa-ipython CMD [NETIF [PORT]]" 169 echo " CMD - IPython Notebooks command (deafult: start)" 170 echo " start start the ipython server" 171 echo " stop stop the ipython server" 172 echo " NETIF - the network interface to start the server on (default: lo)" 173 echo " PORT - the tcp port for the server (default: 8888)" 174} 175 176function _lisa-ipython-start { 177# Get IP address for the specified interface 178IPADDR=$(/sbin/ifconfig $NETIF 2>/dev/null | \ 179 awk '/inet / {print $2}' | \ 180 sed 's/addr://') 181if [ "x$IPADDR" == "x" ]; then 182 echo 183 echo "$NETIF is not a valid network interface" 184 echo 185 echo "Usage: $0 <NETIF>" 186 echo " NETIF - The network interface to start the server on" 187 echo 188 return 1 189fi 190# Setup paths 191PYDIR="$LISA_HOME/ipynb" 192LOGFILE="$PYDIR/server.log" 193PIDFILE="$PYDIR/server.pid" 194URLFILE="$PYDIR/server.url" 195 196# Generate server URL 197TOKEN=$(cat /dev/urandom | tr -dc 'a-fA-F0-9' | fold -w 48 | head -n 1) 198URL="http://$IPADDR:$PORT/?token=$TOKEN" 199 200# Check if an instance is already running 201if [ -f "$PIDFILE" ] && pgrep -F $PIDFILE >/dev/null; then 202 echo "Server already running:" 203 echo " " $(cat $URLFILE) 204 xdg-open $(cat $URLFILE) 205 return 1 206fi 207 208# Start the server bindeed to the specified interface 209echo 210echo 'Notebook server configuration:' 211echo ' URL : ' $URL 212echo ' Folder : ' $PYDIR 213echo ' Logfile : ' $LOGFILE 214echo ' PYTHONPATH : ' 215echo -e "\t${PYTHONPATH//:/\\n\\t}" 216cd $PYDIR 217echo 218echo -n 'Notebook server task: ' 219if which ipython >/dev/null; then 220 local cmd=ipython 221else 222 local cmd=jupyter 223fi 224nohup $cmd notebook --ip=$IPADDR --port=$PORT \ 225 --NotebookApp.token=$TOKEN \ 226 >$LOGFILE 2>&1 & 227echo $! >$PIDFILE 228echo $URL >$URLFILE 229cd - >/dev/null 230} 231 232function _lisa-ipython-stop { 233PYDIR="$LISA_HOME/ipynb" 234PIDFILE="$PYDIR/server.pid" 235if [ -f "$PIDFILE" ] && pgrep -F $PIDFILE >/dev/null; then 236 kill $(<$PIDFILE) 2>/dev/null 237fi 238rm -f $PIDFILE 2>/dev/null 239} 240 241function lisa-ipython { 242CMD=${1:-start} 243 244if [ "x$2" == "x" -a $USER == "vagrant" -a -e /vagrant/src/shell/lisa_shell ]; then 245 # NETIF not set and we are in a vagrant environment. Default to 246 # eth0 as loopback won't let you connect from your host machine. 247 NETIF="eth0" 248else 249 NETIF=${2:-lo} 250fi 251 252PORT=${3:-8888} 253echo 254case "x${CMD^^}" in 255'xSTART') 256 echo "Starting IPython Notebooks..." 257 _lisa-ipython-start $NETIF $PORT 258 ;; 259'xSTOP') 260 echo "Stopping IPython Notebooks..." 261 _lisa-ipython-stop 262 ;; 263"xHELP"|*) 264 _lisa-ipython-usage 265 ;; 266esac 267echo 268echo 269} 270 271function lisa-check-submods { 272if [ ! -f ./libs/devlib/setup.py ] || 273 [ ! -f ./libs/bart/setup.py ] || 274 [ ! -f ./libs/trappy/setup.py ]; then 275 echo "One or more submodules missing, updating"; 276 lisa-update submodules 277fi 278} 279 280################################################################################ 281# LISA Tests utility functions 282################################################################################ 283 284function _lisa-test-usage { 285cat <<EOF 286Usage: lisa-test [args] FILE[:CLASS] 287 Run automated tests. Tests can be found under the tests/ directory. 288 289 This is a wrapper for the 'nosetests' utility, additional arguments are passed 290 to that tool. 291 292 Examples: 293 Run all EAS Acceptance tests: 294 295 lisa-test tests/eas/acceptance.py 296 297 Run ForkMigration test from EAS Acceptance suite: 298 299 lisa-test tests/eas/acceptance.py:ForkMigration 300 301 Run ForkMigration test from EAS Acceptance suite, generating an XML test 302 report via nose's XUnit plugin (see nosetests documentation): 303 304 lisa-test --with-xunit --xunit-file=report.xml tests/eas/acceptance.py:ForkMigration 305 306EOF 307} 308 309function _lisa-test { 310nosetests -v --nocapture --nologcapture \ 311 --logging-config=logging.conf \ 312 $* 313} 314 315function lisa-test { 316CMD=${1:-help} 317echo 318case "x${CMD^^}" in 319"xHELP") 320 _lisa-test-usage 321 ;; 322*) 323 _lisa-test $* 324 local retcode=$? 325esac 326echo 327echo 328return $retcode 329} 330 331function lisa-report { 332CMD=${1^^} 333[ "x$CMD" != "xHELP" ] && CMD=report 334echo 335case "x${CMD^^}" in 336'xREPORT') 337 ./tools/report.py $* 338 ;; 339"xHELP"|*) 340 ./tools/report.py --help 341 ;; 342esac 343echo 344echo 345} 346 347 348################################################################################ 349# LISA Shell MAIN 350################################################################################ 351 352# Setup Shell variables 353PS1="\[${LISASHELL_BLUE}\][LISAShell \[${LISASHELL_LCYAN}\]\W\[${LISASHELL_BLUE}\]] \> \[${LISASHELL_RESET}\]" 354 355# Dump out a nice LISA Shell logo 356clear 357 358# Android post shell initialization script 359android_post=$LISA_HOME/src/shell/android-post.sh 360if [ -f $android_post ]; then 361 source $android_post; 362fi 363 364echo -e '\E[37;44m' 365 366echo " " 367echo " .:: LISA Shell ::. " 368echo " " 369echo -ne "$LISASHELL_RESET$LISASHELL_BLUE" 370cat <<EOF 371 372Welcome to the Linux Integrated System Analysis SHELL! 373 374LISA_HOME : $LISA_HOME 375PYTHONPATH : 376EOF 377echo -e "\t${PYTHONPATH//:/\\n\\t}" 378 379if [ "x$DEVMODE" == "x1" ]; then 380lisa-check-submods 381cat <<EOF 382Submodules : 383EOF 384git submodule status 385fi 386 387cat <<EOF 388 389 390Type "lisa-help" for on-line help on available commands 391 392EOF 393 394# Setup default SHELL text color 395echo -e "$LISASHELL_DEFAULT" 396 397# vim: set tabstop=4: 398