#!/bin/bash

########################################################################
#
# Linux on Hyper-V and Azure Test Code, ver. 1.0.0
# Copyright (c) Microsoft Corporation
#
# All rights reserved.
# 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
#
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
# ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
#
# See the Apache Version 2.0 License for specific language governing
# permissions and limitations under the License.
#
########################################################################

#######################################################################
#
# Description:
#     This script was created to automate the testing of a Linux
#     kernel source tree.  It does this by performing the following
#     steps:
#    1. Make sure we were given a kernel source. If a linux-next git address is provided, make sure that
#       the VM has a NIC (eth0) connect to Internet.
#    2. Configure and build the new kernel
#
# The outputs are directed into files named:
#     Perf_BuildKernel_make.log,
#     Perf_BuildKernel_makemodulesinstall.log,
#     Perf_BuildKernel_makeinstall.log
#
# This test script requires the below test parameters:
#     <param>SOURCE_TYPE=ONLINE</param>
#     <param>LINUX_KERNEL_LOCATION=git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git</param>
#     <param>KERNEL_VERSION=linux-next</param>
#
# A typical XML test definition for this test case would look
# similar to the following:
#		<test>
#			<testName>ICA-BUILD-LINUX-KERNEL</testName>
#			<testScript>Perf_BuildKernel.sh</testScript>
#			<testScriptPs1>ICA-BUILD-LINUX-KERNEL.ps1</testScriptPs1>
#			<files>remote-scripts\Perf_BuildKernel.sh,remote-scripts\Packages\linux-3.18.1.tar.xz,SetupScripts\DetectLinuxDistro.sh</files>
#			<setupType>MediumVM</setupType>
#			<testParams>
#				<param>LINUX_KERNEL_LOCATION=https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git</param>
#				<param>KERNEL_VERSION=linux-next</param>
#				<!-- <param>SOURCE_TYPE=TARBALL</param>
#				<param>TARBALL=linux-3.18.1.tar.xz</param>
#				<param>KERNEL_VERSION=linux-3.18.1</param>  -->
#			</testParams>
#			<TestType></TestType>
#			<TestFeature></TestFeature>
#			<TestID></TestID>
#		</test>
#
#######################################################################

DEBUG_LEVEL=3
CONFIG_FILE=.config

START_DIR=$(pwd)

#
#Detect Distro
#
LinuxDistro=`./DetectLinuxDistro.sh`
if [ $LinuxDistro == "SLES" -o $LinuxDistro == "SUSE" ]; then
    #zypper update
	zypper --non-interactive install git-core make tar gcc bc patch dos2unix wget xz
elif [ $LinuxDistro == "CENTOS" -o $LinuxDistro == "REDHAT" -o $LinuxDistro == "FEDORA" -o $LinuxDistro == "ORACLELINUX" ]; then
	#yum update
	yum install -y git make tar gcc bc patch dos2unix wget xz
elif [ $LinuxDistro == "UBUNTU" ]; then
	apt-get update
	apt-get install -y git make tar gcc bc patch dos2unix wget
fi

#
# Source the constants.sh file so we know what files to operate on.
#
dos2unix -q constants.sh > /dev/null
source ./constants.sh

dbgprint()
{
    if [ $1 -le $DEBUG_LEVEL ]; then
        echo "$2"
    fi
}

UpdateTestState()
{
    echo $1 > ${START_DIR}/state.txt
}

UpdateSummary()
{
    echo $1 >> ${START_DIR}/summary.log
}

#
# Create the state.txt file so the ICA script knows
# we are running
#
UpdateTestState "TestRunning"
if [ -e ${START_DIR}/state.txt ]; then
    dbgprint 0 "State.txt file is created "
    dbgprint 0 "Content of state is : " ; echo `cat ${START_DIR}/state.txt`
fi

#
# Write some useful info to the log file
#
dbgprint 1 "buildKernel.sh - Script to automate building of the kernel"
dbgprint 3 ""
dbgprint 3 "Global values"
dbgprint 3 "  DEBUG_LEVEL = ${DEBUG_LEVEL}"
dbgprint 3 "  SOURCE_TYPE = ${SOURCE_TYPE}"
dbgprint 3 "  LINUX_KERNEL_LOCATION = ${LINUX_KERNEL_LOCATION}"
dbgprint 3 "  TARBALL = ${TARBALL}"
dbgprint 3 "  KERNEL_VERSION = ${KERNEL_VERSION}"
dbgprint 3 "  CONFIG_FILE = ${CONFIG_FILE}"
dbgprint 3 ""

#
# Delete old kernel source tree if it exists.
# This should not be needed, but check to make sure
#
# adding check for summary.log
if [ -e ${START_DIR}/summary.log ]; then
    dbgprint 1 "Cleaning up previous copies of summary.log"
    rm -rf ${START_DIR}/summary.log
fi
# adding check for old kernel source tree
if [ -e ${KERNEL_VERSION} ]; then
    dbgprint 1 "Cleaning up previous copies of source tree"
    dbgprint 3 "Removing the ${KERNEL_VERSION} directory"
    rm -rf ${KERNEL_VERSION}
fi

if [ "${SOURCE_TYPE}" == "TARBALL" ]; then
    dbgprint 1 "Building linux kernel from tarball..."
    #
    # Make sure we were given the $TARBALL file
    #
    if [ ! ${TARBALL} ]; then
        dbgprint 0 "The TARBALL variable is not defined."
        dbgprint 0 "Aborting the test."
        UpdateTestState "TestAborted"
        exit 20
    fi

    dbgprint 3 "Extracting Linux kernel sources from ${TARBALL}"
    tar -xf ${TARBALL}
    sts=$?
    if [ 0 -ne ${sts} ]; then
        dbgprint 0 "tar failed to extract the kernel from the tarball: ${sts}"
        dbgprint 0 "Aborting test."
        UpdateTestState "TestAborted"
        exit 40
    fi

    #
    # The Linux Kernel is extracted to the folder which is named by the version by default
    #
    if [ ! -e ${KERNEL_VERSION} ]; then
        dbgprint 0 "The tar file did not create the directory: ${KERNEL_VERSION}"
        dbgprint 0 "Aborting the test."
        UpdateTestState "TestAborted"
        exit 50
    fi
else
    dbgprint 1 "Building linux-next kernel from git repository..."
    #
    # Make sure we were given the linux-next git location
    #
    if [ ! ${LINUX_KERNEL_LOCATION} ]; then
        dbgprint 0 "The LINUX_KERNEL_LOCATION variable is not defined."
        dbgprint 0 "Aborting the test."
        UpdateTestState "TestAborted"
        exit 20
    fi
    git clone ${LINUX_KERNEL_LOCATION}
fi

cd ${START_DIR}/${KERNEL_VERSION}

#
# Start the testing
#
proc_count=$(cat /proc/cpuinfo | grep --count processor)
dbgprint 1 "Build kernel with $proc_count CPU(s)"

UpdateSummary "KernelRelease=$(uname -r)"
UpdateSummary "ProcessorCount=$proc_count"

UpdateSummary "$(uname -a)"

#
# Create the .config file
#
dbgprint 1 "Creating the .config file."
if [ -f ${START_DIR}/ica/kernel.config.base ]; then
    # Basing a new kernel config on a previous kernel config file will
    # provide flexibility in providing know good config files with certain
    # options enabled/disabled.  Functionality could also potentially be
    # added here for choosing between multiple old config files depending
    # on the distro that the kernel is being compiled on (i.g. if Fedora
    # is detected copy ${START_DIR}/ica/kernel.config.base-fedora to .config before
    # running 'make oldconfig')

    dbgprint 3 "Creating new config based on a previous .config file"
    cp ${START_DIR}/ica/kernel.config.base .config

    # Base the new config on the old one and select the default config
    # option for any new options in the newer kernel version
    yes "" | make oldconfig
else
    dbgprint 3 "Create a default .config file"
    yes "" | make oldconfig
    sts=$?
    if [ 0 -ne ${sts} ]; then
        dbgprint 0 "make defconfig failed."
        dbgprint 0 "Aborting the test."
        UpdateTestState "TestAborted"
        exit 60
    fi

    if [ ! -e ${CONFIG_FILE} ]; then
        dbgprint 0 "make defconfig did not create the '${CONFIG_FILE}'"
        dbgprint 0 "Aborting the test."
        UpdateTestState "TestAborted"
        exit 70
    fi

    #
    # Enable HyperV support
    #
    dbgprint 3 "Enabling HyperV support in the ${CONFIG_FILE}"
    # On this first 'sed' command use --in-place=.orig to make a backup
    # of the original .config file created with 'defconfig'
    sed --in-place=.orig -e s:"# CONFIG_HYPERVISOR_GUEST is not set":"CONFIG_HYPERVISOR_GUEST=y\nCONFIG_HYPERV=y\nCONFIG_HYPERV_UTILS=y\nCONFIG_HYPERV_BALLOON=y\nCONFIG_HYPERV_STORAGE=m\nCONFIG_HYPERV_NET=y\nCONFIG_HYPERV_KEYBOARD=y\nCONFIG_FB_HYPERV=y\nCONFIG_HID_HYPERV_MOUSE=m": ${CONFIG_FILE}

    #
    # Enable Ext4, Reiser support (ext3 is enabled by default)
    #
    sed --in-place -e s:"# CONFIG_EXT4_FS is not set":"CONFIG_EXT4_FS=y\nCONFIG_EXT4_FS_XATTR=y\nCONFIG_EXT4_FS_POSIX_ACL=y\nCONFIG_EXT4_FS_SECURITY=y": ${CONFIG_FILE}
    sed --in-place -e s:"# CONFIG_REISERFS_FS is not set":"CONFIG_REISERFS_FS=y\nCONFIG_REISERFS_PROC_INFO=y\nCONFIG_REISERFS_FS_XATTR=y\nCONFIG_REISERFS_FS_POSIX_ACL=y\nCONFIG_REISERFS_FS_SECURITY=y": ${CONFIG_FILE}

    #
    # Enable Tulip network driver support.  This is needed for the "legacy"
    # network adapter provided by Hyper-V
    #
    sed --in-place -e s:"# CONFIG_TULIP is not set":"CONFIG_TULIP=m\nCONFIG_TULIP_MMIO=y": ${CONFIG_FILE}

    yes "" | make oldconfig
fi
UpdateSummary "make oldconfig: Success"

#
# Build the kernel
#
dbgprint 1 "Building the kernel."

if [ $proc_count -eq 1 ]; then
    (time make) > ${START_DIR}/Perf_BuildKernel_make.log 2>&1
else
    (time make -j $proc_count) > ${START_DIR}/Perf_BuildKernel_make.log 2>&1
fi

sts=$?
if [ 0 -ne ${sts} ]; then
    dbgprint 1 "Kernel make failed: ${sts}"
    dbgprint 1 "Aborting test."
    UpdateTestState "TestAborted"
    UpdateSummary "make: Failed"
    exit 110
else
    UpdateSummary "make: Success"
fi

#
# Build the kernel modules
#
dbgprint 1 "Building the kernel modules."
if [ $proc_count -eq 1 ]; then
    (time make modules_install) > ${START_DIR}/Perf_BuildKernel_makemodulesinstall.log 2>&1
else
    (time make modules_install -j $proc_count) > ${START_DIR}/Perf_BuildKernel_makemodulesinstall.log 2>&1
fi

sts=$?
if [ 0 -ne ${sts} ]; then
    dbgprint 1 "Kernel make failed: ${sts}"
    dbgprint 1 "Aborting test."
    UpdateTestState "TestAborted"
    UpdateSummary "make modules_install: Failed"
    exit 110
else
    UpdateSummary "make modules_install: Success"
fi

#
# Install the kernel
#
dbgprint 1 "Installing the kernel."
if [ $proc_count -eq 1 ]; then
    (time make install) > ${START_DIR}/Perf_BuildKernel_makeinstall.log 2>&1
else
    (time make install -j $proc_count) > ${START_DIR}/Perf_BuildKernel_makeinstall.log 2>&1
fi

sts=$?
if [ 0 -ne ${sts} ]; then
    echo "kernel build failed: ${sts}"
    UpdateTestState "TestAborted"
    UpdateSummary "make install: Failed"
    exit 130
