aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2024-02-12treewide: Use bool intead of int wherever possibleHEADmasterJakub Czapiga55-158/+210
Use boolean type instead of integer to return logical values. This ensures correct values handling and reduction in confusion for developers. TEST=mkdir obj ; ( cd obj && cmake --DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DPICKY_DEVELOPER=ON DUNIT_TESTING=ON .. && make -j \ && ctest --output-on-failure ) Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2024-02-12Add initial CONTRIBUTING.mdAndreas Schneider1-0/+399
2024-02-06clang-format: Update to reflect coding styleAndreas Schneider1-14/+22
2024-02-05cmocka: Implement better memory_equal_display_error()Andreas Schneider1-22/+122
Reviewed-by: Joseph Sutton <jsutton@samba.org>
2024-02-05cmocka: Use bool and uint8_t for memory_equal_display_error()Andreas Schneider1-8/+9
Reviewed-by: Joseph Sutton <jsutton@samba.org>
2024-02-05cmocka: Add all_zero() function and testAndreas Schneider3-0/+57
Reviewed-by: Joseph Sutton <jsutton@samba.org>
2024-02-05tests: Add tests for assert_memory_equal()Andreas Schneider3-0/+105
Reviewed-by: Joseph Sutton <jsutton@samba.org>
2024-02-04cmocka: Fix assert_memory_equal() displayJoseph Sutton1-3/+3
The %x specifier expects an unsigned argument. If char is signed, cmocka_print_error() may incorrectly display values sign-extended. To fix this, use an unsigned char and the corresponding format specifier (%hhx). Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2024-02-03Sanitize XML strings.Jakub Czapiga3-5/+26
Replace characters with their XML string equivalents to allow for them in the tests and groups names. Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2024-02-03Improve c_strreplace implementationJakub Czapiga3-9/+147
Return successfuly if there is nothing to replace. Allow for replacement with superset pattern. Simplified example without fix: c_strreplace("ABCD", "A", "AX") -> "AAAAAA...AAAXBCD" Simplified example with fix: c_strreplace("ABCD", "A", "AX") -> "AXBCD" Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2024-02-02cmocka: Get rid of _expect_in_set()Andreas Schneider2-23/+8
2024-02-02tests: Add test for expect_uint_in_set_count()Andreas Schneider1-1/+17
2024-02-02cmocka: Implement expect_uint_in_set()Andreas Schneider1-0/+21
2024-02-02cmocka: Add expect_uint_in_set_count()Andreas Schneider1-0/+31
2024-02-02cmocka: Implement __expect_uint_in_set()Andreas Schneider2-0/+68
2024-02-02cmocka: Implement expect_int_in_set_count()Andreas Schneider2-16/+37
2024-02-02tests: Add test for expect_int_in_set_count()Andreas Schneider2-0/+34
2024-02-02cmocka: Add expect_int_in_set_count()Andreas Schneider1-0/+31
2024-02-02cmocka: Implement _expect_int_in_set()Andreas Schneider2-0/+67
2024-02-02cmocka: Add missing null check in _expect_check()Andreas Schneider1-0/+1
2024-02-02cmocka: Use uint_value_in_set_display_error() in _assert_not_in_set()Andreas Schneider1-4/+8
2024-02-02cmocka: Reformat expect_check_count() defineAndreas Schneider1-3/+13
2024-02-02cmocka: Reformat expect_check()Andreas Schneider1-2/+8
2024-02-02test: Add a uint64_t test for will_return_uint/mock_uintAndreas Schneider1-0/+19
See #93
2024-01-05Add unit tests for assert_false()Eshan Kelkar3-0/+70
Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2024-01-05Add unit tests for assert_true()Eshan Kelkar3-0/+70
Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2024-01-05Make assert_true(), assert_false() more verboseEshan Kelkar2-3/+16
Both assert_true(expression) and assert_false(expression) print the expression when the assertion fails. Its not very clear on seeing the expression that what exactly is the error, whether its the expression being true or it being false. This commit changes the assert_true() and assert_false() such that on failure of assertion: - assert_true(expression) prints : expression is not true - assert_false(expression) prints : expression is not false Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-08-01include: Remove old MVSC prototypeAndreas Schneider1-6/+0
We do not support such old versions anymore.
2023-08-01include: avoid GCC -Wuninitialized in assert_ptr*Alois Klink2-0/+26
In some cases, using the `assert_ptr_*()` macros causes GCC to throw a `-Wmaybe-unitialized` warning. For example: ```c void * my_ptr = malloc(1); // throws a `-Wmaybe-unitialized` warning assert_non_null(my_ptr); ``` This is because GCC assumes that a function accepting a `const void *` (or other constant pointer type) tries to read the pointer value. See [the `-Wmaybe-unitialized` docs][1]. We can tell GCC that the `_assert_ptr_equal`/`_assert_ptr_not_equal` functions only try to read the pointer address, not the pointer value, by using the [`access` function attribute][2]. Since CMocka supports C99, we can't use the ISO C23 attribute syntax. However, we can use the IBM/GCC/Clang `__attribute__` syntax hidden behind `#ifdef` guards, so that they're ignored on compilers that don't support `__attribute__`. [1]: https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Warning-Options.html#Warning-Options [2]: https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Common-Function-Attributes.html#Common-Function-Attributes on-behalf-of: @nqminds <info@nqminds.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-08-01update meson testswdlkmpx1-2/+14
33 tests: 21 ok, 12 expected fail, 0 fail, 0 skipped Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-08-01meson.build: install library if not a subprojectwdlkmpx1-1/+6
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-08-01cmake: enable WINDOWS_EXPORT_ALL_SYMBOLSAlois Klink2-69/+2
Enable the [`WINDOWS_EXPORT_ALL_SYMBOLS` CMake property][1], which automatically exports all symbols into the `.dll` file. This feature is available since [CMake 3.4][2], which is fine, since the minimum version of CMake CMocka supports is CMake 3.5. It is a bit slower, but it does mean that we no longer need to manually create a `.def` file, as CMake will automatically create one for us. [1]: https://cmake.org/cmake/help/latest/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS.html [2]: https://www.kitware.com//create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/ Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-08-01include: add CMOCKA_DLLEXTERN for MSVC DLLsAlois Klink3-8/+35
Add a new macro called `CMOCKA_DLLEXTERN` that represents Windows DLL storage class specifiers. Essentially, in order to publically export some data in a DLL, you must either declare the function/data with `__declspec(dllexport)`, or list the function/data in a `.def` file (which is what the CMocka project does). In order to import functions from a DLL, `__declspec(dllimport)` may be used for a performance increase. However, **`__declspec(dllimport)` is required for importing data from a DLL**! The new `CMOCKA_DLLEXTERN` macro takes care of this for us, when we're using MSVC. See https://github.com/MicrosoftDocs/cpp-docs/blob/main/docs/cpp/definitions-and-declarations-cpp.md Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-05-0789 add deprecated cm_print_errorAlexander Courtis1-0/+10
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-03-23Allow macros as input for convenience macrosThomas Bong1-19/+22
Nested macros like the cmocka macros that make use of # or ## are not expanded. The `cmocka_tostring` macro makes sure that you can use for example macros redefining symbols like functions. When using cmocka on embedded devices, it may happen that the original function is necessary for it to boot correctly as well as a mocked version for unittests with a prefix `unittest_`. To simplify this, the compiler can be given definitions via the `-D` argument. These replacements are now also possible for the invocations of the cmocka convenience macros like "will_return", "expect_value", ... Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-03-23cmocka: Add overflow check for test_calloc()Alexander Dahl1-1/+10
Makes the implementation behave the same like libc calloc() and not fail with unpredictable errors in test_malloc() anymore. Signed-off-by: Alexander Dahl <ada@thorsis.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-03-23tests: Add test for test_calloc()Alexander Dahl1-0/+20
calloc() is prone to integer overflow on multiplication of its arguments. glibc, musl, and uclibc test for that in its implementations and return NULL in that case with errno set to ENOMEM. cmocka lacks such a check and passes all kinds of overflown values to test_malloc() with different ways to fail. Signed-off-by: Alexander Dahl <ada@thorsis.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-03-22gitlab-ci: Add code coverageAndreas Schneider1-0/+24
2023-03-22gitlab-ci: Do not install CMakeAndreas Schneider1-2/+0
This has been added to windows runners by default now.
2023-03-22cmake: Set CMOCKA_LIBRARIES in package config for backwards compatibilityAlexander Dahl3-3/+21
Projects using cmocka could have done this successfully from version 1.0 to 1.1.5 to build against cmocka: ``` find_package(cmocka 1.0 REQUIRED CONFIG) ``` and later ``` target_link_libraries(myapp ${CMOCKA_LIBRARIES} ) ``` Modern apps should just "link" against 'cmocka::cmocka' instead like it's done in examples already. To not break old builds (as it is the case with cmocka release 1.1.7) we can put that modern target string into the variable CMOCKA_LIBRARIES and thus trick old projects to just use that, keeping compatibility until those projects explicitly use the modern version. Link: https://cmake.org/cmake/help/latest/command/install.html#install-export Link: https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#package-configuration-file Link: https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html#module:CMakePackageConfigHelpers Fixes: #87 Signed-off-by: Alexander Dahl <ada@thorsis.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-02-19cpack: Update ignore files for source package generationAndreas Schneider1-1/+5
Fixes #86
2023-02-03coverity: Add missing functions to model fileAndreas Schneider1-3/+47
2023-02-03gitlab-ci: Build also the coverity model filesAndreas Schneider1-0/+1
2023-02-03coverity: Add makefile to build/test the model filesAndreas Schneider3-1/+60
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