diff options
| author | whitespace / reindent <invalid@invalid.invalid> | 2017-07-17 14:03:14 +0200 | 
|---|---|---|
| committer | whitespace / reindent <invalid@invalid.invalid> | 2017-07-17 14:04:07 +0200 | 
| commit | d62a17aedeb0eebdba98238874bb13d62c48dbf9 (patch) | |
| tree | 3b319b1d61c8b85b4d1f06adf8b844bb8a9b5107 /tests/lib/test_timer_correctness.c | |
| parent | 888ac268a0077fc9ebd1218cec6ae472af0bfc40 (diff) | |
*: reindentreindent-master-after
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'tests/lib/test_timer_correctness.c')
| -rw-r--r-- | tests/lib/test_timer_correctness.c | 245 | 
1 files changed, 119 insertions, 126 deletions
diff --git a/tests/lib/test_timer_correctness.c b/tests/lib/test_timer_correctness.c index 8fbe5bcbd7..43e79ba9d0 100644 --- a/tests/lib/test_timer_correctness.c +++ b/tests/lib/test_timer_correctness.c @@ -55,144 +55,137 @@ static int timers_pending;  static void terminate_test(void)  { -  int exit_code; - -  if (strcmp(log_buf, expected_buf)) -    { -      fprintf(stderr, "Expected output and received output differ.\n"); -      fprintf(stderr, "---Expected output: ---\n%s", expected_buf); -      fprintf(stderr, "---Actual output: ---\n%s", log_buf); -      exit_code = 1; -    } -  else -    { -      printf("Expected output and actual output match.\n"); -      exit_code = 0; -    } - -  thread_master_free(master); -  XFREE(MTYPE_TMP, log_buf); -  XFREE(MTYPE_TMP, expected_buf); -  prng_free(prng); -  XFREE(MTYPE_TMP, timers); - -  exit(exit_code); +	int exit_code; + +	if (strcmp(log_buf, expected_buf)) { +		fprintf(stderr, +			"Expected output and received output differ.\n"); +		fprintf(stderr, "---Expected output: ---\n%s", expected_buf); +		fprintf(stderr, "---Actual output: ---\n%s", log_buf); +		exit_code = 1; +	} else { +		printf("Expected output and actual output match.\n"); +		exit_code = 0; +	} + +	thread_master_free(master); +	XFREE(MTYPE_TMP, log_buf); +	XFREE(MTYPE_TMP, expected_buf); +	prng_free(prng); +	XFREE(MTYPE_TMP, timers); + +	exit(exit_code);  }  static int timer_func(struct thread *thread)  { -  int rv; +	int rv; -  rv = snprintf(log_buf + log_buf_pos, log_buf_len - log_buf_pos, -                "%s\n", (char*)thread->arg); -  assert(rv >= 0); -  log_buf_pos += rv; -  assert(log_buf_pos < log_buf_len); -  XFREE(MTYPE_TMP, thread->arg); +	rv = snprintf(log_buf + log_buf_pos, log_buf_len - log_buf_pos, "%s\n", +		      (char *)thread->arg); +	assert(rv >= 0); +	log_buf_pos += rv; +	assert(log_buf_pos < log_buf_len); +	XFREE(MTYPE_TMP, thread->arg); -  timers_pending--; -  if (!timers_pending) -    terminate_test(); +	timers_pending--; +	if (!timers_pending) +		terminate_test(); -  return 0; +	return 0;  } -static int cmp_timeval(const void* a, const void *b) +static int cmp_timeval(const void *a, const void *b)  { -  const struct timeval *ta = *(struct timeval * const *)a; -  const struct timeval *tb = *(struct timeval * const *)b; - -  if (timercmp(ta, tb, <)) -    return -1; -  if (timercmp(ta, tb, >)) -    return 1; -  return 0; +	const struct timeval *ta = *(struct timeval * const *)a; +	const struct timeval *tb = *(struct timeval * const *)b; + +	if (timercmp(ta, tb, <)) +		return -1; +	if (timercmp(ta, tb, >)) +		return 1; +	return 0;  }  int main(int argc, char **argv)  { -  int i, j; -  struct thread t; -  struct timeval **alarms; - -  master = thread_master_create(NULL); - -  log_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1; -  log_buf_pos = 0; -  log_buf = XMALLOC(MTYPE_TMP, log_buf_len); - -  expected_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1; -  expected_buf_pos = 0; -  expected_buf = XMALLOC(MTYPE_TMP, expected_buf_len); - -  prng = prng_new(0); - -  timers = XMALLOC(MTYPE_TMP, SCHEDULE_TIMERS * sizeof(*timers)); - -  for (i = 0; i < SCHEDULE_TIMERS; i++) -    { -      long interval_msec; -      int ret; -      char *arg; - -      /* Schedule timers to expire in 0..5 seconds */ -      interval_msec = prng_rand(prng) % 5000; -      arg = XMALLOC(MTYPE_TMP, TIMESTR_LEN + 1); -      timers[i] = NULL; -      thread_add_timer_msec(master, timer_func, arg, interval_msec, -                            &timers[i]); -      ret = snprintf(arg, TIMESTR_LEN + 1, "%lld.%06lld", -                     (long long)timers[i]->u.sands.tv_sec, -                     (long long)timers[i]->u.sands.tv_usec); -      assert(ret > 0); -      assert((size_t)ret < TIMESTR_LEN + 1); -      timers_pending++; -    } - -  for (i = 0; i < REMOVE_TIMERS; i++) -    { -      int index; - -      index = prng_rand(prng) % SCHEDULE_TIMERS; -      if (!timers[index]) -        continue; - -      XFREE(MTYPE_TMP, timers[index]->arg); -      thread_cancel(timers[index]); -      timers[index] = NULL; -      timers_pending--; -    } - -  /* We create an array of pointers to the alarm times and sort -   * that array. That sorted array is used to generate a string -   * representing the expected "output" of the timers when they -   * are run. */ -  j = 0; -  alarms = XMALLOC(MTYPE_TMP, timers_pending * sizeof(*alarms)); -  for (i = 0; i < SCHEDULE_TIMERS; i++) -    { -      if (!timers[i]) -        continue; -      alarms[j++] = &timers[i]->u.sands; -    } -  qsort(alarms, j, sizeof(*alarms), cmp_timeval); -  for (i = 0; i < j; i++) -    { -      int ret; - -      ret = snprintf(expected_buf + expected_buf_pos, -                     expected_buf_len - expected_buf_pos, -                     "%lld.%06lld\n", -                     (long long)alarms[i]->tv_sec, -                     (long long)alarms[i]->tv_usec); -      assert(ret > 0); -      expected_buf_pos += ret; -      assert(expected_buf_pos < expected_buf_len); -    } -  XFREE(MTYPE_TMP, alarms); - -  while (thread_fetch(master, &t)) -    thread_call(&t); - -  return 0; +	int i, j; +	struct thread t; +	struct timeval **alarms; + +	master = thread_master_create(NULL); + +	log_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1; +	log_buf_pos = 0; +	log_buf = XMALLOC(MTYPE_TMP, log_buf_len); + +	expected_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1; +	expected_buf_pos = 0; +	expected_buf = XMALLOC(MTYPE_TMP, expected_buf_len); + +	prng = prng_new(0); + +	timers = XMALLOC(MTYPE_TMP, SCHEDULE_TIMERS * sizeof(*timers)); + +	for (i = 0; i < SCHEDULE_TIMERS; i++) { +		long interval_msec; +		int ret; +		char *arg; + +		/* Schedule timers to expire in 0..5 seconds */ +		interval_msec = prng_rand(prng) % 5000; +		arg = XMALLOC(MTYPE_TMP, TIMESTR_LEN + 1); +		timers[i] = NULL; +		thread_add_timer_msec(master, timer_func, arg, interval_msec, +				      &timers[i]); +		ret = snprintf(arg, TIMESTR_LEN + 1, "%lld.%06lld", +			       (long long)timers[i]->u.sands.tv_sec, +			       (long long)timers[i]->u.sands.tv_usec); +		assert(ret > 0); +		assert((size_t)ret < TIMESTR_LEN + 1); +		timers_pending++; +	} + +	for (i = 0; i < REMOVE_TIMERS; i++) { +		int index; + +		index = prng_rand(prng) % SCHEDULE_TIMERS; +		if (!timers[index]) +			continue; + +		XFREE(MTYPE_TMP, timers[index]->arg); +		thread_cancel(timers[index]); +		timers[index] = NULL; +		timers_pending--; +	} + +	/* We create an array of pointers to the alarm times and sort +	 * that array. That sorted array is used to generate a string +	 * representing the expected "output" of the timers when they +	 * are run. */ +	j = 0; +	alarms = XMALLOC(MTYPE_TMP, timers_pending * sizeof(*alarms)); +	for (i = 0; i < SCHEDULE_TIMERS; i++) { +		if (!timers[i]) +			continue; +		alarms[j++] = &timers[i]->u.sands; +	} +	qsort(alarms, j, sizeof(*alarms), cmp_timeval); +	for (i = 0; i < j; i++) { +		int ret; + +		ret = snprintf(expected_buf + expected_buf_pos, +			       expected_buf_len - expected_buf_pos, +			       "%lld.%06lld\n", (long long)alarms[i]->tv_sec, +			       (long long)alarms[i]->tv_usec); +		assert(ret > 0); +		expected_buf_pos += ret; +		assert(expected_buf_pos < expected_buf_len); +	} +	XFREE(MTYPE_TMP, alarms); + +	while (thread_fetch(master, &t)) +		thread_call(&t); + +	return 0;  }  | 