else
    UpdateSummary "make install: Success"
fi

#
# Save the current Kernel version for comparision with the version
# of the new kernel after the reboot.
#
cd ${START_DIR}
dbgprint 3 "Saving version number of current kernel in oldKernelVersion.txt"
uname -r > ${START_DIR}/oldKernelVersion.txt

### Grub Modification ###
# Update grub.conf (we only support v1 right now, grub v2 will have to be added
# later)
grubversion=1
if [ -e /boot/grub/grub.conf ]; then
        grubfile="/boot/grub/grub.conf"
elif [ -e /boot/grub/menu.lst ]; then
        grubfile="/boot/grub/menu.lst"
elif [ -e /boot/grub2/grub.cfg ]; then
        grubversion=2
        grub2-mkconfig -o /boot/grub2/grub.cfg
        grub2-set-default 0
else
        echo "grub v1 files does not appear to be installed on this system. it should use grub v2."
        # the new kernel is the default one to boot next time
        grubversion=2
fi

if [ 1 -eq ${grubversion} ]; then
    echo "Update grub v1 files."
    new_default_entry_num="0"
    # added
    sed --in-place=.bak -e "s/^default\([[:space:]]\+\|=\)[[:digit:]]\+/default\1$new_default_entry_num/" $grubfile
    # Display grub configuration after our change
    echo "Here are the new contents of the grub configuration file:"
    cat $grubfile
fi

# edit /etc/rc.local and /etc/rc.d/rc.local to
# make sure ifup_eth automate run script during boot
#
ifup_eth="ifup eth0 > /dev/null"

#write script path to /etc/rc.local
if [[ -f /etc/rc.local ]]
then
	sed "/^\s*exit 0/i ${ifup_eth}" /etc/rc.local -i

	if ! grep -q "${ifup_eth}" /etc/rc.local
	then
		echo "Add ${ifup_eth} to /etc/rc.local"
		echo $ifup_eth >> /etc/rc.local
	fi
	chmod +x /etc/rc.local
fi

#write script path to /etc/rc.d/rc.local
if [[ -f /etc/rc.d/rc.local ]]
then
	sed "/^\s*exit 0/i ${ifup_eth}" /etc/rc.d/rc.local -i

	if ! grep -q "${ifup_eth}" /etc/rc.d/rc.local
	then
		echo "Add ${ifup_eth} to /etc/rc.d/rc.local"
		echo $ifup_eth >> /etc/rc.d/rc.local
	fi
	chmod +x /etc/rc.d/rc.local
fi

#if distro is SUSE then configure /etc/rc.d/after.local
if [[ -f /etc/SuSE-release ]]
then
	echo "INFO: the distro is SUSE. update /etc/rc.d/after.local" >> ~/summary.log
	echo $ifup_eth >> /etc/rc.d/after.local
	chmod +x /etc/rc.d/after.local
fi

#
# Let the caller know everything worked
#
dbgprint 1 "Exiting with state: TestCompleted."
UpdateTestState "TestCompleted"

exit 0


#!/bin/bash
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
#
# Sample script to run sysbench.
# In this script, we want to bench-mark device IO performance on a mounted folder.
# You can adapt this script to other situations easily like for stripe disks as RAID0.
# The only thing to keep in mind is that each different configuration you're testing
# must log its output to a different directory.
#

HOMEDIR="/root"
LogMsg()
{
    echo "[$(date +"%x %r %Z")] ${1}"
	echo "[$(date +"%x %r %Z")] ${1}" >> "${HOMEDIR}/runlog.txt"
}
LogMsg "Sleeping 10 seconds.."
sleep 10

#export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/oem/bin:/usr/share/oem/python/bin:/opt/bin
CONSTANTS_FILE="$HOMEDIR/constants.sh"
ICA_TESTRUNNING="TestRunning"      # The test is running
ICA_TESTCOMPLETED="TestCompleted"  # The test completed successfully
ICA_TESTABORTED="TestAborted"      # Error during the setup of the test
ICA_TESTFAILED="TestFailed"        # Error occurred during the test
touch ./fioTest.log

if [ -e ${CONSTANTS_FILE} ]; then
    . ${CONSTANTS_FILE}
else
    errMsg="Error: missing ${CONSTANTS_FILE} file"
    LogMsg "${errMsg}"
    UpdateTestState $ICA_TESTABORTED
    exit 10
fi

UpdateTestState()
{
    echo "${1}" > $HOMEDIR/state.txt
}

InstallFIO() {
		DISTRO=`grep -ihs "buntu\|Suse\|Fedora\|Debian\|CentOS\|Red Hat Enterprise Linux" /etc/{issue,*release,*version}`

		if [[ $DISTRO =~ "Ubuntu" ]] || [[ $DISTRO =~ "Debian" ]];
		then
			LogMsg "Detected UBUNTU/Debian"
			until dpkg --force-all --configure -a; sleep 10; do echo 'Trying again...'; done
			apt-get update
			apt-get install -y pciutils gawk mdadm
			apt-get install -y wget sysstat blktrace bc fio
			if [ $? -ne 0 ]; then
				LogMsg "Error: Unable to install fio"
				exit 1
			fi
			mount -t debugfs none /sys/kernel/debug

		elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 6" ]];
		then
			LogMsg "Detected RHEL 6.x"
			LogMsg "INFO: installing required packages"
			rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
			yum -y --nogpgcheck install wget sysstat mdadm blktrace libaio fio
			mount -t debugfs none /sys/kernel/debug

		elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 7" ]];
		then
			LogMsg "Detected RHEL 7.x"
			LogMsg "INFO: installing required packages"
			rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
			yum -y --nogpgcheck install wget sysstat mdadm blktrace libaio fio
			mount -t debugfs none /sys/kernel/debug

		elif [[ $DISTRO =~ "CentOS Linux release 6" ]] || [[ $DISTRO =~ "CentOS release 6" ]];
		then
			LogMsg "Detected CentOS 6.x"
			LogMsg "INFO: installing required packages"
			rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
			yum -y --nogpgcheck install wget sysstat mdadm blktrace libaio fio
			mount -t debugfs none /sys/kernel/debug

		elif [[ $DISTRO =~ "CentOS Linux release 7" ]];
		then
			LogMsg "Detected CentOS 7.x"
			LogMsg "INFO: installing required packages"
			rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
			yum -y --nogpgcheck install wget sysstat mdadm blktrace libaio fio
			mount -t debugfs none /sys/kernel/debug

		elif [[ $DISTRO =~ "SUSE Linux Enterprise Server 12" ]];
		then
			LogMsg "Detected SLES12"
			zypper addrepo http://download.opensuse.org/repositories/benchmark/SLE_12_SP2_Backports/benchmark.repo
			zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys refresh
			zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys remove gettext-runtime-mini-0.19.2-1.103.x86_64
			zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys install sysstat
			zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys install grub2
			zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys install wget mdadm blktrace libaio1 fio

		else
				LogMsg "Unknown Distro"
				UpdateTestState "TestAborted"
				UpdateSummary "Unknown Distro, test aborted"
				return 1
	fi
}

RunFIO()
{
	UpdateTestState ICA_TESTRUNNING
	FILEIO="--size=${fileSize} --direct=1 --ioengine=libaio --filename=fiodata --overwrite=1  "

	####################################
	#All run config set here
	#

	#Log Config

	mkdir $HOMEDIR/FIOLog/jsonLog
	mkdir $HOMEDIR/FIOLog/iostatLog
	mkdir $HOMEDIR/FIOLog/blktraceLog

	#LOGDIR="${HOMEDIR}/FIOLog"
	JSONFILELOG="${LOGDIR}/jsonLog"
	IOSTATLOGDIR="${LOGDIR}/iostatLog"
	BLKTRACELOGDIR="${LOGDIR}/blktraceLog"
	LOGFILE="${LOGDIR}/fio-test.log.txt"

	#redirect blktrace files directory
	Resource_mount=$(mount -l | grep /sdb1 | awk '{print$3}')
	blk_base="${Resource_mount}/blk-$(date +"%m%d%Y-%H%M%S")"
	mkdir $blk_base
	#
	#
	#Test config
	#
	#

	#All possible values for file-test-mode are randread randwrite read write
	#modes='randread randwrite read write'
	iteration=0
	#startThread=1
	#startIO=8
	#numjobs=1

	#Max run config
	#ioruntime=300
	#maxThread=1024
	#maxIO=8
	io_increment=128

	####################################
	echo "Test log created at: ${LOGFILE}"
	echo "===================================== Starting Run $(date +"%x %r %Z") ================================"
	echo "===================================== Starting Run $(date +"%x %r %Z") script generated 2/9/2015 4:24:44 PM ================================" >> $LOGFILE

	chmod 666 $LOGFILE
	echo "Preparing Files: $FILEIO"
	echo "Preparing Files: $FILEIO" >> $LOGFILE
	LogMsg "Preparing Files: $FILEIO"
	# Remove any old files from prior runs (to be safe), then prepare a set of new files.
	rm fiodata
	echo "--- Kernel Version Information ---" >> $LOGFILE
	uname -a >> $LOGFILE
	cat /proc/version >> $LOGFILE
	cat /etc/*-release >> $LOGFILE
	echo "--- PCI Bus Information ---" >> $LOGFILE
	lspci >> $LOGFILE
	echo "--- Drive Mounting Information ---" >> $LOGFILE
	mount >> $LOGFILE
	echo "--- Disk Usage Before Generating New Files ---" >> $LOGFILE
	df -h >> $LOGFILE
	fio --cpuclock-test >> $LOGFILE
	fio $FILEIO --readwrite=read --bs=1M --runtime=1 --iodepth=128 --numjobs=8 --name=prepare
	echo "--- Disk Usage After Generating New Files ---" >> $LOGFILE
	df -h >> $LOGFILE
	echo "=== End Preparation  $(date +"%x %r %Z") ===" >> $LOGFILE
	LogMsg "Preparing Files: $FILEIO: Finished."
	####################################
	#Trigger run from here
	for testmode in $modes; do
		io=$startIO
		while [ $io -le $maxIO ]
		do
			Thread=$startThread
			while [ $Thread -le $maxThread ]
			do
				if [ $Thread -ge 8 ]
				then
					numjobs=8
				else
					numjobs=$Thread
				fi
				iostatfilename="${IOSTATLOGDIR}/iostat-fio-${testmode}-${io}K-${Thread}td.txt"
				nohup iostat -x 5 -t -y > $iostatfilename &
				#capture blktrace output during test
				#LogMsg "INFO: start blktrace for 40 sec on device sdd and sdf"
				#blk_operation="${blk_base}/blktrace-fio-${testmode}-${io}K-${Thread}td/"
				#mkdir $blk_operation
				#blktrace -w 40 -d /dev/sdf -D $blk_operation &
				#blktrace -w 40 -d /dev/sdm -D $blk_operation &
				echo "-- iteration ${iteration} ----------------------------- ${testmode} test, ${io}K bs, ${Thread} threads, ${numjobs} jobs, 5 minutes ------------------ $(date +"%x %r %Z") ---" >> $LOGFILE
				LogMsg "Running ${testmode} test, ${io}K bs, ${Thread} threads ..."
				jsonfilename="${JSONFILELOG}/fio-result-${testmode}-${io}K-${Thread}td.json"
				fio $FILEIO --readwrite=$testmode --bs=${io}K --runtime=$ioruntime --iodepth=$Thread --numjobs=$numjobs --output-format=json --output=$jsonfilename --name="iteration"${iteration} >> $LOGFILE
				#fio $FILEIO --readwrite=$testmode --bs=${io}K --runtime=$ioruntime --iodepth=$Thread --numjobs=$numjobs --name="iteration"${iteration} --group_reporting >> $LOGFILE
				iostatPID=`ps -ef | awk '/iostat/ && !/awk/ { print $2 }'`
				kill -9 $iostatPID
				Thread=$(( Thread*2 ))
				iteration=$(( iteration+1 ))
			done
		io=$(( io * io_increment ))
		done
	done
	####################################
	echo "===================================== Completed Run $(date +"%x %r %Z") script generated 2/9/2015 4:24:44 PM ================================" >> $LOGFILE
	rm fiodata

	compressedFileName="${HOMEDIR}/FIOTest-$(date +"%m%d%Y-%H%M%S").tar.gz"
	LogMsg "INFO: Please wait...Compressing all results to ${compressedFileName}..."
	tar -cvzf $compressedFileName $LOGDIR/

	echo "Test logs are located at ${LOGDIR}"
	UpdateTestState ICA_TESTCOMPLETED
}

CreateRAID0()
{
	disks=$(ls -l /dev | grep sd[c-z]$ | awk '{print $10}')
	#disks=(`fdisk -l | grep 'Disk.*/dev/sd[a-z]' |awk  '{print $2}' | sed s/://| sort| grep -v "/dev/sd[ab]$" `)

	LogMsg "INFO: Check and remove RAID first"
	mdvol=$(cat /proc/mdstat | grep "active raid" | awk {'print $1'})
	if [ -n "$mdvol" ]; then
		echo "/dev/${mdvol} already exist...removing first"
		umount /dev/${mdvol}
		mdadm --stop /dev/${mdvol}
		mdadm --remove /dev/${mdvol}
		mdadm --zero-superblock /dev/sd[c-z][1-5]
	fi

	LogMsg "INFO: Creating Partitions"
	count=0
	for disk in ${disks}
	do
		echo "formatting disk /dev/${disk}"
		(echo d; echo n; echo p; echo 1; echo; echo; echo t; echo fd; echo w;) | fdisk /dev/${disk}
		count=$(( $count + 1 ))
		sleep 1
	done
	LogMsg "INFO: Creating RAID of ${count} devices."
	sleep 1
	mdadm --create ${mdVolume} --level 0 --raid-devices ${count} /dev/sd[c-z][1-5]
	sleep 1
	time mkfs -t $1 -F ${mdVolume}
	mkdir ${mountDir}
	sleep 1
	mount -o nobarrier ${mdVolume} ${mountDir}
	if [ $? -ne 0 ]; then
            LogMsg "Error: Unable to create raid"
            exit 1
	else
		LogMsg "${mdVolume} mounted to ${mountDir} successfully."
	fi

	#LogMsg "INFO: adding fstab entry"
	#echo "${mdVolume}	${mountDir}	ext4	defaults	1 1" >> /etc/fstab
}

