# # 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 </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 " 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 <