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