CreateLVM()
{
	disks=$(ls -l /dev | grep sd[c-z]$ | awk '{print $10}')
	#disks=(`fdisk -l | grep 'Disk.*/dev/sd[a-z]' |awk  '{print $2}' | sed s/://| sort| grep -v "/dev/sd[ab]$" `)

	#LogMsg "INFO: Check and remove LVM first"
	vgExist=$(vgdisplay)
	if [ -n "$vgExist" ]; then
		umount ${mountDir}
		lvremove -A n -f /dev/${vggroup}/lv1
		vgremove ${vggroup} -f
	fi

	LogMsg "INFO: Creating Partition"
	count=0
	for disk in ${disks}
	do
		echo "formatting disk /dev/${disk}"
		(echo d; echo n; echo p; echo 1; echo; echo; echo t; echo fd; echo w;) | fdisk /dev/${disk}
		count=$(( $count + 1 ))
	done

	LogMsg "INFO: Creating LVM with all data disks"
	pvcreate /dev/sd[c-z][1-5]
	vgcreate ${vggroup} /dev/sd[c-z][1-5]
	lvcreate -l 100%FREE -i 12 -I 64 ${vggroup} -n lv1
	time mkfs -t $1 -F /dev/${vggroup}/lv1
	mkdir ${mountDir}
	mount -o nobarrier /dev/${vggroup}/lv1 ${mountDir}
	if [ $? -ne 0 ]; then
            LogMsg "Error: Unable to create LVM "
            exit 1
        fi

	#LogMsg "INFO: adding fstab entry"
	#echo "${mdVolume}	${mountDir}	ext4	defaults	1 1" >> /etc/fstab
}

############################################################
#	Main body
############################################################

HOMEDIR=$HOME
mv $HOMEDIR/FIOLog/ $HOMEDIR/FIOLog-$(date +"%m%d%Y-%H%M%S")/
mkdir $HOMEDIR/FIOLog
LOGDIR="${HOMEDIR}/FIOLog"
DISTRO=`grep -ihs "buntu\|Suse\|Fedora\|Debian\|CentOS\|Red Hat Enterprise Linux" /etc/{issue,*release,*version}`
if [[ $DISTRO =~ "SUSE Linux Enterprise Server 12" ]];
then
	mdVolume="/dev/md/mdauto0"
else
	mdVolume="/dev/md0"
fi
vggroup="vg1"
mountDir="/data"
cd ${HOMEDIR}

InstallFIO

#Creating RAID before triggering test
CreateRAID0 ext4
#CreateLVM ext4

#Run test from here
LogMsg "*********INFO: Starting test execution*********"
cd ${mountDir}
mkdir sampleDIR
RunFIO
LogMsg "*********INFO: Script execution reach END. Completed !!!*********"


#!/bin/bash

#######################################################################
#
# Linux on Hyper-V and Azure Test Code, ver. 1.0.0
# Copyright (c) Microsoft Corporation
#
# All rights reserved.
# 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
#
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
# ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
#
# See the Apache Version 2.0 License for specific language governing
# permissions and limitations under the License.
#
#######################################################################

#######################################################################
#
# perf_IPERF3.sh
# Author : SHITAL SAVEKAR <v-shisav@microsoft.com>
#
# Description:
#	Download and run IPERF3 network performance tests.
#	This script needs to be run on client VM.
#
# Supported Distros:
#	Ubuntu 16.04
#######################################################################

CONSTANTS_FILE="./constants.sh"
ICA_TESTRUNNING="TestRunning"	  # The test is running
ICA_TESTCOMPLETED="TestCompleted"  # The test completed successfully
ICA_TESTABORTED="TestAborted"	  # Error during the setup of the test
ICA_TESTFAILED="TestFailed"		# Error occurred during the test
touch ./IPERF3Test.log

InstallIPERF3()
{
		DISTRO=`grep -ihs "buntu\|Suse\|Fedora\|Debian\|CentOS\|Red Hat Enterprise Linux" /etc/{issue,*release,*version}`
		if [[ $DISTRO =~ "Ubuntu" ]];
		then

			LogMsg "Detected Ubuntu"
			ssh ${1} "until dpkg --force-all --configure -a; sleep 10; do echo 'Trying again...'; done"
			ssh ${1} "apt-get update"
			ssh ${1} "apt-get -y install iperf3 sysstat bc psmisc"
			if [ $IPversion -eq 6 ]; then
				scp ConfigureUbuntu1604IPv6.sh ${1}:
				ssh ${1} "chmod +x ConfigureUbuntu1604IPv6.sh"
				ssh ${1} "./ConfigureUbuntu1604IPv6.sh"
			fi
		elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 6" ]] || [[ $DISTRO =~ "CentOS Linux release 6" ]] || [[ $DISTRO =~ "CentOS release 6" ]];
		then
				LogMsg "Detected Redhat/CentOS 6.x"
				ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm"
				ssh ${1} "yum -y --nogpgcheck install iperf3 sysstat bc psmisc"
				ssh ${1} "iptables -F"

		elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 7" ]] || [[ $DISTRO =~ "CentOS Linux release 7" ]];
		then
				LogMsg "Detected Redhat/CentOS 7.x"
				ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"
				ssh ${1} "yum -y --nogpgcheck install iperf3 sysstat bc psmisc"
				ssh ${1} "iptables -F"

		else
				LogMsg "Unknown Distro"
				UpdateTestState "TestAborted"
				UpdateSummary "Unknown Distro, test aborted"
				return 1
		fi
}

LogMsg()
{
	echo `date "+%b %d %Y %T"` : "${1}"	# Add the time stamp to the log message
	echo "${1}" >> ./IPERF3Test.log
}

UpdateTestState()
{
	echo "${1}" > ./state.txt
}

if [ -e ${CONSTANTS_FILE} ]; then
	source ${CONSTANTS_FILE}
else
	errMsg="Error: missing ${CONSTANTS_FILE} file"
	LogMsg "${errMsg}"
	UpdateTestState $ICA_TESTABORTED
	exit 10
fi

if [ ! ${server} ]; then
	errMsg="Please add/provide value for server in constants.sh. server=<server ip>"
	LogMsg "${errMsg}"
	echo "${errMsg}" >> ./summary.log
	UpdateTestState $ICA_TESTABORTED
	exit 1
fi
if [ ! ${client} ]; then
	errMsg="Please add/provide value for client in constants.sh. client=<client ip>"
	LogMsg "${errMsg}"
	echo "${errMsg}" >> ./summary.log
	UpdateTestState $ICA_TESTABORTED
	exit 1
fi

if [ ! ${testDuration} ]; then
	errMsg="Please add/provide value for testDuration in constants.sh. testDuration=60"
	LogMsg "${errMsg}"
	echo "${errMsg}" >> ./summary.log
	UpdateTestState $ICA_TESTABORTED
	exit 1
fi

if [ ! ${testType} ]; then
		errMsg="Please add/provide value for testType in constants.sh. testType=tcp/udp"
		LogMsg "${errMsg}"
		echo "${errMsg}" >> ./summary.log
		UpdateTestState $ICA_TESTABORTED
		exit 1
fi

if [ ! ${max_parallel_connections_per_instance} ]; then
		errMsg="Please add/provide value for max_parallel_connections_per_instance in constants.sh. max_parallel_connections_per_instance=60"
		LogMsg "${errMsg}"
		echo "${errMsg}" >> ./summary.log
		UpdateTestState $ICA_TESTABORTED
		exit 1
fi

if [ ! ${connections} ]; then
		errMsg="Please add/provide value for connections in constants.sh. connections=(1 2 4 8 ....)"
		LogMsg "${errMsg}"
		echo "${errMsg}" >> ./summary.log
		UpdateTestState $ICA_TESTABORTED
		exit 1
fi

if [ ! ${bufferLengths} ]; then
		errMsg="Please add/provide value for bufferLengths in constants.sh. bufferLengths=(1 8). Note buffer lenghs are in Bytest"
		LogMsg "${errMsg}"
		echo "${errMsg}" >> ./summary.log
		UpdateTestState $ICA_TESTABORTED
		exit 1
fi

if [ ! ${IPversion} ]; then
		errMsg="Please add/provide value for IPversion in constants.sh. IPversion=4/6."
		LogMsg "${errMsg}"
		echo "${errMsg}" >> ./summary.log
		UpdateTestState $ICA_TESTABORTED
		exit 1
fi

if [ $IPversion -eq 6 ]; then
	if [ ! ${serverIpv6} ]; then
			errMsg="Please add/provide value for serverIpv6 in constants.sh"
			LogMsg "${errMsg}"
			echo "${errMsg}" >> ./summary.log
			UpdateTestState $ICA_TESTABORTED
			exit 1
	fi
		if [ ! ${clientIpv6} ]; then
				errMsg="Please add/provide value for clientIpv6 in constants.sh."
				LogMsg "${errMsg}"
				echo "${errMsg}" >> ./summary.log
				UpdateTestState $ICA_TESTABORTED
				exit 1
		fi

fi

#connections=(64 128)
#BufferLenghts are in Bytes
#max_parallel_connections_per_instance=64
#Make & build IPERF3 on client and server Machine

LogMsg "Configuring client ${client}..."
InstallIPERF3 ${client}

LogMsg "Configuring server ${server}..."
InstallIPERF3 ${server}

ssh ${server} "rm -rf iperf-server-*"
ssh ${client} "rm -rf iperf-client-*"
ssh ${client} "rm -rf iperf-server-*"

#connections=(1 2 4 8 16 32 64 128 256 512 1024)
#BufferLenghts are in K
#bufferLenghs=(1 8)

