xref: /aosp_15_r20/external/flashrom/tests/unittest_env.h (revision 0d6140be3aa665ecc836e8907834fcd3e3b018fc)
1*0d6140beSAndroid Build Coastguard Worker /*
2*0d6140beSAndroid Build Coastguard Worker  * This file is part of the flashrom project.
3*0d6140beSAndroid Build Coastguard Worker  *
4*0d6140beSAndroid Build Coastguard Worker  * Copyright 2021 Google LLC
5*0d6140beSAndroid Build Coastguard Worker  *
6*0d6140beSAndroid Build Coastguard Worker  * This program is free software; you can redistribute it and/or modify
7*0d6140beSAndroid Build Coastguard Worker  * it under the terms of the GNU General Public License as published by
8*0d6140beSAndroid Build Coastguard Worker  * the Free Software Foundation; version 2 of the License.
9*0d6140beSAndroid Build Coastguard Worker  *
10*0d6140beSAndroid Build Coastguard Worker  * This program is distributed in the hope that it will be useful,
11*0d6140beSAndroid Build Coastguard Worker  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*0d6140beSAndroid Build Coastguard Worker  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*0d6140beSAndroid Build Coastguard Worker  * GNU General Public License for more details.
14*0d6140beSAndroid Build Coastguard Worker  */
15*0d6140beSAndroid Build Coastguard Worker 
16*0d6140beSAndroid Build Coastguard Worker /*
17*0d6140beSAndroid Build Coastguard Worker  * This header is included in all files when they are built for unit test
18*0d6140beSAndroid Build Coastguard Worker  * environment, for all the files to be covered by dynamic memory allocation
19*0d6140beSAndroid Build Coastguard Worker  * checks (checks for memory leaks, buffer overflows and underflows).
20*0d6140beSAndroid Build Coastguard Worker  *
21*0d6140beSAndroid Build Coastguard Worker  * See flashrom_test_dep in meson.build for more details.
22*0d6140beSAndroid Build Coastguard Worker  *
23*0d6140beSAndroid Build Coastguard Worker  * https://api.cmocka.org/group__cmocka__alloc.html
24*0d6140beSAndroid Build Coastguard Worker  */
25*0d6140beSAndroid Build Coastguard Worker 
26*0d6140beSAndroid Build Coastguard Worker extern void* _test_malloc(const size_t size, const char* file, const int line);
27*0d6140beSAndroid Build Coastguard Worker extern void* _test_realloc(void *ptr, const size_t size, const char* file, const int line);
28*0d6140beSAndroid Build Coastguard Worker extern void* _test_calloc(const size_t number_of_elements, const size_t size,
29*0d6140beSAndroid Build Coastguard Worker                         const char* file, const int line);
30*0d6140beSAndroid Build Coastguard Worker extern void _test_free(void* const ptr, const char* file, const int line);
31*0d6140beSAndroid Build Coastguard Worker 
32*0d6140beSAndroid Build Coastguard Worker #ifdef malloc
33*0d6140beSAndroid Build Coastguard Worker #undef malloc
34*0d6140beSAndroid Build Coastguard Worker #endif
35*0d6140beSAndroid Build Coastguard Worker #ifdef calloc
36*0d6140beSAndroid Build Coastguard Worker #undef calloc
37*0d6140beSAndroid Build Coastguard Worker #endif
38*0d6140beSAndroid Build Coastguard Worker #ifdef realloc
39*0d6140beSAndroid Build Coastguard Worker #undef realloc
40*0d6140beSAndroid Build Coastguard Worker #endif
41*0d6140beSAndroid Build Coastguard Worker #ifdef free
42*0d6140beSAndroid Build Coastguard Worker #undef free
43*0d6140beSAndroid Build Coastguard Worker #endif
44*0d6140beSAndroid Build Coastguard Worker 
45*0d6140beSAndroid Build Coastguard Worker #define malloc(size) _test_malloc(size, __FILE__, __LINE__)
46*0d6140beSAndroid Build Coastguard Worker #define realloc(ptr, size) _test_realloc(ptr, size, __FILE__, __LINE__)
47*0d6140beSAndroid Build Coastguard Worker #define calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__)
48*0d6140beSAndroid Build Coastguard Worker #define free(ptr) _test_free(ptr, __FILE__, __LINE__)
49