File: test_syscall.c

package info (click to toggle)
uid-wrapper 1.2.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 464 kB
  • ctags: 300
  • sloc: ansic: 4,859; makefile: 48; sh: 11
file content (62 lines) | stat: -rw-r--r-- 1,164 bytes parent folder | download
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "config.h"

#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>

#include <string.h>
#include <sys/time.h>
#include <unistd.h>

#ifdef HAVE_SYS_SYSCALL_H
#include <sys/syscall.h>
#endif
#ifdef HAVE_SYSCALL_H
#include <syscall.h>
#endif

#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))

static void test_uwrap_syscall(void **state)
{
	long int rc;
	struct timeval tv1, tv2;
	struct timezone tz1, tz2;

	(void) state; /* unused */

	rc = syscall(SYS_getpid);
	assert_int_equal(rc, getpid());

	ZERO_STRUCT(tv1);
	ZERO_STRUCT(tv2);
	ZERO_STRUCT(tz1);
	ZERO_STRUCT(tz2);

	rc = gettimeofday(&tv1, &tz1);
	assert_int_equal(rc, 0);

#ifdef OSX
	tv2.tv_sec = syscall(SYS_gettimeofday, &tv2, NULL);
#else
	rc = syscall(SYS_gettimeofday, &tv2, &tz2);
	assert_int_equal(rc, 0);
	assert_int_equal(tz1.tz_dsttime, tz2.tz_dsttime);
	assert_int_equal(tz1.tz_minuteswest, tz2.tz_minuteswest);
#endif

	assert_int_equal(tv1.tv_sec, tv2.tv_sec);
}

int main(void) {
	int rc;

	const struct CMUnitTest uwrap_tests[] = {
		cmocka_unit_test(test_uwrap_syscall),
	};

	rc = cmocka_run_group_tests(uwrap_tests, NULL, NULL);

	return rc;
}