for current_buffer in "${bufferLengths[@]}"
		do
		for current_test_connections in "${connections[@]}"
		do
		if [ $current_test_connections -lt $max_parallel_connections_per_instance ]
		then
			num_threads_P=$current_test_connections
			num_threads_n=1
		else
			num_threads_P=$max_parallel_connections_per_instance
			num_threads_n=$(($current_test_connections / $num_threads_P))
		fi

		ssh ${server} "killall iperf3"
		ssh ${client} "killall iperf3"
		LogMsg "Starting $num_threads_n iperf3 server instances on $server.."
		startPort=750
		currentPort=$startPort
		currentIperfInstanses=0
		while [ $currentIperfInstanses -lt $num_threads_n ]
		do
			currentIperfInstanses=$(($currentIperfInstanses+1))
			serverCommand="iperf3 -s -1 -J -i10 -f g -p ${currentPort} > iperf-server-${testType}-IPv${IPversion}-buffer-${current_buffer}-conn-$current_test_connections-instance-${currentIperfInstanses}.txt 2>&1"
			ssh ${server} $serverCommand &
			LogMsg "Executed: $serverCommand"
			currentPort=$(($currentPort+1))
			sleep 0.1
		done

		LogMsg "$num_threads_n iperf server instances started on $server.."
		sleep 5
		LogMsg "Starting client.."
		startPort=750
		currentPort=$startPort
		currentIperfInstanses=0
		if [ $IPversion -eq 4 ]; then
				testServer=$server
		else
				testServer=$serverIpv6
		fi
		#ssh ${client} "./sar-top.sh ${testDuration} $current_test_connections root" &
		#ssh ${server} "./sar-top.sh ${testDuration} $current_test_connections root" &
		while [ $currentIperfInstanses -lt $num_threads_n ]
		do
			currentIperfInstanses=$(($currentIperfInstanses+1))

			if [[ "$testType" == "udp" ]];
			then
				clientCommand="iperf3 -c $testServer -u -b 0 -J -f g -i10 -l ${current_buffer} -t ${testDuration} -p ${currentPort} -P $num_threads_P -${IPversion} > iperf-client-${testType}-IPv${IPversion}-buffer-${current_buffer}-conn-$current_test_connections-instance-${currentIperfInstanses}.txt 2>&1"
			fi
						if [[ "$testType" == "tcp" ]];
						then
								clientCommand="iperf3 -c $testServer -b 0 -J -f g -i10 -l ${current_buffer} -t ${testDuration} -p ${currentPort} -P $num_threads_P -${IPversion} > iperf-client-${testType}-IPv${IPversion}-buffer-${current_buffer}-conn-$current_test_connections-instance-${currentIperfInstanses}.txt 2>&1"
						fi

			ssh ${client} $clientCommand &
			LogMsg "Executed: $clientCommand"
			currentPort=$(($currentPort+1))
			sleep 0.1
		done
		LogMsg "Iperf3 running buffer ${current_buffer}Bytes $num_threads_P X $num_threads_n ..."
		sleep ${testDuration}
		timeoutSeconds=900
		sleep 5
		var=`ps -C "iperf3 -c" --no-headers | wc -l`
		echo $var
		while [[ $var -gt 0 ]];
		do
			timeoutSeconds=`expr $timeoutSeconds - 1`
			if [ $timeoutSeconds -eq 0 ]; then
				LogMsg "Iperf3 running buffer ${current_buffer}K $num_threads_P X $num_threads_n. Timeout."
				LogMsg "killing all iperf3 client threads."
				killall iperf3
				sleep 1
			else
				sleep 1
				var=`ps -C "iperf3 -c" --no-headers | wc -l`
				LogMsg "Iperf3 running buffer ${current_buffer}K $num_threads_P X $num_threads_n. Waiting to finish $var instances."
			fi
		done
		#Sleep extra 5 seconds.
		sleep 5
		LogMsg "Iperf3 Finished buffer ${current_buffer}  $num_threads_P X $num_threads_n ..."
	done
done
scp ${server}:iperf-server-* ./
UpdateTestState ICA_TESTCOMPLETED


#!/bin/bash

#######################################################################
#
# Linux on Hyper-V and Azure Test Code, ver. 1.0.0
# Copyright (c) Microsoft Corporation
#
# All rights reserved.
# 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
#
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
# ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
#
# See the Apache Version 2.0 License for specific language governing
# permissions and limitations under the License.
#
#######################################################################

#######################################################################
#
# perf_lagscope.sh
# Author : SHITAL SAVEKAR <v-shisav@microsoft.com>
#
# Description:
#    Download and run lagscope latency tests.
#    This script needs to be run on client VM.
#
# Supported Distros:
#    Ubuntu 16.04
#######################################################################

CONSTANTS_FILE="./constants.sh"
ICA_TESTRUNNING="TestRunning"		# The test is running
ICA_TESTCOMPLETED="TestCompleted"	# The test completed successfully
ICA_TESTABORTED="TestAborted"		# Error during the setup of the test
ICA_TESTFAILED="TestFailed"			# Error occurred during the test
touch ./lagscopeTest.log

InstallLAGSCOPE() {
		DISTRO=`grep -ihs "buntu\|Suse\|Fedora\|Debian\|CentOS\|Red Hat Enterprise Linux" /etc/{issue,*release,*version}`

		if [[ $DISTRO =~ "Ubuntu" ]];
		then
			LogMsg "Detected UBUNTU"
				LogMsg "Configuring ${1} for lagscope test..."
				ssh ${1} "until dpkg --force-all --configure -a; sleep 10; do echo 'Trying again...'; done"
				ssh ${1} "apt-get update"
				ssh ${1} "apt-get -y install libaio1 sysstat git bc make gcc"
				ssh ${1} "rm -rf lagscope"
				ssh ${1} "git clone https://github.com/Microsoft/lagscope"
				ssh ${1} "cd lagscope/src && make && make install"

		elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 6" ]];
		then
				LogMsg "Detected Redhat 6.x"
				ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm"
				ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc"
				ssh ${1} "yum -y --nogpgcheck install gcc-c++"

				ssh ${1} "wget http://ftp.heanet.ie/mirrors/gnu/libc/glibc-2.14.1.tar.gz"
				ssh ${1} "tar xvf glibc-2.14.1.tar.gz"
				ssh ${1} "mv glibc-2.14.1 glibc-2.14 && cd glibc-2.14 && mkdir build && cd build && ../configure --prefix=/opt/glibc-2.14 && make && make install && export LD_LIBRARY_PATH=/opt/glibc-2.14/lib:$LD_LIBRARY_PATH"

				ssh ${1} "rm -rf lagscope"
				ssh ${1} "git clone https://github.com/Microsoft/lagscope"
				ssh ${1} "cd lagscope/src && make && make install"
				ssh ${1} "iptables -F"

		elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 7" ]];
		then
				LogMsg "Detected Redhat 7.x"
				ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"
				ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc"
				ssh ${1} "rm -rf lagscope"
				ssh ${1} "git clone https://github.com/Microsoft/lagscope"
				ssh ${1} "cd lagscope/src && make && make install"
				ssh ${1} "iptables -F"

		elif [[ $DISTRO =~ "CentOS Linux release 6" ]];
		then
				LogMsg "Detected CentOS 6.x"
				ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm"
				ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc"
				ssh ${1} "yum -y --nogpgcheck install gcc-c++"
				ssh ${1} "rm -rf lagscope"
				ssh ${1} "git clone https://github.com/Microsoft/lagscope"
				ssh ${1} "cd lagscope/src && make && make install"
				ssh ${1} "iptables -F"

		elif [[ $DISTRO =~ "CentOS Linux release 7" ]];
		then
				LogMsg "Detected CentOS 7.x"
				ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"
				ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc"
				ssh ${1} "rm -rf lagscope"
				ssh ${1} "git clone https://github.com/Microsoft/lagscope"
				ssh ${1} "cd lagscope/src && make && make install"
				ssh ${1} "iptables -F"

		elif [[ $DISTRO =~ "SUSE Linux Enterprise Server 12" ]];
		then
		LogMsg "Detected SLES12"
				ssh ${1} "zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys remove gettext-runtime-mini*"
				ssh ${1} "zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys install sysstat git bc make gcc grub2"
				ssh ${1} "rm -rf lagscope"
				ssh ${1} "git clone https://github.com/Microsoft/lagscope"
				ssh ${1} "cd lagscope/src && make && make install"
				ssh ${1} "iptables -F"

		else
				LogMsg "Unknown Distro"
				UpdateTestState "TestAborted"
				UpdateSummary "Unknown Distro, test aborted"
				return 1
	fi
}
LogMsg()
{
    echo `date "+%b %d %Y %T"` : "${1}"    # Add the time stamp to the log message
    echo "${1}" >> ./ntttcpTest.log
}

UpdateTestState()
{
    echo "${1}" > ./state.txt
}

if [ -e ${CONSTANTS_FILE} ]; then
    source ${CONSTANTS_FILE}
else
    errMsg="Error: missing ${CONSTANTS_FILE} file"
    LogMsg "${errMsg}"
    UpdateTestState $ICA_TESTABORTED
    exit 10
fi

if [ ! ${server} ]; then
	errMsg="Please add/provide value for server in constants.sh. server=<server ip>"
	LogMsg "${errMsg}"
	echo "${errMsg}" >> ./summary.log
	UpdateTestState $ICA_TESTABORTED
	exit 1
fi
if [ ! ${client} ]; then
	errMsg="Please add/provide value for client in constants.sh. client=<client ip>"
	LogMsg "${errMsg}"
	echo "${errMsg}" >> ./summary.log
	UpdateTestState $ICA_TESTABORTED
	exit 1
fi

if [ ! ${pingIteration} ]; then
	errMsg="Please add/provide value for pingIteration in constants.sh. pingIteration=1000000"
	LogMsg "${errMsg}"
	echo "${errMsg}" >> ./summary.log
	UpdateTestState $ICA_TESTABORTED
	exit 1
fi

#Make & build ntttcp on client and server Machine

LogMsg "Configuring client ${client}..."
InstallLAGSCOPE ${client}

LogMsg "Configuring server ${server}..."
InstallLAGSCOPE ${server}

#Now, start the ntttcp client on client VM.

LogMsg "Now running Lagscope test"
LogMsg "Starting server."
ssh root@${server} "lagscope -r -D"
sleep 1
LogMsg "lagscope client running..."
ssh root@${client} "lagscope -s${server} -i0 -n${pingIteration} -H > lagscope-n${pingIteration}-output.txt"
LogMsg "Test finsished."
UpdateTestState ICA_TESTCOMPLETED


#!/bin/bash

#######################################################################
#
# Linux on Hyper-V and Azure Test Code, ver. 1.0.0
# Copyright (c) Microsoft Corporation
#
# All rights reserved.
# 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
#
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
# ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
#
# See the Apache Version 2.0 License for specific language governing
# permissions and limitations under the License.
#
#######################################################################

#######################################################################
#
# perf_ntttcp.sh
# Author : SHITAL SAVEKAR <v-shisav@microsoft.com>
#
# Description:
#    Download and run ntttcp network performance tests.
#    This script needs to be run on client VM.
#
# Supported Distros:
#    Ubuntu 16.04
#######################################################################

CONSTANTS_FILE="./constants.sh"
ICA_TESTRUNNING="TestRunning"           # The test is running
ICA_TESTCOMPLETED="TestCompleted"       # The test completed successfully
ICA_TESTABORTED="TestAborted"           # Error during the setup of the test
ICA_TESTFAILED="TestFailed"                     # Error occurred during the test
touch ./ntttcpTest.log

