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