check.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Support code for reporting test results.
  2. Copyright (C) 2016-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <support/check.h>
  16. #include <errno.h>
  17. #include <stdarg.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <support/test-driver.h>
  21. static void
  22. print_failure (const char *file, int line, const char *format, va_list ap)
  23. {
  24. int saved_errno = errno;
  25. printf ("error: %s:%d: ", file, line);
  26. vprintf (format, ap);
  27. puts ("");
  28. errno = saved_errno;
  29. }
  30. int
  31. support_print_failure_impl (const char *file, int line,
  32. const char *format, ...)
  33. {
  34. support_record_failure ();
  35. va_list ap;
  36. va_start (ap, format);
  37. print_failure (file, line, format, ap);
  38. va_end (ap);
  39. return 1;
  40. }
  41. void
  42. support_exit_failure_impl (int status, const char *file, int line,
  43. const char *format, ...)
  44. {
  45. if (status != EXIT_SUCCESS && status != EXIT_UNSUPPORTED)
  46. support_record_failure ();
  47. va_list ap;
  48. va_start (ap, format);
  49. print_failure (file, line, format, ap);
  50. va_end (ap);
  51. exit (status);
  52. }