OpenVPN
mock_msg.c
Go to the documentation of this file.
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-2021 Fox Crypto B.V. <openvpn@foxcrypto.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 
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27 
28 #include <stdarg.h>
29 #include <stddef.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <setjmp.h>
33 #include <stdint.h>
34 #include <cmocka.h>
35 
36 
37 #include "errlevel.h"
38 #include "error.h"
39 
40 unsigned int x_debug_level = 0; /* Default to (almost) no debugging output */
41 bool fatal_error_triggered = false;
42 
43 void
45 {
46  x_debug_level = level;
47 }
48 
49 int
51 {
52  return x_debug_level;
53 }
54 
55 void
56 x_msg_va(const unsigned int flags, const char *format,
57  va_list arglist)
58 {
59  if (flags & M_FATAL)
60  {
61  fatal_error_triggered = true;
62  printf("FATAL ERROR:");
63  }
64  vprintf(format, arglist);
65  printf("\n");
66 }
67 
68 void
69 x_msg(const unsigned int flags, const char *format, ...)
70 {
71  va_list arglist;
72  va_start(arglist, format);
73  x_msg_va(flags, format, arglist);
74  va_end(arglist);
75 }
76 
77 void
78 assert_failed(const char *filename, int line, const char *condition)
79 {
80  mock_assert(false, condition ? condition : "", filename, line);
81  /* Keep compiler happy. Should not happen, mock_assert() does not return */
82  exit(1);
83 }
84 
85 /*
86  * Fail memory allocation. Don't use msg() because it tries
87  * to allocate memory as part of its operation.
88  */
89 void
91 {
92  fprintf(stderr, "Out of Memory\n");
93  exit(1);
94 }
95 
96 bool
97 dont_mute(unsigned int flags)
98 {
99  return true;
100 }
out_of_memory
void out_of_memory(void)
Definition: mock_msg.c:90
x_msg_va
void x_msg_va(const unsigned int flags, const char *format, va_list arglist)
Definition: mock_msg.c:56
M_FATAL
#define M_FATAL
Definition: error.h:95
fatal_error_triggered
bool fatal_error_triggered
Definition: mock_msg.c:41
errlevel.h
dont_mute
bool dont_mute(unsigned int flags)
Check muting filter.
Definition: mock_msg.c:97
x_debug_level
unsigned int x_debug_level
Definition: mock_msg.c:40
x_msg
void x_msg(const unsigned int flags, const char *format,...)
Definition: mock_msg.c:69
assert_failed
void assert_failed(const char *filename, int line, const char *condition)
Definition: mock_msg.c:78
get_debug_level
int get_debug_level(void)
Definition: mock_msg.c:50
config.h
mock_set_debug_level
void mock_set_debug_level(int level)
Mock debug level defaults to 0, which gives clean(-ish) test reports.
Definition: mock_msg.c:44