InstallNTTTCP() {
                DISTRO=`grep -ihs "buntu\|Suse\|Fedora\|Debian\|CentOS\|Red Hat Enterprise Linux" /etc/{issue,*release,*version}`

                if [[ $DISTRO =~ "Ubuntu" ]];
                then
                        LogMsg "Detected UBUNTU"
                                LogMsg "Configuring ${1} for ntttcp test..."
                                ssh ${1} "until dpkg --force-all --configure -a; sleep 10; do echo 'Trying again...'; done"
                                ssh ${1} "apt-get update"
                                ssh ${1} "apt-get -y install libaio1 sysstat git bc make gcc dstat psmisc"
                                ssh ${1} "git clone https://github.com/Microsoft/ntttcp-for-linux.git"
                                ssh ${1} "cd ntttcp-for-linux/src/ && make && make install"
                                ssh ${1} "cp ntttcp-for-linux/src/ntttcp ."
                                ssh ${1} "rm -rf lagscope"
                                ssh ${1} "git clone https://github.com/Microsoft/lagscope"
                                ssh ${1} "cd lagscope/src && make && make install"

                elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 6" ]];
                then
                                LogMsg "Detected Redhat 6.x"
                                ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm"
                                ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc dstat psmisc"
                                ssh ${1} "yum -y --nogpgcheck install gcc-c++"

                                ssh ${1} "wget http://ftp.heanet.ie/mirrors/gnu/libc/glibc-2.14.1.tar.gz"
                                ssh ${1} "tar xvf glibc-2.14.1.tar.gz"
                                ssh ${1} "mv glibc-2.14.1 glibc-2.14 && cd glibc-2.14 && mkdir build && cd build && ../configure --prefix=/opt/glibc-2.14 && make && make install && export LD_LIBRARY_PATH=/opt/glibc-2.14/lib:$LD_LIBRARY_PATH"

                                ssh ${1} "git clone https://github.com/Microsoft/ntttcp-for-linux.git"
                                ssh ${1} "cd ntttcp-for-linux/src/ && make && make install"
                                ssh ${1} "cp ntttcp-for-linux/src/ntttcp ."
                                ssh ${1} "rm -rf lagscope"
                                ssh ${1} "git clone https://github.com/Microsoft/lagscope"
                                ssh ${1} "cd lagscope/src && make && make install"
                                ssh ${1} "iptables -F"

                elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 7" ]];
                then
                                LogMsg "Detected Redhat 7.x"
                                ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"
                                ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc dstat psmisc"
                                ssh ${1} "git clone https://github.com/Microsoft/ntttcp-for-linux.git"
                                ssh ${1} "cd ntttcp-for-linux/src/ && make && make install"
                                ssh ${1} "cp ntttcp-for-linux/src/ntttcp ."
                                ssh ${1} "rm -rf lagscope"
                                ssh ${1} "git clone https://github.com/Microsoft/lagscope"
                                ssh ${1} "cd lagscope/src && make && make install"
                                ssh ${1} "iptables -F"

                elif [[ $DISTRO =~ "CentOS Linux release 6" ]] || [[ $DISTRO =~ "CentOS release 6" ]];
                then
                                LogMsg "Detected CentOS 6.x"
                                ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm"
                                ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc dstat psmisc"
                                ssh ${1} "yum -y --nogpgcheck install gcc-c++"
                                ssh ${1} "git clone https://github.com/Microsoft/ntttcp-for-linux.git"
                                ssh ${1} "cd ntttcp-for-linux/src/ && make && make install"
                                ssh ${1} "cp ntttcp-for-linux/src/ntttcp ."
                                ssh ${1} "rm -rf lagscope"
                                ssh ${1} "git clone https://github.com/Microsoft/lagscope"
                                ssh ${1} "cd lagscope/src && make && make install"
                                ssh ${1} "iptables -F"

                elif [[ $DISTRO =~ "CentOS Linux release 7" ]];
                then
                                LogMsg "Detected CentOS 7.x"
                                ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"
                                ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc dstat psmisc"
                                ssh ${1} "git clone https://github.com/Microsoft/ntttcp-for-linux.git"
                                ssh ${1} "cd ntttcp-for-linux/src/ && make && make install"
                                ssh ${1} "cp ntttcp-for-linux/src/ntttcp ."
                                ssh ${1} "rm -rf lagscope"
                                ssh ${1} "git clone https://github.com/Microsoft/lagscope"
                                ssh ${1} "cd lagscope/src && make && make install"
                                ssh ${1} "iptables -F"

                elif [[ $DISTRO =~ "SUSE Linux Enterprise Server 12" ]];
                then
                LogMsg "Detected SLES12"
                                ssh ${1} "zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys remove gettext-runtime-mini*"
                                ssh ${1} "zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys install sysstat git bc make gcc grub2 dstat psmisc"
                                ssh ${1} "git clone https://github.com/Microsoft/ntttcp-for-linux.git"
                                ssh ${1} "cd ntttcp-for-linux/src/ && make && make install"
                                ssh ${1} "cp ntttcp-for-linux/src/ntttcp ."
                                ssh ${1} "rm -rf lagscope"
                                ssh ${1} "git clone https://github.com/Microsoft/lagscope"
                                ssh ${1} "cd lagscope/src && make && make install"
                                ssh ${1} "iptables -F"

                else
                                LogMsg "Unknown Distro"
                                UpdateTestState "TestAborted"
                                UpdateSummary "Unknown Distro, test aborted"
                                return 1
        fi
}
LogMsg()
{
    echo `date "+%b %d %Y %T"` : "${1}"    # Add the time stamp to the log message
    echo "${1}" >> ./ntttcpTest.log
}

UpdateTestState()
{
    echo "${1}" > ./state.txt
}

if [ -e ${CONSTANTS_FILE} ]; then
    source ${CONSTANTS_FILE}
else
    errMsg="Error: missing ${CONSTANTS_FILE} file"
    LogMsg "${errMsg}"
    UpdateTestState $ICA_TESTABORTED
    exit 10
fi

if [ ! ${server} ]; then
        errMsg="Please add/provide value for server in constants.sh. server=<server ip>"
        LogMsg "${errMsg}"
        echo "${errMsg}" >> ./summary.log
        UpdateTestState $ICA_TESTABORTED
        exit 1
fi
if [ ! ${client} ]; then
        errMsg="Please add/provide value for client in constants.sh. client=<client ip>"
        LogMsg "${errMsg}"
        echo "${errMsg}" >> ./summary.log
        UpdateTestState $ICA_TESTABORTED
        exit 1
fi

if [ ! ${testDuration} ]; then
        errMsg="Please add/provide value for testDuration in constants.sh. testDuration=60"
        LogMsg "${errMsg}"
        echo "${errMsg}" >> ./summary.log
        UpdateTestState $ICA_TESTABORTED
        exit 1
fi

if [ ! ${nicName} ]; then
        errMsg="Please add/provide value for nicName in constants.sh. nicName=eth0/bond0"
        LogMsg "${errMsg}"
        echo "${errMsg}" >> ./summary.log
        UpdateTestState $ICA_TESTABORTED
        exit 1
fi
#Make & build ntttcp on client and server Machine

LogMsg "Configuring client ${client}..."
InstallNTTTCP ${client}

LogMsg "Configuring server ${server}..."
InstallNTTTCP ${server}

#Now, start the ntttcp client on client VM.

ssh root@${client} "wget https://raw.githubusercontent.com/iamshital/linux_performance_test/master/run_ntttcp-for-linux/run-ntttcp-and-tcping.sh"
ssh root@${client} "wget https://raw.githubusercontent.com/iamshital/linux_performance_test/master/run_ntttcp-for-linux/report-ntttcp-and-tcping.sh"
ssh root@${client} "chmod +x run-ntttcp-and-tcping.sh && chmod +x report-ntttcp-and-tcping.sh"
LogMsg "Now running NTTTCP test"
ssh root@${client} "rm -rf ntttcp-test-logs"
ssh root@${client} "./run-ntttcp-and-tcping.sh ntttcp-test-logs ${server} root ${testDuration} ${nicName} '$testConnections'"
ssh root@${client} "./report-ntttcp-and-tcping.sh ntttcp-test-logs '$testConnections'"
ssh root@${client} "cp ntttcp-test-logs/* ."

UpdateTestState ICA_TESTCOMPLETED


#!/bin/bash

#######################################################################
#
# Linux on Hyper-V and Azure Test Code, ver. 1.0.0
# Copyright (c) Microsoft Corporation
#
# All rights reserved.
# 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
#
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
# ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
#
# See the Apache Version 2.0 License for specific language governing
# permissions and limitations under the License.
#
#######################################################################

#######################################################################
#
# perf_orion.sh
# Author : SHITAL SAVEKAR <v-shisav@microsoft.com>
#
# Description:
#    Download and run orion disk performance tests.
#    This script needs to be run on single VM with one data disk attached.
#    This script requires orion.lun file to be present in pwd. It contains the disk names on which we need to perform the test.
#    orion.lun:
#    /dev/sdc
#
# Supported Distros:
#    Ubuntu 16.04
#######################################################################

CONSTANTS_FILE="./constants.sh"
ICA_TESTRUNNING="TestRunning"      # The test is running
ICA_TESTCOMPLETED="TestCompleted"  # The test completed successfully
ICA_TESTABORTED="TestAborted"      # Error during the setup of the test
ICA_TESTFAILED="TestFailed"        # Error occurred during the test
touch ./orionTest.log

LogMsg()
{
    echo `date "+%b %d %Y %T"` : "${1}"    # Add the time stamp to the log message
    echo "${1}" >> ./orionTest.log
}

UpdateTestState()
{
    echo "${1}" > ./state.txt
}

ConfigUbuntu1604()
{
    LogMsg "Running ConfigUbuntu..."
	apt-get update
	apt-get -y install libaio1 sysstat
}

if [ -e ${CONSTANTS_FILE} ]; then
    source ${CONSTANTS_FILE}
else
    errMsg="Error: missing ${CONSTANTS_FILE} file"
    LogMsg "${errMsg}"
    UpdateTestState $ICA_TESTABORTED
    exit 10
fi

ConfigUbuntu1604

if [ -e orion_x86_64 ]; then
    LogMsg "orion binary already exists."
else
    wget ${orionBinaryURL}
fi
chmod +x ./orion_x86_64

UpdateTestState "TestRunning"
#all read
testType="oltp"
LogMsg "Running $testType test.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run oltp -testname orion
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

testType="dss"
LogMsg "Running $testType test.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run dss -testname orion
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

testType="simple"
LogMsg "Running $testType test.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run simple -testname orion
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

testType="normal#1"
LogMsg "Running $testType test iteration #1.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run normal -testname orion
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

#redo the "normal" test

testType="normal#2"
LogMsg "Running $testType test iteration #2.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run normal -testname orion
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

testType="normal#3"
LogMsg "Running $testType test iteration #3.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run normal -testname orion
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

#all write

testType="oltpWrite100"
LogMsg "Running $testType test.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run oltp -testname orion -write 100
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

testType="dssWrite100"
LogMsg "Running $testType test.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run dss -testname orion -write 100
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

testType="advancedWrite100Basic"
LogMsg "Running $testType test.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run advanced -size_small 8 -size_large 1024 -type rand -simulate concat -write 100 -duration 60 -matrix basic
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

testType="advancedWrite100Detailed#1"
LogMsg "Running $testType test iteration #1.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run advanced -size_small 8 -size_large 1024 -type rand -simulate concat -write 100 -duration 60 -matrix detailed
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

#redo the "normal" test
testType="advancedWrite100Detailed#2"
LogMsg "Running $testType test iteration #2.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run advanced -size_small 8 -size_large 1024 -type rand -simulate concat -write 100 -duration 60 -matrix detailed
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

testType="advancedWrite100Detailed#3"
LogMsg "Running $testType test iteration #3.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run advanced -size_small 8 -size_large 1024 -type rand -simulate concat -write 100 -duration 60 -matrix detailed
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

#read50% and write 50%
testType="oltpWrite50"
LogMsg "Running $testType test.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run oltp -testname orion -write 50
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

testType="dssWrite50"
LogMsg "Running $testType test.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run dss -testname orion -write 50
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

testType="advancedWrite50Basic"
LogMsg "Running $testType test.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run advanced -size_small 8 -size_large 1024 -type rand -simulate concat -write 50 -duration 60 -matrix basic
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

testType="advancedWrite50Detailed#1"
LogMsg "Running $testType test iteration #1.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run advanced -size_small 8 -size_large 1024 -type rand -simulate concat -write 50 -duration 60 -matrix detailed
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

#redo the "normal" test
testType="advancedWrite50Detailed#2"
LogMsg "Running $testType test iteration #2.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run advanced -size_small 8 -size_large 1024 -type rand -simulate concat -write 50 -duration 60 -matrix detailed
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

