xref: /xnu-8796.121.2/tests/pid_for_task_test.c (revision c54f35ca767986246321eb901baf8f5ff7923f6a)
1*c54f35caSApple OSS Distributions #include <unistd.h>
2*c54f35caSApple OSS Distributions #include <darwintest.h>
3*c54f35caSApple OSS Distributions #include <mach/mach.h>
4*c54f35caSApple OSS Distributions 
5*c54f35caSApple OSS Distributions T_DECL(pid_for_task_test, "Test pid_for_task with task name port")
6*c54f35caSApple OSS Distributions {
7*c54f35caSApple OSS Distributions 	kern_return_t kr;
8*c54f35caSApple OSS Distributions 	mach_port_t tname;
9*c54f35caSApple OSS Distributions 	pid_t pid;
10*c54f35caSApple OSS Distributions 
11*c54f35caSApple OSS Distributions 	kr = task_name_for_pid(mach_task_self(), getpid(), &tname);
12*c54f35caSApple OSS Distributions 	T_EXPECT_EQ(kr, 0, "task_name_for_pid should succeed on current pid");
13*c54f35caSApple OSS Distributions 	pid_for_task(tname, &pid);
14*c54f35caSApple OSS Distributions 	T_EXPECT_EQ(pid, getpid(), "pid_for_task should return the same value as getpid()");
15*c54f35caSApple OSS Distributions 
16*c54f35caSApple OSS Distributions 	mach_port_deallocate(mach_task_self(), tname);
17*c54f35caSApple OSS Distributions }
18