99d9135a73b11cae8e2fe6a86c77d8bc51ccd4cf
[p2p-testing-infrastructure.git] / ControlScripts / run_campaign.sh
1 #!/bin/bash
2 #
3 # Copyright: George Milescu 2010 - george.milescu@gmail.com
4 #
5 # Bash script used to run a test campaign
6 # The script
7 #  * Generates a campaign ID
8 #  * Reads the campaign setup file
9 #  * Runs each of the scenarios specified in the campaign setup file
10 #  * Generates the graphs
11 #
12 # Script arguments:
13 #  * a file describing the campaign. The file must be located in SetupFiles
14
15 if [ ! $# -eq 1 ]; then
16         echo "usage: $0 campaign-file"
17         exit 1
18 fi
19
20 # Read the global configuration file
21 # Check if the global configuration file exists
22 if [ ! -e globalconfig ]; then
23         echo "Warning: The global config file globalconfig does not exist."
24 else
25         source globalconfig
26 fi
27
28 # Read arguments
29 CAMPAIGN_FILE=$1
30
31 # Generate unique id for the campaign
32 CAMPAIGN_ID=$(date +%Y.%m.%d-%H.%M.%S)
33 CAMPAIGN_NAME=${CAMPAIGN_FILE%\.*}-$CAMPAIGN_ID # Remove the last extension from the campaign file name
34 CAMPAIGN_RESULTS_FOLDER=$RESULTS_FOLDER_REL_PATH/$CAMPAIGN_NAME
35 ERR_LOG=$CAMPAIGN_RESULTS_FOLDER/err.log
36
37
38 # Check if the campaign file exists
39 if [ ! -e $CONFIG_FILES_REL_PATH/$CAMPAIGN_FILE ]; then
40         echo "Error: The campaign file $CONFIG_FILES_REL_PATH/$CAMPAIGN_FILE does not exist."
41         exit 1
42 fi
43
44 # Check if the campaign file is a regular file
45 if [ ! -f $CONFIG_FILES_REL_PATH/$CAMPAIGN_FILE ]; then
46         echo "Error: The campaign file $CONFIG_FILES_REL_PATH/$CAMPAIGN_FILE is not a regular file."
47         exit 1
48 fi
49
50 # Kill all the clients that are still running
51 ./stop_all_clients.sh
52
53
54 # Create the results folder for the campaign
55 # Check if the campaign results folder already exists
56 if [ -d $CAMPAIGN_RESULTS_FOLDER ]; then
57         echo "Error: The folder $CAMPAIGN_RESULTS_FOLDER already exist."
58         exit 1
59 fi
60
61 echo -n "Creating campaign results folder $CAMPAIGN_RESULTS_FOLDER..."
62 mkdir $CAMPAIGN_RESULTS_FOLDER
63 echo "Done"
64
65
66
67 # Parse the campaign file
68 echo -n "Parsing campaign file... "
69 TMP_FILE=/tmp/proxy.camp.$RANDOM
70 rm -f $TMP_FILE
71 cat $CONFIG_FILES_REL_PATH/$CAMPAIGN_FILE | grep -v ^# | grep -v ^$ | tr -s '\t' > $TMP_FILE
72 echo "done"
73 >$ERR_LOG
74
75
76 # Parsing each scenario and starting the tests
77 echo "Running each scenario..."
78 while IFS=$'\t' read SCENARIO_FILE PLOT_SCRIPT; do
79         echo " * $SCENARIO_FILE"
80         
81         #store the current working directory
82         CWD=$(pwd)
83         
84         # Check if the scenario file exists
85         if [ ! -e $CONFIG_FILES_REL_PATH/$SCENARIO_FILE ]; then
86                 echo "Error: The scenario file $CONFIG_FILES_REL_PATH/$SCENARIO_FILE does not exist."
87                 exit 1
88         fi
89         
90         # Check if the scenario file is a regular file
91         if [ ! -f $CONFIG_FILES_REL_PATH/$SCENARIO_FILE ]; then
92                 echo "Error: The scenario file $CONFIG_FILES_REL_PATH/$SCENARIO_FILE is not a regular file."
93                 exit 1
94         fi
95         
96         # Run scenario
97         ACTION=run
98         ./run_scenario.sh $ACTION $SCENARIO_FILE $CAMPAIGN_NAME
99         
100         # Plot graph
101         echo -n "Plotting graph..."
102         # PLOT_SCRIPT receives two arguments:
103         # * the path to the folder where the data files are stored, and where the graph will be saved
104         # * the name (with the id) of the campaign
105         SCENARIO_NAME=${SCENARIO_FILE%\.*}
106         Rscript $CONFIG_FILES_REL_PATH/$PLOT_SCRIPT --args $CAMPAIGN_RESULTS_FOLDER/$SCENARIO_NAME $CAMPAIGN_NAME >> $ERR_LOG 2>&1
107         echo "done"
108         
109         # reutrn to the initial current working directory
110         cd $CWD
111         
112         echo ""
113 done < $TMP_FILE
114 echo "done"
115 rm -f $TMP_FILE
116 unset IFS
117
118
119
120 # Creating the HTML file in the results folder
121 echo -n "Copying the HTML file to results folder..."
122 cp $CONFIG_FILES_REL_PATH/${CAMPAIGN_FILE%\.*}.html $CAMPAIGN_RESULTS_FOLDER/index.html >> $ERR_LOG 2>&1
123 echo "done"
124
125
126
127 # Publishing results to swarm
128 #echo -n "Publishing results to swarm.cs.pub.ro..."
129 #rsync -avP --exclude OldResults ${RESULTS_FOLDER_REL_PATH}/ george@swarm.cs.pub.ro:public_html/p2p-next/proxy-service-tests/ >> $ERR_LOG 2>&1
130 #echo "done"