]> git.saurik.com Git - apple/xnu.git/blobdiff - tests/pid_for_task_test.c
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / tests / pid_for_task_test.c
diff --git a/tests/pid_for_task_test.c b/tests/pid_for_task_test.c
new file mode 100644 (file)
index 0000000..8f8437e
--- /dev/null
@@ -0,0 +1,17 @@
+#include <unistd.h>
+#include <darwintest.h>
+#include <mach/mach.h>
+
+T_DECL(pid_for_task_test, "Test pid_for_task with task name port")
+{
+       kern_return_t kr;
+       mach_port_t tname;
+       pid_t pid;
+
+       kr = task_name_for_pid(mach_task_self(), getpid(), &tname);
+       T_EXPECT_EQ(kr, 0, "task_name_for_pid should succeed on current pid");
+       pid_for_task(tname, &pid);
+       T_EXPECT_EQ(pid, getpid(), "pid_for_task should return the same value as getpid()");
+
+       mach_port_deallocate(mach_task_self(), tname);
+}