Skip to content

Commit

Permalink
Add test-in-container infrastructure.
Browse files Browse the repository at this point in the history
* Makefile (testroot.pristine): New rules to initialize the
test-in-container "testroot".
* Makerules (all-testsuite): Add tests-container.
* Rules (tests-expected): Add tests-container.
(binaries-all-tests): Likewise.
(tests-container): New, run these tests in the testroot container.
* support/Makefile (others): Add *-container, support_paths.c,
xmkdirp, and links-dso-program.
* support/links-dso-program-c.c: New.
* support/links-dso-program.cc: New.
* support/test-container.c: New.
* support/shell-container.c: New.
* support/echo-container.c: New.
* support/true-container.c: New.
* support/xmkdirp.c: New.
* support/xsymlink.c: New.
* support/support_paths.c: New.
* support/support.h: Add support paths prototypes.
* support/xunistd.h: Add xmkdirp () and xsymlink ().

* nss/tst-nss-test3.c: Convert to test-in-container.
* nss/tst-nss-test3.root/: New.
  • Loading branch information
djdelorierh committed Aug 23, 2018
1 parent b35d350 commit 561b0be
Show file tree
Hide file tree
Showing 20 changed files with 1,779 additions and 6 deletions.
25 changes: 25 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
2018-08-22 DJ Delorie <[email protected]>

* Makefile (testroot.pristine): New rules to initialize the
test-in-container "testroot".
* Makerules (all-testsuite): Add tests-container.
* Rules (tests-expected): Add tests-container.
(binaries-all-tests): Likewise.
(tests-container): New, run these tests in the testroot container.
* support/Makefile (others): Add *-container, support_paths.c,
xmkdirp, and links-dso-program.
* support/links-dso-program-c.c: New.
* support/links-dso-program.cc: New.
* support/test-container.c: New.
* support/shell-container.c: New.
* support/echo-container.c: New.
* support/true-container.c: New.
* support/xmkdirp.c: New.
* support/xsymlink.c: New.
* support/support_paths.c: New.
* support/support.h: Add support paths prototypes.
* support/xunistd.h: Add xmkdirp () and xsymlink ().

* nss/tst-nss-test3.c: Convert to test-in-container.
* nss/tst-nss-test3.root/: New.

2018-08-22 Paul Eggert <[email protected]>

regex: port Gnulib code to z/OS POSIX environment
Expand Down
56 changes: 56 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,62 @@ define summarize-tests
@! egrep -q -v '^(X?PASS|XFAIL|UNSUPPORTED):' $(objpfx)$1
endef

# The intention here is to do ONE install of our build into the
# testroot.pristine/ directory, then rsync (internal to
# support/test-container) that to testroot.root/ at the start of each
# test. That way we can promise each test a "clean" install, without
# having to do the install for each test.
#
# In addition, we have to copy some files (which we build) into this
# root in addition to what glibc installs. For example, many tests
# require additional programs including /bin/sh, /bin/true, and
# /bin/echo, all of which we build below to limit library dependencies
# to just those things in glibc and language support libraries which
# we also copy into the into the rootfs. To determine what language
# support libraries we need we build a "test" program in either C or
# (if available) C++ just so we can copy in any shared objects
# (which we do not build) that GCC-compiled programs depend on.


ifeq (,$(CXX))
LINKS_DSO_PROGRAM = links-dso-program-c
else
LINKS_DSO_PROGRAM = links-dso-program
endif

$(tests-container) $(addsuffix /tests,$(subdirs)) : \
$(objpfx)testroot.pristine/install.stamp
$(objpfx)testroot.pristine/install.stamp :
test -d $(objpfx)testroot.pristine || \
mkdir $(objpfx)testroot.pristine
# We need a working /bin/sh for some of the tests.
test -d $(objpfx)testroot.pristine/bin || \
mkdir $(objpfx)testroot.pristine/bin
cp $(objpfx)support/shell-container $(objpfx)testroot.pristine/bin/sh
cp $(objpfx)support/echo-container $(objpfx)testroot.pristine/bin/echo
cp $(objpfx)support/true-container $(objpfx)testroot.pristine/bin/true
# Copy these DSOs first so we can overwrite them with our own.
for dso in `$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1 \
$(objpfx)elf/$(rtld-installed-name) \
$(objpfx)testroot.pristine/bin/sh \
| grep / | sed 's/^[^/]*//' | sed 's/ .*//'` ;\
do \
test -d `dirname $(objpfx)testroot.pristine$$dso` || \
mkdir -p `dirname $(objpfx)testroot.pristine$$dso` ;\
$(test-wrapper) cp $$dso $(objpfx)testroot.pristine$$dso ;\
done
for dso in `$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1 \
$(objpfx)elf/$(rtld-installed-name) \
$(objpfx)support/$(LINKS_DSO_PROGRAM) \
| grep / | sed 's/^[^/]*//' | sed 's/ .*//'` ;\
do \
test -d `dirname $(objpfx)testroot.pristine$$dso` || \
mkdir -p `dirname $(objpfx)testroot.pristine$$dso` ;\
$(test-wrapper) cp $$dso $(objpfx)testroot.pristine$$dso ;\
done
$(MAKE) install DESTDIR=$(objpfx)testroot.pristine
touch $(objpfx)testroot.pristine/install.stamp

