summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2023-02-02coverity: Add URL to modelling descriptionAndreas Schneider1-0/+2
2023-02-02coverity: Add missing type definitionsAndreas Schneider1-0/+22
2023-02-01cmake: Add more compiler warningsAndreas Schneider1-0/+7
See https://fedoraproject.org/wiki/Changes/PortingToModernC
2023-02-01cmake: Use C99 and define GNU and POSIX flags directly at source filesAndreas Schneider4-4/+20
Fixes #50
2023-02-01example: Fix pos value as snprintf returns an intAndreas Schneider1-1/+1
2023-02-01include: Improve expect_check() documentationAndreas Schneider1-14/+11
2023-02-01tests: Mark state in some tests as unusedAndreas Schneider1-0/+8
2023-02-01tests: Make test_expect_check more robustAndreas Schneider1-5/+11
2023-01-29Improve INSTALL.mdAndreas Schneider2-12/+30
Fixes #63
2023-01-29doc: Link to the examples for mockingAndreas Schneider1-1/+1
Fixes #65
2023-01-29include: Improve documentationAndreas Schneider1-23/+24
Fixes #79
2023-01-29tests: Add tests for will_return/mock with ptr and type saftey checkingAndreas Schneider3-10/+59
2023-01-29cmocka: Add some kind of type safety for will_return and mockAndreas Schneider3-32/+130
Fixes #75
2023-01-29tests: Add tests for new will_return and mock macrosAndreas Schneider1-4/+51
2023-01-29include: Add specific will_return and mock macros for different typesAndreas Schneider1-0/+166
2023-01-29include: Add assign_(int|uint|double|ptr)_to_cmocka_value() macrosAndreas Schneider1-0/+21
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-29include: Move values in CMockaValueData union aroundAndreas Schneider1-4/+4
2023-01-29test: Test assert_ptr_equal and _not_equal macrosAlois Klink3-0/+104
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-29include: Remove cast_to_uintptr_type macroAlois Klink1-4/+0
No longer required, as CMocka now never converts pointers to intergers. BREAKING CHANGE: The cast_to_uintptr_type macro has been removed. Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-29include: Remove cast_ptr_to_uintmax_type macroAlois Klink1-4/+0
No longer required, as CMocka can now store pointers directly in a CMockaValueData without casting pointers to `uintmax_t` (not safe on some platforms). BREAKING CHANGE: The cast_ptr_to_uintmax_type() macro has been removed. Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-29cmocka: Improve pointer assert functionsAlois Klink3-15/+60
Use pointer types for assert_* pointer functions, instead of casting to uintmax_t. On some platforms, casting pointers to uintmax_t loses information. As an additional benefit, we can now use the `%p` specifier to print pointers. On GCC, this will print (nil) for NULL pointers. BREAKING CHANGE: The `assert_{not_,}null` and `assert_ptr_{not_,}equal` functions may now throw `Wint-conversion` warnings when used with non-pointer types. on-behalf-of: @nqminds <info@nqminds.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-29test: Test expect_string and expect_memoryAlois Klink1-2/+61
`expect_string` already had tests in the `example/` folder, but `expect_memory`, `expect_not_memory`, and `expect_not_string` were previously untested. Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-29cmocka: Change `_mock` to return CMockaValueDataAlois Klink3-20/+128
Change the `_mock()` function to return CMockaValueData. Additionally, the `will_return_ptr*` functions now must be used for pointer types (we can't use C11 _Generic since CMocka still uses C99). BREAKING CHANGE: `will_return*` may throw compiler errors/warnings when used with pointers. Please use the new `will_return_ptr*` macros instead. on-behalf-of: @nqminds <info@nqminds.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-29cmocka: Make expect_check to use CMockaValueDataAlois Klink4-76/+75
Change all `expect_check*()` macros to use CMockaValueData internally, instead of `uintmax_t`. This breaks ABI compatibility on some platforms. The API for most macros is the same, but the `expect_check()` and `expect_check_count()` macros now need to be called with the new `CMockaValueData` type. BREAKING CHANGE: `expect_check()` and `expect_check_count()` now use the type CMockaValueData in the check function and check data. on-behalf-of: @nqminds <info@nqminds.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-29include: Add cast_ptr_to_cmocka_value() macroAlois Klink1-0/+7
This macro is used to cast a `void *` pointer to a CMockaValueData. Unlike `cast_ptr_to_uintmax_type()`, this macro uses implicit type casts, so the compiler may warn/error if passing an incompatible type. on-behalf-of: @nqminds <info@nqminds.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-29include: Add cast_int_to_cmocka_value() macroAlois Klink1-0/+13
This macro is used to cast data as an integer to a `CMockaValueData`. For backwards compatibility reasons, this explicitly casts to `uintmax_t`, just like the `cast_to_uintmax_type()` macro. For most compilers, this will supress warnings about passing float/intmax_t to this macro. Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-29include: Add CMockaValueData typedefAlois Klink1-0/+21
Currently, CMocka stores pointers by converting them to uintmax_t via uintptr_t. However, on some platforms this doesn't work (casting pointers to uintptr_t is fine, but not going to uintmax_t). The `CMockaValueData` typedef will be used to allow storing multiple types of value in CMocka functions without using undefined behavior. It is currently defined as: ```c typedef union { /** Holds integral types */ uintmax_t uint_val; /** Holds pointer data */ const void *ptr; // The following aren't used by CMocka currently, but are added to // avoid breaking ABI compatibility in the future /** Holds function pointer data */ void *(*func)(void); /** Holds signed integral types */ intmax_t int_val; /** Holds real/floating-pointing types*/ double real_val; // TODO: Should we use `long double` instead } CMockaValueData; ``` I wanted to add `long double` to this union as well, as even if it's not used now, in would be nice to add now to avoid breaking the ABI in the future (`long double` can be 64-,80-, or 128-bits wide), but GCC prints an ugly warning since GCC 4.4 (from 2009) changed their libc ABI on `long double`s in `union`s. `intmax_t` is added just in case any platform has a smaller `intmax_t` than `uintmax_t` (e.g. maybe one's complement platforms like UNISYS). on-behalf-of: @nqminds <info@nqminds.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-29src: disable casting integers to (void *)Alois Klink1-9/+16
Disable casting integers to and from (void *) in free_symbol_map_value. Instead, we can just use a pointer to an integer. Casting an integer to (void *) is implementation-defined, unless that integer was previously casted from `*intptr_t` from a valid pointer. on-behalf-of: @nqminds <info@nqminds.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-29cmake: disable `-Wdeclaration-after-statement`Alois Klink1-2/+0
Disable `-Wdeclaration-after-statement`. Before ISO C99, declaring variables after statements was not allowed by the C standard, but was allowed by GCC as an extension. CMocka now requires a minimum version of C99, since commit 5a4b15870efa2225e6586fbb4c3af05ff0659434, so this behaviour is valid on all compilers. on-behalf-of: @nqminds <info@nqminds.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-29src: set MALLOC_ALIGNMENT to `16`Alois Klink1-1/+6
Hard-code the default `MALLOC_ALIGNMENT` to `16`. On most non-Windows x86_64 platforms, the default alignment should be 16-bytes, as `long double` is an 80-bit large floating point number. C11 has a built-in that's perfect for this, `alignof(max_align_t)`, but unfortunately, cmocka only supports C99. Unfortunately, we can't use `sizeof(long double)`, because on some platforms, it returns 12, which is not a power of 2. A hard-coded value of 16 may be over-aligned on some platforms, but there's no downside to this, other than using up more RAM than normal. on-behalf-of: @nqminds <info@nqminds.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-25Wrapped test and example build in project testChris Schick1-8/+10
- Checks to see if CMocka is the top project - Does not build tests or examples if consumed as a dependency through FetchContent Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-01-24cmake: Do not use CMAKE_(BINARY|SOURCE)_DIR for compile_commands.jsonAndreas Schneider1-2/+2
This should fix being imported by other projects. Fixes #85
2023-01-09cmocka.c: Reduce the call stack consumption of printfXiang Xiao1-7/+7
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: Idf179ad5eb81bbc63eea4f71980857831668e7a8 Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-12-23src: use __builtin_align_down, if availableAlois Klink2-4/+15
In _test_malloc, we manually align a pointer to MALLOC_ALIGNMENT using `& ~(MALLOC_ALIGNMENT - 1)`. However, this has two problems: 1. We're casting the pointer to `size_t`, which isn't guaranteed to hold a pointer. Instead, we should cast to `uintptr_t`. 2. Modifying a pointer as a integer is undefined behavior, and on some platforms (e.g. CHERI), this does not work. C++11 has std::align that does this for us, but unfortunately, there isn't a way to do this in ISO C that is guaranteed to work, except for in Clang v10+, which has a builtin extension called __builtin_align_down that can align pointers safely for us. See: https://clang.llvm.org/docs/LanguageExtensions.html#alignment-builtins on-behalf-of: @nqminds <info@nqminds.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-12-23build: improve AddCMockaTest `LINK_OPTIONS` docsAlois Klink1-1/+4
The `LINK_OPTIONS` argument for `add_cmocka_test()` doesn't set the `LINK_OPTIONS` CMake property, as it was only added in CMake 3.13. These options are mostly the same, but some options that are valid `LINK_OPTIONS` are not valid `LINK_FLAGS` (e.g using `LINKER:` prefixes) This commit documents that the `LINK_OPTIONS` argument instead is used to set the `LINK_FLAGS` CMake property. Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-12-23cmocka: fix setjmp in expect_assert_failure macroAlois Klink1-2/+1
Assigning the result of `setjmp` to a variable is technically undefined behavior in the C standard. Most platforms allow this (NetBSD even uses this syntax in their tests) and GCC/Clang doesn't even give us a warning. Nonetheless, we should follow the ISO C specification. See [ยง 7.13.1.1.4 of the C99 spec.][1] [1]: https://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf on-behalf-of: @nqminds <info@nqminds.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-12-23src: use value=`1` when calling longjmp()Alois Klink1-1/+1
Currently, `longjmp()` is always called with value=`0`. According to the ISO C standard, calling longjmp with value 0 just acts like it is called with value 1. However, some BSD platforms are buggy, and instead make setjmp return 0 and cause an infinite loop. See [NetBSD PR/56066][1]. Calling `longjmp` with value 1 makes the meaning more clear as well. [1]: https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=56066 on-behalf-of: @nqminds <info@nqminds.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-12-21cmocka: fix `float` in assert_double_not_equalAlois Klink1-1/+1
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-12-01Fixed warning when compiling on Windowsmaxime1-0/+1
warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details.
2022-12-01cmake: Fix path relocation in pkgconfig file for mingwBiswapriyo Nath2-5/+11
This fixes path relocation in mingw environment by using predefined Libs and Cflags variable in pkgconfig file. Otherwise, libdir and includedir are not shown in pkgconf output. e.g. * Without predefined variables: - pkgconf -cflags cmocka: No output - pkgconf -libs cmocka: -lcmocka * With predefined variables: - pkgconf -cflags cmocka: -IC:/msys64/mingw64/include - pkgconf -libs cmocka: -LC:/msys64/mingw64/lib -lcmocka Also official documentation suggests to use predefiend keywords here https://people.freedesktop.org/~dbn/pkg-config-guide.html Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-12-01cmocka: Only handle exceptions on platforms supporting itAndreas Schneider2-16/+30
This also issues a warning during compile time.
2022-11-30cmake: build cmocka with C_EXTENSIONS set to ONAlois Klink1-0/+2
When compiling code with CMake [`C_EXTENSIONS` `OFF`][1], (e.g. using `-std=c11` instead of `-std=gnu11`), only standard ISO C is available in C headers like `<setjmp.h>`. Because cmocka uses POSIX extension functions, we need to set `_POSIX_C_SOURCE` to the appropriate level before including these headers. On gcc/clang, this is enabled by default when C_EXTENSIONS ON. Fixes https://gitlab.com/cmocka/cmocka/-/issues/50, e.g. using cmocka from a project that has C_EXTENSIONS OFF. [1]: https://cmake.org/cmake/help/latest/prop_tgt/C_EXTENSIONS.html Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-11-28coverity: Update for new functionsAndreas Schneider1-9/+77
2022-11-28cmocka: Deprecate assert_in_setAndreas Schneider3-27/+2
2022-11-28tests: Add tests for assert_uint_not_in_set()Andreas Schneider3-1/+32
2022-11-28cmocka: Add assert_uint_not_in_set()Andreas Schneider3-0/+49
2022-11-28tests: Add tests for assert_uint_in_set()Andreas Schneider3-2/+33
2022-11-28cmocka: Add assert_uint_in_set()Andreas Schneider3-0/+95
2022-11-28tests: Add tests for assert_not_int_in_set()Andreas Schneider3-1/+38
2022-11-28cmocka: Add assert_int_not_in_set()Andreas Schneider3-0/+49