Author: jonathan
Date: Fri Jun 20 17:14:59 2014
New Revision: 267679
URL: http://svnweb.freebsd.org/changeset/base/267679
Log:
Test RTLD's new LD_LIBRARY_PATH_FDS variable.
Test LD_LIBRARY_PATH_FDS by linking a binary that requires a shared
library that isn't in any of the usual search paths. Ensure this fails
when we don't supply LD_LIBRARY_PATH_FDS or we pass invalid information
in it. Ensure it works when we pass the correct directory in various
places in the variable.
Approved by: rwatson (mentor)
MFC after:3 weeks
Sponsored by: DARPA/AFRL
Added:
head/libexec/rtld-elf/tests/
head/libexec/rtld-elf/tests/Makefile (contents, props changed)
head/libexec/rtld-elf/tests/ld_library_pathfds.c (contents, props changed)
head/libexec/rtld-elf/tests/libpythagoras/
head/libexec/rtld-elf/tests/libpythagoras/Makefile (contents, props changed)
head/libexec/rtld-elf/tests/libpythagoras/pythagoras.c (contents, props
changed)
head/libexec/rtld-elf/tests/libpythagoras/pythagoras.h (contents, props
changed)
head/libexec/rtld-elf/tests/target/
head/libexec/rtld-elf/tests/target/Makefile (contents, props changed)
head/libexec/rtld-elf/tests/target/target.c (contents, props changed)
Modified:
head/etc/mtree/BSD.tests.dist
head/libexec/rtld-elf/Makefile
Modified: head/etc/mtree/BSD.tests.dist
==
--- head/etc/mtree/BSD.tests.dist Fri Jun 20 17:08:32 2014
(r267678)
+++ head/etc/mtree/BSD.tests.dist Fri Jun 20 17:14:59 2014
(r267679)
@@ -90,6 +90,7 @@
..
atf-sh
..
+rtld-elf
..
..
sbin
Modified: head/libexec/rtld-elf/Makefile
==
--- head/libexec/rtld-elf/Makefile Fri Jun 20 17:08:32 2014
(r267678)
+++ head/libexec/rtld-elf/Makefile Fri Jun 20 17:14:59 2014
(r267679)
@@ -80,5 +80,9 @@ beforeinstall:
NO_PIE=yes
+.if ${MK_TESTS} != no
+SUBDIR+= tests
+.endif
+
.include bsd.symver.mk
.include bsd.prog.mk
Added: head/libexec/rtld-elf/tests/Makefile
==
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/libexec/rtld-elf/tests/MakefileFri Jun 20 17:14:59 2014
(r267679)
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+.include bsd.own.mk
+
+TESTSDIR= ${TESTSBASE}/libexec/rtld-elf
+SUBDIR+= libpythagoras target
+
+.PATH: ${.CURDIR:H:H:H:H}/tests
+
+ATF_TESTS_C= ld_library_pathfds
+
+CFLAGS+=-DTESTSDIR=\${TESTSDIR}\
+
+.include bsd.test.mk
Added: head/libexec/rtld-elf/tests/ld_library_pathfds.c
==
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/libexec/rtld-elf/tests/ld_library_pathfds.cFri Jun 20 17:14:59
2014(r267679)
@@ -0,0 +1,220 @@
+/*-
+ * Copyright 2014 Jonathan Anderson.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include atf-c.h
+#include fcntl.h
+#include stdio.h
+
+
+struct descriptors {
+ int binary;
+ int testdir;
+ int root;
+ int etc;
+ int usr;
+};
+
+static voidsetup(struct descriptors *);
+static voidexpect_success(int binary, char *pathfds);
+static voidexpect_missing_library(int binary, char *pathfds);
+
+static voidtry_to_run(int binary, int expected_exit_status,
+char * const *env, const char *expected_out, const char *expected_err);
+static int