Blame elf/tst-create_format1.c

Packit Bot 63bee4
/* Check _dl_exception_create_format.
Packit Bot 63bee4
   Copyright (C) 2018 Free Software Foundation, Inc.
Packit Bot 63bee4
   This file is part of the GNU C Library.
Packit Bot 63bee4
Packit Bot 63bee4
   The GNU C Library is free software; you can redistribute it and/or
Packit Bot 63bee4
   modify it under the terms of the GNU Lesser General Public
Packit Bot 63bee4
   License as published by the Free Software Foundation; either
Packit Bot 63bee4
   version 2.1 of the License, or (at your option) any later version.
Packit Bot 63bee4
Packit Bot 63bee4
   The GNU C Library is distributed in the hope that it will be useful,
Packit Bot 63bee4
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot 63bee4
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Bot 63bee4
   Lesser General Public License for more details.
Packit Bot 63bee4
Packit Bot 63bee4
   You should have received a copy of the GNU Lesser General Public
Packit Bot 63bee4
   License along with the GNU C Library; if not, see
Packit Bot 63bee4
   <http://www.gnu.org/licenses/>.  */
Packit Bot 63bee4
Packit Bot 63bee4
#include <ldsodefs.h>
Packit Bot 63bee4
#include <array_length.h>
Packit Bot 63bee4
Packit Bot 63bee4
#include <support/check.h>
Packit Bot 63bee4
#include <support/xunistd.h>
Packit Bot 63bee4
#include <support/capture_subprocess.h>
Packit Bot 63bee4
Packit Bot 63bee4
#define TEST(es, objn, fmt, ...)					\
Packit Bot 63bee4
  ({									\
Packit Bot 63bee4
     struct dl_exception exception;					\
Packit Bot 63bee4
     _dl_exception_create_format (&exception, objn, fmt, __VA_ARGS__);	\
Packit Bot 63bee4
     TEST_COMPARE_STRING (exception.objname, objn == NULL ? "" : objn);	\
Packit Bot 63bee4
     TEST_COMPARE_STRING (exception.errstring, es);			\
Packit Bot 63bee4
     _dl_exception_free (&exception);					\
Packit Bot 63bee4
   })
Packit Bot 63bee4
Packit Bot 63bee4
static void
Packit Bot 63bee4
do_test_invalid_conversion (void *closure)
Packit Bot 63bee4
{
Packit Bot 63bee4
  TEST ("(null)", NULL, "%p", NULL);
Packit Bot 63bee4
}
Packit Bot 63bee4
Packit Bot 63bee4
/* Exit status after abnormal termination.  */
Packit Bot 63bee4
static int invalid_status;
Packit Bot 63bee4
Packit Bot 63bee4
static void
Packit Bot 63bee4
init_invalid_status (void)
Packit Bot 63bee4
{
Packit Bot 63bee4
  pid_t pid = xfork ();
Packit Bot 63bee4
  if (pid == 0)
Packit Bot 63bee4
    _exit (127);
Packit Bot 63bee4
  xwaitpid (pid, &invalid_status, 0);
Packit Bot 63bee4
  if (WIFEXITED (invalid_status))
Packit Bot 63bee4
    invalid_status = WEXITSTATUS (invalid_status);
Packit Bot 63bee4
}
Packit Bot 63bee4
Packit Bot 63bee4
static int
Packit Bot 63bee4
do_test (void)
Packit Bot 63bee4
{
Packit Bot 63bee4
  init_invalid_status ();
Packit Bot 63bee4
Packit Bot 63bee4
  TEST ("test",      NULL,   "%s",      "test");
Packit Bot 63bee4
  TEST ("test-test", NULL,   "%s-test", "test");
Packit Bot 63bee4
  TEST ("test",      "test", "%s",      "test");
Packit Bot 63bee4
  TEST ("test-test", "test", "%s-test", "test");
Packit Bot 63bee4
Packit Bot 63bee4
  TEST ("test%",      NULL,   "%s%%",      "test");
Packit Bot 63bee4
  TEST ("test%-test", NULL,   "%s%%-test", "test");
Packit Bot 63bee4
  TEST ("test%",      "test", "%s%%",      "test");
Packit Bot 63bee4
  TEST ("test%-test", "test", "%s%%-test", "test");
Packit Bot 63bee4
Packit Bot 63bee4
  TEST ("0000007b",      NULL,   "%x",      123);
Packit Bot 63bee4
  TEST ("0000007b-test", NULL,   "%x-test", 123);
Packit Bot 63bee4
  TEST ("0000007b",      "test", "%x",      123);
Packit Bot 63bee4
  TEST ("0000007b-test", "test", "%x-test", 123);
Packit Bot 63bee4
Packit Bot 63bee4
#define TEST_LONG(es, objn, fmt, ...)				\
Packit Bot 63bee4
  ({								\
Packit Bot 63bee4
     if (sizeof (int) == sizeof (long int))			\
Packit Bot 63bee4
       TEST (es, objn, fmt, __VA_ARGS__);			\
Packit Bot 63bee4
     else							\
Packit Bot 63bee4
       TEST ("ffffffff" es, objn, fmt, __VA_ARGS__);		\
Packit Bot 63bee4
   })
Packit Bot 63bee4
Packit Bot 63bee4
  TEST_LONG ("fffffffd",      NULL,   "%lx",      (long int)~2ul);
Packit Bot 63bee4
  TEST_LONG ("fffffffd-test", NULL,   "%lx-test", (long int)~2ul);
Packit Bot 63bee4
  TEST_LONG ("fffffffd",      "test", "%lx",      (long int)~2ul);
Packit Bot 63bee4
  TEST_LONG ("fffffffd-test", "test", "%lx-test", (long int)~2ul);
Packit Bot 63bee4
Packit Bot 63bee4
  TEST_LONG ("fffffffe",      NULL,   "%zx",      (size_t)~1ul);
Packit Bot 63bee4
  TEST_LONG ("fffffffe-test", NULL,   "%zx-test", (size_t)~1ul);
Packit Bot 63bee4
  TEST_LONG ("fffffffe",      "test", "%zx",      (size_t)~1ul);
Packit Bot 63bee4
  TEST_LONG ("fffffffe-test", "test", "%zx-test", (size_t)~1ul);
Packit Bot 63bee4
Packit Bot 63bee4
  struct support_capture_subprocess result;
Packit Bot 63bee4
  result = support_capture_subprocess (do_test_invalid_conversion, NULL);
Packit Bot 63bee4
  support_capture_subprocess_check (&result, "dl-exception",
Packit Bot 63bee4
				    invalid_status, sc_allow_stderr);
Packit Bot 63bee4
  TEST_COMPARE_STRING (result.err.buffer,
Packit Bot 63bee4
		       "Fatal error: invalid format in exception string\n");
Packit Bot 63bee4
Packit Bot 63bee4
  return 0;
Packit Bot 63bee4
}
Packit Bot 63bee4
Packit Bot 63bee4
#include <support/test-driver.c>