#!/bin/bash # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # $Source: src/build/citest/autocitest $ # # IBM CONFIDENTIAL # # COPYRIGHT International Business Machines Corp. 2011,2014 # # p1 # # Object Code Only (OCO) source materials # Licensed Internal Code Source Materials # IBM HostBoot Licensed Internal Code # # The source code for this program is not published or otherwise # divested of its trade secrets, irrespective of what has been # deposited with the U.S. Copyright Office. # # Origin: 30 # # IBM_PROLOG_END_TAG ################################################################################ ## Simics automation using autosim ## 2011-05-23 mww modified to run hostboot in simics ## 2011-06-02 mww check in first working version. ## Profuse thanks to Patrick Williams for getting this going ## on the Jenkins server!! ## ## Usage: ## autocitest [--quiet] ################################################################################ function waitkb() { ## wait for kbhit to continue ## echo "Hit any key to continue" ## read kb echo "." } function usage() { echo "usage:" echo "$0 [--quiet] backing_tree_dir sandbox_name path_to_hbicore_test_img " } function stopsim() { # Stop simics echo "Stopping simics" autosim $NOWIN $VERBOSE --stopsim if [ $? -ne 0 ] ; then echo "WARNING: Unable to stop simics cleanly" fi } function stopserver() { # Stop simics server echo "Stopping simics server" autosim $NOWIN $VERBOSE --stopserver if [ $? -ne 0 ] ; then echo "WARNING: Unable to stop simics server cleanly" fi } function runtraceHB() { echo "Collect traceHB info..." `pwd` #autosim $NOWIN --simcmd "run-python-file ${SBXHOME}/src/build/simics/hb-simdebug.py" #if [ $? -ne 0 ] ; then # echo "ERROR 3: Unable to run $?" # stopsim # stopserver # exit 1 #fi autosim $NOWIN --simcmd "hb-trace" --timeout 300 if [ $? -ne 0 ] ; then echo "ERROR 4 : Unable to run $?" stopsim stopserver exit 1 fi } ## verbose is the default. VERBOSE=" --verbose" if [ "$1" = "--quiet" ] ; then VERBOSE="" shift fi ## ## set up ## DRIVER="$1" ## backing tree export bb=$DRIVER ## simulate a workon HBICORE_TEST="$2" ## path to hbicore_test.img export SHELL="/bin/bash" ## Needed to fool workon to launch a bash ## shell, which autosim expects. NOWIN="--nowin" ## remote execution does not have a display ## jenkins creates a new workspace for every compile. ## cxxtest-start.sh will verify this and then export WORKSPACE_DIR for us. SBXHOME=$HOSTBOOTROOT if [ "$DRIVER" = "" ] ; then echo "ERROR: you must specify a driver (backing tree) to run the tests with" usage exit 1 fi if [ ! -f "${SBXHOME}/${HBICORE_TEST}" ] ; then echo "ERROR: you must specify a valid hbicore_test.bin file." usage exit 1 fi ## Find the .syms file for the image. Remove extension, add .syms. HBICORE_TEST_SYMS="${HBICORE_TEST%%.*}.syms" CPFILES="${SBXHOME}/src/build/tools/hbDistribute" ## let's get set up cd $SBXHOME echo "$0" echo "VERBOSE = $VERBOSE" echo "NOWIN = $NOWIN" echo "BACKING_TREE = $DRIVER" echo "HBICORE_TEST = $HBICORE_TEST" echo "HBICORE_TEST_SYMS = $HBICORE_TEST_SYMS" echo "SANDBOXRC = $SANDBOXRC" echo "SBXHOME = $SBXHOME" echo "current directory is " `pwd` waitkb timestamp=`date +'%H:%M:%S'` echo "$timestamp Starting autosample test..." # Run set up in current shell echo "run autosimsetup.." export AUTOSIM_WORKDIR=$SANDBOXBASE . autosimsetup waitkb # Start the simics server echo "Starting simics server in sandbox $SANDBOXNAME on machine $MACHINE" autosim $NOWIN $VERBOSE --startserver --wp --sandbox $SANDBOXNAME --machine $MACHINE if [ $? -ne 0 ] ; then echo "ERROR: Unable to start simics server $?" exit 1 fi waitkb # Start simics and wait for it to reach standby echo "Starting simics" # If we are running under Jenkins, do "no remote execution" because built in # /tmp. if [ -z $RUNNING_UNDER_JENKINS -a -z $SANDBOX_IN_TEMP ]; then NRE="" else # Trick autosim into thinking we're running on a vexec system. echo "echo \"Running on server $HOSTNAME ---\"" >> \ ${SANDBOXBASE}/obj/ppc/simu/scripts/hbfw/startup.simics NRE="--sim_parms -nre" fi #autosim $VERBOSE --startsim --chkpt standby <<< chkpt not working yet autosim $NOWIN $VERBOSE --startsim $NRE if [ $? -ne 0 ] ; then echo "ERROR: Unable to start simics $?" stopserver ## kill the server again. exit 1 fi waitkb ## $$TODO Need to wait here for hostboot to finish ## for now just sleep for 20 seconds ## sleep 20 waitkb ## grep for totaltests, etc. These will appear in the hbicore_test.syms file and ## look like the following: ## V,000292b8,00000000,00000008,CxxTest::totaltests ## V,000292c0,00000000,00000008,CxxTest::tracecalls ## V,000292c8,00000000,00000008,CxxTest::warnings ## V,000292d0,00000000,00000008,CxxTest::failedtests ## V,00017888,00000000,00004000,kernel_printk_buffer ## grep for the globals echo "find totaltests, etc in ${SBXHOME}/${HBICORE_TEST_SYMS}" printk_buffer_addr=`grep "kernel_printk_buffer" \ ${SBXHOME}/${HBICORE_TEST_SYMS} | awk '{split($0,a,","); print a[2]}'` printk_buffer_size=`grep "kernel_printk_buffer" \ ${SBXHOME}/${HBICORE_TEST_SYMS} | awk '{split($0,a,","); print a[4]}'` totaltests_addr=`grep "CxxTest::g_TotalTests" \ ${SBXHOME}/${HBICORE_TEST_SYMS} | awk '{split($0,a,","); print a[2]}'` failedtests_addr=`grep "CxxTest::g_FailedTests" \ ${SBXHOME}/${HBICORE_TEST_SYMS} | awk '{split($0,a,","); print a[2]}'` warnings_addr=`grep "CxxTest::g_Warnings" \ ${SBXHOME}/${HBICORE_TEST_SYMS} | awk '{split($0,a,","); print a[2]}'` tracecalls_addr=`grep "CxxTest::g_TraceCalls" \ ${SBXHOME}/${HBICORE_TEST_SYMS} | awk '{split($0,a,","); print a[2]}'` mods_started_addr=`grep "CxxTest::g_ModulesStarted" \ ${SBXHOME}/${HBICORE_TEST_SYMS} | awk '{split($0,a,","); print a[2]}'` mods_completed_addr=`grep "CxxTest::g_ModulesCompleted" \ ${SBXHOME}/${HBICORE_TEST_SYMS} | awk '{split($0,a,","); print a[2]}'` shutdown_status=`grep "CpuManager::cv_shutdown_status" \ ${SBXHOME}/${HBICORE_TEST_SYMS} | awk '{split($0,a,","); print a[2]}'` #Adjust addresses for HRMOR HRMOR=`autosim $NOWIN --simcmd "python \"getHRMOR()\""| tr -d '\n\r'` temp=$(($HRMOR + 0x$printk_buffer_addr)) printk_buffer_addr=`echo "obase=16; $temp" | bc` temp=$(($HRMOR + 0x$totaltests_addr)) totaltests_addr=`echo "obase=16; $temp" | bc` temp=$(($HRMOR + 0x$failedtests_addr)) failedtests_addr=`echo "obase=16; $temp" | bc` temp=$(($HRMOR + 0x$warnings_addr)) warnings_addr=`echo "obase=16; $temp" | bc` temp=$(($HRMOR + 0x$tracecalls_addr)) tracecalls_addr=`echo "obase=16; $temp" | bc` temp=$(($HRMOR + 0x$mods_started_addr)) mods_started_addr=`echo "obase=16; $temp" | bc` temp=$(($HRMOR + 0x$mods_completed_addr)) mods_completed_addr=`echo "obase=16; $temp" | bc` temp=$(($HRMOR + 0x$shutdown_status)) shutdown_status=`echo "obase=16; $temp" | bc` ## note, don't use $VERBOSE here or you get all sorts of extra junk in the output file. echo "Wait for unit test completion." declare -i timeout=0 modsstarted=0 modscompleted=0 loopcount=0 while [ $(($modsstarted)) -lt 1 -o $(($modsstarted)) -ne $(($modscompleted)) ]; do sleep 5 ((loopcount++)) # increment loopcount autosim $NOWIN --simcmd "print ((system_cmp0.phys_mem).read 0x$mods_completed_addr 0x08)" 1> $SBXHOME/modscompleted.log 2> /dev/null modscompleted=`cat $SBXHOME/modscompleted.log | awk '/0x/ {print strtonum($1)}'` autosim $NOWIN --simcmd "print ((system_cmp0.phys_mem).read 0x$mods_started_addr 0x08)" 1> $SBXHOME/modsstarted.log 2> /dev/null modsstarted=`cat $SBXHOME/modsstarted.log | awk '/0x/ {print strtonum($1)}'` echo "ModulesStarted:ModulesCompleted => $modsstarted:$modscompleted" if [ "$loopcount" -gt 120 ]; then echo "ERROR: timed out after 10 minutes" autosim $NOWIN --simcmd "hb-Ps" timeout=$(($modsstarted - $modscompleted)) break fi done echo "====> waiting for shutdown..." loopcount=0 while [ "$loopcount" -lt 6 ]; do autosim $NOWIN --simcmd "print ((system_cmp0.phys_mem).read 0x$shutdown_status 0x08)" 1> $SBXHOME/shutdown_status.log 2> /dev/null shutdown_yet=`cat $SBXHOME/shutdown_status.log | awk '/0x/ {print strtonum($1)}'` if [ "$shutdown_yet" -ne 0 ]; then break fi sleep 5 ((loopcount++)) # increment loopcount done echo "====> dump totaltests..." autosim $NOWIN --simcmd "print ((system_cmp0.phys_mem).read 0x$totaltests_addr 0x08)" 1> $SBXHOME/totaltests.log 2> /dev/null if [ $? -ne 0 ] ; then echo "ERROR: Unable to run $?" stopsim stopserver exit 1 fi totaltests=`cat $SBXHOME/totaltests.log | awk '/0x/ {print strtonum($1)}'` echo "====> dump failedtests..." autosim $NOWIN --simcmd "print ((system_cmp0.phys_mem).read 0x$failedtests_addr 0x08)" 1> $SBXHOME/failedtests.log 2> /dev/null if [ $? -ne 0 ] ; then echo "ERROR: Unable to run $?" stopsim stopserver exit 1 fi failedtests=`cat $SBXHOME/failedtests.log | awk '/0x/ {print strtonum($1)}'` echo "====> dump warnings..." autosim $NOWIN --simcmd "print ((system_cmp0.phys_mem).read 0x$warnings_addr 0x08)" 1> $SBXHOME/warnings.log 2> /dev/null if [ $? -ne 0 ] ; then echo "ERROR: Unable to run $?" stopsim stopserver exit 1 fi warnings=`cat $SBXHOME/warnings.log | awk '/0x/ {print strtonum($1)}'` echo "====> dump tracecalls..." autosim $NOWIN --simcmd "print ((system_cmp0.phys_mem).read 0x$tracecalls_addr 0x08)" 1> $SBXHOME/tracecalls.log 2> /dev/null if [ $? -ne 0 ] ; then echo "ERROR: Unable to run $?" stopsim stopserver exit 1 fi tracecalls=`cat $SBXHOME/tracecalls.log | awk '/0x/ {print strtonum($1)}'` echo "====> dump printk buffer..." autosim $NOWIN --simcmd "(system_cmp0.phys_mem)->map[0][1]->image.save \"${SBXHOME}/testprintk.log\" 0x$printk_buffer_addr 0x$printk_buffer_size" 1> /dev/null 2> /dev/null if [ $? -ne 0 ] ; then echo "ERROR: Unable to run $?" stopsim stopserver exit 1 fi ## run CamVan's python script to dump out the trace logs echo "====> dump trace buffer(s)..." runtraceHB 1> $SBXHOME/traceHB.log 2> /dev/null if [ $? -ne 0 ] ; then echo "ERROR: Unable to run $?" stopsim stopserver exit 1 fi echo "====> dump L3..." autosim $NOWIN --simcmd "hb-dump" if [ $? -ne 0 ] ; then echo "ERROR 4 : Unable to run $?" stopsim stopserver exit 1 fi ######################################################## ## done. Stop the simulation ######################################################## stopsim ## now stop the server. stopserver ## print out ending. timestamp=`date +'%H:%M:%S'` echo "----------------- Printk Buffer -------------------" cat $SBXHOME/testprintk.log shutdown_code="$(grep --text 'Shutdown Requested' $SBXHOME/testprintk.log | awk -F '= 0x' '{ print $2 }')" echo "----------------- traceHB Buffer -------------------" cat $SBXHOME/traceHB.log initfail=0 echo "Shutdown Code = $shutdown_code" if [ "${shutdown_code}" != "1230000" ] then echo "**ERROR : System did not initialize and/or shutdown properly**" initfail=1 fi echo echo "===================================================" if [ $timeout = 0 ] ; then echo "$timestamp Finished autocitest with no Cxx errors." else echo "$timestamp Failed autocitest, modules timed out." echo " failed modules: $timeout" fi echo " total tests: $totaltests" echo " failed tests: $failedtests" echo " warnings: $warnings" echo " trace calls: $tracecalls" echo "===================================================" echo if [ 0 != $timeout ] ; then echo "Modules started: $modsstarted" echo "Modules completed: $modscompleted" exit 1 fi if [ 0 != $(($failedtests)) ] ; then echo "$failedtests testcases failed." exit 1 fi if [ 0 != $(($warnings)) ] ; then echo "$warnings testcase warnings found." exit 1 fi if [ 0 != $(($initfail)) ] ; then echo "Initialization Failure" exit 1 fi exit 0