[PATCH] Remove redundant casts of memory allocating functions returning void *

2021-09-06 Thread Dmitry V. Levin
Return values of functions returning "void *", e.g. calloc, malloc,
realloc, xcalloc, xmalloc, and xrealloc, do not need explicit casts.

Signed-off-by: Dmitry V. Levin 
---
 debuginfod/ChangeLog |  5 +
 debuginfod/debuginfod-client.c   |  2 +-
 lib/ChangeLog|  6 ++
 lib/dynamicsizehash.c|  2 +-
 lib/dynamicsizehash_concurrent.c |  2 +-
 libasm/ChangeLog | 14 ++
 libasm/asm_align.c   |  5 ++---
 libasm/asm_begin.c   |  3 +--
 libasm/asm_fill.c|  3 +--
 libasm/asm_newabssym.c   |  2 +-
 libasm/asm_newcomsym.c   |  2 +-
 libasm/asm_newscn.c  |  2 +-
 libasm/asm_newscngrp.c   |  2 +-
 libasm/asm_newsubscn.c   |  2 +-
 libasm/asm_newsym.c  |  2 +-
 libasm/disasm_begin.c|  2 +-
 libdw/ChangeLog  |  9 +
 libdw/dwarf_begin_elf.c  |  8 
 libdw/dwarf_getpubnames.c|  5 ++---
 libdw/dwarf_getsrclines.c|  2 +-
 libdwelf/ChangeLog   |  6 ++
 libdwelf/dwelf_strtab.c  |  5 ++---
 libdwfl/ChangeLog|  5 +
 libdwfl/linux-pid-attach.c   |  2 +-
 libebl/ChangeLog |  4 
 libebl/eblopenbackend.c  |  2 +-
 libelf/ChangeLog | 14 ++
 libelf/common.h  |  2 +-
 libelf/elf32_updatefile.c|  4 ++--
 libelf/elf_begin.c   |  2 +-
 libelf/elf_getarsym.c|  5 ++---
 libelf/elf_getdata.c |  9 -
 libelf/elf_getscn.c  |  4 ++--
 libelf/elf_newdata.c |  2 +-
 libelf/elf_newscn.c  | 10 +-
 libelf/elf_readall.c |  2 +-
 src/ChangeLog| 13 +
 src/elflint.c|  2 +-
 src/findtextrel.c|  7 ++-
 src/nm.c |  7 +++
 src/readelf.c| 14 ++
 src/strip.c  |  9 -
 tests/ChangeLog  |  4 
 tests/elfcopy.c  |  2 +-
 44 files changed, 141 insertions(+), 75 deletions(-)

diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index c5459823..7e221f54 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,8 @@
+2021-09-06  Dmitry V. Levin  
+
+   * debuginfod-client.c (debuginfod_begin): Remove cast of calloc return
+   value.
+
 2021-08-28  Mark Wielaard  
 
