<commit_before>#!/bin/sh

# Where is the ixbuild program installed
PROGDIR="`realpath | sed 's|/scripts$||g'`" ; export PROGDIR

# Source our functions
. ${PROGDIR}/scripts/functions.sh
. ${PROGDIR}/scripts/functions-tests.sh

start_bhyve()
{
# Lets check status of "tap0" devices
ifconfig tap0 >/dev/null 2>/dev/null
if [ $? -ne 0 ] ; then
  iface=`netstat -f inet -nrW | grep '^default' | awk '{ print $6 }'`
  ifconfig tap0 create
  sysctl net.link.tap.up_on_open=1
  ifconfig bridge0 create
  ifconfig bridge0 addm ${iface} addm tap0
  ifconfig bridge0 up
fi

# Now lets spin-up bhyve and do an installation
######################################################
MFSFILE="${PROGDIR}/tmp/freenas-disk0.img"
echo "Creating $MFSFILE"
rc_halt "truncate -s 5000M $MFSFILE"

cp ${PROGDIR}/tmp/freenas-auto.iso /root/

# Just in case the install hung, we don't need to be waiting for over an hour
echo "Performing bhyve installation..."
count=0

kldstat | grep -q "vmm"
if [ $? -ne 0 ] ; then
  kldload vmm
fi

# Start grub-bhyve
bhyvectl --destroy --vm=$vm >/dev/null 2>/dev/null
echo "(hd0) ${MFSFILE}
(cd0) ${PROGDIR}/tmp/freenas-auto.iso" > ${PROGDIR}/tmp/device.map

# We run the bhyve commands in a seperate screen session, so that they can run
# in jenkins / save output
echo "#!/bin/sh
count=0

grub-bhyve -m ${PROGDIR}/tmp/device.map -r cd0 -M 2048M $vm

daemon -p /tmp/$vm.pid bhyve -AI -H -P -s 0:0,hostbridge -s 1:0,lpc -s 2:0,virtio-net,tap0 -s 3:0,virtio-blk,${MFSFILE} -s 4:0,ahci-cd,${PROGDIR}/tmp/freenas-auto.iso -l com1,stdio -c 4 -m 2048M $vm

# Wait for initial bhyve startup
while :
do
  if [ ! -e "/tmp/$vm.pid" ] ; then break; fi

  pgrep -qF /tmp/$vm.pid
  if [ \$? -ne 0 ] ; then
        break;
  fi

  count=\`expr \$count + 1\`
  if [ \$count -gt 360 ] ; then break; fi
  echo -e \".\c\"

  sleep 10
done

# Cleanup the old VM
bhyvectl --destroy --vm=$vm
"> ${PROGDIR}/tmp/screen-$vm.sh
chmod 755 ${PROGDIR}/tmp/screen-$vm.sh

echo "Running bhyve in screen session, will display when finished..."
screen -Dm -L -S vmscreen ${PROGDIR}/tmp/screen-$vm.sh

# Display output of screen command
cat flush
echo ""

# Check that this device seemed to install properly
dSize=`du -m ${MFSFILE} | awk '{print $1}'`
if [ $dSize -lt 10 ] ; then
   # if the disk image is too small, installation didn't work, bail out!
   echo "bhyve install failed!"
   exit 1
fi

echo "Bhyve installation successful!"
sleep 1

# Exit for now, can't do live run until grub-bhyve is updated
#exit 0

echo "Starting Bhyve testing now!"

# Start grub-bhyve
echo "(hd0) ${MFSFILE}" > ${PROGDIR}/tmp/device.map

# We run the bhyve commands in a seperate screen session, so that they can run
# in jenkins / save output
echo "#!/bin/sh
count=0

grub-bhyve -m ${PROGDIR}/tmp/device.map -M 2048M $vm

daemon -p /tmp/$vm.pid bhyve -AI -H -P -s 0:0,hostbridge -s 1:0,lpc -s 2:0,virtio-net,tap0 -s 3:0,virtio-blk,${MFSFILE} -l com1,stdio -c 4 -m 2048M $vm

# Wait for initial bhyve startup
while :
do
  if [ ! -e "/tmp/$vm.pid" ] ; then break; fi

  pgrep -qF /tmp/$vm.pid
  if [ \$? -ne 0 ] ; then
        break;
  fi

  count=\`expr \$count + 1\`
  if [ \$count -gt 65 ] ; then break; fi
  echo -e \".\c\"

  sleep 10
done
}

stop_vbox()
{
# Cleanup the old VM
bhyvectl --destroy --vm=$vm
"> ${PROGDIR}/tmp/screen-$vm.sh
chmod 755 ${PROGDIR}/tmp/screen-$vm.sh

echo "Running bhyve tests in screen session, will display when finished..."
screen -Dm -L -S vmscreen ${PROGDIR}/tmp/screen-$vm.sh

# Display output of screen command
cat flush
echo "" 
}

start_vbox() 
{
# We now run virtualbox headless
kldunload vmm 2>/dev/null >/dev/null
# Remove bridge0/tap0 so vbox bridge mode works
ifconfig bridge0 destroy >/dev/null 2>/dev/null
ifconfig tap0 destroy >/dev/null 2>/dev/null

# Get the default interface
iface=`netstat -f inet -nrW | grep '^default' | awk '{ print $6 }'`

# Load up VBOX
kldstat | grep -q vboxdrv
if [ $? -eq 0 ] ; then
  kldload vboxdrv
fi
kldstat | grep -q vboxnet
if [ $? -eq 0 ] ; then
  service vboxnet onestart
fi

# Now lets spin-up vbox and do an installation
######################################################
MFSFILE="${PROGDIR}/tmp/freenas-disk0.img"
echo "Creating $MFSFILE"
rc_halt "VBoxManage createhd --filename ${MFSFILE}.vdi --size 10000"

# Remove any crashed / old VM
VBoxManage unregistervm $VM >/dev/null 2>/dev/null
rm -rf "/root/VirtualBox VMs/$VM" >/dev/null 2>/dev/null

# Copy ISO over to /root in case we need to grab it from jenkins node later
if [ "$FLAVOR" = "TRUENAS" ] ; then<commit_msg>Need to more space for certain VM types<commit_after>#!/bin/sh

# Where is the ixbuild program installed
PROGDIR="`realpath | sed 's|/scripts$||g'`" ; export PROGDIR

# Source our functions
. ${PROGDIR}/scripts/functions.sh
. ${PROGDIR}/scripts/functions-tests.sh

start_bhyve()
{
# Lets check status of "tap0" devices
ifconfig tap0 >/dev/null 2>/dev/null
if [ $? -ne 0 ] ; then
  iface=`netstat -f inet -nrW | grep '^default' | awk '{ print $6 }'`
  ifconfig tap0 create
  sysctl net.link.tap.up_on_open=1
  ifconfig bridge0 create
  ifconfig bridge0 addm ${iface} addm tap0
  ifconfig bridge0 up
fi

# Now lets spin-up bhyve and do an installation
######################################################
MFSFILE="${PROGDIR}/tmp/freenas-disk0.img"
echo "Creating $MFSFILE"
rc_halt "truncate -s 5000M $MFSFILE"

cp ${PROGDIR}/tmp/freenas-auto.iso /root/

# Just in case the install hung, we don't need to be waiting for over an hour
echo "Performing bhyve installation..."
count=0

kldstat | grep -q "vmm"
if [ $? -ne 0 ] ; then
  kldload vmm
fi

# Start grub-bhyve
bhyvectl --destroy --vm=$vm >/dev/null 2>/dev/null
echo "(hd0) ${MFSFILE}
(cd0) ${PROGDIR}/tmp/freenas-auto.iso" > ${PROGDIR}/tmp/device.map

# We run the bhyve commands in a seperate screen session, so that they can run
# in jenkins / save output
echo "#!/bin/sh
count=0

grub-bhyve -m ${PROGDIR}/tmp/device.map -r cd0 -M 2048M $vm

daemon -p /tmp/$vm.pid bhyve -AI -H -P -s 0:0,hostbridge -s 1:0,lpc -s 2:0,virtio-net,tap0 -s 3:0,virtio-blk,${MFSFILE} -s 4:0,ahci-cd,${PROGDIR}/tmp/freenas-auto.iso -l com1,stdio -c 4 -m 2048M $vm

# Wait for initial bhyve startup
while :
do
  if [ ! -e "/tmp/$vm.pid" ] ; then break; fi

  pgrep -qF /tmp/$vm.pid
  if [ \$? -ne 0 ] ; then
        break;
  fi

  count=\`expr \$count + 1\`
  if [ \$count -gt 360 ] ; then break; fi
  echo -e \".\c\"

  sleep 10
done

# Cleanup the old VM
bhyvectl --destroy --vm=$vm
"> ${PROGDIR}/tmp/screen-$vm.sh
chmod 755 ${PROGDIR}/tmp/screen-$vm.sh

echo "Running bhyve in screen session, will display when finished..."
screen -Dm -L -S vmscreen ${PROGDIR}/tmp/screen-$vm.sh

# Display output of screen command
cat flush
echo ""

# Check that this device seemed to install properly
dSize=`du -m ${MFSFILE} | awk '{print $1}'`
if [ $dSize -lt 10 ] ; then
   # if the disk image is too small, installation didn't work, bail out!
   echo "bhyve install failed!"
   exit 1
fi

echo "Bhyve installation successful!"
sleep 1

# Exit for now, can't do live run until grub-bhyve is updated
#exit 0

echo "Starting Bhyve testing now!"

# Start grub-bhyve
echo "(hd0) ${MFSFILE}" > ${PROGDIR}/tmp/device.map

# We run the bhyve commands in a seperate screen session, so that they can run
# in jenkins / save output
echo "#!/bin/sh
count=0

grub-bhyve -m ${PROGDIR}/tmp/device.map -M 2048M $vm

daemon -p /tmp/$vm.pid bhyve -AI -H -P -s 0:0,hostbridge -s 1:0,lpc -s 2:0,virtio-net,tap0 -s 3:0,virtio-blk,${MFSFILE} -l com1,stdio -c 4 -m 2048M $vm

# Wait for initial bhyve startup
while :
do
  if [ ! -e "/tmp/$vm.pid" ] ; then break; fi

  pgrep -qF /tmp/$vm.pid
  if [ \$? -ne 0 ] ; then
        break;
  fi

  count=\`expr \$count + 1\`
  if [ \$count -gt 65 ] ; then break; fi
  echo -e \".\c\"

  sleep 10
done
}

stop_vbox()
{
# Cleanup the old VM
bhyvectl --destroy --vm=$vm
"> ${PROGDIR}/tmp/screen-$vm.sh
chmod 755 ${PROGDIR}/tmp/screen-$vm.sh

echo "Running bhyve tests in screen session, will display when finished..."
screen -Dm -L -S vmscreen ${PROGDIR}/tmp/screen-$vm.sh

# Display output of screen command
cat flush
echo "" 
}

start_vbox() 
{
# We now run virtualbox headless
kldunload vmm 2>/dev/null >/dev/null
# Remove bridge0/tap0 so vbox bridge mode works
ifconfig bridge0 destroy >/dev/null 2>/dev/null
ifconfig tap0 destroy >/dev/null 2>/dev/null

# Get the default interface
iface=`netstat -f inet -nrW | grep '^default' | awk '{ print $6 }'`

# Load up VBOX
kldstat | grep -q vboxdrv
if [ $? -eq 0 ] ; then
  kldload vboxdrv
fi
kldstat | grep -q vboxnet
if [ $? -eq 0 ] ; then
  service vboxnet onestart
fi

# Now lets spin-up vbox and do an installation
######################################################
MFSFILE="${PROGDIR}/tmp/freenas-disk0.img"
echo "Creating $MFSFILE"
rc_halt "VBoxManage createhd --filename ${MFSFILE}.vdi --size 20000"

# Remove any crashed / old VM
VBoxManage unregistervm $VM >/dev/null 2>/dev/null
rm -rf "/root/VirtualBox VMs/$VM" >/dev/null 2>/dev/null

# Copy ISO over to /root in case we need to grab it from jenkins node later
if [ "$FLAVOR" = "TRUENAS" ] ; then
{'fraction_non_alphanumeric': 0.16501432033487554, 'fraction_numerical': 0.023793787177792465, 'mean_word_length': 3.373314065510597, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6516411', 'n_tokens_mistral': 3672, 'n_tokens_neox': 3452, 'n_words': 1136}