From: Eugene Syromyatnikov Date: Sun, 2 Sep 2018 19:28:41 +0000 (+0200) Subject: delay: use parse_ts for parsing delay value X-Git-Tag: v5.3~74 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6b5a9d30b99cf99b27dc27a25ede9a0410d97b52;p=strace delay: use parse_ts for parsing delay value * delay.c (fill_delay_data): Change intval argument to struct timespec *val, assign val to ts. * delay.h (fill_delay_data): Update function declaration. * filter_qualify.c (parse_delay_token): Parse input with parse_ts, supply the resulting struct timespec to fill_delay_data. * tests/delay.c (check_): New function for providing diagnostic in case of check failure. (check_delay): Use it. * tests/delay.test: Check new delay syntax. --- diff --git a/delay.c b/delay.c index e32dc502..538992ff 100644 --- a/delay.c +++ b/delay.c @@ -46,7 +46,7 @@ alloc_delay_data(void) } void -fill_delay_data(uint16_t delay_idx, int intval, bool isenter) +fill_delay_data(uint16_t delay_idx, struct timespec *val, bool isenter) { if (delay_idx >= delay_data_vec_size) error_func_msg_and_die("delay_idx >= delay_data_vec_size"); @@ -57,8 +57,7 @@ fill_delay_data(uint16_t delay_idx, int intval, bool isenter) else ts = &(delay_data_vec[delay_idx].ts_exit); - ts->tv_sec = intval / 1000000; - ts->tv_nsec = intval % 1000000 * 1000; + *ts = *val; } static bool diff --git a/delay.h b/delay.h index fa111c76..1dc27304 100644 --- a/delay.h +++ b/delay.h @@ -9,7 +9,7 @@ # define STRACE_DELAY_H uint16_t alloc_delay_data(void); -void fill_delay_data(uint16_t delay_idx, int intval, bool isenter); +void fill_delay_data(uint16_t delay_idx, struct timespec *val, bool isenter); bool is_delay_timer_armed(void); void delay_timer_expired(void); void arm_delay_timer(const struct tcb *); diff --git a/filter_qualify.c b/filter_qualify.c index 52652e61..fe9b7710 100644 --- a/filter_qualify.c +++ b/filter_qualify.c @@ -99,14 +99,15 @@ parse_delay_token(const char *input, struct inject_opts *fopts, bool isenter) if (fopts->data.flags & flag) /* duplicate */ return false; - long long intval = string_to_ulonglong(input); - if (intval < 0) /* couldn't parse */ + struct timespec tsval; + + if (parse_ts(input, &tsval) < 0) /* couldn't parse */ return false; if (fopts->data.delay_idx == (uint16_t) -1) fopts->data.delay_idx = alloc_delay_data(); /* populate .ts_enter or .ts_exit */ - fill_delay_data(fopts->data.delay_idx, intval, isenter); + fill_delay_data(fopts->data.delay_idx, &tsval, isenter); fopts->data.flags |= flag; return true; diff --git a/tests/delay.c b/tests/delay.c index 82544336..486d48b8 100644 --- a/tests/delay.c +++ b/tests/delay.c @@ -8,6 +8,7 @@ */ #include "tests.h" +#include #include #include #include @@ -30,6 +31,22 @@ usecs_from_ts(const struct timespec *const ts) return (int64_t) ts->tv_sec * 1000000 + ts->tv_nsec / 1000; } +static void +check_(const int64_t got, const bool ge, const int64_t orig, const int nproc, + const int exitcode) +{ + const int64_t thresh = (orig * (ge ? nproc - 1 : nproc + 1)) / nproc; + + if (ge ? got >= thresh : got <= thresh) + return; + + fprintf(stderr, "Got delay of %" PRId64 ", %s than threshold value of " + "%" PRId64 " (expected nominal delay value is %" PRId64 + ")\n", got, ge ? "less" : "more", thresh, orig); + + _exit(exitcode); +} + static void check_delay(const struct timeval *const tv0, const struct timespec *const ts, @@ -42,17 +59,10 @@ check_delay(const struct timeval *const tv0, const int64_t us = usecs_from_ts(ts); const int64_t us1 = usecs_from_tv(tv1); - if (us - us0 < delay_exit * (nproc - 1) / nproc) - _exit(1); - - if (us - us0 > delay_exit * (nproc + 1) / nproc) - _exit(2); - - if (us1 - us < delay_enter * (nproc - 1) / nproc) - _exit(3); - - if (us1 - us > delay_enter * (nproc + 1) / nproc) - _exit(4); + check_(us - us0, true, delay_exit, nproc, 1); + check_(us - us0, false, delay_exit, nproc, 2); + check_(us1 - us, true, delay_enter, nproc, 3); + check_(us1 - us, false, delay_enter, nproc, 4); } static void diff --git a/tests/delay.test b/tests/delay.test index df8552c7..b5bcf27d 100755 --- a/tests/delay.test +++ b/tests/delay.test @@ -9,8 +9,15 @@ . "${srcdir=.}/init.sh" -delay_enter=800000 -delay_exit=1600000 -run_strace -f -r -egettimeofday \ - -einject=gettimeofday:delay_enter=$delay_enter:delay_exit=$delay_exit \ - ../delay 4 $delay_enter $delay_exit +while read -r denter dexit denter_us dexit_us; do + [ -n "$denter" ] || continue + + run_strace -f -r -egettimeofday \ + -einject=gettimeofday:delay_enter=$denter:delay_exit=$dexit \ + ../delay 4 $denter_us $dexit_us +done <<-EOF + 800000 1600000 800000 1600000 + 8e5 1.6s 800000 1600000 + 800ms 1.6e+6us 800000 1600000 + +8e8ns .16E7 800000 1600000 +EOF