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