* debuginfod.cxx (parse_opt): Turn the -d arg ":memory:" into
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 7d4b220f..d41723ce 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -1359,7 +1359,7 @@ debuginfod_begin (void)
 {
   debuginfod_client *client;
   size_t size = sizeof (struct debuginfod_client);
-  client = (debuginfod_client *) calloc (1, size);
+  client = calloc (1, size);
 
   if (client != NULL)
 {
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 60d32082..563b0b6a 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,9 @@
+2021-09-06  Dmitry V. Levin  
+
+   * dynamicsizehash.c (INIT(NAME)): Remove cast of calloc return value.
+   * dynamicsizehash_concurrent.c (INIT(NAME)): Remove cast of malloc
+   return value.
+
 2021-08-23  Saleem Abdulrasool  
 
* system.h: Remove inline definition for error and error_message_count
diff --git a/lib/dynamicsizehash.c b/lib/dynamicsizehash.c
index f9406eba..76c86dad 100644
--- a/lib/dynamicsizehash.c
+++ b/lib/dynamicsizehash.c
@@ -184,7 +184,7 @@ INIT(NAME) (NAME *htab, size_t init_size)
 #ifdef ITERATE
   htab->first = NULL;
 #endif
-  htab->table = (void *) calloc ((init_size + 1), sizeof (htab->table[0]));
+  htab->table = calloc ((init_size + 1), sizeof (htab->table[0]));
   if (htab->table == NULL)
 return -1;
 
diff --git a/lib/dynamicsizehash_concurrent.c b/lib/dynamicsizehash_concurrent.c
index 2d53bec6..4e2e2476 100644
--- a/lib/dynamicsizehash_concurrent.c
+++ b/lib/dynamicsizehash_concurrent.c
@@ -355,7 +355,7 @@ INIT(NAME) (NAME *htab, size_t init_size)
 
   pthread_rwlock_init(&htab->resize_rwl, NULL);
 
-  htab->table = (void *) malloc ((init_size + 1) * sizeof (htab->table[0]));
+  htab->table = malloc ((init_size + 1) * sizeof (htab->table[0]));
   if (htab->table == NULL)
   return -1;
 
diff --git a/libasm/ChangeLog b/libasm/ChangeLog
index 85e723e6..c65fd21b 100644
--- a/libasm/ChangeLog
+++ b/libasm/ChangeLog
@@ -1,3 +1,17 @@
+2021-09-06  Dmitry V. Levin  
+
+   * asm_align.c (__libasm_ensure_section_space): Remove casts of calloc
+   return values.
+   * asm_begin.c (asm_begin): Remove cast of malloc return value.
+   * asm_fill.c (asm_fill): Likewise.
+   * asm_newabssym.c (asm_newabssym): Likewise.
+   * asm_newcomsym.c (asm_newcomsym): Likewise.
+   * asm_newscn.c (asm_newscn): Likewise.
+   * asm_newscngrp.c (a

[PATCH 1/2] Introduce xasprintf

2021-09-06 Thread Dmitry V. Levin
Similar to other x* functions, xasprintf is like asprintf except that
it dies in case of an error.

Signed-off-by: Dmitry V. Levin 
---
 lib/ChangeLog   |  6 ++
 lib/Makefile.am |  2 +-
 lib/libeu.h |  2 ++
 lib/xasprintf.c | 52 +
 4 files changed, 61 insertions(+), 1 deletion(-)
 create mode 100644 lib/xasprintf.c

diff --git a/lib/ChangeLog b/lib/ChangeLog
index 60d32082..59d1d51c 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,9 @@
+2021-09-06  Dmitry V. Levin  
+
+   * xasprintf.c: New file.
+   * Makefile.am (libeu_a_SOURCES): Add it.
+   * libeu.h (xasprintf): New prototype.
+
 2021-08-23  Saleem Abdulrasool  
 
* system.h: Remove inline definition for error and error_message_count
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 766fbcd7..42ddf5ae 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -33,7 +33,7 @@ AM_CPPFLAGS += -I$(srcdir)/../libelf
 
 noinst_LIBRARIES = libeu.a
 
-libeu_a_SOURCES = xstrdup.c xstrndup.c xmalloc.c next_prime.c \
+libeu_a_SOURCES = xasprintf.c xstrdup.c xstrndup.c xmalloc.c next_prime.c \
  crc32.c crc32_file.c \
  color.c error.c printversion.c
 
diff --git a/lib/libeu.h b/lib/libeu.h
index ecb4d011..e849a79e 100644
--- a/lib/libeu.h
+++ b/lib/libeu.h
@@ -39,6 +39,8 @@ extern void *xrealloc (void *, size_t) __attribute__ 
((__malloc__));
 extern char *xstrdup (const char *) __attribute__ ((__malloc__));
 extern char *xstrndup (const char *, size_t) __attribute__ ((__malloc__));
 
+extern char *xasprintf(const char *fmt, ...)
+   __attribute__ ((format (printf, 1, 2))) __attribute__ ((__malloc__));
 
 extern uint32_t crc32 (uint32_t crc, unsigned char *buf, size_t len);
 extern int crc32_file (int fd, uint32_t *resp);
diff --git a/lib/xasprintf.c b/lib/xasprintf.c
new file mode 100644
index ..179ea2e8
--- /dev/null
+++ b/lib/xasprintf.c
@@ -0,0 +1,52 @@
+/* A wrapper around vasprintf that dies in case of an error.
+   Copyright (c) 2021 Dmitry V. Levin 
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+ * the GNU Lesser General Public License as published by the Free
+   Software Foundation; either version 3 of the License, or (at
+   your option) any later version
+
+   or
+
+ * the GNU General Public License as published by the Free
+   Software Foundation; either version 2 of the License, or (at
+   your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils 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
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see .  */
+
+#ifdef HAVE_CONFIG_H
+# include 
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include "libeu.h"
+#include "system.h"
+
+char *
+xasprintf (const char *fmt, ...)
+{
+  char *res;
+  va_list ap;
+
+  va_start (ap, fmt);
+  if (unlikely (vasprintf (&res, fmt, ap) < 0))
+error (EXIT_FAILURE, 0, _("memory exhausted"));
+  va_end(ap);
+
+  return res;
+}
-- 
ldv


[PATCH 2/2] Use xasprintf instead of asprintf followed by error(EXIT_FAILURE)

2021-09-06 Thread Dmitry V. Levin
Signed-off-by: Dmitry V. Levin 
---
 lib/ChangeLog |  3 +++
 lib/color.c   |  6 ++
 src/ChangeLog |  7 +++
 src/objdump.c | 17 -
 src/readelf.c | 14 ++
 src/unstrip.c |  8 ++--
 6 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/lib/ChangeLog b/lib/ChangeLog
index 59d1d51c..8e630417 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,5 +1,8 @@
 2021-09-06  Dmitry V. Levin  
 
+   * color.c (parse_opt): Replace asprintf followed by error(EXIT_FAILURE)
+   with xasprintf.
+
* xasprintf.c: New file.
* Makefile.am (libeu_a_SOURCES): Add it.
* libeu.h (xasprintf): New prototype.
diff --git a/lib/color.c b/lib/color.c
index 454cb7ca..e43b6143 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -188,10 +188,8 @@ valid arguments are:\n\
if (name_len == known[i].len
&& memcmp (start, known[i].name, name_len) == 0)
  {
-   if (asprintf (known[i].varp, "\e[%.*sm",
- (int) (env - val), val) < 0)
- error (EXIT_FAILURE, errno,
-_("cannot allocate memory"));
+   *known[i].varp =
+ xasprintf ("\e[%.*sm", (int) (env - val), 
val);
break;
  }
}
diff --git a/src/ChangeLog b/src/ChangeLog
index b729eaa4..297627df 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2021-09-06  Dmitry V. Levin  
+
+   * objdump.c (show_disasm): Replace asprintf followed by
+   error(EXIT_FAILURE) with xasprintf.
+   * readelf.c (handle_gnu_hash): Likewise.
+   * unstrip.c (handle_output_dir_module, main): Likewise.
+
 2021-08-20  Saleem Abdulrasool  
 
* elfclassify.c: Remove error.h include.
diff --git a/src/objdump.c b/src/objdump.c
index 3a93248c..f7ea6c92 100644
--- a/src/objdump.c
+++ b/src/objdump.c
@@ -717,15 +717,14 @@ show_disasm (Ebl *ebl, const char *fname, uint32_t 
shstrndx)
  info.address_color = color_address;
  info.bytes_color = color_bytes;
 
- if (asprintf (&fmt, "%s%%7m 
%s%%.1o,%s%%.2o,%s%%.3o,,%s%%.4o%s%%.5o%%34a %s%%l",
-   color_mnemonic ?: "",
-   color_operand1 ?: "",
-   color_operand2 ?: "",
-   color_operand3 ?: "",
-color_operand4 ?: "",
-color_operand5 ?: "",
-   color_label ?: "") < 0)
-   error (EXIT_FAILURE, errno, _("cannot allocate memory"));
+ fmt = xasprintf ("%s%%7m 
%s%%.1o,%s%%.2o,%s%%.3o,,%s%%.4o%s%%.5o%%34a %s%%l",
+  color_mnemonic ?: "",
+  color_operand1 ?: "",
+  color_operand2 ?: "",
+  color_operand3 ?: "",
+  color_operand4 ?: "",
+  color_operand5 ?: "",
+  color_label ?: "");
}
  else
{
diff --git a/src/readelf.c b/src/readelf.c
index 8191bde2..80b40918 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -3448,17 +3448,15 @@ handle_gnu_hash (Ebl *ebl, Elf_Scn *scn, GElf_Shdr 
*shdr, size_t shstrndx)
   nbits += (word & 0x) + ((word >> 16) & 0x);
 }
 
-  char *str;
-  if (unlikely (asprintf (&str, _("\
+  char *str = xasprintf (_("\
  Symbol Bias: %u\n\
  Bitmask Size: %zu bytes  %" PRIuFAST32 "%% bits set  2nd hash shift: %u\n"),
- (unsigned int) symbias,
- bitmask_words * sizeof (Elf32_Word),
- ((nbits * 100 + 50)
-  / (uint_fast32_t) (bitmask_words
+(unsigned int) symbias,
+bitmask_words * sizeof (Elf32_Word),
+((nbits * 100 + 50)
+ / (uint_fast32_t) (bitmask_words
  * sizeof (Elf32_Word) * 8)),
- (unsigned int) shift) == -1))
-error (EXIT_FAILURE, 0, _("memory exhausted"));
+ (unsigned int) shift);
 
   print_hash_info (ebl, scn, shdr, shstrndx, maxlength, nbucket, nsyms,
   lengths, str);
diff --git a/src/unstrip.c b/src/unstrip.c
index 6618ec9b..aacc9aad 100644
--- a/src/unstrip.c
+++ b/src/unstrip.c
@@ -2401,9 +2401,7 @@ handle_output_dir_module (const char *output_dir, 
Dwfl_Module *mod, bool force,
   if (file == NULL && ignore)
 return;
 
-  char *output_file;
-  if (asprintf (&output_file, "%s/%s", output_dir, modnames ? name : file) < 0)
-error (EXIT_FAILURE, 0, _("memory exhausted"));
+  char *output_file = xasprin

Re: Buildbot failure in Wildebeest Builder on whole buildset

2021-09-06 Thread Mark Wielaard
On Sat, 2021-09-04 at 01:47 +0200, Mark Wielaard wrote:
> On Fri, Sep 03, 2021 at 02:08:40PM +, 
> build...@builder.wildebeest.org wrote:
> > The Buildbot has detected a new failure on builder elfutils-debian-
> > armhf while building elfutils.
> > Full details are available at:
> > https://builder.wildebeest.org/buildbot/#builders/15/builds/603
> > 
> > Buildbot URL: https://builder.wildebeest.org/buildbot/
> > 
> > Worker for this Build: debian-armhf
> > 
> > Build Reason: 
> > Blamelist: Mark Wielaard 
> > 
> > BUILD FAILED: failed test (failure)
> 
> So some of the builders did pass without any failures. But some had
> errors, and not all the same ones. I couldn't replicate locally
> (everything was green) both with make check and make distcheck.
> 
> But looking at the tests I noticed not all used a clean new cache and
> some used the default database.
> 
> So hopefully the attached patch makes things a bit more stable by
> explicitly setting the DEBUGINFOD_CACHE_PATH and invoke debuginfod
> with a fresh sqlite database.

Sadly we still have failures even with this patch:
https://builder.wildebeest.org/buildbot/#/changes/2567

The good news is that elfutils-fedora-x86_64, elfutils-fedora-ppc64le,
elfutils-fedora-s390x, elfutils-debian-i386, elfutils-fedora-ppc64 and
elfutils-debian-armhf are fully green, but...

On elfutils-centos-x86_64 make check fails with:

FAIL: run-debuginfod-tmp-home.sh
FAIL: run-debuginfod-writable.sh

On elfutils-debian-arm64 make check fails with:

FAIL: run-debuginfod-federation-sqlite.sh

On elfutils-centos-x86_64 make check first timed out (!?!)
then it failed with:

FAIL: run-debuginfod-tmp-home.sh
FAIL: run-debuginfod-writable.sh

On elfutils-debian-amd64 make check failed with:

FAIL: run-debuginfod-archive-groom.sh

The failures still look somewhat random (although less random than
before). I don't yet know why.

Cheers,

Mark


[PATCH] findtextrel: do not use unbound alloca

2021-09-06 Thread Dmitry V. Levin
This fixes the following compilation warning:

findtextrel.c:184:1: warning: stack usage might be unbounded [-Wstack-usage=]

Signed-off-by: Dmitry V. Levin 
---
 src/ChangeLog |  5 +
 src/Makefile.am   |  1 -
 src/findtextrel.c | 31 +--
 3 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 297627df..2238916f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
 2021-09-06  Dmitry V. Levin  
 
+   * findtextrel.c: Include "libeu.h".
+   (process_file): Use xasprintf instead of alloca followed by series
+   of mempcpy and stpcpy.
+   * Makefile.am (findtextrel_no_Wstack_usage): Remove.
+
* objdump.c (show_disasm): Replace asprintf followed by
error(EXIT_FAILURE) with xasprintf.
* readelf.c (handle_gnu_hash): Likewise.
diff --git a/src/Makefile.am b/src/Makefile.am
index 88d0ac8f..ee695d5d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -61,7 +61,6 @@ nm_no_Wstack_usage = yes
 size_no_Wstack_usage = yes
 strip_no_Wstack_usage = yes
 elflint_no_Wstack_usage = yes
-findtextrel_no_Wstack_usage = yes
 elfcmp_no_Wstack_usage = yes
 objdump_no_Wstack_usage = yes
 ranlib_no_Wstack_usage = yes
diff --git a/src/findtextrel.c b/src/findtextrel.c
index 220ee909..4bee80ae 100644
--- a/src/findtextrel.c
+++ b/src/findtextrel.c
@@ -36,6 +36,7 @@
 #include 
 
 #include 
+#include "libeu.h"
 #include "system.h"
 
 struct segments
@@ -185,25 +186,17 @@ process_file (const char *fname, bool more_than_one)
 {
   int result = 0;
   void *knownsrcs = NULL;
+  char *new_fname = NULL;
 
-  size_t fname_len = strlen (fname);
-  size_t rootdir_len = strlen (rootdir);
   const char *real_fname = fname;
   if (fname[0] == '/' && (rootdir[0] != '/' || rootdir[1] != '\0'))
-{
-  /* Prepend the user-provided root directory.  */
-  char *new_fname = alloca (rootdir_len + fname_len + 2);
-  *((char *) mempcpy (stpcpy (mempcpy (new_fname, rootdir, rootdir_len),
- "/"),
- fname, fname_len)) = '\0';
-  real_fname = new_fname;
-}
+real_fname = new_fname = xasprintf ("%s/%s", rootdir, fname);
 
   int fd = open (real_fname, O_RDONLY);
   if (fd == -1)
 {
   error (0, errno, _("cannot open '%s'"), fname);
-  return 1;
+  goto err_free;
 }
 
   Elf *elf = elf_begin (fd, ELF_C_READ_MMAP, NULL);
@@ -225,6 +218,8 @@ process_file (const char *fname, bool more_than_one)
   elf_end (elf);
 err_close:
   close (fd);
+err_free:
+  free (new_fname);
   return 1;
 }
 
@@ -362,18 +357,10 @@ cannot get program header index at offset %zd: %s"),
 is specified with an absolute path.  */
   if (dw == NULL && fname[0] == '/')
{
- size_t debuginfo_rootlen = strlen (debuginfo_root);
- char *difname = (char *) alloca (rootdir_len + debuginfo_rootlen
-  + fname_len + 8);
- strcpy (mempcpy (stpcpy (mempcpy (mempcpy (difname, rootdir,
-rootdir_len),
-   debuginfo_root,
-   debuginfo_rootlen),
-  "/"),
-  fname, fname_len),
- ".debug");
-
+ char *difname =
+   xasprintf("%s%s/%s.debug", rootdir, debuginfo_root, fname);
  fd2 = open (difname, O_RDONLY);
+ free (difname);
  if (fd2 != -1
  && (elf2 = elf_begin (fd2, ELF_C_READ_MMAP, NULL)) != NULL)
dw = dwarf_begin_elf (elf2, DWARF_C_READ, NULL);
-- 
ldv


Re: Buildbot failure in Wildebeest Builder on whole buildset

2021-09-06 Thread Mark Wielaard
Hi,

On Mon, Sep 06, 2021 at 05:07:50PM +0200, Mark Wielaard wrote:
> On Sat, 2021-09-04 at 01:47 +0200, Mark Wielaard wrote:
> > On Fri, Sep 03, 2021 at 02:08:40PM +, 
> > build...@builder.wildebeest.org wrote:
> > > The Buildbot has detected a new failure on builder elfutils-debian-
> > > armhf while building elfutils.
> > > Full details are available at:
> > > https://builder.wildebeest.org/buildbot/#builders/15/builds/603
> > > 
> > > Buildbot URL: https://builder.wildebeest.org/buildbot/
> > > 
> > > Worker for this Build: debian-armhf
> > > 
> > > Build Reason: 
> > > Blamelist: Mark Wielaard 
> > > 
> > > BUILD FAILED: failed test (failure)
> > 
> > So some of the builders did pass without any failures. But some had
> > errors, and not all the same ones. I couldn't replicate locally
> > (everything was green) both with make check and make distcheck.
> > 
> > But looking at the tests I noticed not all used a clean new cache and
> > some used the default database.
> > 
> > So hopefully the attached patch makes things a bit more stable by
> > explicitly setting the DEBUGINFOD_CACHE_PATH and invoke debuginfod
> > with a fresh sqlite database.
> 
> Sadly we still have failures even with this patch:
> https://builder.wildebeest.org/buildbot/#/changes/2567
> 
> The good news is that elfutils-fedora-x86_64, elfutils-fedora-ppc64le,
> elfutils-fedora-s390x, elfutils-debian-i386, elfutils-fedora-ppc64 and
> elfutils-debian-armhf are fully green, but...
> 
> On elfutils-centos-x86_64 make check fails with:
> 
> FAIL: run-debuginfod-tmp-home.sh
> FAIL: run-debuginfod-writable.sh
> 
> On elfutils-debian-arm64 make check fails with:
> 
> FAIL: run-debuginfod-federation-sqlite.sh
> 
> On elfutils-centos-x86_64 make check first timed out (!?!)
> then it failed with:
> 
> FAIL: run-debuginfod-tmp-home.sh
> FAIL: run-debuginfod-writable.sh
> 
> On elfutils-debian-amd64 make check failed with:
> 
> FAIL: run-debuginfod-archive-groom.sh
> 
> The failures still look somewhat random (although less random than
> before). I don't yet know why.

This doesn't really explain the above failures, but there were still
two tests that didn't use their own debuginfod client cache. Also one
set a useless, but confusing DEBUGINFOD_URLS.

Still looking for explanations of the other FAILS (which I cannot
reproduce locally).

Cheers,

Mark>From 44a36e39fc7df2a3e2f9f278f79f65233d774a48 Mon Sep 17 00:00:00 2001
From: Mark Wielaard 
Date: Mon, 6 Sep 2021 21:48:38 +0200
Subject: [PATCH] tests: Set DEBUGINFOD_CACHE_PATH for
 run-debuginfod-{file,query-retry}.sh

---
 tests/ChangeLog | 7 +++
 tests/run-debuginfod-file.sh| 6 +++---
 tests/run-debuginfod-query-retry.sh | 2 +-
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 178697bb..c1760877 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2021-09-06  Mark Wielaard  
+
+	* run-debuginfod-file.sh: Set DEBUGINFOD_CACHE_PATH. Export
+	correct DEBUGINFOD_URLS.
+	* run-debuginfod-query-retry.sh: Add DEBUGINFOD_CACHE_PATH
+	to env.
+
 2021-09-03  Mark Wielaard  
 
 	* run-debuginfod-000-permission.sh: Set DEBUGINFOD_CACHE_PATH
diff --git a/tests/run-debuginfod-file.sh b/tests/run-debuginfod-file.sh
index 22c956dd..341bbc68 100755
--- a/tests/run-debuginfod-file.sh
+++ b/tests/run-debuginfod-file.sh
@@ -22,7 +22,7 @@
 set -x
 unset VALGRIND_CMD
 
-export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/   # or without trailing /
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
 
 # Test fetching a file using file:// . No debuginfod server needs to be run for
 # this test.
@@ -30,11 +30,11 @@ local_dir=${PWD}/mocktree/buildid/aabbccdd/sourc
 mkdir -p ${local_dir}
 echo "int main() { return 0; }" > ${local_dir}/main.c
 # first test that is doesn't work, when no DEBUGINFOD_URLS is set
-DEBUGINFOD_URLS=""
+export DEBUGINFOD_URLS=""
 testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aabbccdd /my/path/main.c && false || true
 
 # Now test is with proper DEBUGINFOD_URLS
-DEBUGINFOD_URLS="file://${PWD}/mocktree/"
+export DEBUGINFOD_URLS="file://${PWD}/mocktree/"
 filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aabbccdd /my/path/main.c`
 cmp $filename ${local_dir}/main.c
 
diff --git a/tests/run-debuginfod-query-retry.sh b/tests/run-debuginfod-query-retry.sh
index 3c5542d5..c9192510 100755
--- a/tests/run-debuginfod-query-retry.sh
+++ b/tests/run-debuginfod-query-retry.sh
@@ -24,7 +24,7 @@ unset VALGRIND_CMD
 
 
 # set up tests for retrying failed queries.
-retry_attempts=`(testrun env DEBUGINFOD_URLS=http://255.255.255.255/JUNKJUNK DEBUGINFOD_RETRY_LIMIT=10 DEBUGINFOD_VERBOSE=1 \
+retry_attempts=`(testrun env DEBUGINFOD_URLS=http://255.255.255.255/JUNKJUNK DEBUGINFOD_RETRY_LIMIT=10 DEBUGINFOD_VERBOSE=

Re: Buildbot failure in Wildebeest Builder on whole buildset

2021-09-06 Thread Mark Wielaard
On Mon, Sep 06, 2021 at 10:02:11PM +0200, Mark Wielaard wrote:
> This doesn't really explain the above failures, but there were still
> two tests that didn't use their own debuginfod client cache. Also one
> set a useless, but confusing DEBUGINFOD_URLS.
> 
> Still looking for explanations of the other FAILS (which I cannot
> reproduce locally).

As expected there are still several failures on the buildbot workers,
but I did manage to replicate one failure locally. It happened because
PORT1 and PORT2 were equal.

ss -atn | fgrep ":$PORT2" && $PORT1 -ne $PORT2 || break

Does actually break when PORT1 == PORT2. The && -ne should have been
|| -eq. But just simplify the port selection a bit to use
non-overlapping ranges (split the 100 possible ports in 0-49 for port1
and 50-99 for port2).

Also because of a typo on error only the metrics of port1 were
shown. Fix the typo so we can better diagnose the remaining failures.

Cheers,

Mark>From 7880ccb6483e76847cdf1c6c4e45a2180bee820a Mon Sep 17 00:00:00 2001
From: Mark Wielaard 
Date: Mon, 6 Sep 2021 23:04:06 +0200
Subject: [PATCH] tests: Print metrics for both ports on error and fix port
 selection

On error we would only print the metrics of one port (twice) because
of a typo. Also PORT1 and PORT2 could be equal because of a logic
error. Fix the typo and simplify the port selection by using
non-overlapping ranges to select PORT1 and PORT2.
---
 tests/ChangeLog  | 7 +++
 tests/debuginfod-subr.sh | 8 
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index c1760877..14eb4d98 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2021-09-06  Mark Wielaard  
+
+	* debuginfod-subr.sh (err): Change ports to port in for loop so both
+	PORT1 and PORT2 are used.
+	(get_ports): Simplify port selection by using for 50 for PORT1 and
+	second 50 for PORT2.
+
 2021-09-06  Mark Wielaard  
 
 	* run-debuginfod-file.sh: Set DEBUGINFOD_CACHE_PATH. Export
diff --git a/tests/debuginfod-subr.sh b/tests/debuginfod-subr.sh
index 3222a2b0..7d238436 100755
--- a/tests/debuginfod-subr.sh
+++ b/tests/debuginfod-subr.sh
@@ -39,7 +39,7 @@ trap cleanup 0 1 2 3 5 9 15
 errfiles_list=
 err() {
 echo ERROR REPORTS
-for ports in $PORT1 $PORT2
+for port in $PORT1 $PORT2
 do
 echo ERROR REPORT $port metrics
 curl -s http://127.0.0.1:$port/metrics
@@ -129,13 +129,13 @@ archive_test() {
 
 get_ports() {
   while true; do
-PORT1=`expr '(' $RANDOM % 100 ')' + $base`
+PORT1=`expr '(' $RANDOM % 50 ')' + $base`
 ss -atn | fgrep ":$PORT1" || break
   done
 # Some tests will use two servers, so assign the second var
   while true; do
-PORT2=`expr '(' $RANDOM % 100 ')' + $base`
-ss -atn | fgrep ":$PORT2" && $PORT1 -ne $PORT2 || break
+PORT2=`expr '(' $RANDOM % 50 ')' + $base + 50`
+ss -atn | fgrep ":$PORT2" || break
   done
 
 }
-- 
2.32.0



Buildbot failure in Wildebeest Builder on whole buildset

2021-09-06 Thread buildbot
The Buildbot has detected a new failure on builder elfutils-fedora-x86_64 while 
building elfutils.
Full details are available at:
https://builder.wildebeest.org/buildbot/#builders/3/builds/814

Buildbot URL: https://builder.wildebeest.org/buildbot/

Worker for this Build: fedora-x86_64

Build Reason: 
Blamelist: Mark Wielaard 

BUILD FAILED: failed test (failure)

Sincerely,
 -The BuildbotThe Buildbot has detected a new failure on builder 
elfutils-debian-i386 while building elfutils.
Full details are available at:
https://builder.wildebeest.org/buildbot/#builders/4/builds/810

Buildbot URL: https://builder.wildebeest.org/buildbot/

Worker for this Build: debian-i386

Build Reason: 
Blamelist: Mark Wielaard 

BUILD FAILED: failed test (failure)

Sincerely,
 -The BuildbotThe Buildbot has detected a new failure on builder 
elfutils-fedora-ppc64 while building elfutils.
Full details are available at:
https://builder.wildebeest.org/buildbot/#builders/12/builds/763

Buildbot URL: https://builder.wildebeest.org/buildbot/

Worker for this Build: fedora-ppc64

Build Reason: 
Blamelist: Mark Wielaard 

BUILD FAILED: failed test (failure)

Sincerely,
 -The Buildbot



[COMMITTED] tests: Only export DEBUGINFOD_URLS when necessary

2021-09-06 Thread Mark Wielaard
A couple of test set DEBUGINFOD_URLS before starting a debuginfd
server causing the server to query itself or a nonexisting debuginfod
server as delegate. In most cases it should be set after, except for
the testcase that explicitly checks for errors when using an invalid
URL.

Signed-off-by: Mark Wielaard 
---
 tests/ChangeLog| 10 ++
 tests/run-debuginfod-archive-groom.sh  |  3 ++-
 tests/run-debuginfod-archive-rename.sh |  3 ++-
 tests/run-debuginfod-federation-link.sh|  1 -
 tests/run-debuginfod-federation-metrics.sh |  2 +-
 tests/run-debuginfod-federation-sqlite.sh  |  1 -
 6 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 14eb4d98..436a1c45 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,13 @@
+2021-09-06  Mark Wielaard  
+
+   * run-debuginfod-archive-groom.sh: Set DEBUGINFOD_URLS after starting
+   debuginfod server.
+   * run-debuginfod-archive-rename.sh: Likewise.
+   * run-debuginfod-federation-link.sh: Don't set DEBUGINFOD_URLS.
+   * run-debuginfod-federation-sqlite.sh: Likewise.
+   * run-debuginfod-federation-metrics.sh: Add comment why invalid
+   DEBUGINFOD_URLS is set.
+
 2021-09-06  Mark Wielaard  
 
* debuginfod-subr.sh (err): Change ports to port in for loop so both
diff --git a/tests/run-debuginfod-archive-groom.sh 
b/tests/run-debuginfod-archive-groom.sh
index 4b991f53..1e616448 100755
--- a/tests/run-debuginfod-archive-groom.sh
+++ b/tests/run-debuginfod-archive-groom.sh
@@ -29,7 +29,6 @@ DB=${PWD}/.debuginfod_tmp.sqlite
 tempfiles $DB
 export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
 export DEBUGINFOD_TIMEOUT=10
-export DEBUGINFOD_URLS='http://127.0.0.1:'$PORT1
 
 # Clean old dirictories
 mkdir R ${PWD}/F
@@ -112,6 +111,8 @@ rm -rf extracted
 
 wait_ready $PORT1 'found_sourcerefs_total{source=".rpm archive"}' $sourcefiles
 
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
+
 # common source file sha1
 SHA=f4a1a8062be998ae93b8f1cd744a398c6de6dbb1
 # fedora31
diff --git a/tests/run-debuginfod-archive-rename.sh 
b/tests/run-debuginfod-archive-rename.sh
index 38697eee..7ad4786e 100755
--- a/tests/run-debuginfod-archive-rename.sh
+++ b/tests/run-debuginfod-archive-rename.sh
@@ -28,7 +28,6 @@ get_ports
 DB=${PWD}/.debuginfod_tmp.sqlite
 export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
 export DEBUGINFOD_TIMEOUT=10
-export DEBUGINFOD_URLS='http://127.0.0.1:'$PORT1
 tempfiles $DEBUGINFOD_CACHE_PATH $DB
 # Clean old dirictories
 mkdir R ${PWD}/F
@@ -84,6 +83,8 @@ wait_ready $PORT1 'thread_work_total{role="traverse"}' 4
 wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
 wait_ready $PORT1 'thread_busy{role="scan"}' 0
 
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
+
 # retest rhel7
 archive_test bc1febfd03ca05e030f0d205f7659db29f8a4b30 
/usr/src/debug/hello-1.0/hello.c $SHA
 archive_test f0aa15b8aba4f3c28cac3c2a73801fefa644a9f2 
/usr/src/debug/hello-1.0/hello.c $SHA
diff --git a/tests/run-debuginfod-federation-link.sh 
b/tests/run-debuginfod-federation-link.sh
index ae5d4381..42b8f101 100755
--- a/tests/run-debuginfod-federation-link.sh
+++ b/tests/run-debuginfod-federation-link.sh
@@ -25,7 +25,6 @@ unset VALGRIND_CMD
 DB=${PWD}/.debuginfod_tmp.sqlite
 export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
 export DEBUGINFOD_TIMEOUT=10
-export DEBUGINFOD_URLS='http://127.0.0.1:'$PORT1
 tempfiles $DB
 
 # Clean old dirictories
diff --git a/tests/run-debuginfod-federation-metrics.sh 
b/tests/run-debuginfod-federation-metrics.sh
index 9998a04a..2e7550a6 100755
--- a/tests/run-debuginfod-federation-metrics.sh
+++ b/tests/run-debuginfod-federation-metrics.sh
@@ -25,7 +25,7 @@ unset VALGRIND_CMD
 DB=${PWD}/.debuginfod_tmp.sqlite
 export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
 export DEBUGINFOD_TIMEOUT=10
-export DEBUGINFOD_URLS='http://127.0.0.1:0' # Note invalid
+export DEBUGINFOD_URLS='http://127.0.0.1:0' # Note invalid, will trigger 
error_count metric
 tempfiles $DB
 # Clean old dirictories
 mkdir D L F
diff --git a/tests/run-debuginfod-federation-sqlite.sh 
b/tests/run-debuginfod-federation-sqlite.sh
index d10a3385..a323b98e 100755
--- a/tests/run-debuginfod-federation-sqlite.sh
+++ b/tests/run-debuginfod-federation-sqlite.sh
@@ -25,7 +25,6 @@ unset VALGRIND_CMD
 DB=${PWD}/.debuginfod_tmp.sqlite
 export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
 export DEBUGINFOD_TIMEOUT=10
-export DEBUGINFOD_URLS='http://127.0.0.1:0' # Note invalid
 tempfiles $DB
 
 # Clean old dirictories
-- 
2.32.0



Re: Buildbot failure in Wildebeest Builder on whole buildset

2021-09-06 Thread Mark Wielaard
Hi,

On Mon, Sep 06, 2021 at 10:02:11PM +0200, Mark Wielaard wrote:
> Still looking for explanations of the other FAILS (which I cannot
> reproduce locally).

I think I finally got it. The thing that all the tests that are
(sometimes) failing have in commen is that they use SIGUSR1 or SIGUSR2
to trigger a new scan or groom cycle. But they don't check whether the
initial scan or groom cycle has finished. So the attached patch
explicitly does that before the first SIGUSR1 or SIGUSR2 is fired at
the debuginfod server.

Pushed,

Mark

>From dbd4c8766ea80cb0b6294a6755a556017215eb99 Mon Sep 17 00:00:00 2001
From: Mark Wielaard 
Date: Tue, 7 Sep 2021 01:50:51 +0200
Subject: [PATCH] tests: Make sure to wait for initial scan and groom cycle

At startup the debuginfod server does a scan and groom cycle. Make
sure to wait for that before triggering a new one with SIGUSR1 or
SIGURST2.

Signed-off-by: Mark Wielaard 
---
 tests/ChangeLog| 17 +
 tests/run-debuginfod-archive-groom.sh  | 13 +
 tests/run-debuginfod-archive-rename.sh | 12 
 tests/run-debuginfod-archive-test.sh   |  4 +++-
 tests/run-debuginfod-artifact-running.sh   |  8 +---
 tests/run-debuginfod-dlopen.sh |  6 +-
 tests/run-debuginfod-extraction.sh |  6 --
 tests/run-debuginfod-federation-link.sh|  9 +++--
 tests/run-debuginfod-federation-metrics.sh |  2 +-
 tests/run-debuginfod-federation-sqlite.sh  | 10 +++---
 tests/run-debuginfod-malformed.sh  |  5 -
 tests/run-debuginfod-regex.sh  |  7 +--
 tests/run-debuginfod-tmp-home.sh   |  5 -
 tests/run-debuginfod-writable.sh   |  5 -
 14 files changed, 83 insertions(+), 26 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 436a1c45..61080c52 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,20 @@
+2021-09-06  Mark Wielaard  
+
+	* run-debuginfod-archive-groom.sh: Wait for initial scan and groom
+	cycle.
+	* run-debuginfod-archive-rename.sh: Likewise.
+	* run-debuginfod-federation-sqlite.sh: Likewise.
+	* run-debuginfod-archive-test.sh: Wait for initial scan cycle.
+	* run-debuginfod-artifact-running.sh: Likewise.
+	* run-debuginfod-dlopen.sh: Likewise.
+	* run-debuginfod-extraction.sh: Likewise.
+	* run-debuginfod-federation-link.sh: Likewise.
+	* run-debuginfod-federation-metrics.sh: Likewise.
+	* run-debuginfod-malformed.sh: Likewise.
+	* run-debuginfod-regex.sh: Likewise.
+	* run-debuginfod-tmp-home.sh: Likewise.
+	* run-debuginfod-writable.sh: Likewise.
+
 2021-09-06  Mark Wielaard  
 
 	* run-debuginfod-archive-groom.sh: Set DEBUGINFOD_URLS after starting
diff --git a/tests/run-debuginfod-archive-groom.sh b/tests/run-debuginfod-archive-groom.sh
index 1e616448..1e7bd67a 100755
--- a/tests/run-debuginfod-archive-groom.sh
+++ b/tests/run-debuginfod-archive-groom.sh
@@ -57,9 +57,12 @@ cp -rvp ${abs_srcdir}/debuginfod-rpms R
 if [ "$zstd" = "false" ]; then  # nuke the zstd fedora 31 ones
 rm -vrf R/debuginfod-rpms/fedora31
 fi
+
+# wait till the initial scan is done before triggering a new one
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
 kill -USR1 $PID1
 # Now there should be 1 files in the index
-wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
 wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
 wait_ready $PORT1 'thread_busy{role="scan"}' 0
 
@@ -72,7 +75,7 @@ tempfiles vlog3
 cp -rvp ${abs_srcdir}/debuginfod-tars Z
 kill -USR1 $PID1
 # Wait till both files are in the index and scan/index fully finished
-wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
 wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
 wait_ready $PORT1 'thread_busy{role="scan"}' 0
 
@@ -83,7 +86,7 @@ txz=$(find Z -name \*tar.xz | wc -l)
 
 kill -USR1 $PID1  # two hits of SIGUSR1 may be needed to resolve .debug->dwz->srefs
 # Wait till both files are in the index and scan/index fully finished
-wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 4
 wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
 wait_ready $PORT1 'thread_busy{role="scan"}' 0
 
@@ -136,9 +139,11 @@ RPM_BUILDID=d44d42cbd7d915bc938c81333a21e355a6022fb7 # in rhel6/ subdir
 # Drop some of the artifacts, run a groom cycle; confirm that
 # debuginfod has forgotten them, but remembers others
 rm -r R/debuginfod-rpms/rhel6/*
+
+wait_ready $PORT1 'thread_work_total{role="groom"}' 1
 kill -USR2 $PID1  # groom cycle
 ## 1 groom cycle already took place at/soon-after startup, so -USR2 makes 2
-wait_ready $PORT1 'thread_work_total{role="groom"}' 1
+wait_ready $PORT1 'thread_work_total{role="groom"}' 2
 # Expect 4 rpms containing 2 buildids to be deleted by the groom
 wait_ready $PORT1 'groomed_

Buildbot failure in Wildebeest Builder on whole buildset

2021-09-06 Thread buildbot
The Buildbot has detected a new failure on builder elfutils-debian-armhf while 
building elfutils.
Full details are available at:
https://builder.wildebeest.org/buildbot/#builders/15/builds/607

Buildbot URL: https://builder.wildebeest.org/buildbot/

Worker for this Build: debian-armhf

Build Reason: 
Blamelist: Mark Wielaard 

BUILD FAILED: failed test (failure)

Sincerely,
 -The Buildbot



Buildbot failure in Wildebeest Builder on whole buildset

2021-09-06 Thread buildbot
The Buildbot has detected a new failure on builder elfutils-debian-i386 while 
building elfutils.
Full details are available at:
https://builder.wildebeest.org/buildbot/#builders/4/builds/813

Buildbot URL: https://builder.wildebeest.org/buildbot/

Worker for this Build: debian-i386

Build Reason: 
Blamelist: Mark Wielaard 

BUILD FAILED: failed test (failure)

Sincerely,
 -The Buildbot