}
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");
else
ts = &(delay_data_vec[delay_idx].ts_exit);
- ts->tv_sec = intval / 1000000;
- ts->tv_nsec = intval % 1000000 * 1000;
+ *ts = *val;
}
static bool
# 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 *);
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;
*/
#include "tests.h"
+#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
#include <stdint.h>
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,
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
. "${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