-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmulticlient
78 lines (67 loc) · 1.66 KB
/
multiclient
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
function callvalgrind {
valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all "$@"
}
function randint {
# random between $1 and $2 (both inclusive)
echo $(($1 + RANDOM % ($2 - $1 + 1)))
}
function randstring {
# string of $3 numbers between $1 and $2 (both inclusive)
local s=""
local counter=$3
while [ $counter -gt 0 ]
do
local digit=$(randint $1 $2)
s="$s $digit"
((counter--))
done
echo $s
}
function launchclients {
# $1 - number of clients
# $2 - time
# $3 - 1..number
# $4 - 1..total
# $5 - 0..seat
local counter=$1
while [ $counter -gt 0 ]
do
local time=$2
local number=$(randint 0 $3)
local min=$(((2 * $number + 3) / 3))
local total=$(randint $min $4)
local string=$(randstring 0 $5 $total)
./client "$time" "$number" "$string" >> out.txt 2>&1 & disown
((counter--))
done
}
function launchclients-valgrind {
# $1 - number of clients
# $2 - time
# $3 - 1..number
# $4 - 1..total
# $5 - 0..seat
local counter=$1
while [ $counter -gt 0 ]
do
local time=$2
local number=$(randint 0 $3)
local min=$(((2 * $number + 3) / 3))
local total=$(randint $min $4)
local string=$(randstring 0 $5 $total)
callvalgrind ./client "$time" "$number" "$string" >> out.txt 2>&1 & disown
((counter--))
done
}
echo "$@"
# clear out.txt from a previous call
> out.txt
if [[ "$1" = "valgrind" ]]; then
shift
launchclients-valgrind "$1" "$2" "$3" "$4" "$5"
else
launchclients "$1" "$2" "$3" "$4" "$5"
fi
echo "Done"
exit 0