tests-special-notdir = $(patsubst $(objpfx)%, %, $(tests-special))
tests: $(tests-special)
$(..)scripts/merge-test-results.sh -s $(objpfx) "" \
Expand Down
3 changes: 2 additions & 1 deletion Makerules
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,8 @@ xcheck: xtests
# The only difference between MODULE_NAME=testsuite and MODULE_NAME=nonlib is
# that almost all internal declarations from config.h, libc-symbols.h, and
# include/*.h are not available to 'testsuite' code, but are to 'nonlib' code.
all-testsuite := $(strip $(tests) $(xtests) $(test-srcs) $(test-extras))
all-testsuite := $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) \
$(tests-container))
ifneq (,$(all-testsuite))
cpp-srcs-left = $(all-testsuite)
lib := testsuite
Expand Down
21 changes: 18 additions & 3 deletions Rules
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@ others: $(py-const)

ifeq ($(run-built-tests),no)
tests: $(addprefix $(objpfx),$(filter-out $(tests-unsupported), \
$(tests) $(tests-internal)) \
$(tests) $(tests-internal) \
$(tests-container)) \
$(test-srcs)) $(tests-special) \
$(tests-printers-programs)
xtests: tests $(xtests-special)
else
tests: $(tests:%=$(objpfx)%.out) $(tests-internal:%=$(objpfx)%.out) \
$(tests-container:%=$(objpfx)%.out) \
$(tests-special) $(tests-printers-out)
xtests: tests $(xtests:%=$(objpfx)%.out) $(xtests-special)
endif
Expand All @@ -145,7 +147,8 @@ xtests-special-notdir = $(patsubst $(objpfx)%, %, $(xtests-special))
ifeq ($(run-built-tests),no)
tests-expected =
else
tests-expected = $(tests) $(tests-internal) $(tests-printers)
tests-expected = $(tests) $(tests-internal) $(tests-printers) \
$(tests-container)
endif
tests:
$(..)scripts/merge-test-results.sh -s $(objpfx) $(subdir) \
Expand All @@ -158,7 +161,8 @@ xtests:

ifeq ($(build-programs),yes)
binaries-all-notests = $(others) $(sysdep-others)
binaries-all-tests = $(tests) $(tests-internal) $(xtests) $(test-srcs)
binaries-all-tests = $(tests) $(tests-internal) $(xtests) $(test-srcs) \
$(tests-container)
binaries-all = $(binaries-all-notests) $(binaries-all-tests)
binaries-static-notests = $(others-static)
binaries-static-tests = $(tests-static) $(xtests-static)
Expand Down Expand Up @@ -248,6 +252,17 @@ $(objpfx)%.out: /dev/null $(objpfx)% # Make it 2nd arg for canned sequence.
$(make-test-out) > $@; \
$(evaluate-test)


# Any tests that require an isolated container (filesystem, network
# and pid namespaces) in which to run, should be added to
# tests-container.
$(tests-container:%=$(objpfx)%.out): $(objpfx)%.out : $(if $(wildcard $(objpfx)%.files),$(objpfx)%.files,/dev/null) $(objpfx)%
$(test-wrapper-env) $(run-program-env) $(run-via-rtld-prefix) \
$(common-objpfx)support/test-container env $(run-program-env) $($*-ENV) \
$(host-test-program-cmd) $($*-ARGS) > $@; \
$(evaluate-test)


