Use libnss_files.so for tests posix/bug-ga2 and resolv/tst-leaks2 [BZ #26821]
Commit Message
The tests posix/bug-ga2-mem and resolv/mtrace-tst-leaks2 are failing on
fedora 33 as mtrace reports memory leaks.
The /etc/nsswitch.conf differs between
Fedora 32: hosts: files dns myhostname
Fedora 33: hosts: files resolve [!UNAVAIL=return] myhostname dns
Therefore /lib64/libnss_resolve.so.2 (from systemd) and the dependencies
libgcc_s.so.1 and libpthread.so.0 are loaded.
Usually all malloc'ed resources from getaddrinfo / gethostbyname are freed
and the libraries are dlclose'd in nss/nsswitch.c:libc_freeres_fn (free_mem).
Unfortunately, /lib64/libnss_resolve.so.2 is marked with DF_1_NODELETE.
As this library is not unmapped, you'll see "Memory not freed".
Therefore those tests are now only relying on libnss_files.so by making
them test-container tests and providing the required configuration files.
By moving the tests to tests-container, those are now running with
"make check". Therefore the mtrace part of the tests are also moved
from "make xcheck" to "make check".
bug-ga2.c is now using test-driver.c in order to support WAIT_FOR_DEBUGGER
environment variable.
---
posix/Makefile | 6 +++---
posix/bug-ga2.c | 13 +++++++------
posix/bug-ga2.root/etc/hosts | 1 +
posix/bug-ga2.root/etc/nsswitch.conf | 2 ++
posix/bug-ga2.root/etc/services | 1 +
resolv/Makefile | 7 +++----
resolv/tst-leaks2.c | 6 ++++--
resolv/tst-leaks2.root/etc/hosts | 1 +
resolv/tst-leaks2.root/etc/nsswitch.conf | 1 +
9 files changed, 23 insertions(+), 15 deletions(-)
create mode 100644 posix/bug-ga2.root/etc/hosts
create mode 100644 posix/bug-ga2.root/etc/nsswitch.conf
create mode 100644 posix/bug-ga2.root/etc/services
create mode 100644 resolv/tst-leaks2.root/etc/hosts
create mode 100644 resolv/tst-leaks2.root/etc/nsswitch.conf
Comments
On Fri, Nov 20, 2020 at 4:08 AM Stefan Liebler via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> The tests posix/bug-ga2-mem and resolv/mtrace-tst-leaks2 are failing on
> fedora 33 as mtrace reports memory leaks.
>
> The /etc/nsswitch.conf differs between
> Fedora 32: hosts: files dns myhostname
> Fedora 33: hosts: files resolve [!UNAVAIL=return] myhostname dns
>
> Therefore /lib64/libnss_resolve.so.2 (from systemd) and the dependencies
> libgcc_s.so.1 and libpthread.so.0 are loaded.
>
> Usually all malloc'ed resources from getaddrinfo / gethostbyname are freed
> and the libraries are dlclose'd in nss/nsswitch.c:libc_freeres_fn (free_mem).
> Unfortunately, /lib64/libnss_resolve.so.2 is marked with DF_1_NODELETE.
> As this library is not unmapped, you'll see "Memory not freed".
>
> Therefore those tests are now only relying on libnss_files.so by making
> them test-container tests and providing the required configuration files.
>
> By moving the tests to tests-container, those are now running with
> "make check". Therefore the mtrace part of the tests are also moved
> from "make xcheck" to "make check".
>
> bug-ga2.c is now using test-driver.c in order to support WAIT_FOR_DEBUGGER
> environment variable.
> ---
> posix/Makefile | 6 +++---
> posix/bug-ga2.c | 13 +++++++------
> posix/bug-ga2.root/etc/hosts | 1 +
> posix/bug-ga2.root/etc/nsswitch.conf | 2 ++
> posix/bug-ga2.root/etc/services | 1 +
> resolv/Makefile | 7 +++----
> resolv/tst-leaks2.c | 6 ++++--
> resolv/tst-leaks2.root/etc/hosts | 1 +
> resolv/tst-leaks2.root/etc/nsswitch.conf | 1 +
> 9 files changed, 23 insertions(+), 15 deletions(-)
> create mode 100644 posix/bug-ga2.root/etc/hosts
> create mode 100644 posix/bug-ga2.root/etc/nsswitch.conf
> create mode 100644 posix/bug-ga2.root/etc/services
> create mode 100644 resolv/tst-leaks2.root/etc/hosts
> create mode 100644 resolv/tst-leaks2.root/etc/nsswitch.conf
>
LGTM.
Thanks.
On 11/20/20 2:40 PM, H.J. Lu wrote:
> On Fri, Nov 20, 2020 at 4:08 AM Stefan Liebler via Libc-alpha
> <libc-alpha@sourceware.org> wrote:
>>
>> The tests posix/bug-ga2-mem and resolv/mtrace-tst-leaks2 are failing on
>> fedora 33 as mtrace reports memory leaks.
>>
>> The /etc/nsswitch.conf differs between
>> Fedora 32: hosts: files dns myhostname
>> Fedora 33: hosts: files resolve [!UNAVAIL=return] myhostname dns
>>
>> Therefore /lib64/libnss_resolve.so.2 (from systemd) and the dependencies
>> libgcc_s.so.1 and libpthread.so.0 are loaded.
>>
>> Usually all malloc'ed resources from getaddrinfo / gethostbyname are freed
>> and the libraries are dlclose'd in nss/nsswitch.c:libc_freeres_fn (free_mem).
>> Unfortunately, /lib64/libnss_resolve.so.2 is marked with DF_1_NODELETE.
>> As this library is not unmapped, you'll see "Memory not freed".
>>
>> Therefore those tests are now only relying on libnss_files.so by making
>> them test-container tests and providing the required configuration files.
>>
>> By moving the tests to tests-container, those are now running with
>> "make check". Therefore the mtrace part of the tests are also moved
>> from "make xcheck" to "make check".
>>
>> bug-ga2.c is now using test-driver.c in order to support WAIT_FOR_DEBUGGER
>> environment variable.
>> ---
>> posix/Makefile | 6 +++---
>> posix/bug-ga2.c | 13 +++++++------
>> posix/bug-ga2.root/etc/hosts | 1 +
>> posix/bug-ga2.root/etc/nsswitch.conf | 2 ++
>> posix/bug-ga2.root/etc/services | 1 +
>> resolv/Makefile | 7 +++----
>> resolv/tst-leaks2.c | 6 ++++--
>> resolv/tst-leaks2.root/etc/hosts | 1 +
>> resolv/tst-leaks2.root/etc/nsswitch.conf | 1 +
>> 9 files changed, 23 insertions(+), 15 deletions(-)
>> create mode 100644 posix/bug-ga2.root/etc/hosts
>> create mode 100644 posix/bug-ga2.root/etc/nsswitch.conf
>> create mode 100644 posix/bug-ga2.root/etc/services
>> create mode 100644 resolv/tst-leaks2.root/etc/hosts
>> create mode 100644 resolv/tst-leaks2.root/etc/nsswitch.conf
>>
>
> LGTM.
>
> Thanks.
>
I've just committed it and I've also closed the bugzilla.
Thanks,
Stefan
@@ -106,7 +106,8 @@ tests := test-errno tstgetopt testfnm runtests runptests \
tests-internal := bug-regex5 bug-regex20 bug-regex33 \
tst-rfc3484 tst-rfc3484-2 tst-rfc3484-3 \
tst-glob_lstat_compat tst-spawn4-compat
-xtests := bug-ga2 tst-getaddrinfo4 tst-getaddrinfo5
+tests-container := bug-ga2
+xtests := tst-getaddrinfo4 tst-getaddrinfo5
ifeq (yes,$(build-shared))
test-srcs := globtest
tests += wordexp-test tst-exec tst-spawn tst-spawn2 tst-spawn3
@@ -153,8 +154,7 @@ tests-special += $(objpfx)bug-regex2-mem.out $(objpfx)bug-regex14-mem.out \
$(objpfx)tst-boost-mem.out $(objpfx)tst-getconf.out \
$(objpfx)bug-glob2-mem.out $(objpfx)tst-vfork3-mem.out \
$(objpfx)tst-fnmatch-mem.out $(objpfx)bug-regex36-mem.out \
- $(objpfx)tst-glob-tilde-mem.out
-xtests-special += $(objpfx)bug-ga2-mem.out
+ $(objpfx)tst-glob-tilde-mem.out $(objpfx)bug-ga2-mem.out
endif
include ../Rules
@@ -3,9 +3,10 @@
#include <netdb.h>
#include <stdio.h>
#include <string.h>
+#include <support/check.h>
-int
-main (void)
+static int
+do_test (void)
{
struct addrinfo hints, *res;
int i, ret;
@@ -20,11 +21,11 @@ main (void)
ret = getaddrinfo ("www.gnu.org", "http", &hints, &res);
if (ret)
- {
- printf ("%s\n", gai_strerror (ret));
- return 1;
- }
+ FAIL_EXIT1 ("%s\n", gai_strerror (ret));
+
freeaddrinfo (res);
}
return 0;
}
+
+#include <support/test-driver.c>
new file mode 100644
@@ -0,0 +1 @@
+192.0.2.1 www.gnu.org
new file mode 100644
@@ -0,0 +1,2 @@
+services: files
+hosts: files
new file mode 100644
@@ -0,0 +1 @@
+http 80/tcp
@@ -32,7 +32,7 @@ routines := herror inet_addr inet_ntop inet_pton nsap_addr res_init \
resolv_context resolv_conf
tests = tst-aton tst-leaks tst-inet_ntop
-xtests = tst-leaks2
+tests-container = tst-leaks2
tests-internal += tst-inet_aton_exact
@@ -125,9 +125,8 @@ endif
ifeq ($(run-built-tests),yes)
ifneq (no,$(PERL))
-tests-special += $(objpfx)mtrace-tst-leaks.out
-xtests-special += $(objpfx)mtrace-tst-leaks2.out
-tests-special += $(objpfx)mtrace-tst-resolv-res_ninit.out
+tests-special += $(objpfx)mtrace-tst-leaks.out $(objpfx)mtrace-tst-leaks2.out \
+ $(objpfx)mtrace-tst-resolv-res_ninit.out
endif
endif
@@ -21,6 +21,7 @@
#include <mcheck.h>
#include <netdb.h>
#include <resolv.h>
+#include <support/check.h>
static int
do_test (void)
@@ -28,8 +29,9 @@ do_test (void)
mtrace ();
for (int i = 0; i < 20; ++i)
{
- res_init ();
- gethostbyname ("www.gnu.org");
+ TEST_VERIFY_EXIT (res_init () == 0);
+ if (gethostbyname ("www.gnu.org") == NULL)
+ FAIL_EXIT1 ("%s\n", hstrerror (h_errno));
}
return 0;
}
new file mode 100644
@@ -0,0 +1 @@
+192.0.2.1 www.gnu.org
new file mode 100644
@@ -0,0 +1 @@
+hosts: files