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 22 source src/shell/lisa_colors 23 24 # By default use internal libraries 25 DEVMODE=${DEVMODE:-1} 26 27 # Get base installation path of LISA 28 export LISA_HOME="$(pwd)" 29 30 # Run any android scripts before launching 31 android_pre=$LISA_HOME/src/shell/android-pre.sh 32 if [ -f $android_pre ]; then 33 source $android_pre; 34 fi 35 36 export PYTHONPATH='' 37 export PYTHONPATH=$LISA_HOME/libs/utils:$PYTHONPATH 38 export PYTHONPATH=$LISA_HOME/libs/wlgen:$PYTHONPATH 39 export PYTHONPATH=$LISA_HOME:$PYTHONPATH 40 41 if [ "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 45 fi 46 47 ################################################################################ 48 # Generic LISA Shell commands 49 ################################################################################ 50 51 # LISA Shell On-Line HELP 52 function lisa-help { 53 clear 54 echo -ne '\E[37;42m' 55 echo " " 56 echo " .:: LISA Shell - HELP On-Line ::. " 57 echo " " 58 echo -ne "$LISASHELL_RESET$LISASHELL_GREEN" 59 cat $LISA_HOME/LisaShell.txt 60 echo -ne "$LISASHELL_DEFAULT" 61 } 62 63 function lisa-version { 64 echo -ne "$LISASHELL_GREEN" 65 cat <<EOF 66 67 .:: LISA ($(git describe --all)) 68 69 Submodules version: 70 $(git submodule status) 71 72 73 EOF 74 echo -ne "$LISASHELL_DEFAULT" 75 } 76 77 ################################################################################ 78 # LISA Update utility functions 79 ################################################################################ 80 81 function _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 90 function _lisa-update-submodules { 91 echo -ne "${LISASHELL_BLUE}" 92 if [ "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' 99 fi 100 echo -ne "$LISASHELL_DEFAULT" 101 } 102 103 function _lisa-update-all { 104 echo -ne "${LISASHELL_BLUE}" 105 echo -e "*** Update LISA installation" 106 107 git update-index -q --refresh 108 ret=$? 109 if [ $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 113 fi 114 115 git diff-index --quiet --ignore-submodules HEAD 116 ret=$? 117 if [ $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 121 fi 122 123 curr_commit=$(git rev-parse HEAD) 124 remote_name=$(git remote -v | grep -i ARM-software/lisa | grep -m 1 fetch | awk '{print $1}') 125 if [ -z "$remote_name" ]; then 126 echo "Couldn't find ARM-Software upstream remote, can't automatically update" 127 return 1 128 fi 129 git merge-base --is-ancestor $curr_commit $remote_name/master 130 ret=$? 131 if [ $ret -ne 0 ]; then 132 echo "You have committed changes that are not part of $remote_name/master" 133 echo "Please move to the master branch before running lisa-update" 134 return $ret 135 fi 136 137 git pull --ff-only $remote_name master 138 ret=$? 139 if [ $ret -ne 0 ]; then 140 # git pull should have printed some error. Abort and propagate the error code. 141 return $ret 142 fi 143 144 _lisa-update-submodules 145 146 echo -ne "$LISASHELL_DEFAULT" 147 } 148 149 function lisa-update { 150 CMD=${1:-all} 151 echo 152 case "x${CMD^^}" in 153 'xSUBMODULES') 154 _lisa-update-submodules 155 ;; 156 'xALL') 157 _lisa-update-all 158 ;; 159 "xHELP"|*) 160 _lisa-update-usage 161 ;; 162 esac 163 echo 164 echo 165 } 166 167 ################################################################################ 168 # LISA Notebooks utility functions 169 ################################################################################ 170 171 function _lisa-ipython-usage { 172 echo "Usage: lisa-ipython CMD [NETIF [PORT]]" 173 echo " CMD - IPython Notebooks command (deafult: start)" 174 echo " start start the ipython server" 175 echo " stop stop the ipython server" 176 echo " NETIF - the network interface to start the server on (default: lo)" 177 echo " PORT - the tcp port for the server (default: 8888)" 178 } 179 180 function _lisa-ipython-start { 181 # Get IP address for the specified interface 182 IPADDR=$(/sbin/ifconfig $NETIF 2>/dev/null | \ 183 awk '/inet / {print $2}' | \ 184 sed 's/addr://') 185 if [ "x$IPADDR" == "x" ]; then 186 echo 187 echo "$NETIF is not a valid network interface" 188 echo 189 echo "Usage: $0 <NETIF>" 190 echo " NETIF - The network interface to start the server on" 191 echo 192 return 1 193 fi 194 # Setup paths 195 PYDIR="$LISA_HOME/ipynb" 196 LOGFILE="$PYDIR/server.log" 197 PIDFILE="$PYDIR/server.pid" 198 URLFILE="$PYDIR/server.url" 199 200 # Generate server URL 201 TOKEN=$(cat /dev/urandom | tr -dc 'a-fA-F0-9' | fold -w 48 | head -n 1) 202 URL="http://$IPADDR:$PORT/?token=$TOKEN" 203 204 # Check if an instance is already running 205 if [ -f "$PIDFILE" ] && pgrep -F $PIDFILE >/dev/null; then 206 echo "Server already running:" 207 echo " " $(cat $URLFILE) 208 xdg-open $(cat $URLFILE) 209 return 1 210 fi 211 212 # Start the server bindeed to the specified interface 213 echo 214 echo 'Notebook server configuration:' 215 echo ' URL : ' $URL 216 echo ' Folder : ' $PYDIR 217 echo ' Logfile : ' $LOGFILE 218 echo ' PYTHONPATH : ' 219 echo -e "\t${PYTHONPATH//:/\\n\\t}" 220 cd $PYDIR 221 echo 222 echo -n 'Notebook server task: ' 223 if which ipython >/dev/null; then 224 local cmd=ipython 225 else 226 local cmd=jupyter 227 fi 228 nohup $cmd notebook --ip=$IPADDR --port=$PORT \ 229 --NotebookApp.token=$TOKEN \ 230 >$LOGFILE 2>&1 & 231 echo $! >$PIDFILE 232 echo $URL >$URLFILE 233 cd - >/dev/null 234 } 235 236 function _lisa-ipython-stop { 237 PYDIR="$LISA_HOME/ipynb" 238 PIDFILE="$PYDIR/server.pid" 239 if [ -f "$PIDFILE" ] && pgrep -F $PIDFILE >/dev/null; then 240 kill $(<$PIDFILE) 2>/dev/null 241 fi 242 rm -f $PIDFILE 2>/dev/null 243 } 244 245 function lisa-ipython { 246 CMD=${1:-start} 247 248 if [ "x$2" == "x" -a $USER == "vagrant" -a -e /vagrant/src/shell/lisa_shell ]; then 249 # NETIF not set and we are in a vagrant environment. Default to 250 # eth0 as loopback won't let you connect from your host machine. 251 NETIF="eth0" 252 else 253 NETIF=${2:-lo} 254 fi 255 256 PORT=${3:-8888} 257 echo 258 case "x${CMD^^}" in 259 'xSTART') 260 echo "Starting IPython Notebooks..." 261 _lisa-ipython-start $NETIF $PORT 262 ;; 263 'xSTOP') 264 echo "Stopping IPython Notebooks..." 265 _lisa-ipython-stop 266 ;; 267 "xHELP"|*) 268 _lisa-ipython-usage 269 ;; 270 esac 271 echo 272 echo 273 } 274 275 function lisa-check-submods { 276 if [ ! -f ./libs/devlib/setup.py ] || 277 [ ! -f ./libs/bart/setup.py ] || 278 [ ! -f ./libs/trappy/setup.py ]; then 279 echo "One or more submodules missing, updating"; 280 lisa-update submodules 281 fi 282 } 283 284 ################################################################################ 285 # LISA Tests utility functions 286 ################################################################################ 287 288 function _lisa-test-usage { 289 cat <<EOF 290 Usage: lisa-test [--iterations ITERATIONS] [args] FILE[:CLASS] 291 Run automated tests. Tests can be found under the tests/ directory. 292 293 --iterations (or -n) sets the number of iterations to use for 294 each workload/target-conf, for tests that support this usage. 0 means use 295 the test's default iteration count. 296 297 This is a wrapper for the 'nosetests' utility, additional arguments are passed 298 to that tool. 299 300 Examples: 301 Run all EAS Generic tests: 302 303 lisa-test tests/eas/generic.py 304 305 Run RampUp test from EAS Generic suite: 306 307 lisa-test tests/eas/generic.py:RampUp 308 309 Run RampUp test from EAS Generic suite, generating an XML test 310 report via nose's XUnit plugin (see nosetests documentation): 311 312 lisa-test --with-xunit --xunit-file=report.xml tests/eas/generic.py:RampUp 313 314 Run RampUp test from EAS Generic suite, repeating the 315 workload 10 times and reporting how many times the test run 316 passed: 317 318 lisa-test --iterations 10 tests/eas/generic.py:RampUp 319 320 Run EAS Generic suite, repeating each workload 10 times: 321 322 lisa-test --iterations 10 tests/eas/generic.py 323 EOF 324 } 325 326 function _lisa-test { 327 nosetests -v --nocapture --nologcapture \ 328 --logging-config=logging.conf \ 329 $* 330 } 331 332 function lisa-test { 333 local iterations=0 # Means use default - see libs/utils/test.py 334 local extra_args="" 335 336 echo 337 while [[ $# -gt 0 ]]; do 338 case "$1" in 339 help|-h|--help) 340 _lisa-test-usage 341 return 0 342 ;; 343 -n|--iterations) 344 iterations="$2" 345 shift 346 ;; 347 *) 348 # Unrecognised args are passed through to nosetests 349 extra_args="$extra_args $1" 350 ;; 351 esac 352 shift 353 done 354 355 if [ -z "$extra_args" ]; then 356 # No arguments provided, default to "help" 357 _lisa-test-usage 358 return 1 359 fi 360 361 (export LISA_TEST_ITERATIONS=$iterations; _lisa-test $extra_args) 362 local retcode=$? 363 echo 364 echo 365 return $retcode 366 } 367 368 function lisa-report { 369 CMD=${1^^} 370 [ "x$CMD" != "xHELP" ] && CMD=report 371 echo 372 case "x${CMD^^}" in 373 'xREPORT') 374 ./tools/report.py $* 375 ;; 376 "xHELP"|*) 377 ./tools/report.py --help 378 ;; 379 esac 380 echo 381 echo 382 } 383 384 385 ################################################################################ 386 # LISA Shell MAIN 387 ################################################################################ 388 389 # Setup Shell variables 390 PS1="\[${LISASHELL_BLUE}\][LISAShell \[${LISASHELL_LCYAN}\]\W\[${LISASHELL_BLUE}\]] \> \[${LISASHELL_RESET}\]" 391 392 # Dump out a nice LISA Shell logo 393 clear 394 395 # Android post shell initialization script 396 android_post=$LISA_HOME/src/shell/android-post.sh 397 if [ -f $android_post ]; then 398 source $android_post; 399 fi 400 401 echo -e '\E[37;44m' 402 403 echo " " 404 echo " .:: LISA Shell ::. " 405 echo " " 406 echo -ne "$LISASHELL_RESET$LISASHELL_BLUE" 407 cat <<EOF 408 409 Welcome to the Linux Integrated System Analysis SHELL! 410 411 LISA_HOME : $LISA_HOME 412 PYTHONPATH : 413 EOF 414 echo -e "\t${PYTHONPATH//:/\\n\\t}" 415 416 if [ "x$DEVMODE" == "x1" ]; then 417 lisa-check-submods 418 cat <<EOF 419 Submodules : 420 EOF 421 git submodule status 422 fi 423 424 cat <<EOF 425 426 427 Type "lisa-help" for on-line help on available commands 428 429 EOF 430 431 # Setup default SHELL text color 432 echo -e "$LISASHELL_DEFAULT" 433 434 # vim: set tabstop=4: 435