2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 * Copyright 2021 Mariusz Zaborski <oshogbo@FreeBSD.org>
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.
38 setup(const atf_tc_t *tc)
42 testdir = opendir_fd(atf_tc_get_config_var(tc, "srcdir"));
43 ATF_REQUIRE(testdir >= 0);
45 binaryfd = openat(testdir, TARGET_ELF_NAME, O_RDONLY);
46 ATF_REQUIRE(binaryfd >= 0);
47 libraryfd = openat(testdir, TARGET_LIBRARY, O_RDONLY);
48 ATF_REQUIRE(libraryfd >= 0);
53 ATF_TC_WITHOUT_HEAD(missing_library);
54 ATF_TC_BODY(missing_library, tc)
58 expect_missing_library(binaryfd, NULL);
61 ATF_TC_WITHOUT_HEAD(bad_librarys);
62 ATF_TC_BODY(bad_librarys, tc)
66 ATF_REQUIRE(asprintf(&senv, "LD_PRELOAD_FDS=::") > 0);
69 expect_missing_library(binaryfd, senv);
72 ATF_TC_WITHOUT_HEAD(single_library);
73 ATF_TC_BODY(single_library, tc)
80 asprintf(&senv, "LD_PRELOAD_FDS=%d", libraryfd) > 0);
82 expect_success(binaryfd, senv);
85 ATF_TC_WITHOUT_HEAD(two_librarys);
86 ATF_TC_BODY(two_librarys, tc)
93 asprintf(&senv, "LD_PRELOAD_FDS=%d:%d", libraryfd, libraryfd) > 0);
95 expect_success(binaryfd, senv);
98 /* Register test cases with ATF. */
102 ATF_TP_ADD_TC(tp, missing_library);
103 ATF_TP_ADD_TC(tp, bad_librarys);
104 ATF_TP_ADD_TC(tp, single_library);
105 ATF_TP_ADD_TC(tp, two_librarys);
107 return atf_no_error();