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