# tests-unsupported lists tests that we will not try to build at all in
# this configuration. Note this runs every time because it does not
# actually create its target. The dependency on Makefile is meant to
Expand Down
4 changes: 3 additions & 1 deletion nss/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ tests-internal = tst-field
tests = test-netdb test-digits-dots tst-nss-getpwent bug17079 \
tst-nss-test1 \
tst-nss-test2 \
tst-nss-test3 \
tst-nss-test4 \
tst-nss-test5
xtests = bug-erange

tests-container = \
tst-nss-test3

# Tests which need libdl
ifeq (yes,$(build-shared))
tests += tst-nss-files-hosts-erange
Expand Down
6 changes: 5 additions & 1 deletion nss/tst-nss-test3.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ do_test (void)
int i;
struct group *g = NULL;

__nss_configure_lookup ("group", "test1");
/* Previously we used __nss_configure_lookup to isolate the test
from the host environment and to get it to lookup from our new
test1 NSS service module, but now this test is run in a different
root filesystem via the test-container support and we directly
configure the use of the test1 NSS service. */

setgrent ();

Expand Down
1 change: 1 addition & 0 deletions nss/tst-nss-test3.root/etc/nsswitch.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
group test1
2 changes: 2 additions & 0 deletions nss/tst-nss-test3.root/tst-nss-test3.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cp $B/nss/libnss_test1.so $L/libnss_test1.so.2
cp $B/nss/libnss_test2.so $L/libnss_test2.so.2
42 changes: 42 additions & 0 deletions support/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ libsupport-routines = \
support_format_netent \
support_isolate_in_subprocess \
support_openpty \
support_paths \
support_quote_blob \
support_record_failure \
support_run_diff \
Expand Down Expand Up @@ -85,6 +86,7 @@ libsupport-routines = \
xmalloc \
xmemstream \
xmkdir \
xmkdirp \
xmmap \
xmprotect \
xmunmap \
Expand Down Expand Up @@ -140,6 +142,7 @@ libsupport-routines = \
xsocket \
xstrdup \
xstrndup \
xsymlink \
xsysconf \
xunlink \
xwaitpid \
Expand All @@ -152,6 +155,45 @@ ifeq ($(build-shared),yes)
libsupport-inhibit-o += .o
endif

CFLAGS-support_paths.c = \
-DSRCDIR_PATH=\"`cd .. ; pwd`\" \
-DOBJDIR_PATH=\"`cd $(objpfx)/..; pwd`\" \
-DINSTDIR_PATH=\"$(prefix)\" \
-DLIBDIR_PATH=\"$(libdir)\"

ifeq (,$(CXX))
LINKS_DSO_PROGRAM = links-dso-program-c
else
LINKS_DSO_PROGRAM = links-dso-program
LDLIBS-links-dso-program = -lstdc++ -lgcc_s
endif

others: \
$(objpfx)test-container \
$(objpfx)shell-container \
$(objpfx)echo-container \
$(objpfx)true-container \
$(objpfx)$(LINKS_DSO_PROGRAM)

ifeq ($(build-programs),yes)
endif

LDLIBS-test-container = $(libsupport)

others += test-container
others-noinstall += test-container

others += shell-container echo-container true-container
others-noinstall += shell-container echo-container true-container

others += $(LINKS_DSO_PROGRAM)
others-noinstall += $(LINKS_DSO_PROGRAM)

$(objpfx)test-container : $(libsupport)
$(objpfx)shell-container : $(libsupport)
$(objpfx)echo-container : $(libsupport)
$(objpfx)true-container : $(libsupport)

tests = \
README-testing \
tst-support-namespace \
Expand Down
34 changes: 34 additions & 0 deletions support/echo-container.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Minimal /bin/echo for in-container use.
Copyright (C) 2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */

#include <stdio.h>

int
main (int argc, const char **argv)
{
int i;

for (i = 1; i < argc; i++)
{
if (i > 1)
putchar (' ');
fputs (argv[i], stdout);
}
putchar ('\n');
return 0;
}
9 changes: 9 additions & 0 deletions support/links-dso-program-c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <stdio.h>

int
main (int argc, char **argv)
{
/* Complexity to keep gcc from optimizing this away. */
printf ("This is a test %s.\n", argc > 1 ? argv[1] : "null");
return 0;
}
11 changes: 11 additions & 0 deletions support/links-dso-program.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <iostream>

using namespace std;

int
main (int argc, char **argv)
{
/* Complexity to keep gcc from optimizing this away. */
cout << (argc > 1 ? argv[1] : "null");
return 0;
}
Loading

0 comments on commit 561b0be

Please sign in to comment.