mock_msg.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * OpenVPN -- An application to securely tunnel IP networks
  3. * over a single UDP port, with support for SSL/TLS-based
  4. * session authentication and key exchange,
  5. * packet encryption, packet authentication, and
  6. * packet compression.
  7. *
  8. * Copyright (C) 2016-2018 Fox Crypto B.V. <openvpn@fox-it.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. */
  23. #ifdef HAVE_CONFIG_H
  24. #include "config.h"
  25. #elif defined(_MSC_VER)
  26. #include "config-msvc.h"
  27. #endif
  28. #include <stdarg.h>
  29. #include <stddef.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <setjmp.h>
  33. #include <cmocka.h>
  34. #include "errlevel.h"
  35. #include "error.h"
  36. unsigned int x_debug_level = 0; /* Default to (almost) no debugging output */
  37. bool fatal_error_triggered = false;
  38. void
  39. mock_set_debug_level(int level)
  40. {
  41. x_debug_level = level;
  42. }
  43. void
  44. x_msg_va(const unsigned int flags, const char *format,
  45. va_list arglist)
  46. {
  47. if (flags & M_FATAL)
  48. {
  49. fatal_error_triggered = true;
  50. printf("FATAL ERROR:");
  51. }
  52. vprintf(format, arglist);
  53. printf("\n");
  54. }
  55. void
  56. x_msg(const unsigned int flags, const char *format, ...)
  57. {
  58. va_list arglist;
  59. va_start(arglist, format);
  60. x_msg_va(flags, format, arglist);
  61. va_end(arglist);
  62. }
  63. void
  64. assert_failed(const char *filename, int line, const char *condition)
  65. {
  66. mock_assert(false, condition ? condition : "", filename, line);
  67. /* Keep compiler happy. Should not happen, mock_assert() does not return */
  68. exit(1);
  69. }
  70. /*
  71. * Fail memory allocation. Don't use msg() because it tries
  72. * to allocate memory as part of its operation.
  73. */
  74. void
  75. out_of_memory(void)
  76. {
  77. fprintf(stderr, "Out of Memory\n");
  78. exit(1);
  79. }
  80. bool
  81. dont_mute(unsigned int flags)
  82. {
  83. return true;
  84. }