2 * Copyright 2014 Jonathan Anderson.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 static void setup(struct descriptors *, const atf_tc_t *);
46 ATF_TC_WITHOUT_HEAD(missing_library);
47 ATF_TC_BODY(missing_library, tc)
49 struct descriptors files;
52 expect_missing_library(files.binary, NULL);
56 ATF_TC_WITHOUT_HEAD(wrong_library_directories);
57 ATF_TC_BODY(wrong_library_directories, tc)
59 struct descriptors files;
64 asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d", files.etc) > 0);
66 expect_missing_library(files.binary, pathfds);
70 ATF_TC_WITHOUT_HEAD(bad_library_directories);
71 ATF_TC_BODY(bad_library_directories, tc)
73 struct descriptors files;
77 ATF_REQUIRE(asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=::") > 0);
79 expect_missing_library(files.binary, pathfds);
83 ATF_TC_WITHOUT_HEAD(single_library_directory);
84 ATF_TC_BODY(single_library_directory, tc)
86 struct descriptors files;
91 asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d", files.testdir) > 0);
93 expect_success(files.binary, pathfds);
97 ATF_TC_WITHOUT_HEAD(first_library_directory);
98 ATF_TC_BODY(first_library_directory, tc)
100 struct descriptors files;
105 asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d:%d",
106 files.testdir, files.etc) > 0);
108 expect_success(files.binary, pathfds);
112 ATF_TC_WITHOUT_HEAD(middle_library_directory);
113 ATF_TC_BODY(middle_library_directory, tc)
115 struct descriptors files;
120 asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d:%d:%d",
121 files.root, files.testdir, files.usr) > 0);
123 expect_success(files.binary, pathfds);
127 ATF_TC_WITHOUT_HEAD(last_library_directory);
128 ATF_TC_BODY(last_library_directory, tc)
130 struct descriptors files;
135 asprintf(&pathfds, "LD_LIBRARY_PATH_FDS=%d:%d",
136 files.root, files.testdir) > 0);
138 expect_success(files.binary, pathfds);
143 /* Register test cases with ATF. */
146 ATF_TP_ADD_TC(tp, missing_library);
147 ATF_TP_ADD_TC(tp, wrong_library_directories);
148 ATF_TP_ADD_TC(tp, bad_library_directories);
149 ATF_TP_ADD_TC(tp, single_library_directory);
150 ATF_TP_ADD_TC(tp, first_library_directory);
151 ATF_TP_ADD_TC(tp, middle_library_directory);
152 ATF_TP_ADD_TC(tp, last_library_directory);
154 return atf_no_error();
159 setup(struct descriptors *dp, const atf_tc_t *tc)
162 dp->testdir = opendir_fd(atf_tc_get_config_var(tc, "srcdir"));
163 ATF_REQUIRE(dp->testdir >= 0);
165 (dp->binary = openat(dp->testdir, TARGET_ELF_NAME, O_RDONLY)) >= 0);
167 ATF_REQUIRE((dp->root = opendir_fd("/")) >= 0);
168 ATF_REQUIRE((dp->etc = opendirat(dp->root, "etc")) >= 0);
169 ATF_REQUIRE((dp->usr = opendirat(dp->root, "usr")) >= 0);