Merge "bugfix: tc063 fails to get the correct result in ubuntu node"
[yardstick.git] / yardstick / benchmark / scenarios / networking / netperf_benchmark.bash
1 #!/bin/bash
2
3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 set -e
13
14 # Commandline arguments
15 OPTIONS_SIZE="$#"
16 OPTIONS="$@"
17 OUTPUT_FILE=/tmp/netperf-out.log
18
19 # run netperf test
20 run_netperf()
21 {
22     netperf $OPTIONS > $OUTPUT_FILE
23 }
24
25 # write the result to stdout in json format
26 output_json()
27 {
28     #ARR=($OPTIONS)
29     #declare -p ARR
30     read -r -a ARR <<< "$OPTIONS"
31     opt_size=0
32     while [ $opt_size -lt "$OPTIONS_SIZE" ]
33     do
34         if [ "${ARR[$opt_size]}" = "-O" ]
35         then
36             break
37         fi
38         opt_size=$((opt_size+1))
39     done
40     opt_size=$((opt_size+1))
41     out_opt="${ARR[$opt_size]}"
42     IFS=, read -r -a PARTS <<< "$out_opt"
43     #declare -p PARTS
44     part_num=${#PARTS[*]}
45     tran_num=0
46     for f in "${PARTS[@]}"
47     do
48         array_name[$tran_num]=$(echo "$f" | tr '[A-Z]' '[a-z]')
49         tran_num=$((tran_num+1))
50     done
51     read -r -a DATA_PARTS <<< "$(sed -n '$p' $OUTPUT_FILE)"
52     out_str="{"
53     for((i=0;i<part_num-1;i++))
54     do
55         modify_str=\"${array_name[i]}\":\"${DATA_PARTS[i]}\",
56         out_str=$out_str$modify_str
57     done
58     modify_str=\"${array_name[part_num-1]}\":\"${DATA_PARTS[part_num-1]}\"
59     out_str=$out_str$modify_str"}"
60
61     echo -e "$out_str"
62 }
63
64 # main entry
65 main()
66 {
67     # run the test
68     run_netperf
69
70     # output result
71     output_json
72 }
73
74 main