testType="advancedWrite50Detailed#3"
LogMsg "Running $testType test iteration #3.."
dateTime="$(date +"%m-%d-%Y-%H-%M-%S")"
iostat -x -d 1 4000 2>&1 > "orion-${testType}-${dateTime}.iostat.diskio.log"  &
vmstat 1 4000 2>&1 > "orion-${testType}-${dateTime}.vmstat.memory.cpu.log"  &
./orion_x86_64 -run advanced -size_small 8 -size_large 1024 -type rand -simulate concat -write 50 -duration 60 -matrix detailed
pkill -f iostat
pkill -f vmstat
mv *_iops.csv "orion-${testType}-${dateTime}-iops.csv"
mv *_lat.csv "orion-${testType}-${dateTime}-lat.csv"
mv *_mbps.csv "orion-${testType}-${dateTime}-mbps.csv"
mv *_summary.txt "orion-${testType}-${dateTime}-summary.txt"
mv *_trace.txt "orion-${testType}-${dateTime}-trace.txt"
LogMsg "$testType test finished."

UpdateTestState "TestCompleted"


#!/bin/bash

#######################################################################
#
# Linux on Hyper-V and Azure Test Code, ver. 1.0.0
# Copyright (c) Microsoft Corporation
#
# All rights reserved.
# 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
#
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
# ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
#
# See the Apache Version 2.0 License for specific language governing
# permissions and limitations under the License.
#
#######################################################################

#######################################################################
#
# perf_redis.sh
# Author : SHITAL SAVEKAR <v-shisav@microsoft.com>
#
# Description:
#    Download and run redis benchmark tests.
#    This script needs to be run on client VM.
#
# Supported Distros:
#    Ubuntu 16.04
#######################################################################

CONSTANTS_FILE="./constants.sh"
ICA_TESTRUNNING="TestRunning"      # The test is running
ICA_TESTCOMPLETED="TestCompleted"  # The test completed successfully
ICA_TESTABORTED="TestAborted"      # Error during the setup of the test
ICA_TESTFAILED="TestFailed"        # Error occurred during the test
touch ./redisTest.log
ConfigureRedisUbuntu()
{
        LogMsg "Configuring ${1} for redis test..."
        ssh ${1} "apt-get update"
        ssh ${1} "apt-get -y install libaio1 sysstat gcc"
        ssh ${1} "wget http://download.redis.io/releases/redis-${redisVersion}.tar.gz"
        ssh ${1} "tar -xvf  redis-${redisVersion}.tar.gz && cd redis-${redisVersion}/ && make && make install"
        ssh ${1} "cp -ar redis-${redisVersion}/src/* ."
        LogMsg "${1} configured for Redis."
}

LogMsg()
{
    echo `date "+%b %d %Y %T"` : "${1}"    # Add the time stamp to the log message
    echo `date "+%b %d %Y %T"` : "${1}" >> ./redisTest.log
}

UpdateTestState()
{
    LogMsg "${1}" > ./state.txt
}

if [ -e ${CONSTANTS_FILE} ]; then
    source ${CONSTANTS_FILE}
else
    errMsg="Error: missing ${CONSTANTS_FILE} file"
    LogMsg "${errMsg}"
    UpdateTestState $ICA_TESTABORTED
    exit 10
fi

if [ ! ${server} ]; then
        errMsg="Please add/provide value for server in constants.sh. server=<server ip>"
        LogMsg "${errMsg}"
        LogMsg "${errMsg}" >> ./summary.log
        UpdateTestState $ICA_TESTABORTED
        exit 1
fi
LogMsg "Server=${server}"

if [ ! ${client} ]; then
        errMsg="Please add/provide value for client in constants.sh. client=<client ip>"
        LogMsg "${errMsg}"
        LogMsg "${errMsg}" >> ./summary.log
        UpdateTestState $ICA_TESTABORTED
        exit 1
fi

LogMsg "Client=${client}"
if [ ! ${test_pipeline_collection} ]; then
        errMsg="Please add/provide value for test_pipeline_collection in constants.sh. test_pipeline_collection=(1 2 4 8 16)"
        LogMsg "${errMsg}"
        LogMsg "${errMsg}" >> ./summary.log
        UpdateTestState $ICA_TESTABORTED
        exit 1
fi
LogMsg "test_pipeline_collection=${test_pipeline_collection}"

if [ ! ${redisVersion} ]; then
        errMsg="Please add/provide value for redisVersion in constants.sh. redisVersion=2.8.17"
        LogMsg "${errMsg}"
        LogMsg "${errMsg}" >> ./summary.log
        UpdateTestState $ICA_TESTABORTED
        exit 1
fi
LogMsg "redisVersion=${redisVersion}"
if [ ! ${redis_test_suites} ]; then
        errMsg="Please add/provide value for redis_test_suites in constants.sh. redis_test_suites=get,set"
        LogMsg "${errMsg}"
        LogMsg "${errMsg}" >> ./summary.log
        UpdateTestState $ICA_TESTABORTED
        exit 1
fi

#Make & build Redis on client and server Machine

LogMsg "Configuring client ${client}..."
ConfigureRedisUbuntu ${client}

LogMsg "Configuring server ${server}..."
ConfigureRedisUbuntu ${server}

pkill -f redis-benchmark
ssh root@${server} pkill -f redis-server > /dev/null

t=0
while [ "x${test_pipeline_collection[$t]}" != "x" ]
do
        pipelines=${test_pipeline_collection[$t]}
        LogMsg "NEXT TEST: $pipelines pipelines"

        # prepare running redis-server
        LogMsg "Starting redis-server..."
        ssh root@${server} "sar -n DEV 1 900"   2>&1 > redis-server-pipelines-${pipelines}.sar.netio.log  &
        ssh root@${server} "iostat -x -d 1 900" 2>&1 > redis-server-pipelines-${pipelines}.iostat.diskio.log  &
        ssh root@${server} "vmstat 1 900"       2>&1 > redis-server-pipelines-${pipelines}.vmstat.memory.cpu.log  &

		#start running the redis-server on server
        ssh root@${server} "./redis-server  > /dev/null  &"
        LogMsg "Server started successfully. Sleeping 10 Secondss.."
        sleep 10

        # prepare running redis-benchmark
        sar -n DEV 1 900   2>&1  > redis-client-pipelines-${pipelines}.sar.netio.log &
        iostat -x -d 1 900 2>&1  > redis-client-pipelines-${pipelines}.iostat.diskio.log &
        vmstat 1 900       2>&1  > redis-client-pipelines-${pipelines}.vmstat.memory.cpu.log &

        #start running the redis-benchmark on client
        LogMsg "Starting redis-benchmark on client..."
        LogMsg "-> Test running with ${pipelines} pipelines."
        ./redis-benchmark -h $server -c 1000 -P $pipelines -t $redis_test_suites -d 4000 -n 10000000 > redis-client-pipelines-${pipelines}.set.get.log
        LogMsg "-> done"

        #cleanup redis-server
        LogMsg "Cleaning Server..."
        ssh root@${server} pkill -f sar 2>&1 > /dev/null
        ssh root@${server} pkill -f iostat 2>&1 > /dev/null
        ssh root@${server} pkill -f vmstat 2>&1 > /dev/null
        ssh root@${server} pkill -f redis-server 2>&1 > /dev/null

        #cleanup redis-benchmark
        LogMsg "Cleaning Client..."
        pkill -f sar 2>&1 > /dev/null
        pkill -f iostat 2>&1 > /dev/null
        pkill -f vmstat 2>&1 > /dev/null
        pkill -f redis-benchmark 2>&1 > /dev/null
        t=$(($t + 1))
		LogMsg "Sleeping 30 Seconds..."
		sleep 30
done
UpdateTestState ICA_TESTCOMPLETED


ï»¿#!/bin/bash
./package-download-test.sh
if [[ $? == 0 ]]; then
        echo 'PASS' > Summary.log
else
        echo 'FAIL' > Summary.log
fi
echo 'TestCompleted' > state.txt


#!/bin/bash
echo 'TestRunning' > state.txt
sudo bash rhui-rpm-source-check.sh > RHUI-BVT-VERIFY-RPM-SOURCE.sh.log
if [[ $? == 0 ]]; then
        echo 'PASS' > Summary.log
else
        echo 'FAIL' > Summary.log
fi
echo 'TestCompleted' > state.txt


#!/bin/bash
#
# It runs the ycsb bechmark test on given server
# ./run-ycsb.sh
#######
CONSTANTS_FILE="/root/constants.sh"

if [ -e ${CONSTANTS_FILE} ]; then
    source ${CONSTANTS_FILE}
else
    errMsg="Error: missing ${CONSTANTS_FILE} file"
    LogMsg "${errMsg}"
    echo "${errMsg}" >> ~/summary.log
    UpdateTestState $ICA_TESTABORTED
    exit 10
fi

log_folder="/root/benchmark/mongodb/logs"

echo "Running ycsb benchmark test on server $MD_SERVER"
ssh root@${MD_SERVER} mkdir -p $log_folder

t=0
while [ "x${test_threads_collection[$t]}" != "x" ]
do
	threads=${test_threads_collection[$t]}
	echo "TEST RUNNING WITH: $threads threads"
	# prepare running mongodb-server
	echo "prepare running mongodb-server"
	ssh root@${MD_SERVER} "mkdir -p $log_folder/$threads"
	ssh root@${MD_SERVER} "sar -n DEV 1 ${maxexecutiontime}   2>&1 > $log_folder/$threads/$threads-mongodb-server.sar.netio.log " &
	ssh root@${MD_SERVER} "iostat -x -d 1 ${maxexecutiontime} 2>&1 > $log_folder/$threads/$threads-mongodb-server.iostat.diskio.log " &
	ssh root@${MD_SERVER} "vmstat 1 ${maxexecutiontime} 2>&1 > $log_folder/$threads/$threads-mongodb-server.vmstat.memory.cpu.log " &

	# prepare running mongodb-benchmark(ycsb)
	echo "prepare running mongodb-benchmark(ycsb)"
	mkdir -p $log_folder/$threads
	sar -n DEV 1 ${maxexecutiontime}   2>&1 > $log_folder/$threads/$threads-mongodb-client.sar.netio.log  &
	iostat -x -d 1 ${maxexecutiontime} 2>&1 > $log_folder/$threads/$threads-mongodb-client.iostat.diskio.log &
	vmstat 1 ${maxexecutiontime} 2>&1 > $log_folder/$threads/$threads-mongodb-client.vmstat.memory.cpu.log &

	#start running the mongodb(ycsb)-benchmark on client
	echo "-> TEST RUNNING with threads $threads .."
	echo "CMD: ./ycsb-0.5.0/bin/ycsb  run  mongodb-async -s -P workloadAzure -p mongodb.url=mongodb://${MD_SERVER}:27017/ycsb?w=0 -threads $threads > $log_folder/$threads/$threads.ycsb.run.log"
	./ycsb-0.5.0/bin/ycsb  run  mongodb-async -s -P workloadAzure -p mongodb.url=mongodb://${MD_SERVER}:27017/ycsb?w=0 -threads $threads > $log_folder/$threads/$threads-mongodb.ycsb.run.log
	echo "-> TEST END with threads $threads"

	#cleanup mongodb-server
	echo "cleanup mongodb-server"
	ssh root@${MD_SERVER} pkill -f sar
	ssh root@${MD_SERVER} pkill -f iostat
	ssh root@${MD_SERVER} pkill -f vmstat

	#cleanup mongodb-benchmark(ycsb)
	echo "cleanup mongodb-benchmark(ycsb)"
	pkill -f sar
	pkill -f iostat
	pkill -f vmstat

	echo "sleep 60 seconds"
	sleep 60
	t=$(($t + 1))
	echo "$t"
done


#!/bin/bash
#
# This script collects all the required logs during the network performance test.
# Author: Srikanth M
# Email	: v-srm@microsoft.com
#

