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