File: test-nsutils.c

package info (click to toggle)
nagios4 4.4.6-4.1
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 22,336 kB
  • sloc: ansic: 97,631; sh: 12,619; javascript: 5,483; perl: 2,624; makefile: 1,265; php: 381; ruby: 95
file content (41 lines) | stat: -rw-r--r-- 1,018 bytes parent folder | download | duplicates (3)
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
#define _GNU_SOURCE
#include <stdio.h>
#include "nsutils.c"
#include "t-utils.h"
#include <sys/time.h>
#include <time.h>

int main(int argc, char **argv)
{
	struct timeval start, stop;
	float f_delta;
	int msec_delta;
	char *s1;
	const char *s2;

	t_set_colors(0);
	t_verbose = 1;
	t_start("tv_delta tests");

	stop.tv_sec = start.tv_sec = time(NULL);
	stop.tv_usec = 2500;
	start.tv_usec = 0;
	msec_delta = tv_delta_msec(&start, &stop);
	t_ok(msec_delta == 2, "tv_delta_msec()");
	f_delta = tv_delta_f(&start, &stop) * 1000;
	t_ok((double)f_delta == (double)2.5, "tv_delta_f() * 1000 is %.2f and should be 2.5", f_delta);
	gettimeofday(&start, NULL);
	memcpy(&stop, &start, sizeof(start));
	stop.tv_sec += 100;

	asprintf(&s1, "arg varg foo %d", 12);
	s2 = mkstr("arg varg foo %d", 12);
	ok_str(s1, s2, "mkstr() must build proper strings");
	if (real_online_cpus() > 0) {
		t_pass("%d online cpus detected", real_online_cpus());
	} else {
		t_fail("Can't determine the number of online cpus");
	}

	return t_end();
}