blob: c5501dd5a32b0681991b197b1b6f6a6ab2a0ab85 (
plain)
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
#
# Selection of tests for the %{time_since:} xlat
#
# Somewhat limited in what we can do here, as it bases its
# responses off the current system time. So we need to do some
# comparisons rather than actual value checks.
#
#
# %{time_since:...} should never return 0
#
update {
&Tmp-Integer64-0 := "%{time_since:s}"
&Tmp-Integer64-1 := "%{time_since:ms}"
&Tmp-Integer64-2 := "%{time_since:us}"
}
if (&Tmp-Integer64-0 == 0 || &Tmp-Integer64-1 == 0 || &Tmp-Integer64-2 == 0) {
test_fail
}
#
# and they should all be different
#
if (&Tmp-Integer64-0 == &Tmp-Integer64-1 || \
&Tmp-Integer64-1 == &Tmp-Integer64-2 || \
&Tmp-Integer64-2 == &Tmp-Integer64-0) {
test_fail
}
#
# %c and %{time_since:s:0} should match
#
update {
&Tmp-Integer-9 := 0
}
update {
&Tmp-Integer-0 := "%c"
&Tmp-Integer-1 := "%{time_since:s 0}"
&Tmp-Integer-2 := "%{time_since:s &Tmp-Integer-9}"
}
if (&Tmp-Integer-0 != &Tmp-Integer-1) {
if (&Tmp-Integer-0 != "%{expr:&Tmp-Integer-1 - 1}") {
# at a push, %{time_since:s 0} might be one second later,
# depending on when the test ran
test_fail
}
}
if (&Tmp-Integer-1 != &Tmp-Integer-2) {
if (&Tmp-Integer-1 != "%{expr:&Tmp-Integer-2 - 1}") {
test_fail
}
}
#
# If we run time_since 3 times, they should be the same or increasing
#
update {
&Tmp-Integer64-0 := "%{time_since:s 0}"
}
update {
&Tmp-Integer64-1 := "%{time_since:s }"
}
update {
&Tmp-Integer64-2 := "%{time_since:s}"
}
if (&Tmp-Integer64-0 > &Tmp-Integer64-1 || \
&Tmp-Integer64-1 > &Tmp-Integer64-2 || \
&Tmp-Integer64-0 > &Tmp-Integer64-2) {
test_fail
}
#
# It's way past the year 2020, so this should only fail if the
# computer's clock is very wrong...
#
if (&Tmp-Integer64-0 < 1600000000) {
test_fail
}
#
# Similar for milliseconds
#
update {
&Tmp-Integer64-3 := "%{time_since:ms &request:Tmp-Integer-6}"
}
update {
&Tmp-Integer64-4 := "%{time_since:ms}"
}
update {
&Tmp-Integer64-5 := "%{time_since:ms &Tmp-Integer-9}"
}
if (&Tmp-Integer64-3 > &Tmp-Integer64-4 || \
&Tmp-Integer64-4 > &Tmp-Integer64-5 || \
&Tmp-Integer64-3 > &Tmp-Integer64-5) {
test_fail
}
#
# ...and microseconds
#
update session-state {
&Tmp-Integer-7 := 0
}
update {
&Tmp-Integer64-6 := "%{time_since:us &session-state:Tmp-Integer-7 }"
}
update {
&Tmp-Integer64-7 := "%{time_since:us }"
}
update {
&Tmp-Integer64-8 := "%{time_since:us}"
}
if (&Tmp-Integer64-6 > &Tmp-Integer64-7 || \
&Tmp-Integer64-7 > &Tmp-Integer64-8 || \
&Tmp-Integer64-6 > &Tmp-Integer64-8) {
test_fail
}
if ("%{expr:&Tmp-Integer64-7 - &Tmp-Integer64-6}" > 250) {
# you have a really slow computer if the time between
# getting these took more than 250us
test_fail
}
#
# Seconds component * 1000 must always be same or less than
# milliseconds, and microseconds.
#
if ("%{expr:%{time_since:s 0} * 1000}" > "%{time_since:ms 0}") {
test_fail
}
if ("%{expr:%{time_since:ms 0} * 1000}" > "%{time_since:us 0}") {
test_fail
}
if ("%{expr:%{time_since:s 0} * 1000000}" > "%{time_since:us 0}") {
test_fail
}
#
# Test for some errors
#
# missing time base
update {
&Tmp-Integer-0 := "%{time_since:}"
}
if (!(&Module-Failure-Message[*] == 'Time base (ms, us, s) missing in time_since xlat')) {
test_fail
}
update {
&Module-Failure-Message !* ANY
}
# invalid time base
update {
&Tmp-Integer-0 := "%{time_since:bob}"
}
if (!(&Module-Failure-Message[*] == 'Time base (ms, us, s) missing in time_since xlat')) {
test_fail
}
update {
&Module-Failure-Message !* ANY
}
# negative values
update {
&Tmp-Integer-0 := "%{time_since:ms -1234}"
}
if (!(&Module-Failure-Message[*] == 'time_since xlat only accepts positive integers')) {
test_fail
}
update {
&Module-Failure-Message !* ANY
}
# invalid attribute
update {
&Tmp-Integer-0 := "%{time_since:us &Test-Non-Existant-Attr}"
}
if (!(&Module-Failure-Message[*] == 'Unable to parse attribute in time_since xlat')) {
test_fail
}
update {
&Module-Failure-Message !* ANY
}
# silly text
update {
&Tmp-Integer-0 := "%{time_since:us test random text}"
}
if (!(&Module-Failure-Message[*] == 'Failed parsing "test random text" as integer')) {
test_fail
}
update {
&Module-Failure-Message !* ANY
}
# attribute not in list (warning, so check output)
update {
&Tmp-Integer-0 := "%{time_since:us &reply:Tmp-Integer-4}"
}
if (&Tmp-Integer-0 != 0) {
test_fail
}
test_pass
|