]> git.saurik.com Git - apple/xnu.git/blame - tests/host_notifications.c
xnu-4903.270.47.tar.gz
[apple/xnu.git] / tests / host_notifications.c
CommitLineData
39037602
A
1#include <sys/time.h>
2#include <mach/mach.h>
3#include <mach/mach_host.h>
4
5#include <darwintest.h>
6
0a7de745
A
7static void
8do_test(int notify_type, void (^trigger_block)(void))
9{
39037602
A
10 mach_port_t port;
11 T_ASSERT_MACH_SUCCESS(mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port), NULL);
12
13 T_ASSERT_MACH_SUCCESS(host_request_notification(mach_host_self(), notify_type, port), NULL);
14
15 trigger_block();
16
17 struct {
18 mach_msg_header_t hdr;
19 mach_msg_trailer_t trailer;
20 } message = { .hdr = {
0a7de745
A
21 .msgh_bits = 0,
22 .msgh_size = sizeof(mach_msg_header_t),
23 .msgh_remote_port = MACH_PORT_NULL,
24 .msgh_local_port = port,
25 .msgh_voucher_port = MACH_PORT_NULL,
26 .msgh_id = 0,
27 }};
39037602
A
28
29 T_ASSERT_EQ(MACH_RCV_TOO_LARGE, mach_msg_receive(&message.hdr), NULL);
30 mach_msg_destroy(&message.hdr);
31}
32
813fb2f6 33T_DECL(host_notify_calendar_change, "host_request_notification(HOST_NOTIFY_CALENDAR_CHANGE)", T_META_CHECK_LEAKS(false), T_META_LTEPHASE(LTE_POSTINIT))
39037602
A
34{
35 do_test(HOST_NOTIFY_CALENDAR_CHANGE, ^{
36 struct timeval tm;
0a7de745
A
37 if (gettimeofday(&tm, NULL) != 0 || settimeofday(&tm, NULL) != 0) {
38 T_SKIP("Unable to settimeofday()");
39037602
A
39 }
40 });
41}
42
813fb2f6 43T_DECL(host_notify_calendar_set, "host_request_notification(HOST_NOTIFY_CALENDAR_SET)", T_META_CHECK_LEAKS(false), T_META_LTEPHASE(LTE_POSTINIT))
39037602
A
44{
45 do_test(HOST_NOTIFY_CALENDAR_SET, ^{
46 struct timeval tm;
0a7de745
A
47 if (gettimeofday(&tm, NULL) != 0 || settimeofday(&tm, NULL) != 0) {
48 T_SKIP("Unable to settimeofday()");
39037602
A
49 }
50 });
51}