forked from PowerMeMobile/smppsink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·175 lines (137 loc) · 5.97 KB
/
test.sh
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
SMPPLOAD=$(which smppload 2>/dev/null || echo $SCRIPT_DIR/smppload)
HOST=localhost
PORT=2775
SYSTEM_TYPE=smpp
SYSTEM_ID=test
PASSWORD=test
SRC_ADDR=375296660002
DST_ADDR=375296543210
EXIT=0
function check() {
local command="$1"
local encoding="$2"
local delivery="$3"
local invert="$4"
local pattern="$5"
local count=${6-1}
case "$delivery" in
!dlr) dlr_flag=0;;
dlr) dlr_flag=1
esac
case "$encoding" in
gsm0338) encoding=0;;
ascii) encoding=1;;
latin1) encoding=3;;
ucs2) encoding=8
esac
echo -en "$command\t$encoding\t$delivery\t"
$SMPPLOAD --host=$HOST --port=$PORT \
--system_type=$SYSTEM_TYPE --system_id=$SYSTEM_ID --password=$PASSWORD \
--source=$SRC_ADDR --destination=$DST_ADDR --body="$command" --data_coding="$encoding" \
--delivery=$dlr_flag --submit_timeout=5000 --delivery_timeout=5000 --count=$count \
-vv | grep "$pattern" > /dev/null
ret=$?
if [[ $ret == 0 && "$invert" == "with" ]]; then
echo -e "\e[32mOK\e[0m"
elif [[ $ret == 1 && "$invert" == "w/o" ]]; then
echo -e "\e[32mOK\e[0m"
else
echo -e "\e[31mFAIL\e[0m"
EXIT=1
fi
}
function check_count() {
local command="$1"
local encoding="$2"
local delivery="$3"
local invert="$4"
local pattern="$5"
local send_count="$6"
local expected_count="$7"
case "$delivery" in
!dlr) dlr_flag=0;;
dlr) dlr_flag=1
esac
case "$encoding" in
gsm0338) encoding=0;;
ascii) encoding=1;;
latin1) encoding=3;;
ucs2) encoding=8
esac
echo -en "$command\t$encoding\t$delivery\t"
$SMPPLOAD --host=$HOST --port=$PORT \
--system_type=$SYSTEM_TYPE --system_id=$SYSTEM_ID --password=$PASSWORD \
--source=$SRC_ADDR --destination=$DST_ADDR --body="$command" --data_coding="$encoding" \
--delivery=$dlr_flag --submit_timeout=5000 --delivery_timeout=5000 --count=$send_count \
-vv | grep "$pattern" | wc -l | grep $expected_count > /dev/null
ret=$?
if [[ $ret == 0 ]]; then
echo -e "\e[32mOK\e[0m"
else
echo -e "\e[31mFAIL\e[0m"
EXIT=1
fi
}
# try to start
$SCRIPT_DIR/../_build/default/rel/smppsink/bin/smppsink start > /dev/null
start_ret=$?
if [[ $start_ret == 0 ]]; then
# give time to init
sleep 5
fi
check "submit: 0" latin1 !dlr w/o "ERROR"
check "submit: 0x0" latin1 !dlr w/o "ERROR"
check "submit: 1" latin1 !dlr with "ERROR: Failed with: (0x00000001)"
check "submit: 0x1" latin1 !dlr with "ERROR: Failed with: (0x00000001)"
check "submit: {status: 1}" latin1 !dlr with "ERROR: Failed with: (0x00000001)"
check "submit: {status: 1, delay: 0}" latin1 !dlr with "ERROR: Failed with: (0x00000001)"
check "{submit: 1}" latin1 !dlr with "ERROR: Failed with: (0x00000001)"
check "{submit: {status: 1}}" latin1 !dlr with "ERROR: Failed with: (0x00000001)"
check "{submit: {status: 1, delay: 0}}" latin1 !dlr with "ERROR: Failed with: (0x00000001)"
check "receipt: enroute" latin1 !dlr w/o "stat:ENROUTE"
check "receipt: enroute" latin1 dlr with "stat:ENROUTE"
check "receipt: {status: enroute}" latin1 dlr with "stat:ENROUTE"
check "receipt: {status: enroute, delay: 0}" latin1 dlr with "stat:ENROUTE"
check "{receipt: enroute}" latin1 dlr with "stat:ENROUTE"
check "receipt: {status: enroute}" latin1 dlr with "stat:ENROUTE"
check "receipt: {status: enroute, delay: 0}" latin1 dlr with "stat:ENROUTE"
check "{submit: 0, receipt: enroute}" latin1 dlr with "stat:ENROUTE"
check "{submit: {status: 0, delay: 0}, receipt: {status: enroute, delay: 0}}" latin1 dlr with "stat:ENROUTE"
check "{submit: 1, receipt: unknown}" latin1 dlr with "ERROR: Failed with: (0x00000001)"
# w/o spaces
check "{submit:{status:0,delay:0},receipt:{status:enroute,delay:0}}" latin1 dlr with "stat:ENROUTE"
# diff encoding
check "submit:{status:1}" gsm0338 !dlr with "ERROR: Failed with: (0x00000001)"
check "submit:{status:1}" ascii !dlr with "ERROR: Failed with: (0x00000001)"
check "submit:{status:1}" latin1 !dlr with "ERROR: Failed with: (0x00000001)"
#check "submit:{status:1}" ucs2 !dlr with "ERROR: Failed with: (0x00000001)"
check "submit:{delay:-1}" latin1 !dlr w/o "ERROR"
check "submit:{delay:1}" latin1 !dlr w/o "ERROR"
check "submit:{delay:inf}" latin1 !dlr with "ERROR: Timeout"
check "receipt:{delay:inf}" latin1 dlr with "ERROR: Delivery timeout"
check "submit:{delay:xyz}" latin1 !dlr w/o "ERROR"
# allow receipt status to be any string and integer
check "receipt:abc" latin1 dlr with "stat:abc"
check "receipt:{status:abc}" latin1 dlr with "stat:abc"
check "receipt:123" latin1 dlr with "stat:123"
check "receipt:{status:123}" latin1 dlr with "stat:123"
#
check "submit:{status:[]}" latin1 !dlr w/o "ERROR"
check "submit:{status:[]}" latin1 dlr with "stat:DELIVRD"
check "submit:{status:{value:1,freq:1.0}}" latin1 !dlr with "ERROR: Failed with: (0x00000001)"
check "submit:{status:[{value:1,freq:1.0}]}" latin1 !dlr with "ERROR: Failed with: (0x00000001)"
# NB! Random algorithm (exsplus) and seed dependent results
check "{submit:{status:{value:1,freq:0.3}},seed:1}" latin1 !dlr with "Send success: 77" 100
check "{submit:{status:{value:1,freq:0.3}},seed:3}" latin1 !dlr with "Send success: 63" 100
check "{submit:{status:[{value:0,freq:0.7},{value:1,freq:0.3}]},seed:5}" latin1 !dlr with "Send success: 71" 100
check "{submit:{status:[{value:0,freq:0.7},{value:1,freq:0.3}]},seed:7}" latin1 !dlr with "Send success: 69" 100
check_count "{receipt:{status:{value:enroute,freq:0.3}},seed:1}" latin1 dlr with "stat:ENROUTE" 100 46
check_count "{receipt:{status:[{value:enroute,freq:0.3}]},seed:2}" latin1 dlr with "stat:ENROUTE" 100 68
check_count "{receipt:{status:[{value:enroute,freq:0.3},{value:accepted,freq:0.2}]},seed:3}" latin1 dlr with "stat:ACCEPTD" 100 40
# stop if wasn't running
if [[ $start_ret == 0 ]]; then
$SCRIPT_DIR/../_build/default/rel/smppsink/bin/smppsink stop > /dev/null
fi
exit $EXIT