3 # Copyright: George Milescu 2010 - george.milescu@gmail.com
5 # Bash script used to run a test campaign
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
13 # * a file describing the campaign. The file must be located in SetupFiles
15 if [ ! $# -eq 1 ]; then
16 echo "usage: $0 campaign-file"
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."
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
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."
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."
50 # Kill all the clients that are still running
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."
61 echo -n "Creating campaign results folder $CAMPAIGN_RESULTS_FOLDER..."
62 mkdir $CAMPAIGN_RESULTS_FOLDER
67 # Parse the campaign file
68 echo -n "Parsing campaign file... "
69 TMP_FILE=/tmp/proxy.camp.$RANDOM
71 cat $CONFIG_FILES_REL_PATH/$CAMPAIGN_FILE | grep -v ^# | grep -v ^$ | tr -s '\t' > $TMP_FILE
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"
81 #store the current working directory
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."
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."
98 ./run_scenario.sh $ACTION $SCENARIO_FILE $CAMPAIGN_NAME
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
109 # reutrn to the initial current working directory
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
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