1 #include <spawn_private.h>
2 #include "subsystem_root_path.h"
4 #include <darwintest.h>
5 #include <darwintest_utils.h>
7 #define UNENTITLED_EXECUTABLE_PATH "./subsystem_root_path_helper"
8 #define ENTITLED_EXECUTABLE_PATH "./subsystem_root_path_helper_entitled"
10 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
12 T_DECL(subsystem_root_path
,
13 "Test the support for setting subsystem_root_path",
14 T_META_CHECK_LEAKS(false))
16 char * args
[] = { ENTITLED_EXECUTABLE_PATH
, HELPER_BEHAVIOR_NOT_SET
, "/main_root/", NULL
};
18 posix_spawnattr_t attr
= NULL
;
20 T_ASSERT_EQ_INT(_spawn_and_wait(args
, NULL
), 0, "posix_spawn without attributes");
21 T_ASSERT_POSIX_SUCCESS(posix_spawnattr_init(&attr
), "posix_spawnattr_init");
22 T_ASSERT_EQ_INT(_spawn_and_wait(args
, &attr
), 0, "posix_spawn with attributes");
23 T_ASSERT_POSIX_SUCCESS(posix_spawnattr_set_subsystem_root_path_np(&attr
, args
[2]), "Set subsystem root path");
25 args
[1] = HELPER_BEHAVIOR_SET
;
27 T_ASSERT_EQ_INT(_spawn_and_wait(args
, &attr
), 0, "posix_spawn with subsystem root path");
28 T_ASSERT_POSIX_SUCCESS(posix_spawnattr_set_subsystem_root_path_np(&attr
, NULL
), "Clear subsystem root path attribute");
30 args
[1] = HELPER_BEHAVIOR_NOT_SET
;
32 T_ASSERT_EQ_INT(_spawn_and_wait(args
, &attr
), 0, "Spawn without subsystem root path");
34 T_ASSERT_POSIX_SUCCESS(posix_spawnattr_set_subsystem_root_path_np(&attr
, args
[2]), "Set subsystem root path (again)");
36 args
[1] = HELPER_BEHAVIOR_FORK_EXEC
;
38 T_ASSERT_EQ_INT(_spawn_and_wait(args
, &attr
), 0, "Subsystem root path inheritence across fork/exec");
40 args
[1] = HELPER_BEHAVIOR_SPAWN
;
42 T_ASSERT_EQ_INT(_spawn_and_wait(args
, &attr
), 0, "Subsystem root path override through posix_spawn");
44 args
[0] = UNENTITLED_EXECUTABLE_PATH
;
46 T_ASSERT_NE_INT(_spawn_and_wait(args
, &attr
), 0, "Entitlement check");
47 T_ASSERT_POSIX_SUCCESS(posix_spawnattr_destroy(&attr
), "posix_spawnattr_destroy");