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