7961a5b40fec52a7183a0536aee38b076b97f5d9
[csit.git] / dpdk-tests / dpdk_scripts / cleanup_dpdk.sh
1 #!/bin/bash
2
3 set -x
4
5 # Setting variables
6 DPDK_VERSION=dpdk-17.02
7 ROOTDIR=/tmp/openvpp-testing
8 TESTPMDLOG=screenlog.0
9 PWDDIR=$(pwd)
10
11 # Setting command line arguments
12 port1_driver=$1
13 port1_pci=$2
14 port2_driver=$3
15 port2_pci=$4
16
17 # Try to kill the testpmd
18 sudo pgrep testpmd
19 if [ $? -eq "0" ]; then
20     success=false
21     sudo pkill testpmd
22     echo "RC = $?"
23     for attempt in {1..5}; do
24         echo "Checking if testpmd is still alive, attempt nr ${attempt}"
25         sudo pgrep testpmd
26         if [ $? -eq "1" ]; then
27             echo "testpmd is dead"
28             success=true
29             break
30         fi
31         echo "testpmd is still alive, waiting 1 second"
32         sleep 1
33     done
34     if [ "$success" = false ]; then
35         echo "The command sudo pkill testpmd failed"
36         sudo pkill -9 testpmd
37         echo "RC = $?"
38         exit 1
39     fi
40 else
41     echo "testpmd is not running"
42 fi
43
44 # Remove hugepages
45 sudo rm -f /dev/hugepages/*
46
47 # Unbind interfaces
48 cd ${ROOTDIR}/${DPDK_VERSION}/
49 sudo ./usertools/dpdk-devbind.py -b ${port1_driver} ${port1_pci} || \
50     { echo "Unbind ${port1_pci} failed"; exit 1; }
51 sudo ./usertools/dpdk-devbind.py -b ${port2_driver} ${port2_pci} || \
52     { echo "Unbind ${port1_pci} failed"; exit 1; }
53
54 sleep 2
55
56 if1_name=`./usertools/dpdk-devbind.py --s | grep "${port1_pci}" | sed -n 's/.*if=\(\S\)/\1/p' | awk -F' ' '{print $1}'`
57 if2_name=`./usertools/dpdk-devbind.py --s | grep "${port2_pci}" | sed -n 's/.*if=\(\S\)/\1/p' | awk -F' ' '{print $1}'`
58
59 # Remove igb_uio driver
60 rmmod igb_uio || \
61     { echo "Removing igb_uio failed"; exit 1; }
62
63 cd ${PWDDIR}