Skip to content

Commit 036f7cc

Browse files
yousukseungnealcardwell
authored andcommitted
net-test: packetdrill: improve dyanmic tolerance of blocking syscall
Packetdrill calculates the dynamic tolerance based on delta between time of the last and current event. This delta value is irrelevant for a blocking system call and the last event is unpredictable and dand epends on the timing. Instead we can use the delta between the start and end time specified in the packetdrill with an ellipse. This change will make some flaky packetdrill tests with a blocking syscall green. Signed-off-by: Yousuk Seung <[email protected]> Change-Id: I0c92ef2003262c6e504f9997cffbc6158b95d53a
1 parent 4c04617 commit 036f7cc

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

gtests/net/packetdrill/run.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ s64 now_usecs(struct state *state)
174174
*/
175175
int verify_time(struct state *state, enum event_time_t time_type,
176176
s64 script_usecs, s64 script_usecs_end,
177-
s64 live_usecs, struct event *last_event,
177+
s64 live_usecs, s64 last_event_usecs,
178178
const char *description, char **error)
179179
{
180180
s64 expected_usecs = script_usecs - state->script_start_time_usecs;
@@ -189,8 +189,8 @@ int verify_time(struct state *state, enum event_time_t time_type,
189189
if (time_type == ANY_TIME)
190190
return STATUS_OK;
191191

192-
if (last_event) {
193-
s64 delta = script_usecs - last_event->time_usecs;
192+
if (last_event_usecs != NO_TIME_RANGE) {
193+
s64 delta = script_usecs - last_event_usecs;
194194
long dynamic_tolerance;
195195

196196
dynamic_tolerance = (state->config->tolerance_percent / 100.0) * delta;
@@ -291,7 +291,7 @@ void check_event_time(struct state *state, s64 live_usecs)
291291
state->event->time_usecs,
292292
state->event->time_usecs_end,
293293
live_usecs,
294-
state->last_event,
294+
last_event_time_usecs(state),
295295
description, &error)) {
296296
die("%s:%d: %s\n",
297297
state->config->script_path,

gtests/net/packetdrill/run.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ static inline s64 live_time_to_script_time_usecs(struct state *state,
154154
return script_time_usecs;
155155
}
156156

157+
/* Get the time of the last event if exists, or NO_TIME_RANGE. */
158+
static inline s64 last_event_time_usecs(struct state *state)
159+
{
160+
return state->last_event == NULL ? NO_TIME_RANGE :
161+
state->last_event->time_usecs;
162+
}
163+
157164
/*
158165
* See if something that happened at the given actual live wall time
159166
* in microseconds happened reasonably close to the time at which we
@@ -167,7 +174,7 @@ static inline s64 live_time_to_script_time_usecs(struct state *state,
167174
*/
168175
extern int verify_time(struct state *state, enum event_time_t time_type,
169176
s64 script_usecs, s64 script_usecs_end,
170-
s64 live_usecs, struct event *last_event,
177+
s64 live_usecs, s64 last_event_usecs,
171178
const char *description, char **error);
172179
extern void check_event_time(struct state *state, s64 live_usecs);
173180

gtests/net/packetdrill/run_packet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ static int verify_outbound_live_packet(
14111411
DEBUGP("packet time_usecs: %lld\n", live_packet->time_usecs);
14121412
if (verify_time(state, time_type, script_usecs,
14131413
script_usecs_end, live_packet->time_usecs,
1414-
state->last_event,
1414+
last_event_time_usecs(state),
14151415
"outbound packet", error)) {
14161416
non_fatal = true;
14171417
goto out;

gtests/net/packetdrill/run_system_call.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3521,13 +3521,18 @@ static void *system_call_thread(void *arg)
35213521
*/
35223522
invoke_system_call(state, event, syscall);
35233523

3524-
/* Check end time for the blocking system call. */
3524+
/* Check end time for the blocking system call.
3525+
* For a blocking system call we compute the
3526+
* dynamic tolerance based on the start and end
3527+
* time. The last event here is unpredictable
3528+
* and irrelevant.
3529+
*/
35253530
assert(state->syscalls->live_end_usecs >= 0);
35263531
if (verify_time(state,
35273532
event->time_type,
35283533
syscall->end_usecs, 0,
35293534
state->syscalls->live_end_usecs,
3530-
state->last_event,
3535+
event->time_usecs,
35313536
"system call return", &error)) {
35323537
die("%s:%d: %s\n",
35333538
state->config->script_path,

0 commit comments

Comments
 (0)