if [[ $# == 3 ]]
then
	duration=$1
	filename=$2
	username=$3
	logFolder="logs-`hostname`"
elif [[ $# == 5 ]]
then
	duration=$1
	filename=$2
	username=$3
	testtype=$4
	buffersize=$5
	logFolder="logs-`hostname`-$testtype-$buffersize"
else
	echo "Usage: bash $0 <duration> <filename> <username>"
	exit -1
fi

code_path="/home/$username/code/"
. $code_path/azuremodules.sh

capture_cpu(){
	for i in $(seq 1 $duration)
	do
		date_j=`date +"%T"`
		top_j=`top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}'`
		echo $date_j,$top_j>> $filename-top.csv
		sleep 1
	done
}

capture_connections(){
	for i in $(seq 1 $duration)
	do
		date_i=`date +"%T"`
		netstat_i=`netstat -natp | grep iperf | grep ESTA | wc -l`
		echo $date_i,$netstat_i >> $filename-connections.csv
		sleep 1
	done
}

if [[ `which iperf3` == "" ]]
then
    echo "iperf3 not installed\n Installing now..."
    install_package "iperf3"
fi

if [[ `which sar` == "" ]]
then
    echo "iperf3 not installed\n Installing now..."
    install_package "sysstat"
fi

vm_bus_ver=`modinfo hv_vmbus| grep ^version| awk '{print $2}'`

#logs_dir=$code_path/logs-`hostname`-`uname -r`-`get_lis_version`/$filename
logs_dir=$code_path/$logFolder/$filename
filename=$logs_dir/$filename
mkdir -p  $logs_dir

echo $filename-top.csv $duration $filename $filename-sar.log
[ -f $filename-top.csv  ] && rm -rf $filename-top.csv
[ -f $filename-sar.log  ] && rm -rf $filename-sar.log
[ -f $filename-vmstat.log  ] && rm -rf $filename-vmstat.log
[ -f $filename-connections.csv  ] && rm -rf $filename-connections.csv

echo "uname: -------------------------------------------------" > $filename-sar.log
uname -a 2>&1 >> $filename-sar.log
echo "LIS version: --------------------------------------------" >> $filename-sar.log
modinfo hv_vmbus 2>&1 >> $filename-sar.log
echo "----------------------------------------------------------" >> $filename-sar.log
echo "Number of CPU cores" `nproc` >> $filename-sar.log
echo "Memory" `free -h| grep Mem| awk '{print $2}'` >> $filename-sar.log
echo "Host Build Version" `dmesg | grep "Host Build" | sed "s/.*Host Build://"| awk '{print  $1}'| sed "s/;//"`  >> $filename-sar.log

sar -n DEV 1 $duration 2>&1 >> $filename-sar.log&
sar_pid=$!
vmstat 1 $duration > $filename-vmstat.log&
vmstat_pid=$!
capture_cpu &
capture_cpu_pid=$!
capture_connections &
capture_connections_pid=$!

sleep $duration
kill -9 $sar_pid $capture_cpu_pid $capture_connections_pid $vmstat_pid
dmesg > $filename-dmesg.log
exit 0


#!/bin/bash
#
# This script serves as iperf server.
# Author: Srikanth M
# Email	: v-srm@microsoft.com
#

if [[ $# == 1 ]]
then
	username=$1
elif [[ $# == 3 ]]
then
	username=$1
	testtype=$2
	buffersize=$3
else
	echo "Usage: bash $0 <vm_loginuser>"
	exit -1
fi

ICA_TESTRUNNING="TestRunning"      # The test is running
ICA_TESTCOMPLETED="TestCompleted"  # The test completed successfully
ICA_TESTABORTED="TestAborted"      # Error during setup of test
ICA_TESTFAILED="TestFailed"        # Error during running of test

LogMsg()
{
    echo `date "+%a %b %d %T %Y"` : ${1}    # To add the timestamp to the log file
}

UpdateTestState()
{
    echo $1 > $code_path/state.txt
}

#
# Create the state.txt file so ICA knows we are running
#
LogMsg "Updating test case state to running"
UpdateTestState $ICA_TESTRUNNING

code_path="/home/$username/code"
. $code_path/azuremodules.sh

if [[ `which iperf3` == "" ]]
then
    echo "iperf3 not installed\n Installing now..."
    install_package "iperf3"
fi

for port_number in `seq 8001 8101`
do
	iperf3 -s -D -p $port_number
done

while [ `netstat -natp | grep iperf | grep ESTA | wc -l` -eq 0 ]
do
	sleep 1
	echo "waiting..."
done

duration=300
for number_of_connections  in 1 2 4 8 16 32 64 128 256 512 1024
do
	for port_number in `seq 8001 8501`
	do
		iperf3 -s -D -p $port_number
		if [ $? -ne 0 ]; then
			LogMsg "iperf3 failed to connect server"
			echo "iperf3 failed to connect server"
			UpdateTestState $ICA_TESTFAILED
			exit 80
		fi
	done
	bash $code_path/sar-top.sh $duration $number_of_connections $username $testtype $buffersize&
	if [ $? -ne 0 ]; then
		LogMsg "sar-top failed to execute"
		echo "sar-top failed to execute"
		UpdateTestState $ICA_TESTFAILED
		exit 80
	fi
	sleep $(($duration+10))
done

logs_dir=logs-`hostname`-$testtype-$buffersize

collect_VM_properties $code_path/$logs_dir/VM_properties.csv

bash $code_path/generate_csvs.sh $code_path/$logs_dir $testtype $buffersize
if [ $? -ne 0 ]; then
	LogMsg "Failed to generate test results .csv file"
	echo "Failed to generate test results .csv file"
	UpdateTestState $ICA_TESTFAILED
	exit 80
fi
mv /etc/rc.d/after.local.bkp /etc/rc.d/after.local
mv /etc/rc.local.bkp /etc/rc.local
mv /etc/rc.d/rc.local.bkp /etc/rc.d/rc.local
echo "$testtype $buffersize test is Completed at Server"

#
# Let ICA know we completed successfully
#
LogMsg "Updating test case state to completed"
UpdateTestState $ICA_TESTCOMPLETED


#!/bin/bash

echo "DOWNLOADING_KERNEL"
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.14.1.tar.xz
if [ $? = '0' ]; then
        echo "KERNEL_DOWNLOADED"
        echo "EXTRACTING_FILES"
        tar -xf linux-3.14.1.tar.xz
        echo "COPYING_TO_HOME_DIRECTORY"
        cp -ar ./linux-3.14.1/* ~
        echo "DOWNLOADING_KERNBENCH"
        wget http://ck.kolivas.org/apps/kernbench/kernbench-0.50/kernbench
        if [ $? = '0' ]; then
                echo "KERNBENCH_DOWNLOAD_DONE"
                chmod +x kernbench
                echo "READY_FOR_KERNBENCH_START"
        else
                echo "KERNBENCH_DOWNLOAD_FAILED"
        fi
else
        echo "KERNEL_DOWNLOAD_FAILED"
fi


#!/bin/bash
i=1
while [ $i = '1' ]
do
	./kernbench
done


#!/bin/sh
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
#
# Sample script to run sysbench.
# In this script, we want to test 3 different devices, all mounted on the same
# machine.  You can adapt this script to other situations easily.  The only
# thing to keep in mind is that each different configuration you're testing
# must log its output to a different directory.
#
# For any info contact v-shisav@microsoft.com

while echo $1 | grep ^- > /dev/null; do
    eval $( echo $1 | sed 's/-//g' | tr -d '\012')=$2
    shift
    shift
done
PrepareFiles=$PrepareFiles
RunTest=$RunTest
CleanUp=$CleanUp
CustomLogDir=$CustomLogDir
testIO=$testIO
testThread=$testThread
ioRuntime=$ioRuntime
testMode=$testMode
fileSize=$fileSize
set -u
set -x
#export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/oem/bin:/usr/share/oem/python/bin:/opt/bin

FILEIO="--test=fileio --file-total-size=${fileSize} --file-extra-flags=dsync --file-fsync-freq=0"
#FILEIO="--test=fileio --file-total-size=134G "

####################################
#All run config set here
#
LOGDIR=$CustomLogDir
mkdir -p $CustomLogDir
LOGFILE="${LOGDIR}/sysbench.log.txt"
#FILE PREPARE
echo "===================================== Starting Run $(date +"%x %r %Z") script generated 2/9/2015 4:24:44 PM ================================" >> $LOGFILE
if [ "$PrepareFiles" = "yes" ]; then
	echo "" > $LOGFILE
	chmod 666 $LOGFILE
	echo "SYSBENCH-FILE-PREPARE-PROGRESS" > $LOGDIR/CurrentSysbenchStatus.txt
	echo "Preparing Files: $FILEIO"
	echo "Preparing Files: $FILEIO" >> $LOGFILE
	# Remove any old files from prior runs (to be safe), then prepare a set of new files.
	sysbench $FILEIO cleanup
	echo "--- Disk Usage Before Generating New Files ---" >> $LOGFILE
	df >> $LOGFILE
	iostatfilename="${LOGDIR}/iostat-sysbench-file-prepare.txt"
	nohup iostat -x 5 -t -y > $iostatfilename &
	sysbench $FILEIO prepare
	echo "--- Disk Usage After Generating New Files ---" >> $LOGFILE
	df >> $LOGFILE
	echo "=== End Preparation  $(date +"%x %r %Z") ===" >> $LOGFILE
	echo "SYSBENCH-FILE-PREPARE-FINISH" > $LOGDIR/CurrentSysbenchStatus.txt
	iostatPID=`ps -ef | awk '/iostat/ && !/awk/ { print $2 }'`
	kill -9 $iostatPID
fi
#TEST RUN
if [ "$RunTest" = "yes" ]; then
	iostatfilename="${LOGDIR}/iostat-sysbench-${testMode}-${testIO}-${testThread}.txt"
	nohup iostat -x 5 -t -y > $iostatfilename &
	echo "------------------------------- ${testMode}, ${testIO}, ${testThread} threads ${ioRuntime} seconds------------------ $(date +"%x %r %Z") ---" >> $LOGFILE
	echo "SYSBENCH-TEST-RUNNING-${testMode}-${testIO}K-${testThread}-${ioRuntime}" > $LOGDIR/CurrentSysbenchStatus.txt
	sysbench $FILEIO --file-test-mode=$testMode --file-block-size=${testIO} --max-requests=0 --max-time=$ioRuntime --num-threads=$testThread run >> $LOGFILE
	iostatPID=`ps -ef | awk '/iostat/ && !/awk/ { print $2 }'`
	kill -9 $iostatPID
	echo "SYSBENCH-TEST-FINISHED" > $LOGDIR/CurrentSysbenchStatus.txt
fi
#CLEANUP
if [ "$CleanUp" = "yes" ]; then
	echo "===================================== Completed Run $(date +"%x %r %Z") script generated 2/9/2015 4:24:44 PM ================================" >> $LOGFILE
	sysbench $FILEIO cleanup >> $LOGFILE
fi


#!/bin/bash
#
# usage::-
# nohup bash sysbench-full-io-test.sh &
# or
#./sysbench-full-io-test.sh &
#
# For any info contact v-avchat@microsoft.com

set -u
set -x
#export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/oem/bin:/usr/share/oem/python/bin:/opt/bin

FILEIO="--test=fileio --file-total-size=134G --file-extra-flags=dsync --file-fsync-freq=0"
#FILEIO="--test=fileio --file-total-size=134G "

####################################
#All run config set here
#

if [[ $# == 1 ]]
then
	username=$1
else
	echo "Usage: bash $0 <vm_loginuser>"
	exit -1
fi
code_path="/home/$username/code"
. $code_path/azuremodules.sh
mv $code_path/sysbenchlog/ $code_path/sysbenchlog-$(date +"%m%d%Y-%H%M%S")/
sleep 5
mkdir $code_path/sysbenchlog
LOGDIR="${code_path}/sysbenchlog"
LOGFILE="${LOGDIR}/sysbench.log.txt"

if [[ `which sysbench` == "" ]]
then
	install_package sysbench
	check_exit_status "Sysbench package installation" exit
fi

if [[ `which iostat` == "" ]]
then
	install_package sysstat
	check_exit_status "Sysstat package installation"
fi

echo "uname: -------------------------------------------------" > $LOGFILE
uname -a 2>&1 >> $LOGFILE
echo "LIS version: --------------------------------------------" >> $LOGFILE
modinfo hv_vmbus 2>&1 >> $LOGFILE
echo "----------------------------------------------------------" >> $LOGFILE
echo "Number of CPU cores" `nproc` >> $LOGFILE
echo "Memory" `free -h| grep Mem| awk '{print $2}'` >> $LOGFILE
echo "Host Build Version" `dmesg | grep "Host Build" | sed "s/.*Host Build://"| awk '{print  $1}'| sed "s/;//"`  >> $LOGFILE
echo "Data disks attached" `fdisk -l | grep 'Disk.*/dev/sd[a-z]' |awk  '{print $2}' | sed s/://| sort| grep -v "/dev/sd[ab]$"| wc -l`  >> $LOGFILE

iteration=0
ioruntime=300
maxThread=1024
maxIo=32

#All possible values for file-test-mode are rndrd rndwr rndrw seqrd seqwr seqrewr
modes='rndrd rndwr rndrw seqrd seqrewr'
#modes='rndrd rndwr rndrw seqrd seqwr seqrewr'

startThread=1
startIO=4
####################################

echo "Test log created at: ${LOGFILE}"
echo "===================================== Starting Run $(date +"%x %r %Z") ================================"
echo "===================================== Starting Run $(date +"%x %r %Z") script generated 2/9/2015 4:24:44 PM ================================" >> $LOGFILE

chmod 666 $LOGFILE
echo "Preparing Files: $FILEIO"
echo "Preparing Files: $FILEIO" >> $LOGFILE
# Remove any old files from prior runs (to be safe), then prepare a set of new files.
sysbench $FILEIO cleanup
echo "--- Disk Usage Before Generating New Files ---" >> $LOGFILE
df >> $LOGFILE
sysbench $FILEIO prepare
echo "--- Disk Usage After Generating New Files ---" >> $LOGFILE
df >> $LOGFILE
echo "=== End Preparation  $(date +"%x %r %Z") ===" >> $LOGFILE

####################################
#Trigger run from here
for testmode in $modes; do
	io=$startIO
	while [ $io -le $maxIo ]
	do
		Thread=$startThread
		while [ $Thread -le $maxThread ]
		do
			iostatfilename="${LOGDIR}/iostat-sysbench-${testmode}-${io}K-${Thread}.txt"
			nohup iostat -x 5 -t -y > $iostatfilename &
			echo "-- iteration ${iteration} ----------------------------- ${testmode}, ${io}K, ${Thread} threads, 5 minutes ------------------ $(date +"%x %r %Z") ---" >> $LOGFILE
			sysbench $FILEIO --file-test-mode=$testmode --file-block-size=${io}"K" --max-requests=0 --max-time=$ioruntime --num-threads=$Thread run >> $LOGFILE
			iostatPID=`ps -ef | awk '/iostat/ && !/awk/ { print $2 }'`
			kill -9 $iostatPID
			Thread=$(( Thread*2 ))
			iteration=$(( iteration+1 ))
		done
		io=$(( io*2 ))
	done
done
####################################
echo "===================================== Completed Run $(date +"%x %r %Z") script generated 2/9/2015 4:24:44 PM ================================" >> $LOGFILE
sysbench $FILEIO cleanup >> $LOGFILE

compressedFileName="SysbenchIOTest"$(date +"%m%d%Y-%H%M%S")".tar.gz"
echo "Please wait...Compressing all results to ${compressedFileName}..."
tar -cvzf $compressedFileName $LOGDIR/*.txt
mv $compressedFileName $LOGDIR/$compressedFileName
####################################
find_log_diff () {
LogMax=`(echo "l($1)/l(2)" | bc -l| sed 's/\..*$//')`
LogMin=`(echo "l($2)/l(2)" | bc -l| sed 's/\..*$//')`
diff=$(($LogMax - $LogMin + 1))
echo $diff
}

IO_difference=`find_log_diff $maxIo $startIO`
Thread_difference=`find_log_diff $maxThread $startThread`
Total_Modes=`echo $modes| wc -w`
total_iterations=$(($IO_difference * $Thread_difference *Total_Modes - 1))
echo $total_iterations

last_iteration=`tail -150 $LOGFILE | grep iteration| tail -1 | awk '{print $3}'`

if [ $last_iteration == $total_iterations ]
then
	echo "SYSBENCH TEST COMPLETED" >> $LOGFILE
	echo "SYSBENCH TEST COMPLETED"
else
	echo "SYSBENCH TEST ABORTED" >> $LOGFILE
	echo "SYSBENCH TEST ABORTED"
fi

####################################
bash $code_path/sysbench-log-parser.sh $LOGFILE

echo "Test logs are located at ${LOGDIR}"

vm_bus_ver=`modinfo hv_vmbus| grep ^version| awk '{print $2}'`
tar -cvf $code_path/logs-`hostname`-`uname -r`-$vm_bus_ver.tar $code_path/*


#!/bin/bash
#
# This script converts Sysbench IO output file into csv format.
# Author: Srikanth Myakam
# Email	: v-srm@microsoft.com
####

syslog_file_name=$1

if [ "$#" -ne 1 ]; then
  echo "Usage: $0 <sysbench-output.log>" >&2
  exit 1
fi

if [ ! -f $syslog_file_name ]; then
    echo "$1: File not found!"
	exit 1
fi

csv_file=`echo $syslog_file_name | sed s/\.log\.txt//`
csv_file=$csv_file.csv
echo $csv_file

res_AvgLatency=(`cat $syslog_file_name | grep "avg:" | awk '{print $2}' | sed s/ms//`)
res_BlockSize=(`cat $syslog_file_name | grep "Block size "| sed "s/Block size //"`)
res_FileSize=(`cat $syslog_file_name | grep "total file size"| sed "s/ total file size//"`)
res_IOMode=(`cat $syslog_file_name | grep "Using .* I/O mode" | sed 's/Using \(.*\) I\/O mode/\1/'`)
res_IOPS=(`cat $syslog_file_name | grep "Requests/sec executed"| awk '{print $1}'`)
res_Iteration=(`cat $syslog_file_name | grep "iteration "| awk '{print $3}'`)
res_MaxLatency=(`cat $syslog_file_name | grep "max:" | awk '{print $2}' | sed s/ms//`)
res_MinLatency=(`cat $syslog_file_name | grep "min:" | awk '{print $2}' | sed s/ms//`)
res_OtherOperations=(`cat $syslog_file_name | grep "Operations performed:"| awk  '{print $7}'`)
res_PercentileLatency=(`cat $syslog_file_name | grep "approx.  95 percentile:" | awk '{print $4}' | sed s/ms//`)
res_ReadBytes=(`cat $syslog_file_name | grep "Read "| awk '{print $2}'`)
res_ReadOperations=(`cat $syslog_file_name | grep "Operations performed:"| awk  '{print $3}'`)
res_StartTime=(`cat $syslog_file_name | grep "iteration "| awk '{print $12 ":" $13 ":" $14}'`)
res_TestType=(`cat $syslog_file_name | grep "iteration"| awk  '{print $5}'| sed s/,//`)
res_Throughput=(`cat $syslog_file_name | grep "Read " | awk '{print $8}' | sed s/\(//| sed s/\)//`)
res_TotalEvents=(`cat $syslog_file_name | grep "total number of events:"  | awk '{print $5}'`)
res_TotalOperations=(`cat $syslog_file_name | grep "Operations performed:"| awk  '{print $10}'`)
res_TotalTime=(`cat $syslog_file_name | grep "total time: " | awk '{print $3}'| sed s/s//`)
res_WriteBytes=(`cat $syslog_file_name | grep "Read "| awk '{print $4}'`)
res_WriteOperations=(`cat $syslog_file_name | grep "Operations performed:"| awk  '{print $5}'`)
res_threads=(`cat $syslog_file_name | grep "Number of threads:" | sed "s/Number of threads: //"`)
res_TotalBytes=(`cat $syslog_file_name | grep "Read "| awk '{print $7}'`)
res_kernel_version=(`cat $syslog_file_name | grep "Linux.*x86_64.*GNU"| awk '{print $3}'`)
res_total_cpu_cores=(`cat $syslog_file_name| grep "Number of CPU cores" | awk '{print $5}'`)
res_LIS_version=(`cat $syslog_file_name| grep "^version:"| awk '{print $2}'`)
res_Host_version=(`cat $syslog_file_name| grep "Host Build Version" | awk '{print $4}'`)
res_total_memory=(`cat $syslog_file_name |grep "^Memory" | awk '{print $2}'`)
res_total_disks=(`cat $syslog_file_name |grep "^Data disks attached" | awk '{print $4}'`)

if [ "x$res_LIS_version" == "x" ]
then
	res_LIS_version="Default LIS Version"
fi

echo "" > $csv_file-tmp
echo ",VM Properties," >> $csv_file-tmp
echo ",Kernel version,"$res_kernel_version >> $csv_file-tmp
echo ",Total CPU cores,"$res_total_cpu_cores >> $csv_file-tmp
echo ",Memory,"$res_total_memory >> $csv_file-tmp
echo ",Disks,"$res_total_disks >> $csv_file-tmp
echo ",LIS Version,"$res_LIS_version >> $csv_file-tmp
echo ",Host Version,"$res_Host_version >> $csv_file-tmp
echo "" >> $csv_file-tmp

echo "Iteration,StartTime,Threads,FileSize,BlockSize,IOMode,TestType,ReadOperations,WriteOperations,OtherOperations,TotalOperations,ReadBytes,WriteBytes,TotalBytes,Throughput,IOPS,TotalTime(s),TotalEvents,MinLatency(ms),AvgLatency(ms),MaxLatency(ms), 95% PercentileLatency(ms)" > $csv_file

count=0

while [ "x${res_Iteration[$count]}" != "x" ]
do
	echo "${res_Iteration[$count]}, ${res_StartTime[$count]}, ${res_threads[$count]}, ${res_FileSize[$count]}, ${res_BlockSize[$count]}, ${res_IOMode[$count]},  ${res_TestType[$count]}, ${res_ReadOperations[$count]}, ${res_WriteOperations[$count]}, ${res_OtherOperations[$count]}, ${res_TotalOperations[$count]}, ${res_ReadBytes[$count]}, ${res_WriteBytes[$count]}, ${res_TotalBytes[$count]}, ${res_Throughput[$count]}, ${res_IOPS[$count]}, ${res_TotalTime[$count]}, ${res_TotalEvents[$count]}, ${res_MinLatency[$count]}, ${res_AvgLatency[$count]}, ${res_MaxLatency[$count]}, ${res_PercentileLatency[$count]}, "  >> $csv_file
	((count++))
done

echo ",Max IOPS of each mode," >> $csv_file-tmp
echo ",Test Mode Max IOPS," >> $csv_file-tmp
modes='rndrd rndwr rndrw seqrd seqwr seqrewr'
for testmode in $modes
do
	max_iops=`cat $csv_file | grep $testmode | sed 's/.*\/sec,//'| sed  's/,.*$//'| sed "s/\\..*//"| sort -g|tail -1`
	if  [ "x$max_iops" != "x" ]
	then
		echo ",$testmode,$max_iops," >> $csv_file-tmp
	fi
done

echo "" >> $csv_file-tmp
echo ",Max IOPS of each BlockSize," >> $csv_file-tmp
modes='rndrd rndwr rndrw seqrd seqwr seqrewr'
block_sizes='1K 2K 4K 8K 16K 32K'
echo ",Test Mode,Block Size,Max IOPS," >> $csv_file-tmp
for testmode in $modes
do
	for block in $block_sizes
	do
		max_iops=`cat $csv_file | grep $testmode | grep " $block" | sed 's/.*\/sec,//'| sed  's/,.*$//'| sed "s/\\..*//"| sort -g|tail -1`
		if  [ "x$max_iops" != "x" ]
		then
			echo ",$testmode,$block,$max_iops," >> $csv_file-tmp
		fi
	done
done

echo "" >> $csv_file-tmp
cat $csv_file >> $csv_file-tmp
mv $csv_file-tmp $csv_file

sed -i  -e  "s/rndrd/Random Read/" $csv_file
sed -i  -e  "s/rndrw/Random Read Write/" $csv_file
sed -i  -e  "s/rndwr/Random Write/" $csv_file
sed -i  -e  "s/seqrd/Sequential Read/" $csv_file
sed -i  -e  "s/seqrewr/Sequential Read Write/" $csv_file
sed -i  -e  "s/seqwr/Sequential Write/" $csv_file

echo "Output csv file: $csv_file created successfully." >> $syslog_file_name
echo "LOGPARSER COMPLETED." >> $syslog_file_name