Projects
openEuler:Mainline
cmocka
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 5
View file
_service:tar_scm:cmocka.spec
Changed
@@ -1,6 +1,6 @@ Name: cmocka -Version: 1.1.5 -Release: 3 +Version: 1.1.7 +Release: 1 License: ASL 2.0 Summary: An elegant unit testing framework for C with support for mock objects @@ -87,9 +87,12 @@ %{_libdir}/pkgconfig/cmocka.pc %{_libdir}/cmake/cmocka/cmocka-config-version.cmake %{_libdir}/cmake/cmocka/cmocka-config.cmake -%{_libdir}/libcmocka-static.a +%{_libdir}/cmake/cmocka/cmocka-config-noconfig.cmake %changelog +* Wed Jun 21 2023 yaoxin <yao_xin001@hoperun.com> - 1.1.7-1 +- Update to 1.1.7 + * Mon May 31 2021 baizhonggui <baizhonggui@huawei.com> - 1.1.5-3 - Add gcc in BuildRequires
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/.gitlab-ci.yml
Deleted
@@ -1,400 +0,0 @@ -variables: - BUILD_IMAGES_PROJECT: cmocka/gitlab-build-images - FEDORA_BUILD: buildenv-fedora - CENTOS7_BUILD: buildenv-centos7 - TUMBLEWEED_BUILD: buildenv-tumbleweed - MINGW_BUILD: buildenv-mingw - DEBIAN_CROSS_BUILD: buildenv-debian-cross - -centos7/x86_64: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$CENTOS7_BUILD - script: - - mkdir -p obj && cd obj && cmake3 - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DPICKY_DEVELOPER=ON - -DUNIT_TESTING=ON .. && - make -j$(nproc) && ctest --output-on-failure - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -fedora/x86_64: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD - script: - - mkdir -p obj && cd obj && cmake - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DPICKY_DEVELOPER=ON - -DUNIT_TESTING=ON .. && - make -j$(nproc) && ctest --output-on-failure - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -fedora/address-sanitizer: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD - script: - - mkdir -p obj && cd obj && cmake - -DCMAKE_BUILD_TYPE=AddressSanitizer - -DPICKY_DEVELOPER=ON - -DUNIT_TESTING=ON .. && - make -j$(nproc) && ctest --output-on-failure - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -fedora/memory-sanitizer: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD - script: - - mkdir -p obj && cd obj && cmake - -DCMAKE_BUILD_TYPE=MemorySanitizer - -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ - -DUNIT_TESTING=ON .. - && make -j$(nproc) && ctest --output-on-failure - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -fedora/undefined-sanitizer: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD - script: - - mkdir -p obj && cd obj && cmake - -DCMAKE_BUILD_TYPE=UndefinedSanitizer - -DUNIT_TESTING=ON .. - && make -j$(nproc) && ctest --output-on-failure - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -fedora/csbuild: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$FEDORA_BUILD - script: - - | - if -z "$CI_COMMIT_BEFORE_SHA" ; then - export CI_COMMIT_BEFORE_SHA=$(git rev-parse "${CI_COMMIT_SHA}~20") - fi - - # Check if the commit exists in this branch - # This is not the case for a force push - git branch --contains $CI_COMMIT_BEFORE_SHA 2>/dev/null || export CI_COMMIT_BEFORE_SHA=$(git rev-parse "${CI_COMMIT_SHA}~20") - - export CI_COMMIT_RANGE="$CI_COMMIT_BEFORE_SHA..$CI_COMMIT_SHA" - - - csbuild - --build-dir=obj-csbuild - --prep-cmd="cmake -DCMAKE_BUILD_TYPE=Debug -DPICKY_DEVELOPER=ON -DUNIT_TESTING=ON @SRCDIR@" - --build-cmd "make clean && make -j$(nproc)" - --git-commit-range $CI_COMMIT_RANGE - --color - --print-current --print-fixed - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj-csbuild/ - -freebsd/x86_64: - image: - script: - - mkdir -p obj && cd obj && cmake - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DPICKY_DEVELOPER=ON - -DUNIT_TESTING=ON .. && - make && ctest --output-on-failure - tags: - - freebsd - except: - - tags - only: - - branches@cmocka/cmocka - - branches@cryptomilk/cmocka - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -fedora/mingw64: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$MINGW_BUILD - script: - - export WINEPATH=/usr/x86_64-w64-mingw32/sys-root/mingw/bin - - export WINEDEBUG=-all - - mkdir -p obj && cd obj && mingw64-cmake - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DPICKY_DEVELOPER=ON - -DUNIT_TESTING=ON .. && - make -j$(nproc) && - ctest --output-on-failure - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -fedora/mingw32: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$MINGW_BUILD - script: - - export WINEPATH=/usr/i686-w64-mingw32/sys-root/mingw/bin - - export WINEDEBUG=-all - - mkdir -p obj && cd obj && mingw32-cmake - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DPICKY_DEVELOPER=ON - -DWITH_SFTP=ON -DWITH_SERVER=ON -DWITH_ZLIB=ON --DWITH_PCAP=ON - -DUNIT_TESTING=ON .. && - make -j$(nproc) && - ctest --output-on-failure - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -.Debian.cross.template: &Debian_cross_template - stage: test - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$DEBIAN_CROSS_BUILD - script: - - build=$(dpkg-architecture -qDEB_HOST_GNU_TYPE) - - host="${CI_JOB_NAME#*.cross.}" - - mkdir -p obj && cd obj && cmake - -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-Debian-mips.cmake - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DUNIT_TESTING=ON .. && - make -j$(nproc) && - ctest --output-on-failure -j$(nproc) - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -Debian.cross.mips-linux-gnu: - <<: *Debian_cross_template - -tumbleweed/x86_64/gcc: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD - script: - - mkdir -p obj && cd obj && cmake - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DPICKY_DEVELOPER=ON - -DUNIT_TESTING=ON .. && - make -j$(nproc) && ctest --output-on-failure - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -tumbleweed/x86/gcc: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD - script: - - mkdir -p obj && cd obj && cmake - -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-m32.cmake - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DPICKY_DEVELOPER=ON - -DUNIT_TESTING=ON .. && - make -j$(nproc) && ctest --output-on-failure - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -tumbleweed/x86_64/gcc7: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD - script: - - mkdir -p obj && cd obj && cmake - -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7 - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DPICKY_DEVELOPER=ON - -DUNIT_TESTING=ON .. && - make -j$(nproc) && ctest --output-on-failure - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -tumbleweed/x86/gcc7: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD - script: - - mkdir -p obj && cd obj && cmake - -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-m32.cmake - -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7 - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DPICKY_DEVELOPER=ON - -DUNIT_TESTING=ON .. && - make -j$(nproc) && ctest --output-on-failure - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -tumbleweed/x86_64/clang: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD - script: - - mkdir -p obj && cd obj && cmake - -DCMAKE_BUILD_TYPE=RelWithDebInfo - -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ - -DPICKY_DEVELOPER=ON - -DUNIT_TESTING=ON .. && - make -j$(nproc) && ctest --output-on-failure - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -tumbleweed/docs: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD - script: - - mkdir -p obj && cd obj && cmake .. && make docs - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -tumbleweed/static-analysis: - image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD - script: - - export CCC_CC=clang - - export CCC_CXX=clang++ - - mkdir -p obj && cd obj && scan-build cmake - -DCMAKE_BUILD_TYPE=Debug - -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ - -DPICKY_DEVELOPER=ON - -DUNIT_TESTING=ON .. && - scan-build --status-bugs -o scan make -j$(nproc) - tags: - - shared - except: - - tags - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/scan - -visualstudio/x86_64: - script: - - $env:VCPKG_DEFAULT_TRIPLET="x64-windows" - - mkdir obj - - cd obj - - cmake - -A x64 - -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_TOOLCHAIN_FILE" - -DPICKY_DEVELOPER=ON - -DUNIT_TESTING=ON .. - - cmake --build . - - ctest --output-on-failure - tags: - - vs2017 - - windows - except: - - tags - only: - - branches@cmocka/cmocka - - branches@ansasaki/cmocka - - branches@cryptomilk/cmocka - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/ - -visualstudio/x86: - script: - - $env:VCPKG_DEFAULT_TRIPLET="x86-windows" - - mkdir obj - - cd obj - - cmake - -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_TOOLCHAIN_FILE" - -DPICKY_DEVELOPER=ON - -DWITH_SFTP=ON -DWITH_SERVER=ON -DWITH_ZLIB=ON -DWITH_PCAP=ON - -DUNIT_TESTING=ON .. - - cmake --build . - - ctest --output-on-failure - tags: - - vs2017 - - windows - except: - - tags - only: - - branches@cmocka/cmocka - - branches@ansasaki/cmocka - - branches@cryptomilk/cmocka - artifacts: - expire_in: 1 week - when: on_failure - paths: - - obj/
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/5.patch
Deleted
@@ -1,34 +0,0 @@ -From addb1927eb979310a01abc65f29a5408a970da11 Mon Sep 17 00:00:00 2001 -From: Richard Bayerle <richi.bayerle@gmail.com> -Date: Sun, 24 Feb 2019 16:38:05 +0000 -Subject: PATCH XML output is JUnit XML, not xUnit XML. - ---- - doc/mainpage.dox | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/doc/mainpage.dox b/doc/mainpage.dox -index 4c26d96..c378bb1 100644 ---- a/doc/mainpage.dox -+++ b/doc/mainpage.dox -@@ -33,7 +33,7 @@ The CMocka library provides: - - Very well tested - - Testing of memory leaks, buffer overflows and underflows. - - A set of assert macros. -- - Several supported output formats (stdout, TAP, xUnit XML, Subunit) -+ - Several supported output formats (stdout, TAP, JUnit XML, Subunit) - - License: Apache License 2.0 - - @section main-test A cmocka test -@@ -119,7 +119,7 @@ supported values are: - - <tt>STDOUT</tt> for the default standard output printer - - <tt>SUBUNIT</tt> for subunit output - - <tt>TAP</tt> for Test Anything Protocol (TAP) output -- - <tt>XML</tt> for xUnit XML format -+ - <tt>XML</tt> for JUnit XML format - The case doesn't matter. - - The XML output goes to stderr by default. If the environment variable --- -2.18.1 -
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/cmocka-config.cmake.in
Deleted
@@ -1,15 +0,0 @@ -@PACKAGE_INIT@ - -get_filename_component(CMOCKA_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) - -if (EXISTS "${CMOCKA_CMAKE_DIR}/CMakeCache.txt") - # In build tree - include(${CMOCKA_CMAKE_DIR}/cmocka-build-tree-settings.cmake) -else() - set(CMOCKA_INCLUDE_DIR @PACKAGE_INCLUDE_INSTALL_DIR@) -endif() - -set(CMOCKA_LIBRARY @PACKAGE_LIB_INSTALL_DIR@/@CMOCKA_LIBRARY_NAME@) -set(CMOCKA_LIBRARIES @PACKAGE_LIB_INSTALL_DIR@/@CMOCKA_LIBRARY_NAME@) - -mark_as_advanced(CMOCKA_LIBRARY CMOCKA_INCLUDE_DIR)
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/doc/index.html
Deleted
@@ -1,706 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> -<html><head> -<title>cmocka</title> -</head> -<body> -<h1>cmocka Unit Testing Framework</h1> -<p>cmocka is a lightweight library that is used to author C unit tests.</p> - -<ul>Contents - <li><a href="#Motivation">Motivation</a></li> - <li><a href="#Overview">Overview</a></li> - <li><a href="#Test_Execution">Test Execution</a> - <li><a href="#Exception_Handling">Exception Handling</a></li> - <li><a href="#Failure_Conditions">Failure Conditions</a></li> - <li><a href="#Assertions">Assertions</a></li> - <ul> - <li><a href="#Assert_Macros">Assert Macros</a></li> - </ul> - <li><a href="#Dynamic_Memory_Allocation">Dynamic Memory Allocation</a></li> - <li><a href="#Mock_Functions">Mock functions</a></li> - <ul> - <li><a href="#Return_Values">Return Values</a></li> - <li><a href="#Checking_Parameters">Checking Parameters</a></li> - </ul> - <li><a href="#Test_State">Test State</a></li> - <li><a href="#Example">Example</a></li> -</ul> - -<a name="Motivation"><h2>Motivation</h2></a> -<p>There are a variety of C unit testing frameworks available however many of -them are fairly complex and require the latest compiler technology. Some -development requires the use of old compilers which makes it difficult to -use some unit testing frameworks. In addition many unit testing frameworks -assume the code being tested is an application or module that is targeted to -the same platform that will ultimately execute the test. Because of this -assumption many frameworks require the inclusion of standard C library headers -in the code module being tested which may collide with the custom or -incomplete implementation of the C library utilized by the code under test.</p> - -<p>cmocka only requires a test application is linked with the standard C -library which minimizes conflicts with standard C library headers. Also, -cmocka tries avoid the use of some of the newer features of C compilers.</p> - -<p>This results in cmocka being a relatively small library that can be used -to test a variety of exotic code. If a developer wishes to simply test an -application with the latest compiler then other unit testing frameworks maybe -preferable.</p> - -<a name="Overview"><h2>Overview</h2></a> -<p>cmocka tests are compiled into stand-alone executables and linked with -the cmocka library, the standard C library and module being tested. Any -symbols external to the module being tested should be mocked - replaced with -functions that return values determined by the test - within the test -application. Even though significant differences may exist between the target -execution environment of a code module and the environment used to test the -code the unit testing is still valid since its goal is to test the logic of a -code modules at a functional level and not necessarily all of its interactions -with the target execution environment.</p> - -<p>It may not be possible to compile a module into a test application without -some modification, therefore the preprocessor symbol <b>UNIT_TESTING</b> should -be defined when cmocka unit test applications are compiled so code within the -module can be conditionally compiled for tests.</p> - -<a name="Test_Execution"><h2>Test Execution</h2></a> -<p>cmocka unit test cases are functions with the signature -<b>void function(void **state)</b>. cmocka test applications initialize a -table with test case function pointers using <b>unit_test*()</b> macros. This -table is then passed to the <b>run_tests()</b> macro to execute the tests. - -<b>run_tests()</b> sets up the appropriate exception / signal handlers and -other data structures prior to running each test function. When a unit test -is complete <b>run_tests()</b> performs various checks to determine whether -the test succeeded.</p> - -<h4>Using run_tests()</h4> -<a href="../example/run_tests.c">run_tests.c</a> -<listing> -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> - -// A test case that does nothing and succeeds. -void null_test_success(void **state) { -} - -int main(int argc, char* argv) { - const UnitTest tests = { - unit_test(null_test_success), - }; - return run_tests(tests); -} -</listing> - -<a name="Exception_Handling"><h2>Exception Handling</h2></a> -<p>Before a test function is executed by <b>run_tests()</b>, -exception / signal handlers are overridden with a handler that simply -displays an error and exits a test function if an exception occurs. If an -exception occurs outside of a test function, for example in cmocka itself, -the application aborts execution and returns an error code.</p> - -<a name="Failure_Conditions"><h2>Failure Conditions</h2></a> -<p>If a failure occurs during a test function that's executed via -<b>run_tests()</b>, the test function is aborted and the application's -execution resumes with the next test function. - -Test failures are ultimately signalled via the cmocka function <b>fail()</b>. -The following events will result in the cmocka library signalling a test -failure... - -<ul> - <li><a href="#Assertions">Assertions</a></li> - <li><a href="#Exception_Handling">Exceptions</a></li> - <li><a href="#Dynamic_Memory_Allocation">Memory leaks</a></li> - <li><a href="#Test_State">Mismatched setup and tear down functions</a></li> - <li><a href="#Return_Values">Missing mock return values</a></li> - <li><a href="#Return_Values">Unused mock return values</a></li> - <li><a href="#Checking_Parameters">Missing expected parameter values</a></li> - <li><a href="#Checking_Parameters">Unused expected parameter values</a></li> -</ul> -</p> - -<a name="Assertions"><h2>Assertions</h2></a> -<p>Runtime assert macros like the standard C library's <b>assert()</b> should -be redefined in modules being tested to use cmocka's <b>mock_assert()</b> -function. Normally <b>mock_assert()</b> signals a -<a href="#Failure_Conditions">test failure</a>. If a function is called using -the <b>expect_assert_failure()</b> macro, any calls to <b>mock_assert()</b> -within the function will result in the execution of the test. If no -calls to <b>mock_assert()</b> occur during the function called via -<b>expect_assert_failure()</b> a test failure is signalled.</p> - -<h4>Using mock_assert()</h4> -<a href="../example/assert_module.c">assert_module.c</a> -<listing> -#include <assert.h> - -// If unit testing is enabled override assert with mock_assert(). -#ifdef UNIT_TESTING -extern void mock_assert(const int result, const char* const expression, - const char * const file, const int line); -#undef assert -#define assert(expression) \ - mock_assert((int)(expression), #expression, __FILE__, __LINE__); -#endif // UNIT_TESTING - -void increment_value(int * const value) { - assert(value); - (*value) ++; -} - -void decrement_value(int * const value) { - if (value) { - *value --; - } -} -</listing> -<a href="../example/assert_module_test.c">assert_module_test.c</a> -<listing> -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> - -extern void increment_value(int * const value); - -/* This test case will fail but the assert is caught by run_tests() and the - * next test is executed. */ -void increment_value_fail(void **state) { - increment_value(NULL); -} - -// This test case succeeds since increment_value() asserts on the NULL pointer. -void increment_value_assert(void **state) { - expect_assert_failure(increment_value(NULL)); -} - -/* This test case fails since decrement_value() doesn't assert on a NULL - * pointer. */ -void decrement_value_fail(void **state) { - expect_assert_failure(decrement_value(NULL)); -} - -int main(int argc, char *argv) { - const UnitTest tests = { - unit_test(increment_value_fail), - unit_test(increment_value_assert), - unit_test(decrement_value_fail), - }; - return run_tests(tests); -} -</listing> - -<h3><a name="Assert_Macros">Assert Macros</a></h3> - -<p>cmocka provides an assortment of assert macros that tests applications -should use use in preference to the C standard library's assert macro. On an -assertion failure a cmocka assert macro will write the failure to the -standard error stream and signal a test failure. Due to limitations of the -C language the general C standard library assert() and cmocka's -assert_true() and assert_false() macros can only display the expression that -caused the assert failure. cmocka's type specific assert macros, -assert_{type}_equal() and assert_{type}_not_equal(), display the data that -caused the assertion failure which increases data visibility aiding -debugging of failing test cases.</p> - -<h4>Using assert_{type}_equal() macros</h4> -<a href="../example/assert_macro.c">assert_macro.c</a> -<listing> -#include <string.h> - -static const char* status_code_strings = { - "Address not found", - "Connection dropped", - "Connection timed out", -}; - -const char* get_status_code_string(const unsigned int status_code) { - return status_code_stringsstatus_code; -}; - -unsigned int string_to_status_code(const char* const status_code_string) { - unsigned int i; - for (i = 0; i < sizeof(status_code_strings) / - sizeof(status_code_strings0); i++) { - if (strcmp(status_code_stringsi, status_code_string) == 0) { - return i; - } - } - return ~0U; -} -</listing> -<a href="../example/assert_macro_test.c">assert_macro_test.c</a> -<listing> -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> - -extern const char* get_status_code_string(const unsigned int status_code); -extern unsigned int string_to_status_code( - const char* const status_code_string); - -/* This test will fail since the string returned by get_status_code_string(0) - * doesn't match "Connection timed out". */ -void get_status_code_string_test(void **state) { - assert_string_equal(get_status_code_string(0), "Address not found"); - assert_string_equal(get_status_code_string(1), "Connection timed out"); -} - -// This test will fail since the status code of "Connection timed out" isn't 1 -void string_to_status_code_test(void **state) { - assert_int_equal(string_to_status_code("Address not found"), 0); - assert_int_equal(string_to_status_code("Connection timed out"), 1); -} - -int main(int argc, char *argv) { - const UnitTest tests = { - unit_test(get_status_code_string_test), - unit_test(string_to_status_code_test), - }; - return run_tests(tests); -} -</listing> - -<a name="Dynamic_Memory_Allocation"><h2>Dynamic Memory Allocation</h2></a> - -<p>To test for memory leaks, buffer overflows and underflows a module being -tested by cmocka should replace calls to <b>malloc()</b>, <b>calloc()</b> and -<b>free()</b> to <b>test_malloc()</b>, <b>test_calloc()</b> and -<b>test_free()</b> respectively. Each time a block is deallocated using -<b>test_free()</b> it is checked for corruption, if a corrupt block is found -a <a href="#Failure_Conditions">test failure</a> is signalled. All blocks -allocated using the <b>test_*()</b> allocation functions are tracked by the -cmocka library. When a test completes if any allocated blocks (memory leaks) -remain they are reported and a test failure is signalled.</p> -<p>For simplicity cmocka currently executes all tests in one process. -Therefore all test cases in a test application share a single address space -which means memory corruption from a single test case could potentially cause -the test application to exit prematurely.</p> - -<h4>Using cmocka's Allocators</h4> -<a href="../example/allocate_module.c">allocate_module.c</a> -<listing> -#include <malloc.h> - -#ifdef UNIT_TESTING -extern void* _test_malloc(const size_t size, const char* file, const int line); -extern void* _test_calloc(const size_t number_of_elements, const size_t size, - const char* file, const int line); -extern void _test_free(void* const ptr, const char* file, const int line); - -#define malloc(size) _test_malloc(size, __FILE__, __LINE__) -#define calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__) -#define free(ptr) _test_free(ptr, __FILE__, __LINE__) -#endif // UNIT_TESTING - -void leak_memory() { - int * const temporary = (int*)malloc(sizeof(int)); - *temporary = 0; -} - -void buffer_overflow() { - char * const memory = (char*)malloc(sizeof(int)); - memorysizeof(int) = '!'; - free(memory); -} - -void buffer_underflow() { - char * const memory = (char*)malloc(sizeof(int)); - memory-1 = '!'; - free(memory); -} -</listing> -<a href="../example/allocate_module_test.c">allocate_module_test.c</a> -<listing> -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> - -extern void leak_memory(); -extern void buffer_overflow(); -extern void buffer_underflow(); - -// Test case that fails as leak_memory() leaks a dynamically allocated block. -void leak_memory_test(void **state) { - leak_memory(); -} - -// Test case that fails as buffer_overflow() corrupts an allocated block. -void buffer_overflow_test(void **state) { - buffer_overflow(); -} - -// Test case that fails as buffer_underflow() corrupts an allocated block. -void buffer_underflow_test(void **state) { - buffer_underflow(); -} - -int main(int argc, char* argv) { - const UnitTest tests = { - unit_test(leak_memory_test), - unit_test(buffer_overflow_test), - unit_test(buffer_underflow_test), - }; - return run_tests(tests); -} -</listing> - -<a name="Mock_Functions"><h2>Mock Functions</h2></a> - -<p>A unit test should ideally isolate the function or module being tested -from any external dependencies. This can be performed using mock functions -that are either statically or dynamically linked with the module being tested. -Mock functions must be statically linked when the code being tested directly -references external functions. Dynamic linking is simply the process of -setting a function pointer in a table used by the tested module to reference -a mock function defined in the unit test.</p> - -<a name="Return_Values"><h3>Return Values</h3></a> - -<p>In order to simplify the implementation of mock functions cmocka provides -functionality which stores return values for mock functions in each test -case using <b>will_return()</b>. These values are then returned by each mock -function using calls to <b>mock()</b>. - -Values passed to <b>will_return()</b> are added to a queue for each function -specified. Each successive call to <b>mock()</b> from a function removes a -return value from the queue. This makes it possible for a mock function to use -multiple calls to <b>mock()</b> to return output parameters in addition to a -return value. In addition this allows the specification of return values for -multiple calls to a mock function.</p> - -<h4>Using will_return()</h4> -<a href="../example/database.h">database.h</a> -<listing> -typedef struct DatabaseConnection DatabaseConnection; - -/* Function that takes an SQL query string and sets results to an array of - * pointers with the result of the query. The value returned specifies the - * number of items in the returned array of results. The returned array of - * results are statically allocated and should not be deallocated using free() - */ -typedef unsigned int (*QueryDatabase)( - DatabaseConnection* const connection, const char * const query_string, - void *** const results); - -// Connection to a database. -struct DatabaseConnection { - const char *url; - unsigned int port; - QueryDatabase query_database; -}; - -// Connect to a database. -DatabaseConnection* connect_to_database(const char * const url, - const unsigned int port); -</listing> -<a href="../example/customer_database.c">customer_database.c</a> -<listing> -#include <stddef.h> -#include <stdio.h> -#include <database.h> -#ifdef _WIN32 -#define snprintf _snprintf -#endif // _WIN32 - -// Connect to the database containing customer information. -DatabaseConnection* connect_to_customer_database() { - return connect_to_database("customers.abcd.org", 321); -} - -/* Find the ID of a customer by his/her name returning a value > 0 if - * successful, 0 otherwise. */ -unsigned int get_customer_id_by_name( - DatabaseConnection * const connection, - const char * const customer_name) { - char query_string256; - int number_of_results; - void **results; - snprintf(query_string, sizeof(query_string), - "SELECT ID FROM CUSTOMERS WHERE NAME = %s", customer_name); - number_of_results = connection->query_database(connection, query_string, - &results); - if (number_of_results != 1) { - return -1; - } - return (unsigned int)results0; -} -</listing> -<a href="../example/customer_database_test.c">customer_database_test.c</a> -<listing> -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> -#include <database.h> - - -extern DatabaseConnection* connect_to_customer_database(); -extern unsigned int get_customer_id_by_name( - DatabaseConnection * const connection, const char * const customer_name); - -// Mock query database function. -unsigned int mock_query_database( - DatabaseConnection* const connection, const char * const query_string, - void *** const results) { - *results = (void**)mock(); - return (unsigned int)mock(); -} - -// Mock of the connect to database function. -DatabaseConnection* connect_to_database(const char * const database_url, - const unsigned int port) { - return (DatabaseConnection*)mock(); -} - -void test_connect_to_customer_database(void **state) { - will_return(connect_to_database, 0x0DA7ABA53); - assert_true(connect_to_customer_database() == - (DatabaseConnection*)0x0DA7ABA53); -} - -/* This test fails as the mock function connect_to_database() will have no - * value to return. */ -void fail_connect_to_customer_database(void **state) { - will_return(connect_to_database, 0x0DA7ABA53); - assert_true(connect_to_customer_database() == - (DatabaseConnection*)0x0DA7ABA53); -} - -void test_get_customer_id_by_name(void **state) { - DatabaseConnection connection = { - "somedatabase.somewhere.com", 12345678, mock_query_database - }; - // Return a single customer ID when mock_query_database() is called. - int customer_ids = 543; - will_return(mock_query_database, &customer_ids); - will_return(mock_query_database, 1); - assert_int_equal(get_customer_id_by_name(&connection, "john doe"), 543); -} - -int main(int argc, char* argv) { - const UnitTest tests = { - unit_test(test_connect_to_customer_database), - unit_test(fail_connect_to_customer_database), - unit_test(test_get_customer_id_by_name), - }; - return run_tests(tests); -} -</listing> - -<a name="Checking_Parameters"><h3>Checking Parameters</h3></a> -<p>In addition to storing the return values of mock functions, cmocka -provides functionality to store expected values for mock function parameters -using the expect_*() functions provided. A mock function parameter can then -be validated using the check_expected() macro. - -<p>Successive calls to expect_*() macros for a parameter queues values to -check the specified parameter. check_expected() checks a function parameter -against the next value queued using expect_*(), if the parameter check fails a -test failure is signalled. In addition if check_expected() is called and -no more parameter values are queued a test failure occurs.</p> - -<h4>Using expect_*()</h4> -<a href="../example/product_database.c">product_database.c</a> -<listing> -#include <database.h> - -// Connect to the database containing customer information. -DatabaseConnection* connect_to_product_database() { - return connect_to_database("products.abcd.org", 322); -} -</listing> -<a href="../example/product_database_test.c">product_database_test.c</a> -<listing> -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> -#include <database.h> - -extern DatabaseConnection* connect_to_product_database(); - -/* Mock connect to database function. - * NOTE: This mock function is very general could be shared between tests - * that use the imaginary database.h module. */ -DatabaseConnection* connect_to_database(const char * const url, - const unsigned int port) { - check_expected(url); - check_expected(port); - return (DatabaseConnection*)mock(); -} - -void test_connect_to_product_database(void **state) { - expect_string(connect_to_database, url, "products.abcd.org"); - expect_value(connect_to_database, port, 322); - will_return(connect_to_database, 0xDA7ABA53); - assert_int_equal(connect_to_product_database(), 0xDA7ABA53); -} - -/* This test will fail since the expected URL is different to the URL that is - * passed to connect_to_database() by connect_to_product_database(). */ -void test_connect_to_product_database_bad_url(void **state) { - expect_string(connect_to_database, url, "products.abcd.com"); - expect_value(connect_to_database, port, 322); - will_return(connect_to_database, 0xDA7ABA53); - assert_int_equal((int)connect_to_product_database(), 0xDA7ABA53); -} - -/* This test will fail since the mock connect_to_database() will attempt to - * retrieve a value for the parameter port which isn't specified by this - * test function. */ -void test_connect_to_product_database_missing_parameter(void **state) { - expect_string(connect_to_database, url, "products.abcd.org"); - will_return(connect_to_database, 0xDA7ABA53); - assert_int_equal((int)connect_to_product_database(), 0xDA7ABA53); -} - -int main(int argc, char* argv) { - const UnitTest tests = { - unit_test(test_connect_to_product_database), - unit_test(test_connect_to_product_database_bad_url), - unit_test(test_connect_to_product_database_missing_parameter), - }; - return run_tests(tests); -} -</listing> - -<a name="Test_State"><h2>Test State</h2></a> - -<p>cmocka allows the specification of multiple setup and tear down functions -for each test case. Setup functions, specified by the <b>unit_test_setup()</b> -or <b>unit_test_setup_teardown()</b> macros allow common initialization to be -shared between multiple test cases. In addition, tear down functions, -specified by the <b>unit_test_teardown()</b> or -<b>unit_test_setup_teardown()</b> macros provide a code path that is always -executed for a test case even when it fails.</p> - -<h4>Using unit_test_setup_teardown()</h4> -<a href="../example/key_value.c">key_value.c</a> -<listing> -#include <stddef.h> -#include <stdlib.h> -#include <string.h> - -typedef struct KeyValue { - unsigned int key; - const char* value; -} KeyValue; - -static KeyValue *key_values = NULL; -static unsigned int number_of_key_values = 0; - -void set_key_values(KeyValue * const new_key_values, - const unsigned int new_number_of_key_values) { - key_values = new_key_values; - number_of_key_values = new_number_of_key_values; -} - -// Compare two key members of KeyValue structures. -int key_value_compare_keys(const void *a, const void *b) { - return (int)((KeyValue*)a)->key - (int)((KeyValue*)b)->key; -} - -// Search an array of key value pairs for the item with the specified value. -KeyValue* find_item_by_value(const char * const value) { - unsigned int i; - for (i = 0; i < number_of_key_values; i++) { - if (strcmp(key_valuesi.value, value) == 0) { - return &key_valuesi; - } - } - return NULL; -} - -// Sort an array of key value pairs by key. -void sort_items_by_key() { - qsort(key_values, number_of_key_values, sizeof(*key_values), - key_value_compare_keys); -} -</listing> -<a href="../example/key_value_test.c">key_value_test.c</a> -<listing> -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <string.h> -#include <cmocka.h> - -/* This is duplicated here from the module setup_teardown.c to reduce the - * number of files used in this test. */ -typedef struct KeyValue { - unsigned int key; - const char* value; -} KeyValue; - -void set_key_values(KeyValue * const new_key_values, - const unsigned int new_number_of_key_values); -extern KeyValue* find_item_by_value(const char * const value); -extern void sort_items_by_key(); - -static KeyValue key_values = { - { 10, "this" }, - { 52, "test" }, - { 20, "a" }, - { 13, "is" }, -}; - -void create_key_values(void **state) { - KeyValue * const items = (KeyValue*)test_malloc(sizeof(key_values)); - memcpy(items, key_values, sizeof(key_values)); - *state = (void*)items; - set_key_values(items, sizeof(key_values) / sizeof(key_values0)); -} - -void destroy_key_values(void **state) { - test_free(*state); - set_key_values(NULL, 0); -} - -void test_find_item_by_value(void **state) { - unsigned int i; - for (i = 0; i < sizeof(key_values) / sizeof(key_values0); i++) { - KeyValue * const found = find_item_by_value(key_valuesi.value); - assert_true(found); - assert_int_equal(found->key, key_valuesi.key); - assert_string_equal(found->value, key_valuesi.value); - } -} - -void test_sort_items_by_key(void **state) { - unsigned int i; - KeyValue * const kv = *state; - sort_items_by_key(); - for (i = 1; i < sizeof(key_values) / sizeof(key_values0); i++) { - assert_true(kvi - 1.key < kvi.key); - } -} - -int main(int argc, char* argv) { - const UnitTest tests = { - unit_test_setup_teardown(test_find_item_by_value, create_key_values, - destroy_key_values), - unit_test_setup_teardown(test_sort_items_by_key, create_key_values, - destroy_key_values), - }; - return run_tests(tests); -} -</listing> - -<a name="Example"><h2>Example</h2></a> - -<p>A small command line calculator -<a href="../example/calculator.c">calculator.c</a> application -and test application that full exercises the calculator application -<a href="../example/calculator_test.c">calculator_test.c</a> -are provided as an example of cmocka's features discussed in this document. -</p> - -<hr> -<address></address> -<!-- hhmts start --> Last modified: Wed Jul 22 12:11:43 PDT 2009 <!-- hhmts end --> -</body> </html>
View file
_service:tar_scm:cmocka-1.1.7.tar.xz/49.patch
Added
@@ -0,0 +1,1628 @@ +From 6a99bd773e986a615272ed0611d4fc7636b01a03 Mon Sep 17 00:00:00 2001 +From: maxime <maximeandrighetto@gmail.com> +Date: Tue, 9 Aug 2022 16:37:34 +0900 +Subject: PATCH 1/8 Fixed warning when compiling on Windows: warning C4996: + 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO + C++ conformant name: _strdup. See online help for details. + +--- + include/cmocka_private.h | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/include/cmocka_private.h b/include/cmocka_private.h +index 4d3ff30..7ee4a76 100644 +--- a/include/cmocka_private.h ++++ b/include/cmocka_private.h +@@ -40,6 +40,7 @@ + # define strcasecmp _stricmp + # define strncasecmp _strnicmp + # define strtok_r strtok_s ++# define strdup _strdup + + # if defined(HAVE__SNPRINTF_S) + # undef snprintf +-- +GitLab + + +From 7f2705e48bcde685189764303246601c13d66718 Mon Sep 17 00:00:00 2001 +From: maxime <maximeandrighetto@gmail.com> +Date: Tue, 9 Aug 2022 16:40:08 +0900 +Subject: PATCH 2/8 Improve the implementation of the TAP output by printing + the message, severity, data, etc. in a YAML diagnostics section, as specified + by the TAP14 specification. + +--- + src/cmocka.c | 66 +++++++++++++++++++++++++++++----------------------- + 1 file changed, 37 insertions(+), 29 deletions(-) + +diff --git a/src/cmocka.c b/src/cmocka.c +index 2518590..1ab88fe 100644 +--- a/src/cmocka.c ++++ b/src/cmocka.c +@@ -2725,7 +2725,7 @@ static void cmprintf_group_start_tap(const size_t num_tests) + { + static bool version_printed = false; + if (!version_printed) { +- print_message("TAP version 13\n"); ++ print_message("TAP version 14\n"); + version_printed = true; + } + +@@ -2749,6 +2749,8 @@ static void cmprintf_tap(enum cm_printf_type type, + const char *test_name, + const char *error_message) + { ++ int print_error_message = 0; ++ + switch (type) { + case PRINTF_TEST_START: + break; +@@ -2756,42 +2758,48 @@ static void cmprintf_tap(enum cm_printf_type type, + print_message("ok %u - %s\n", (unsigned)test_number, test_name); + break; + case PRINTF_TEST_FAILURE: ++ case PRINTF_TEST_ERROR: + print_message("not ok %u - %s\n", (unsigned)test_number, test_name); +- if (error_message != NULL) { +- char *msg; +- char *p; ++ print_error_message = 1; ++ break; ++ case PRINTF_TEST_SKIPPED: ++ print_message("ok %u - %s # SKIP\n", (unsigned)test_number, test_name); ++ break; ++ } + +- msg = strdup(error_message); +- if (msg == NULL) { +- return; +- } +- p = msg; ++ if ((print_error_message == 1) && (error_message != NULL)) { ++ char *msg; ++ char *p; ++ const char *indent = ""; + +- while (p0 != '\0') { +- char *q = p; ++ msg = strdup(error_message); ++ if (msg == NULL) { ++ return; ++ } ++ p = msg; + +- p = strchr(q, '\n'); +- if (p != NULL) { +- p0 = '\0'; +- } ++ print_message(" ---\n"); + +- print_message("# %s\n", q); ++ print_message(" message: \""); ++ while (p0 != '\0') { ++ char *q = p; + +- if (p == NULL) { +- break; +- } +- p++; ++ p = strchr(q, '\n'); ++ if (p != NULL) { ++ p0 = '\0'; ++ print_message("%s%s\\n\\\n", indent, q); ++ } else { ++ print_message("%s%s\"\n", indent, q); ++ break; + } +- libc_free(msg); ++ p++; ++ indent = " "; + } +- break; +- case PRINTF_TEST_SKIPPED: +- print_message("ok %u # SKIP %s\n", (unsigned)test_number, test_name); +- break; +- case PRINTF_TEST_ERROR: +- print_message("not ok %u - %s %s\n", +- (unsigned)test_number, test_name, error_message); +- break; ++ libc_free(msg); ++ ++ print_message(" severity: %s\n", (type == PRINTF_TEST_FAILURE) ? "fail" : "error"); ++ ++ print_message(" ...\n"); + } + } + +-- +GitLab + + +From 9874464dc7858475ace081dc748b0f399213b473 Mon Sep 17 00:00:00 2001 +From: maxime <maximeandrighetto@gmail.com> +Date: Tue, 9 Aug 2022 16:44:18 +0900 +Subject: PATCH 3/8 Added functions so that custom data can be attached to + the current test. I'm open to a different implementation, but I basically + needed a mechanism that is flexible enough to print any kind of data whether + a test passes or fails. For example, on the app using cmocka, I wanted to be + able to redefine the assert_* macros to automatically include data such as + 'expected', 'got' when a test fails. Currently the data are only used by the + TAP output. + +--- + include/cmocka.h | 51 +++++++++++++ + src/cmocka.c | 185 ++++++++++++++++++++++++++++++++++++++++++++--- + src/cmocka.def | 6 ++ + 3 files changed, 231 insertions(+), 11 deletions(-) + +diff --git a/include/cmocka.h b/include/cmocka.h +index 1897240..18f0da3 100644 +--- a/include/cmocka.h ++++ b/include/cmocka.h +@@ -1742,6 +1742,45 @@ void stop(void); + #define stop() _stop() + #endif + ++#ifdef DOXYGEN ++/** ++ * @brief Initialize a list of data for the current test. ++ */ ++int attach_test_data(size_t size); ++ ++/** ++ * @brief Expand the list of data for the current test. ++ */ ++int extend_test_data(size_t size); ++ ++/** ++ * @brief Append Boolean data for the current test. ++ */ ++void append_test_data_boolean(const char * const name, int value); ++ ++/** ++ * @brief Append Integer data for the current test. ++ */ ++void append_test_data_integer(const char * const name, uintmax_t value); ++ ++/** ++ * @brief Append Pointer data for the current test. ++ */ ++void append_test_data_pointer(const char * const name, void * const value); ++ ++/** ++ * @brief Append String data for the current test. ++ */ ++void append_test_data_string(const char * const name, const char * value); ++#else ++#define attach_test_data(s) _attach_test_data(s, __FILE__, __LINE__) ++#define extend_test_data(s) _extend_test_data(s, __FILE__, __LINE__) ++#define append_test_data_boolean(n, v) _append_test_data_boolean(n, v, __FILE__, __LINE__) ++#define append_test_data_integer(n, v) _append_test_data_integer(n, v, __FILE__, __LINE__) ++#define append_test_data_pointer(n, v) _append_test_data_pointer(n, v, __FILE__, __LINE__) ++#define append_test_data_string(n, v) _append_test_data_string(n, v, __FILE__, __LINE__) ++#endif ++ + #ifdef DOXYGEN + /** + * @brief Forces the test to fail immediately and quit, printing the reason. +@@ -2436,6 +2475,18 @@ CMOCKA_NORETURN void _skip(const char * const file, const int line); + + CMOCKA_NORETURN void _stop(void); + ++int _attach_test_data(size_t size, const char * const file, const int line); ++ ++int _extend_test_data(size_t size, const char * const file, const int line); ++ ++void _append_test_data_boolean(const char * const name, int value, const char * const file, const int line); ++ ++void _append_test_data_integer(const char * const name, uintmax_t value, const char * const file, const int line); ++ ++void _append_test_data_pointer(const char * const name, void * const value, const char * const file, const int line); ++ ++void _append_test_data_string(const char * const name, const char * value, const char * const file, const int line); ++ + /* Test runner */ + int _cmocka_run_group_tests(const char *group_name, + const struct CMUnitTest * const tests, +diff --git a/src/cmocka.c b/src/cmocka.c +index 1ab88fe..8bc13d8 100644 +--- a/src/cmocka.c ++++ b/src/cmocka.c +@@ -201,6 +201,19 @@ typedef struct CheckMemoryData { + size_t size; + } CheckMemoryData; + ++typedef enum CMDataType { ++ DATA_TYPE_BOOLEAN, ++ DATA_TYPE_INTEGER, ++ DATA_TYPE_POINTER, ++ DATA_TYPE_STRING, ++} CMDataType; ++ ++typedef struct CMData { ++ char *name; ++ void *value; ++ CMDataType type; ++} CMData; ++ + static ListNode* list_initialize(ListNode * const node); + static ListNode* list_add(ListNode * const head, ListNode *new_node); + static ListNode* list_add_value(ListNode * const head, const void *value, +@@ -270,6 +283,11 @@ const char *global_last_failed_assert = NULL; + static int global_skip_test; + static int global_stop_test; + ++/* Keeps an array of CMData to be printed for TAP output. */ ++static CMOCKA_THREAD CMData** global_test_data = NULL; ++static CMOCKA_THREAD size_t global_test_data_max_size; ++static CMOCKA_THREAD size_t global_test_data_len; ++ + /* Keeps a map of the values that functions will have to return to provide */ + /* mocked interfaces. */ + static CMOCKA_THREAD ListNode global_function_result_map_head; +@@ -410,6 +428,107 @@ void _stop(void) + exit(EXIT_FAILURE); + } + ++static void free_test_data(void) { ++ if (global_test_data) { ++ CMData* d; ++ size_t i; ++ for (i = 0; i < global_test_data_len; i++) { ++ d = global_test_datai; ++ if (d) { ++ free(d->name); ++ switch (d->type) { ++ case DATA_TYPE_STRING: ++ free(d->value); ++ default: ++ break; ++ } ++ free(d); ++ } ++ } ++ free(global_test_data); ++ ++ global_test_data = NULL; ++ global_test_data_max_size = 0; ++ global_test_data_len = 0; ++ } ++} ++ ++int _attach_test_data(size_t size, const char * const file, const int line) { ++ if (size > 0) { ++ free_test_data(); ++ global_test_data = (CMData**)malloc(size * sizeof(CMData*)); ++ if (!global_test_data) { ++ cmocka_print_error(SOURCE_LOCATION_FORMAT ": error: Failed to initialize data list.\n", file, line); ++ return 1; ++ } else { ++ global_test_data_max_size = size; ++ global_test_data_len = 0; ++ } ++ } ++ return 0; ++} ++ ++int _extend_test_data(size_t size, const char * const file, const int line) { ++ if (size > 0) { ++ CMData** tmp; ++ size_t tmp_size = global_test_data_max_size + size; ++ ++ tmp = (CMData**)realloc(global_test_data, tmp_size * sizeof(CMData*)); ++ if (!tmp) { ++ cmocka_print_error(SOURCE_LOCATION_FORMAT ": error: Failed to expand data list.\n", file, line); ++ return 1; ++ } else { ++ global_test_data = tmp; ++ global_test_data_max_size = tmp_size; ++ } ++ } ++ return 0; ++} ++ ++static void _append_test_data(const char * const name, void * const value, CMDataType type, const char * const file, const int line) { ++ CMData* d; ++ ++ if (!global_test_data) { ++ if (_attach_test_data(10, file, line) == 1) { ++ return; ++ } ++ } else if (global_test_data_len + 1 > global_test_data_max_size) { ++ if (_extend_test_data(10, file, line) == 1) { ++ return; ++ } ++ } ++ ++ d = (CMData*)malloc(sizeof(CMData)); ++ if (d) { ++ d->name = strdup(name); ++ switch (type) { ++ case DATA_TYPE_STRING: ++ d->value = strdup(value); ++ break; ++ default: ++ d->value = value; ++ } ++ d->type = type; ++ global_test_dataglobal_test_data_len++ = d; ++ } ++} ++ ++void _append_test_data_boolean(const char * const name, int value, const char * const file, const int line) { ++ _append_test_data(name, cast_uintmax_type_to_pointer(void * const, value), DATA_TYPE_BOOLEAN, file, line); ++} ++ ++void _append_test_data_integer(const char * const name, uintmax_t value, const char * const file, const int line) { ++ _append_test_data(name, cast_uintmax_type_to_pointer(void * const, value), DATA_TYPE_INTEGER, file, line); ++} ++ ++void _append_test_data_pointer(const char * const name, void * const value, const char * const file, const int line) { ++ _append_test_data(name, value, DATA_TYPE_POINTER, file, line); ++} ++ ++void _append_test_data_string(const char * const name, const char * value, const char * const file, const int line) { ++ _append_test_data(name, (void * const)value, DATA_TYPE_STRING, file, line); ++} ++ + /* Initialize a SourceLocation structure. */ + static void initialize_source_location(SourceLocation * const location) { + assert_non_null(location); +@@ -2747,8 +2866,12 @@ static void cmprintf_group_finish_tap(const char *group_name, + static void cmprintf_tap(enum cm_printf_type type, + size_t test_number, + const char *test_name, +- const char *error_message) ++ const char *error_message, ++ CMData** test_data) + { ++ CMData* d; ++ size_t i; ++ int diagnostics_opened = 0; + int print_error_message = 0; + + switch (type) { +@@ -2779,6 +2902,7 @@ static void cmprintf_tap(enum cm_printf_type type, + p = msg; + + print_message(" ---\n"); ++ diagnostics_opened = 1; + + print_message(" message: \""); + while (p0 != '\0') { +@@ -2798,7 +2922,39 @@ static void cmprintf_tap(enum cm_printf_type type, + libc_free(msg); + + print_message(" severity: %s\n", (type == PRINTF_TEST_FAILURE) ? "fail" : "error"); ++ } ++ ++ if (test_data) { ++ if (diagnostics_opened == 0) { ++ print_message(" ---\n"); ++ diagnostics_opened = 1; ++ } ++ print_message(" data:\n"); ++ ++ for (i = 0; i < global_test_data_len; i++) { ++ d = test_datai; ++ switch (d->type) { ++ case DATA_TYPE_BOOLEAN: ++ print_message(" %s: %s\n", ++ d->name, (int)cast_ptr_to_uintmax_type(d->value) != (int)0 ? "true" : "false"); ++ break; ++ case DATA_TYPE_INTEGER: ++ print_message(" %s: %#jx\n", ++ d->name, cast_ptr_to_uintmax_type(d->value)); ++ break; ++ case DATA_TYPE_POINTER: ++ print_message(" %s: %p\n", ++ d->name, d->value); ++ break; ++ case DATA_TYPE_STRING: ++ print_message(" %s: '%s'\n", ++ d->name, (const char *)(d->value)); ++ break; ++ } ++ } ++ } + ++ if (diagnostics_opened == 1) { + print_message(" ...\n"); + } + } +@@ -2886,7 +3042,8 @@ static void cmprintf_group_finish(const char *group_name, + static void cmprintf(enum cm_printf_type type, + size_t test_number, + const char *test_name, +- const char *error_message) ++ const char *error_message, ++ CMData** test_data) + { + uint32_t output; + +@@ -2899,7 +3056,7 @@ static void cmprintf(enum cm_printf_type type, + cmprintf_subunit(type, test_name, error_message); + } + if (output & CM_OUTPUT_TAP) { +- cmprintf_tap(type, test_number, test_name, error_message); ++ cmprintf_tap(type, test_number, test_name, error_message, test_data); + } + } + +@@ -3253,7 +3410,7 @@ int _cmocka_run_group_tests(const char *group_name, + struct CMUnitTestState *cmtest = &cm_testsi; + size_t test_number = i + 1; + +- cmprintf(PRINTF_TEST_START, test_number, cmtest->test->name, NULL); ++ cmprintf(PRINTF_TEST_START, test_number, cmtest->test->name, NULL, NULL); + + if (group_state != NULL) { + cmtest->state = group_state; +@@ -3270,28 +3427,32 @@ int _cmocka_run_group_tests(const char *group_name, + cmprintf(PRINTF_TEST_SUCCESS, + test_number, + cmtest->test->name, +- cmtest->error_message); ++ cmtest->error_message, ++ global_test_data); + total_passed++; + break; + case CM_TEST_SKIPPED: + cmprintf(PRINTF_TEST_SKIPPED, + test_number, + cmtest->test->name, +- cmtest->error_message); ++ cmtest->error_message, ++ global_test_data); + total_skipped++; + break; + case CM_TEST_FAILED: + cmprintf(PRINTF_TEST_FAILURE, + test_number, + cmtest->test->name, +- cmtest->error_message); ++ cmtest->error_message, ++ global_test_data); + total_failed++; + break; + default: + cmprintf(PRINTF_TEST_ERROR, + test_number, + cmtest->test->name, +- "Internal cmocka error"); ++ "Internal cmocka error", ++ NULL); + total_errors++; + break; + } +@@ -3305,9 +3466,11 @@ int _cmocka_run_group_tests(const char *group_name, + cmprintf(PRINTF_TEST_ERROR, + test_number, + cmtest->test->name, +- err_msg); ++ err_msg, ++ NULL); + total_errors++; + } ++ free_test_data(); + } + } else { + if (cm_error_message != NULL) { +@@ -3316,7 +3479,7 @@ int _cmocka_run_group_tests(const char *group_name, + cm_error_message = NULL; + } + cmprintf(PRINTF_TEST_ERROR, 0, +- group_name, " FAILED GROUP SETUP"); ++ group_name, " FAILED GROUP SETUP", NULL); + total_errors++; + } + +@@ -3334,7 +3497,7 @@ int _cmocka_run_group_tests(const char *group_name, + cm_error_message = NULL; + } + cmprintf(PRINTF_TEST_ERROR, 0, +- group_name, " FAILED GROUP TEARDOWN"); ++ group_name, " FAILED GROUP TEARDOWN", NULL); + } + } + +diff --git a/src/cmocka.def b/src/cmocka.def +index f56b9a5..edeeffa 100644 +--- a/src/cmocka.def ++++ b/src/cmocka.def +@@ -1,5 +1,9 @@ + LIBRARY cmocka + EXPORTS ++ _append_test_data_boolean ++ _append_test_data_integer ++ _append_test_data_pointer ++ _append_test_data_string + _assert_double_equal + _assert_double_not_equal + _assert_float_equal +@@ -20,6 +24,7 @@ EXPORTS + _assert_uint_equal + _assert_uint_in_range + _assert_uint_not_equal ++ _attach_test_data + _check_expected + _cmocka_run_group_tests + _expect_any +@@ -35,6 +40,7 @@ EXPORTS + _expect_not_value + _expect_string + _expect_value ++ _extend_test_data + _fail + _function_called + _mock +-- +GitLab + + +From 3565734f7029a8a0c1600b292e641ec90e63ae17 Mon Sep 17 00:00:00 2001 +From: maxime <maximeandrighetto@gmail.com> +Date: Tue, 9 Aug 2022 16:47:28 +0900 +Subject: PATCH 4/8 Added skip_with_note() function to provide an explanation + about why the test is to be skipped. + +--- + include/cmocka.h | 13 ++++++++++++ + src/cmocka.c | 55 ++++++++++++++++++++++++++++++++++++++++-------- + src/cmocka.def | 1 + + 3 files changed, 60 insertions(+), 9 deletions(-) + +diff --git a/include/cmocka.h b/include/cmocka.h +index 18f0da3..827e7a0 100644 +--- a/include/cmocka.h ++++ b/include/cmocka.h +@@ -1728,6 +1728,17 @@ void skip(void); + #define skip() _skip(__FILE__, __LINE__) + #endif + ++#ifdef DOXYGEN ++/** ++ * @brief Forces the test to not be executed, but marked as skipped. ++ * ++ * @paramin note Explanation about why the test is skipped. ++ */ ++void skip_with_note(const char * const note, void); ++#else ++#define skip_with_note(note) _skip_with_note(note, __FILE__, __LINE__) ++#endif ++ + #ifdef DOXYGEN + /** + * @brief Forces the test to be stopped immediately. +@@ -2473,6 +2484,8 @@ CMOCKA_NORETURN void _fail(const char * const file, const int line); + + CMOCKA_NORETURN void _skip(const char * const file, const int line); + ++CMOCKA_NORETURN void _skip_with_note(const char * const note, const char * const file, const int line); ++ + CMOCKA_NORETURN void _stop(void); + + int _attach_test_data(size_t size, const char * const file, const int line); +diff --git a/src/cmocka.c b/src/cmocka.c +index 8bc13d8..9c8c340 100644 +--- a/src/cmocka.c ++++ b/src/cmocka.c +@@ -281,6 +281,7 @@ jmp_buf global_expect_assert_env; + int global_expecting_assert = 0; + const char *global_last_failed_assert = NULL; + static int global_skip_test; ++static const char * global_skip_test_note = NULL; + static int global_stop_test; + + /* Keeps an array of CMData to be printed for TAP output. */ +@@ -385,6 +386,7 @@ struct CMUnitTestState { + const char *error_message; /* The error messages by the test */ + enum CMUnitTestStatus status; /* PASSED, FAILED, ABORT ... */ + double runtime; /* Time calculations */ ++ const char *skip_note; /* Explanation when the test is skipped */ + }; + + /* Exit the currently executing test. */ +@@ -419,6 +421,17 @@ void _skip(const char * const file, const int line) + exit(EXIT_FAILURE); + } + ++void _skip_with_note(const char * const note, const char * const file, const int line) ++{ ++ cmocka_print_error(SOURCE_LOCATION_FORMAT ": Skipped (%s)!\n", file, line, note); ++ global_skip_test = 1; ++ global_skip_test_note = note; ++ exit_test(true); ++ ++ /* Unreachable */ ++ exit(EXIT_FAILURE); ++} ++ + void _stop(void) + { + global_stop_test = 1; +@@ -2738,7 +2751,12 @@ static void cmprintf_group_finish_xml(const char *group_name, + } + break; + case CM_TEST_SKIPPED: +- fprintf(fp, " <skipped/>\n"); ++ if (cmtest->skip_note) { ++ fprintf(fp, " <skipped><!CDATA%s></skipped>\n", ++ cmtest->skip_note); ++ } else { ++ fprintf(fp, " <skipped/>\n"); ++ } + break; + + case CM_TEST_PASSED: +@@ -2813,7 +2831,8 @@ static void cmprintf_group_finish_standard(const char *group_name, + + static void cmprintf_standard(enum cm_printf_type type, + const char *test_name, +- const char *error_message) ++ const char *error_message, ++ const char *skip_note) + { + switch (type) { + case PRINTF_TEST_START: +@@ -2829,7 +2848,11 @@ static void cmprintf_standard(enum cm_printf_type type, + print_message(" FAILED %s\n", test_name); + break; + case PRINTF_TEST_SKIPPED: +- print_message(" SKIPPED %s\n", test_name); ++ if (skip_note) { ++ print_message(" SKIPPED %s - %s\n", test_name, skip_note); ++ } else { ++ print_message(" SKIPPED %s\n", test_name); ++ } + break; + case PRINTF_TEST_ERROR: + if (error_message != NULL) { +@@ -2867,6 +2890,7 @@ static void cmprintf_tap(enum cm_printf_type type, + size_t test_number, + const char *test_name, + const char *error_message, ++ const char *skip_note, + CMData** test_data) + { + CMData* d; +@@ -2886,7 +2910,11 @@ static void cmprintf_tap(enum cm_printf_type type, + print_error_message = 1; + break; + case PRINTF_TEST_SKIPPED: +- print_message("ok %u - %s # SKIP\n", (unsigned)test_number, test_name); ++ if (skip_note) { ++ print_message("ok %u - %s # SKIP %s\n", (unsigned)test_number, test_name, skip_note); ++ } else { ++ print_message("ok %u - %s # SKIP\n", (unsigned)test_number, test_name); ++ } + break; + } + +@@ -2977,6 +3005,7 @@ static void cmprintf_subunit(enum cm_printf_type type, + } + break; + case PRINTF_TEST_SKIPPED: ++ /* TODO: should we print the explanation in DETAILS region as explained here: https://github.com/testing-cabal/subunit */ + print_message("skip: %s\n", test_name); + break; + case PRINTF_TEST_ERROR: +@@ -3043,6 +3072,7 @@ static void cmprintf(enum cm_printf_type type, + size_t test_number, + const char *test_name, + const char *error_message, ++ const char *skip_note, + CMData** test_data) + { + uint32_t output; +@@ -3050,13 +3080,13 @@ static void cmprintf(enum cm_printf_type type, + output = cm_get_output(); + + if (output & CM_OUTPUT_STANDARD) { +- cmprintf_standard(type, test_name, error_message); ++ cmprintf_standard(type, test_name, error_message, skip_note); + } + if (output & CM_OUTPUT_SUBUNIT) { + cmprintf_subunit(type, test_name, error_message); + } + if (output & CM_OUTPUT_TAP) { +- cmprintf_tap(type, test_number, test_name, error_message, test_data); ++ cmprintf_tap(type, test_number, test_name, error_message, skip_note, test_data); + } + } + +@@ -3298,7 +3328,9 @@ static int cmocka_run_one_tests(struct CMUnitTestState *test_state) + } else { + if (global_skip_test) { + test_state->status = CM_TEST_SKIPPED; ++ test_state->skip_note = global_skip_test_note; + global_skip_test = 0; /* Do not skip the next test */ ++ global_skip_test_note = NULL; + } else { + test_state->status = CM_TEST_FAILED; + } +@@ -3410,7 +3442,7 @@ int _cmocka_run_group_tests(const char *group_name, + struct CMUnitTestState *cmtest = &cm_testsi; + size_t test_number = i + 1; + +- cmprintf(PRINTF_TEST_START, test_number, cmtest->test->name, NULL, NULL); ++ cmprintf(PRINTF_TEST_START, test_number, cmtest->test->name, NULL, NULL, NULL); + + if (group_state != NULL) { + cmtest->state = group_state; +@@ -3428,6 +3460,7 @@ int _cmocka_run_group_tests(const char *group_name, + test_number, + cmtest->test->name, + cmtest->error_message, ++ cmtest->skip_note, + global_test_data); + total_passed++; + break; +@@ -3436,6 +3469,7 @@ int _cmocka_run_group_tests(const char *group_name, + test_number, + cmtest->test->name, + cmtest->error_message, ++ cmtest->skip_note, + global_test_data); + total_skipped++; + break; +@@ -3444,6 +3478,7 @@ int _cmocka_run_group_tests(const char *group_name, + test_number, + cmtest->test->name, + cmtest->error_message, ++ cmtest->skip_note, + global_test_data); + total_failed++; + break; +@@ -3452,6 +3487,7 @@ int _cmocka_run_group_tests(const char *group_name, + test_number, + cmtest->test->name, + "Internal cmocka error", ++ NULL, + NULL); + total_errors++; + break; +@@ -3467,6 +3503,7 @@ int _cmocka_run_group_tests(const char *group_name, + test_number, + cmtest->test->name, + err_msg, ++ NULL, + NULL); + total_errors++; + } +@@ -3479,7 +3516,7 @@ int _cmocka_run_group_tests(const char *group_name, + cm_error_message = NULL; + } + cmprintf(PRINTF_TEST_ERROR, 0, +- group_name, " FAILED GROUP SETUP", NULL); ++ group_name, " FAILED GROUP SETUP", NULL, NULL); + total_errors++; + } + +@@ -3497,7 +3534,7 @@ int _cmocka_run_group_tests(const char *group_name, + cm_error_message = NULL; + } + cmprintf(PRINTF_TEST_ERROR, 0, +- group_name, " FAILED GROUP TEARDOWN", NULL); ++ group_name, " FAILED GROUP TEARDOWN", NULL, NULL); + } + } + +diff --git a/src/cmocka.def b/src/cmocka.def +index edeeffa..3b29014 100644 +--- a/src/cmocka.def ++++ b/src/cmocka.def +@@ -45,6 +45,7 @@ EXPORTS + _function_called + _mock + _skip ++ _skip_with_note + _stop + _test_calloc + _test_free +-- +GitLab + + +From e28858ac8ddab8237497db6330b51d0e0500a6ef Mon Sep 17 00:00:00 2001 +From: maxime <maximeandrighetto@gmail.com> +Date: Tue, 9 Aug 2022 16:50:06 +0900 +Subject: PATCH 5/8 Added support for TODO tests, which represent features to + be implemented. According to the TAP specification, these tests must not be + treated as a test failure if they fail (see + https://testanything.org/tap-version-14-specification.html). + +--- + include/cmocka.h | 24 +++++++ + src/cmocka.c | 175 +++++++++++++++++++++++++++++++++++++++++++---- + src/cmocka.def | 2 + + 3 files changed, 189 insertions(+), 12 deletions(-) + +diff --git a/include/cmocka.h b/include/cmocka.h +index 827e7a0..10138d7 100644 +--- a/include/cmocka.h ++++ b/include/cmocka.h +@@ -1753,6 +1753,26 @@ void stop(void); + #define stop() _stop() + #endif + ++#ifdef DOXYGEN ++/** ++ * @brief Mark the test as TODO, for a feature that is not fully implemented yet. ++ */ ++void todo(void); ++#else ++#define todo() _todo(__FILE__, __LINE__) ++#endif ++ ++#ifdef DOXYGEN ++/** ++ * @brief Mark the test as TODO, for a feature that is not fully implemented yet. ++ * ++ * @paramin note Explanation about why the test is marked as TODO. ++ */ ++void todo_with_note(const char * const note, void); ++#else ++#define todo_with_note(note) _todo_with_note(note, __FILE__, __LINE__) ++#endif ++ + #ifdef DOXYGEN + /** + * @brief Initialize a list of data for the current test. +@@ -2488,6 +2508,10 @@ CMOCKA_NORETURN void _skip_with_note(const char * const note, const char * const + + CMOCKA_NORETURN void _stop(void); + ++void _todo(const char * const file, const int line); ++ ++void _todo_with_note(const char * const note, const char * const file, const int line); ++ + int _attach_test_data(size_t size, const char * const file, const int line); + + int _extend_test_data(size_t size, const char * const file, const int line); +diff --git a/src/cmocka.c b/src/cmocka.c +index 9c8c340..978a477 100644 +--- a/src/cmocka.c ++++ b/src/cmocka.c +@@ -283,6 +283,8 @@ const char *global_last_failed_assert = NULL; + static int global_skip_test; + static const char * global_skip_test_note = NULL; + static int global_stop_test; ++static int global_todo_test; ++static const char * global_todo_test_note = NULL; + + /* Keeps an array of CMData to be printed for TAP output. */ + static CMOCKA_THREAD CMData** global_test_data = NULL; +@@ -377,6 +379,8 @@ enum CMUnitTestStatus { + CM_TEST_FAILED, + CM_TEST_ERROR, + CM_TEST_SKIPPED, ++ CM_TEST_TODO_OK, ++ CM_TEST_TODO, + }; + + struct CMUnitTestState { +@@ -387,6 +391,7 @@ struct CMUnitTestState { + enum CMUnitTestStatus status; /* PASSED, FAILED, ABORT ... */ + double runtime; /* Time calculations */ + const char *skip_note; /* Explanation when the test is skipped */ ++ const char *todo_note; /* Explanation when the test is marked as TODO */ + }; + + /* Exit the currently executing test. */ +@@ -441,6 +446,17 @@ void _stop(void) + exit(EXIT_FAILURE); + } + ++void _todo(const char * const file, const int line) ++{ ++ global_todo_test = 1; ++} ++ ++void _todo_with_note(const char * const note, const char * const file, const int line) ++{ ++ global_todo_test = 1; ++ global_todo_test_note = note; ++} ++ + static void free_test_data(void) { + if (global_test_data) { + CMData* d; +@@ -2661,6 +2677,8 @@ enum cm_printf_type { + PRINTF_TEST_FAILURE, + PRINTF_TEST_ERROR, + PRINTF_TEST_SKIPPED, ++ PRINTF_TEST_TODO_OK, ++ PRINTF_TEST_TODO, + }; + + static int xml_printed; +@@ -2671,6 +2689,8 @@ static void cmprintf_group_finish_xml(const char *group_name, + size_t total_failed, + size_t total_errors, + size_t total_skipped, ++ size_t total_todo_ok, ++ size_t total_todo, + double total_runtime, + struct CMUnitTestState *cm_tests) + { +@@ -2726,13 +2746,15 @@ static void cmprintf_group_finish_xml(const char *group_name, + + fprintf(fp, "<testsuites>\n"); + fprintf(fp, " <testsuite name=\"%s\" time=\"%.3f\" " +- "tests=\"%u\" failures=\"%u\" errors=\"%u\" skipped=\"%u\" >\n", ++ "tests=\"%u\" failures=\"%u\" errors=\"%u\" skipped=\"%u\" todo_ok=\"%u\" todo=\"%u\" >\n", + group_name, + total_runtime, /* seconds */ + (unsigned)total_executed, + (unsigned)total_failed, + (unsigned)total_errors, +- (unsigned)total_skipped); ++ (unsigned)total_skipped, ++ (unsigned)total_todo_ok, ++ (unsigned)total_todo); + + for (i = 0; i < total_executed; i++) { + struct CMUnitTestState *cmtest = &cm_testsi; +@@ -2741,6 +2763,18 @@ static void cmprintf_group_finish_xml(const char *group_name, + cmtest->test->name, cmtest->runtime); + + switch (cmtest->status) { ++ case CM_TEST_TODO_OK: ++ case CM_TEST_TODO: ++ if (cmtest->todo_note) { ++ fprintf(fp, " <todo><!CDATA%s></todo>\n", ++ cmtest->todo_note); ++ } else { ++ fprintf(fp, " <todo/>\n"); ++ } ++ if (cmtest->status == CM_TEST_TODO_OK) { ++ break; ++ } ++ // fall through + case CM_TEST_ERROR: + case CM_TEST_FAILED: + if (cmtest->error_message != NULL) { +@@ -2789,6 +2823,8 @@ static void cmprintf_group_finish_standard(const char *group_name, + size_t total_failed, + size_t total_errors, + size_t total_skipped, ++ size_t total_todo_ok, ++ size_t total_todo, + struct CMUnitTestState *cm_tests) + { + size_t i; +@@ -2799,6 +2835,34 @@ static void cmprintf_group_finish_standard(const char *group_name, + print_error(" PASSED %u test(s).\n", + (unsigned)(total_passed)); + ++ if (total_todo_ok) { ++ print_message(" TODO OK %s: %zu test(s), listed below:\n", ++ group_name, ++ total_todo_ok); ++ for (i = 0; i < total_executed; i++) { ++ struct CMUnitTestState *cmtest = &cm_testsi; ++ ++ if (cmtest->status == CM_TEST_TODO_OK) { ++ print_message(" TODO OK %s\n", cmtest->test->name); ++ } ++ } ++ print_message("\n %u TODO TEST(S) PASSED - Consider promoting to normal test(s).\n", (unsigned)(total_todo_ok)); ++ } ++ ++ if (total_todo) { ++ print_message(" TODO %s: %zu test(s), listed below:\n", ++ group_name, ++ total_todo); ++ for (i = 0; i < total_executed; i++) { ++ struct CMUnitTestState *cmtest = &cm_testsi; ++ ++ if (cmtest->status == CM_TEST_TODO) { ++ print_message(" TODO %s\n", cmtest->test->name); ++ } ++ } ++ print_message("\n %u TODO TEST(S)\n", (unsigned)(total_todo)); ++ } ++ + if (total_skipped) { + print_error(" SKIPPED %s: %zu test(s), listed below:\n", + group_name, +@@ -2832,7 +2896,8 @@ static void cmprintf_group_finish_standard(const char *group_name, + static void cmprintf_standard(enum cm_printf_type type, + const char *test_name, + const char *error_message, +- const char *skip_note) ++ const char *skip_note, ++ const char *todo_note) + { + switch (type) { + case PRINTF_TEST_START: +@@ -2854,6 +2919,23 @@ static void cmprintf_standard(enum cm_printf_type type, + print_message(" SKIPPED %s\n", test_name); + } + break; ++ case PRINTF_TEST_TODO_OK: ++ if (todo_note) { ++ print_message(" TODO OK %s - %s\n", test_name, todo_note); ++ } else { ++ print_message(" TODO OK %s\n", test_name); ++ } ++ break; ++ case PRINTF_TEST_TODO: ++ if (todo_note) { ++ print_message(" TODO %s - %s\n", test_name, todo_note); ++ } else { ++ print_message(" TODO %s\n", test_name); ++ } ++ if (error_message != NULL) { ++ print_error(" ERROR --- %s\n", error_message); ++ } ++ break; + case PRINTF_TEST_ERROR: + if (error_message != NULL) { + print_error("%s\n", error_message); +@@ -2877,10 +2959,12 @@ static void cmprintf_group_start_tap(const size_t num_tests) + static void cmprintf_group_finish_tap(const char *group_name, + size_t total_executed, + size_t total_passed, +- size_t total_skipped) ++ size_t total_skipped, ++ size_t total_todo_ok, ++ size_t total_todo) + { + const char *status = "not ok"; +- if (total_passed + total_skipped == total_executed) { ++ if (total_passed + total_skipped + total_todo_ok + total_todo == total_executed) { + status = "ok"; + } + print_message("# %s - %s\n", status, group_name); +@@ -2891,6 +2975,7 @@ static void cmprintf_tap(enum cm_printf_type type, + const char *test_name, + const char *error_message, + const char *skip_note, ++ const char *todo_note, + CMData** test_data) + { + CMData* d; +@@ -2916,6 +3001,21 @@ static void cmprintf_tap(enum cm_printf_type type, + print_message("ok %u - %s # SKIP\n", (unsigned)test_number, test_name); + } + break; ++ case PRINTF_TEST_TODO_OK: ++ if (todo_note) { ++ print_message("ok %u - %s # TODO %s\n", (unsigned)test_number, test_name, todo_note); ++ } else { ++ print_message("ok %u - %s # TODO\n", (unsigned)test_number, test_name); ++ } ++ break; ++ case PRINTF_TEST_TODO: ++ if (todo_note) { ++ print_message("not ok %u - %s # TODO %s\n", (unsigned)test_number, test_name, todo_note); ++ } else { ++ print_message("not ok %u - %s # TODO\n", (unsigned)test_number, test_name); ++ } ++ print_error_message = 1; ++ break; + } + + if ((print_error_message == 1) && (error_message != NULL)) { +@@ -3004,6 +3104,9 @@ static void cmprintf_subunit(enum cm_printf_type type, + print_message(" \n%s\n\n", error_message); + } + break; ++ case PRINTF_TEST_TODO_OK: ++ case PRINTF_TEST_TODO: ++ /* TODO: not sure about the subunit specification for TODO tests. Looks like they consider them as skipped. */ + case PRINTF_TEST_SKIPPED: + /* TODO: should we print the explanation in DETAILS region as explained here: https://github.com/testing-cabal/subunit */ + print_message("skip: %s\n", test_name); +@@ -3035,6 +3138,8 @@ static void cmprintf_group_finish(const char *group_name, + size_t total_failed, + size_t total_errors, + size_t total_skipped, ++ size_t total_todo_ok, ++ size_t total_todo, + double total_runtime, + struct CMUnitTestState *cm_tests) + { +@@ -3049,13 +3154,17 @@ static void cmprintf_group_finish(const char *group_name, + total_failed, + total_errors, + total_skipped, ++ total_todo_ok, ++ total_todo, + cm_tests); + } + if (output & CM_OUTPUT_TAP) { + cmprintf_group_finish_tap(group_name, + total_executed, + total_passed, +- total_skipped); ++ total_skipped, ++ total_todo_ok, ++ total_todo); + } + if (output & CM_OUTPUT_XML) { + cmprintf_group_finish_xml(group_name, +@@ -3063,6 +3172,8 @@ static void cmprintf_group_finish(const char *group_name, + total_failed, + total_errors, + total_skipped, ++ total_todo_ok, ++ total_todo, + total_runtime, + cm_tests); + } +@@ -3073,6 +3184,7 @@ static void cmprintf(enum cm_printf_type type, + const char *test_name, + const char *error_message, + const char *skip_note, ++ const char *todo_note, + CMData** test_data) + { + uint32_t output; +@@ -3080,13 +3192,13 @@ static void cmprintf(enum cm_printf_type type, + output = cm_get_output(); + + if (output & CM_OUTPUT_STANDARD) { +- cmprintf_standard(type, test_name, error_message, skip_note); ++ cmprintf_standard(type, test_name, error_message, skip_note, todo_note); + } + if (output & CM_OUTPUT_SUBUNIT) { + cmprintf_subunit(type, test_name, error_message); + } + if (output & CM_OUTPUT_TAP) { +- cmprintf_tap(type, test_number, test_name, error_message, skip_note, test_data); ++ cmprintf_tap(type, test_number, test_name, error_message, skip_note, todo_note, test_data); + } + } + +@@ -3324,17 +3436,27 @@ static int cmocka_run_one_tests(struct CMUnitTestState *test_state) + &test_state->state, + NULL); + if (rc == 0) { +- test_state->status = CM_TEST_PASSED; ++ if (global_todo_test) { ++ test_state->status = CM_TEST_TODO_OK; ++ test_state->todo_note = global_todo_test_note; ++ } else { ++ test_state->status = CM_TEST_PASSED; ++ } + } else { + if (global_skip_test) { + test_state->status = CM_TEST_SKIPPED; + test_state->skip_note = global_skip_test_note; + global_skip_test = 0; /* Do not skip the next test */ + global_skip_test_note = NULL; ++ } else if (global_todo_test) { ++ test_state->status = CM_TEST_TODO; ++ test_state->todo_note = global_todo_test_note; + } else { + test_state->status = CM_TEST_FAILED; + } + } ++ global_todo_test = 0; ++ global_todo_test_note = NULL; + rc = 0; + } + +@@ -3380,6 +3502,8 @@ int _cmocka_run_group_tests(const char *group_name, + size_t total_executed = 0; + size_t total_errors = 0; + size_t total_skipped = 0; ++ size_t total_todo_ok = 0; ++ size_t total_todo = 0; + double total_runtime = 0; + size_t i; + int rc; +@@ -3442,7 +3566,7 @@ int _cmocka_run_group_tests(const char *group_name, + struct CMUnitTestState *cmtest = &cm_testsi; + size_t test_number = i + 1; + +- cmprintf(PRINTF_TEST_START, test_number, cmtest->test->name, NULL, NULL, NULL); ++ cmprintf(PRINTF_TEST_START, test_number, cmtest->test->name, NULL, NULL, NULL, NULL); + + if (group_state != NULL) { + cmtest->state = group_state; +@@ -3461,6 +3585,7 @@ int _cmocka_run_group_tests(const char *group_name, + cmtest->test->name, + cmtest->error_message, + cmtest->skip_note, ++ cmtest->todo_note, + global_test_data); + total_passed++; + break; +@@ -3470,6 +3595,7 @@ int _cmocka_run_group_tests(const char *group_name, + cmtest->test->name, + cmtest->error_message, + cmtest->skip_note, ++ cmtest->todo_note, + global_test_data); + total_skipped++; + break; +@@ -3479,15 +3605,37 @@ int _cmocka_run_group_tests(const char *group_name, + cmtest->test->name, + cmtest->error_message, + cmtest->skip_note, ++ cmtest->todo_note, + global_test_data); + total_failed++; + break; ++ case CM_TEST_TODO_OK: ++ cmprintf(PRINTF_TEST_TODO_OK, ++ test_number, ++ cmtest->test->name, ++ cmtest->error_message, ++ cmtest->skip_note, ++ cmtest->todo_note, ++ global_test_data); ++ total_todo_ok++; ++ break; ++ case CM_TEST_TODO: ++ cmprintf(PRINTF_TEST_TODO, ++ test_number, ++ cmtest->test->name, ++ cmtest->error_message, ++ cmtest->skip_note, ++ cmtest->todo_note, ++ global_test_data); ++ total_todo++; ++ break; + default: + cmprintf(PRINTF_TEST_ERROR, + test_number, + cmtest->test->name, + "Internal cmocka error", + NULL, ++ NULL, + NULL); + total_errors++; + break; +@@ -3504,6 +3652,7 @@ int _cmocka_run_group_tests(const char *group_name, + cmtest->test->name, + err_msg, + NULL, ++ NULL, + NULL); + total_errors++; + } +@@ -3516,7 +3665,7 @@ int _cmocka_run_group_tests(const char *group_name, + cm_error_message = NULL; + } + cmprintf(PRINTF_TEST_ERROR, 0, +- group_name, " FAILED GROUP SETUP", NULL, NULL); ++ group_name, " FAILED GROUP SETUP", NULL, NULL, NULL); + total_errors++; + } + +@@ -3534,7 +3683,7 @@ int _cmocka_run_group_tests(const char *group_name, + cm_error_message = NULL; + } + cmprintf(PRINTF_TEST_ERROR, 0, +- group_name, " FAILED GROUP TEARDOWN", NULL, NULL); ++ group_name, " FAILED GROUP TEARDOWN", NULL, NULL, NULL); + } + } + +@@ -3544,6 +3693,8 @@ int _cmocka_run_group_tests(const char *group_name, + total_failed, + total_errors, + total_skipped, ++ total_todo_ok, ++ total_todo, + total_runtime, + cm_tests); + +diff --git a/src/cmocka.def b/src/cmocka.def +index 3b29014..19e09e8 100644 +--- a/src/cmocka.def ++++ b/src/cmocka.def +@@ -51,6 +51,8 @@ EXPORTS + _test_free + _test_malloc + _test_realloc ++ _todo ++ _todo_with_note + _will_return + cmocka_print_error + cmocka_set_message_output +-- +GitLab + + +From a671237d6719c5c9b244ba4c589b8ca7bfc5d2bd Mon Sep 17 00:00:00 2001 +From: maxime <maximeandrighetto@gmail.com> +Date: Tue, 9 Aug 2022 16:51:00 +0900 +Subject: PATCH 6/8 Quick fix on cmprintf_group_finish_standard() because the + line breaks for messages such as "\n %u SKIPPED TEST(S)\n" made them appear + closer to the next list of tests than the lists they are related to. + +--- + src/cmocka.c | 16 ++++++++-------- + 1 file changed, 8 insertions(+), 8 deletions(-) + +diff --git a/src/cmocka.c b/src/cmocka.c +index 978a477..54fb01a 100644 +--- a/src/cmocka.c ++++ b/src/cmocka.c +@@ -2836,7 +2836,7 @@ static void cmprintf_group_finish_standard(const char *group_name, + (unsigned)(total_passed)); + + if (total_todo_ok) { +- print_message(" TODO OK %s: %zu test(s), listed below:\n", ++ print_message("\n TODO OK %s: %zu test(s), listed below:\n", + group_name, + total_todo_ok); + for (i = 0; i < total_executed; i++) { +@@ -2846,11 +2846,11 @@ static void cmprintf_group_finish_standard(const char *group_name, + print_message(" TODO OK %s\n", cmtest->test->name); + } + } +- print_message("\n %u TODO TEST(S) PASSED - Consider promoting to normal test(s).\n", (unsigned)(total_todo_ok)); ++ print_message(" %u TODO TEST(S) PASSED - Consider promoting to normal test(s).\n", (unsigned)(total_todo_ok)); + } + + if (total_todo) { +- print_message(" TODO %s: %zu test(s), listed below:\n", ++ print_message("\n TODO %s: %zu test(s), listed below:\n", + group_name, + total_todo); + for (i = 0; i < total_executed; i++) { +@@ -2860,11 +2860,11 @@ static void cmprintf_group_finish_standard(const char *group_name, + print_message(" TODO %s\n", cmtest->test->name); + } + } +- print_message("\n %u TODO TEST(S)\n", (unsigned)(total_todo)); ++ print_message(" %u TODO TEST(S)\n", (unsigned)(total_todo)); + } + + if (total_skipped) { +- print_error(" SKIPPED %s: %zu test(s), listed below:\n", ++ print_error("\n SKIPPED %s: %zu test(s), listed below:\n", + group_name, + total_skipped); + for (i = 0; i < total_executed; i++) { +@@ -2874,11 +2874,11 @@ static void cmprintf_group_finish_standard(const char *group_name, + print_error(" SKIPPED %s\n", cmtest->test->name); + } + } +- print_error("\n %zu SKIPPED TEST(S)\n", total_skipped); ++ print_error(" %zu SKIPPED TEST(S)\n", total_skipped); + } + + if (total_failed) { +- print_error(" FAILED %s: %zu test(s), listed below:\n", ++ print_error("\n FAILED %s: %zu test(s), listed below:\n", + group_name, + total_failed); + for (i = 0; i < total_executed; i++) { +@@ -2888,7 +2888,7 @@ static void cmprintf_group_finish_standard(const char *group_name, + print_error(" FAILED %s\n", cmtest->test->name); + } + } +- print_error("\n %zu FAILED TEST(S)\n", ++ print_error(" %zu FAILED TEST(S)\n", + (total_failed + total_errors)); + } + } +-- +GitLab + + +From 6c99594f6fb42128565a7bd9108fdf7efeb09ad5 Mon Sep 17 00:00:00 2001 +From: maxime <maximeandrighetto@gmail.com> +Date: Sun, 28 Aug 2022 00:58:11 +0900 +Subject: PATCH 7/8 fixed compilation warnings + +--- + src/cmocka.c | 15 ++++++++------- + 1 file changed, 8 insertions(+), 7 deletions(-) + +diff --git a/src/cmocka.c b/src/cmocka.c +index 54fb01a..cdb8d50 100644 +--- a/src/cmocka.c ++++ b/src/cmocka.c +@@ -468,6 +468,7 @@ static void free_test_data(void) { + switch (d->type) { + case DATA_TYPE_STRING: + free(d->value); ++ break; + default: + break; + } +@@ -2762,21 +2763,19 @@ static void cmprintf_group_finish_xml(const char *group_name, + fprintf(fp, " <testcase name=\"%s\" time=\"%.3f\" >\n", + cmtest->test->name, cmtest->runtime); + +- switch (cmtest->status) { +- case CM_TEST_TODO_OK: +- case CM_TEST_TODO: ++ if ((cmtest->status == CM_TEST_TODO) || (cmtest->status == CM_TEST_TODO_OK)) { + if (cmtest->todo_note) { + fprintf(fp, " <todo><!CDATA%s></todo>\n", + cmtest->todo_note); + } else { + fprintf(fp, " <todo/>\n"); + } +- if (cmtest->status == CM_TEST_TODO_OK) { +- break; +- } +- // fall through ++ } ++ ++ switch (cmtest->status) { + case CM_TEST_ERROR: + case CM_TEST_FAILED: ++ case CM_TEST_TODO: + if (cmtest->error_message != NULL) { + fprintf(fp, " <failure><!CDATA%s></failure>\n", + cmtest->error_message); +@@ -2784,6 +2783,7 @@ static void cmprintf_group_finish_xml(const char *group_name, + fprintf(fp, " <failure message=\"Unknown error\" />\n"); + } + break; ++ + case CM_TEST_SKIPPED: + if (cmtest->skip_note) { + fprintf(fp, " <skipped><!CDATA%s></skipped>\n", +@@ -2795,6 +2795,7 @@ static void cmprintf_group_finish_xml(const char *group_name, + + case CM_TEST_PASSED: + case CM_TEST_NOT_STARTED: ++ case CM_TEST_TODO_OK: + break; + } + +-- +GitLab + + +From 7e3088264336fafb43bc4dbf842c657320a4c749 Mon Sep 17 00:00:00 2001 +From: maxime <maximeandrighetto@gmail.com> +Date: Sun, 28 Aug 2022 01:06:58 +0900 +Subject: PATCH 8/8 Fixed YAML syntax errors that occurred when messages or + string data printed to the TAP output contained quotes or ended with a + newline. + +--- + src/cmocka.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++---- + 1 file changed, 72 insertions(+), 5 deletions(-) + +diff --git a/src/cmocka.c b/src/cmocka.c +index cdb8d50..78288d9 100644 +--- a/src/cmocka.c ++++ b/src/cmocka.c +@@ -2971,6 +2971,43 @@ static void cmprintf_group_finish_tap(const char *group_name, + print_message("# %s - %s\n", status, group_name); + } + ++static char* escape_quotes(const char* str) { ++ size_t len = strlen(str); ++ const char *p1 = str; ++ const char *p2 = NULL; ++ char *result; ++ ++ while ((p1 = strchr(p1, '"'))) { ++ len++; ++ p1++; ++ } ++ ++ result = (char*)malloc(sizeof(char) * (len + 1)); ++ if (!result) { ++ return NULL; ++ } ++ result0 = 0; ++ ++ p1 = str; ++ while ((p2 = strchr(p1, '"'))) { ++#ifdef _WIN32 ++ strncat_s(result, len + 1, p1, p2 - p1); ++ strcat_s(result, len + 1, "\\\""); ++#else ++ strncat(result, p1, p2 - p1); ++ strcat(result, "\\\""); ++#endif ++ p1 = p2 + 1; ++ } ++#ifdef _WIN32 ++ strcat_s(result, len + 1, p1); ++#else ++ strcat(result, p1); ++#endif ++ ++ return result; ++} ++ + static void cmprintf_tap(enum cm_printf_type type, + size_t test_number, + const char *test_name, +@@ -2980,6 +3017,7 @@ static void cmprintf_tap(enum cm_printf_type type, + CMData** test_data) + { + CMData* d; ++ const char *valueStr; + size_t i; + int diagnostics_opened = 0; + int print_error_message = 0; +@@ -3021,19 +3059,33 @@ static void cmprintf_tap(enum cm_printf_type type, + + if ((print_error_message == 1) && (error_message != NULL)) { + char *msg; ++ char *tmp; + char *p; ++ char quoteChar; + const char *indent = ""; + + msg = strdup(error_message); + if (msg == NULL) { + return; + } +- p = msg; ++ ++ // Use double quotes if the message contains single quotes, then escape double quotes if needed. ++ quoteChar = strchr(msg, '\'') ? '"' : '\''; ++ if ((quoteChar == '"') && strchr(msg, '"')) { ++ tmp = escape_quotes(msg); ++ libc_free(msg); ++ if (tmp == NULL) { ++ return; ++ } ++ msg = tmp; ++ } + + print_message(" ---\n"); + diagnostics_opened = 1; + +- print_message(" message: \""); ++ print_message(" message: %c", quoteChar); ++ ++ p = msg; + while (p0 != '\0') { + char *q = p; + +@@ -3042,7 +3094,7 @@ static void cmprintf_tap(enum cm_printf_type type, + p0 = '\0'; + print_message("%s%s\\n\\\n", indent, q); + } else { +- print_message("%s%s\"\n", indent, q); ++ print_message("%s%s", indent, q); + break; + } + p++; +@@ -3050,6 +3102,8 @@ static void cmprintf_tap(enum cm_printf_type type, + } + libc_free(msg); + ++ print_message("%c\n", quoteChar); ++ + print_message(" severity: %s\n", (type == PRINTF_TEST_FAILURE) ? "fail" : "error"); + } + +@@ -3076,8 +3130,21 @@ static void cmprintf_tap(enum cm_printf_type type, + d->name, d->value); + break; + case DATA_TYPE_STRING: +- print_message(" %s: '%s'\n", +- d->name, (const char *)(d->value)); ++ valueStr = (const char *)(d->value); ++ if (strchr(valueStr, '\'')) { ++ if (strchr(valueStr, '"')) { ++ char *escapedVal = escape_quotes(valueStr); ++ print_message(" %s: \"%s\"\n", ++ d->name, escapedVal ? escapedVal : "<MISSING>"); ++ free(escapedVal); ++ } else { ++ print_message(" %s: \"%s\"\n", ++ d->name, valueStr); ++ } ++ } else { ++ print_message(" %s: '%s'\n", ++ d->name, valueStr); ++ } + break; + } + } +-- +GitLab +
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/CMakeLists.txt -> _service:tar_scm:cmocka-1.1.7.tar.xz/CMakeLists.txt
Changed
@@ -15,7 +15,7 @@ include(DefineCompilerFlags) include(DefinePlatformDefaults) -project(cmocka VERSION 1.1.5 LANGUAGES C) +project(cmocka VERSION 1.1.7 LANGUAGES C) # global needed variables set(APPLICATION_NAME ${PROJECT_NAME}) @@ -27,7 +27,7 @@ # Increment AGE. Set REVISION to 0 # If the source code was changed, but there were no interface changes: # Increment REVISION. -set(LIBRARY_VERSION "0.7.0") +set(LIBRARY_VERSION "0.8.0") set(LIBRARY_SOVERSION "0") # include cmake files @@ -65,7 +65,7 @@ endif () # pkg-config file -configure_file(cmocka.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmocka.pc) +configure_file(cmocka.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmocka.pc @ONLY) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/cmocka.pc @@ -75,36 +75,19 @@ pkgconfig ) -# cmake config files -if (WIN32) - set(CMOCKA_LIBRARY_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX}) -else() - set(CMOCKA_LIBRARY_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}) -endif() - -set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE INTERNAL "") -set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE INTERNAL "") -configure_package_config_file(${PROJECT_NAME}-config.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake - PATH_VARS - INCLUDE_INSTALL_DIR LIB_INSTALL_DIR - INSTALL_DESTINATION - ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) - write_basic_package_version_file(${PROJECT_NAME}-config-version.cmake COMPATIBILITY AnyNewerVersion) -install( - FILES - ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake - ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake - DESTINATION - ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} - COMPONENT - devel -) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + COMPONENT devel) # Add 'make dist' target which makes sure to invoke cmake before add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source) + +# Link combile database for clangd +execute_process(COMMAND cmake -E create_symlink + "${cmocka_BINARY_DIR}/compile_commands.json" + "${cmocka_SOURCE_DIR}/compile_commands.json")
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/CPackConfig.cmake -> _service:tar_scm:cmocka-1.1.7.tar.xz/CPackConfig.cmake
Changed
@@ -16,7 +16,11 @@ ### source generator set(CPACK_SOURCE_GENERATOR "TXZ") -set(CPACK_SOURCE_IGNORE_FILES "~$;.swp$;/.svn/;/.git/;.gitignore;/obj*;tags;cscope.*;.ycm_extra_conf.pyc") +set(CPACK_SOURCE_IGNORE_FILES "~$;.swp$;/.git;/.gitignore") +string(APPEND CPACK_SOURCE_IGNORE_FILES ";/build*;/obj*") +string(APPEND CPACK_SOURCE_IGNORE_FILES ";/tags;/cscope\.*") +string(APPEND CPACK_SOURCE_IGNORE_FILES ";/.ycm_extra_conf.pyc;") +string(APPEND CPACK_SOURCE_IGNORE_FILES ";/.clangd;/.cache;/compile_commands.json") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") if (WIN32)
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/ChangeLog -> _service:tar_scm:cmocka-1.1.7.tar.xz/ChangeLog
Changed
@@ -1,3 +1,18 @@ +Thu Feb 23 2023 Andreas Schneider <asn@cryptomilk.org> + * cmocka version 1.1.7 + * Update ignore list for source tarball generation + +Fri Feb 16 2023 Andreas Schneider <asn@cryptomilk.org> + * cmocka version 1.1.6 + * Added new assert macros to compare 2 double given an epsilon + * Added meson build system + * Added header with version to TAP13 output + * Fixed issues with MSVC + * Fixed TAP output for skipped tests + * Fixed issue with fail_msg + * CMake generated configs for find_package(cmocka) + * Documentation improvements + Thu Mar 28 2019 Andreas Schneider <asn@cryptomilk.org> * cmocka version 1.1.5 * Added cmocka_set_skip_filter()
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/ConfigureChecks.cmake -> _service:tar_scm:cmocka-1.1.7.tar.xz/ConfigureChecks.cmake
Changed
@@ -70,6 +70,9 @@ check_struct_has_member("struct timespec" tv_sec "time.h" HAVE_STRUCT_TIMESPEC) endif (HAVE_TIME_H) +# TYPES +check_type_size(uintptr_t UINTPTR_T) + # FUNCTIONS check_function_exists(calloc HAVE_CALLOC) check_function_exists(exit HAVE_EXIT)
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/DefineOptions.cmake -> _service:tar_scm:cmocka-1.1.7.tar.xz/DefineOptions.cmake
Changed
@@ -1,13 +1,5 @@ -option(WITH_STATIC_LIB "Build with a static library" OFF) +option(BUILD_SHARED_LIBS "Build shared libraries" ON) option(WITH_CMOCKERY_SUPPORT "Install a cmockery header" OFF) option(WITH_EXAMPLES "Build examples" ON) option(UNIT_TESTING "Build with unit testing" OFF) option(PICKY_DEVELOPER "Build with picky developer flags" OFF) - -if (WITH_STATIC_LIB) - set(BUILD_STATIC_LIB ON) -endif (WITH_STATIC_LIB) - -if (UNIT_TESTING) - set(BUILD_STATIC_LIB ON) -endif (UNIT_TESTING)
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/INSTALL.md -> _service:tar_scm:cmocka-1.1.7.tar.xz/INSTALL.md
Changed
@@ -1,18 +1,33 @@ -# How to build from source +# Installing cmocka -## Requirements +## Use a package manger (also on Windows) -### Common requirements +If you're using a BSD or Linux distribution, cmocka is already packaged and +you should find it in your package manager. + + <your package manager> install cmocka-devel + or + <your package manager> install libcmocka-devel + +For Windows it is recommended to use: https://vcpkg.io/ + + vcpkg install cmocka + +## Building from source + +### Requirements + +#### Common requirements In order to build cmocka, you need to install several components: - A C compiler -- CMake(http://www.cmake.org) >= 2.8.0. +- CMake(http://www.cmake.org) >= 3.5.0. Note that these version numbers are version we know works correctly. If you build and run cmocka successfully with an older version, please let us know. -## Building +### Building First, you need to configure the compilation, using CMake. Go inside the `build` dir. Create it if it doesn't exist. @@ -29,7 +44,7 @@ available generators for MSVC on Windows. We only support Visual Studio 2013 or newer which supports C99. -### CMake standard options +#### CMake standard options Here is a list of the most interesting options provided out of the box by CMake. @@ -40,7 +55,7 @@ - CMAKE_C_COMPILER: The path to the C compiler - CMAKE_CXX_COMPILER: The path to the C++ compiler -### CMake options defined for cmocka +#### CMake options defined for cmocka Options are defined in the following files: @@ -50,29 +65,31 @@ `cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DUNIT_TESTING=ON ..` -### Browsing/editing CMake options +#### Browsing/editing CMake options In addition to passing options on the command line, you can browse and edit -CMake options using `cmakesetup` (Windows), `cmake-gui` or `ccmake` (GNU/Linux +CMake options using `cmake-gui.exe` (Windows) or `ccmake` (GNU/Linux and MacOS X). - Go to the build dir - On Windows: run `cmakesetup` - On GNU/Linux and MacOS X: run `ccmake ..` -## Installing +More at https://cmake.org/runningcmake/ + +### Installing If you want to install cmocka after compilation run: make install -## Running +### Running The cmocka library can be found in the `build/src` directory. You can run the binaries in `build/examples/*` which is a are example tests. -## Testing +### Testing As mention above you can turn on the unit tests and make it possible to easily execute them:
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/README.md -> _service:tar_scm:cmocka-1.1.7.tar.xz/README.md
Changed
@@ -13,7 +13,8 @@ To compile the cmocka library and example applications run, create a build dir, and in the build dir call 'cmake /path/to/cmocka' followed by 'make'. On -Windows you can use the cmake gui. More details can be found in the INSTALL file. +Windows you can use the cmake gui. More details can be found in the INSTALL.md +file. Website -------
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/cmake/Modules/AddCMockaTest.cmake -> _service:tar_scm:cmocka-1.1.7.tar.xz/cmake/Modules/AddCMockaTest.cmake
Changed
@@ -118,3 +118,26 @@ ) endfunction (ADD_CMOCKA_TEST) + +function(ADD_CMOCKA_TEST_ENVIRONMENT _TARGET_NAME) + if (WIN32 OR CYGWIN OR MINGW OR MSVC) + file(TO_NATIVE_PATH "${cmocka-library_BINARY_DIR}" CMOCKA_DLL_PATH) + + if (TARGET_SYSTEM_EMULATOR) + set(DLL_PATH_ENV "WINEPATH=${CMOCKA_DLL_PATH};$ENV{WINEPATH}") + else() + set(DLL_PATH_ENV "PATH=${CMOCKA_DLL_PATH}\\${CMAKE_BUILD_TYPE};$ENV{PATH}") + endif() + # + # IMPORTANT NOTE: The set_tests_properties(), below, internally + # stores its name/value pairs with a semicolon delimiter. + # because of this we must protect the semicolons in the path + # + string(REPLACE ";" "\\;" DLL_PATH_ENV "${DLL_PATH_ENV}") + + set_tests_properties(${_TARGET_NAME} + PROPERTIES + ENVIRONMENT + "${DLL_PATH_ENV}") + endif() +endfunction()
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/cmocka-build-tree-settings.cmake.in -> _service:tar_scm:cmocka-1.1.7.tar.xz/cmocka-build-tree-settings.cmake.in
Changed
@@ -1,1 +1,3 @@ -set(CMOCKA_INLUDE_DIR @PROJECT_SOURCE_DIR@/include) +set_and_check(CMOCKA_INLUDE_DIR @PROJECT_SOURCE_DIR@/include) +set_and_check(CMOCKA_LIBRARY @PROJECT_BINARY_DIR@/src/@CMOCKA_LIBRARY_NAME@) +set_and_check(CMOCKA_LIBRARIES @PROJECT_BINARY_DIR@/src/@CMOCKA_LIBRARY_NAME@)
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/cmocka.pc.cmake -> _service:tar_scm:cmocka-1.1.7.tar.xz/cmocka.pc.cmake
Changed
@@ -1,5 +1,11 @@ -Name: ${PROJECT_NAME} +# cmocka pkg-config source file + +prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ + +Name: @PROJECT_NAME@ Description: The cmocka unit testing library -Version: ${PROJECT_VERSION} -Libs: -L${CMAKE_INSTALL_FULL_LIBDIR} -lcmocka -Cflags: -I${CMAKE_INSTALL_FULL_INCLUDEDIR} +Version: @PROJECT_VERSION@ +Libs: -L${libdir} -lcmocka +Cflags: -I${includedir}
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/config.h.cmake -> _service:tar_scm:cmocka-1.1.7.tar.xz/config.h.cmake
Changed
@@ -75,6 +75,10 @@ #cmakedefine HAVE_STRUCT_TIMESPEC 1 +/***************************** TYPES *****************************/ + +#cmakedefine HAVE_UINTPTR_T 1 + /*************************** FUNCTIONS ***************************/ /* Define to 1 if you have the `calloc' function. */
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/doc/mainpage.dox -> _service:tar_scm:cmocka-1.1.7.tar.xz/doc/mainpage.dox
Changed
@@ -49,6 +49,7 @@ @code #include <stdarg.h> #include <stddef.h> +#include <stdint.h> #include <setjmp.h> #include <cmocka.h> @@ -79,9 +80,9 @@ Mock objects include some logic and the test driver is able to modify the behaviour and state. The object can call some functions or act on different input (abort a test if it is wrong). The test driver injects what it expects -the mock object to return. CMocka provides and API to easily mock code. +the mock object to return. CMocka provides an API to easily mock code. -<a href="https://lwn.net/Articles/558106/">Learn more ...</a> +Check out the examples <a href="https://git.cryptomilk.org/projects/cmocka.git/tree/example/mock">here</a>. @section main-embedded Embedded platforms
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/example/CMakeLists.txt -> _service:tar_scm:cmocka-1.1.7.tar.xz/example/CMakeLists.txt
Changed
@@ -1,28 +1,5 @@ project(cmocka-examples C) -function(ADD_CMOCKA_TEST_ENVIRONMENT _TARGET_NAME) - if (WIN32 OR CYGWIN OR MINGW) - file(TO_NATIVE_PATH "${cmocka-library_BINARY_DIR}" CMOCKA_DLL_PATH) - - if (TARGET_SYSTEM_EMULATOR) - set(DLL_PATH_ENV "WINEPATH=${CMOCKA_DLL_PATH};$ENV{WINEPATH}") - else() - set(DLL_PATH_ENV "PATH=${CMOCKA_DLL_PATH};$ENV{PATH}") - endif() - # - # IMPORTANT NOTE: The set_tests_properties(), below, internally - # stores its name/value pairs with a semicolon delimiter. - # because of this we must protect the semicolons in the path - # - string(REPLACE ";" "\\;" DLL_PATH_ENV "${DLL_PATH_ENV}") - - set_tests_properties(${_TARGET_NAME} - PROPERTIES - ENVIRONMENT - "${DLL_PATH_ENV}") - endif() -endfunction() - set_source_files_properties(calculator.c allocate_module.c assert_module.c @@ -35,13 +12,16 @@ add_cmocka_test(simple_test SOURCES simple_test.c COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} - LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) + LINK_OPTIONS ${DEFAULT_LINK_FLAGS} + LINK_LIBRARIES cmocka::cmocka) add_cmocka_test_environment(simple_test) ### Allocate module test add_cmocka_test(allocate_module_test SOURCES allocate_module.c allocate_module_test.c - LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) + COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} + LINK_OPTIONS ${DEFAULT_LINK_FLAGS} + LINK_LIBRARIES cmocka::cmocka) add_cmocka_test_environment(allocate_module_test) set_tests_properties(allocate_module_test @@ -51,7 +31,9 @@ ### Assert macro test add_cmocka_test(assert_macro_test SOURCES assert_macro.c assert_macro_test.c - LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) + COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} + LINK_OPTIONS ${DEFAULT_LINK_FLAGS} + LINK_LIBRARIES cmocka::cmocka) add_cmocka_test_environment(assert_macro_test) set_tests_properties(assert_macro_test @@ -61,7 +43,9 @@ ### Assert module test add_cmocka_test(assert_module_test SOURCES assert_module.c assert_module_test.c - LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) + COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} + LINK_OPTIONS ${DEFAULT_LINK_FLAGS} + LINK_LIBRARIES cmocka::cmocka) add_cmocka_test_environment(assert_module_test) set_tests_properties(assert_module_test
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/example/mock/chef_wrap/CMakeLists.txt -> _service:tar_scm:cmocka-1.1.7.tar.xz/example/mock/chef_wrap/CMakeLists.txt
Changed
@@ -7,7 +7,7 @@ ) add_executable(waiter_test_wrap waiter_test_wrap.c chef.c) -target_link_libraries(waiter_test_wrap ${CMOCKA_SHARED_LIBRARY}) +target_link_libraries(waiter_test_wrap cmocka::cmocka) add_test(waiter_test_wrap ${CMAKE_CURRENT_BINARY_DIR}/waiter_test_wrap)
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/example/mock/uptime/CMakeLists.txt -> _service:tar_scm:cmocka-1.1.7.tar.xz/example/mock/uptime/CMakeLists.txt
Changed
@@ -12,7 +12,7 @@ add_cmocka_test(test_uptime SOURCES test_uptime.c COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} - LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) + LINK_LIBRARIES cmocka::cmocka) set_property(TARGET test_uptime PROPERTY
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/include/cmocka.h -> _service:tar_scm:cmocka-1.1.7.tar.xz/include/cmocka.h
Changed
@@ -1,6 +1,6 @@ /* * Copyright 2008 Google Inc. - * Copyright 2014-2018 Andreas Schneider <asn@cryptomilk.org> + * Copyright 2014-2022 Andreas Schneider <asn@cryptomilk.org> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,6 +46,7 @@ * @code * #include <stdarg.h> * #include <stddef.h> + * #include <stdint.h> * #include <setjmp.h> * #include <stdint.h> * @endcode @@ -111,12 +112,16 @@ # define FloatPrintfFormat "%f" #endif /* FloatPrintfFormat */ +#ifndef DoublePrintfFormat +# define DoublePrintfFormat "%f" +#endif /* DoublePrintfFormat */ + /* Perform an unsigned cast to LargestIntegralType. */ #define cast_to_largest_integral_type(value) \ ((LargestIntegralType)(value)) /* Smallest integral type capable of holding a pointer. */ -#if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED) +#if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED) && !defined(HAVE_UINTPTR_T) # if defined(_WIN32) /* WIN32 is an ILP32 platform */ typedef unsigned int uintptr_t; @@ -168,6 +173,14 @@ #define CMOCKA_DEPRECATED #endif +#if defined(__GNUC__) +#define CMOCKA_NORETURN __attribute__ ((noreturn)) +#elif defined(_MSC_VER) +#define CMOCKA_NORETURN __declspec(noreturn) +#else +#define CMOCKA_NORETURN +#endif + #define WILL_RETURN_ALWAYS -1 #define WILL_RETURN_ONCE -2 @@ -175,7 +188,7 @@ * @defgroup cmocka_mock Mock Objects * @ingroup cmocka * - * Mock objects mock objects are simulated objects that mimic the behavior of + * Mock objects are simulated objects that mimic the behavior of * real objects. Instead of calling the real objects, the tested object calls a * mock object that merely asserts that the correct methods were called, with * the expected parameters, in the correct order. @@ -667,7 +680,7 @@ #ifdef DOXYGEN /** - * @brief Add an event to check if a parameter is the given value. + * @brief Add an event to check if a parameter is the given integer based value. * * The event is triggered by calling check_expected() in the mocked function. * @@ -677,7 +690,10 @@ * * @paramin value The value to check. * - * @see check_expected(). + * @see check_expected() + * @see expect_string() + * @see expect_memory() + * @see expect_any() */ void expect_value(#function, #parameter, LargestIntegralType value); #else @@ -687,7 +703,8 @@ #ifdef DOXYGEN /** - * @brief Add an event to repeatedly check if a parameter is the given value. + * @brief Add an event to repeatedly check if a parameter is the given integer + * based value. * * The event is triggered by calling check_expected() in the mocked function. * @@ -702,6 +719,8 @@ * to -1 the value will always be returned. * * @see check_expected(). + * @see expect_not_string() + * @see expect_not_memory() */ void expect_value_count(#function, #parameter, LargestIntegralType value, size_t count); #else @@ -1282,6 +1301,50 @@ __FILE__, __LINE__) #endif +#ifdef DOXYGEN +/** + * @brief Assert that the two given double are equal given an epsilon. + * + * The function prints an error message to standard error and terminates the + * test by calling fail() if the double are not equal (given an epsilon). + * + * @paramin a The first double to compare. + * + * @paramin b The double to compare against the first one. + * + * @paramin epsilon The epsilon used as margin for double comparison. + */ +void assert_double_equal(double a, double b, double epsilon); +#else +#define assert_double_equal(a, b, epsilon) \ + _assert_double_equal((double)a, \ + (double)b, \ + (double)epsilon, \ + __FILE__, __LINE__) +#endif + +#ifdef DOXYGEN +/** + * @brief Assert that the two given double are not equal given an epsilon. + * + * The function prints an error message to standard error and terminates the + * test by calling fail() if the double are not equal (given an epsilon). + * + * @paramin a The first double to compare. + * + * @paramin b The double to compare against the first one. + * + * @paramin epsilon The epsilon used as margin for double comparison. + */ +void assert_double_not_equal(double a, double b, double epsilon); +#else +#define assert_double_not_equal(a, b, epsilon) \ + _assert_double_not_equal((float)a, \ + (double)b, \ + (double)epsilon, \ + __FILE__, __LINE__) +#endif + #ifdef DOXYGEN /** @@ -1297,8 +1360,7 @@ void assert_string_equal(const char *a, const char *b); #else #define assert_string_equal(a, b) \ - _assert_string_equal((const char*)(a), (const char*)(b), __FILE__, \ - __LINE__) + _assert_string_equal((a), (b), __FILE__, __LINE__) #endif #ifdef DOXYGEN @@ -1315,8 +1377,7 @@ void assert_string_not_equal(const char *a, const char *b); #else #define assert_string_not_equal(a, b) \ - _assert_string_not_equal((const char*)(a), (const char*)(b), __FILE__, \ - __LINE__) + _assert_string_not_equal((a), (b), __FILE__, __LINE__) #endif #ifdef DOXYGEN @@ -1473,7 +1534,10 @@ * created (e.g. expect_function_call()) than consumed with function_called(). * There are provisions such as ignore_function_calls() which allow this * restriction to be circumvented in tests where mock calls for the code under - * test are not the focus of the test. + * test are not the focus of the test. function_called() must be called from + * the same thread as expect_function_call(), and that thread must have been + * initialized for use by cmocka (see also the Threading section of the main + * documentation page(index.html#main-threads)). * * The following example illustrates how a unit test instructs cmocka * to expect a function_called() from a particular mock, @@ -1643,7 +1707,7 @@ void fail_msg(const char *msg, ...); #else #define fail_msg(msg, ...) do { \ - print_error("ERROR: " msg "\n", ##__VA_ARGS__); \ + cm_print_error("ERROR: " msg "\n", ##__VA_ARGS__); \ fail(); \ } while (0) #endif @@ -1787,7 +1851,7 @@ * @code * static int setup(void **state) { * int *answer = malloc(sizeof(int)); - * if (*answer == NULL) { + * if (answer == NULL) { * return -1; * } * *answer = 42; @@ -1855,7 +1919,7 @@ * @code * static int setup(void **state) { * int *answer = malloc(sizeof(int)); - * if (*answer == NULL) { + * if (answer == NULL) { * return -1; * } * *answer = 42; @@ -2273,6 +2337,12 @@ void _assert_float_not_equal(const float a, const float n, const float epsilon, const char* const file, const int line); +void _assert_double_equal(const double a, const double n, + const double epsilon, const char* const file, + const int line); +void _assert_double_not_equal(const double a, const double n, + const double epsilon, const char* const file, + const int line); void _assert_int_equal( const LargestIntegralType a, const LargestIntegralType b, const char * const file, const int line); @@ -2308,9 +2378,9 @@ const char* file, const int line); void _test_free(void* const ptr, const char* file, const int line); -void _fail(const char * const file, const int line); +CMOCKA_NORETURN void _fail(const char * const file, const int line); -void _skip(const char * const file, const int line); +CMOCKA_NORETURN void _skip(const char * const file, const int line); int _run_test( const char * const function_name, const UnitTestFunction Function, @@ -2333,6 +2403,7 @@ void print_error(const char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2); void vprint_message(const char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0); void vprint_error(const char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0); +void cm_print_error(const char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2); enum cm_message_output { CM_OUTPUT_STDOUT,
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/include/cmocka_private.h -> _service:tar_scm:cmocka-1.1.7.tar.xz/include/cmocka_private.h
Changed
@@ -28,6 +28,7 @@ # ifdef _MSC_VER # include <stdio.h> /* _snprintf */ +# include <string.h> /* strtok_s */ # undef inline # define inline __inline @@ -38,6 +39,7 @@ # define strcasecmp _stricmp # define strncasecmp _strnicmp +# define strtok_r strtok_s # if defined(HAVE__SNPRINTF_S) # undef snprintf
View file
_service:tar_scm:cmocka-1.1.7.tar.xz/meson.build
Added
@@ -0,0 +1,60 @@ +project('cmocka', 'c', + version : '1.1.5', + license : 'Apache-2.0') + +cc = meson.get_compiler('c') + +conf = configuration_data() + +foreach hdr : 'assert.h', 'inttypes.h', 'io.h', 'malloc.h', 'memory.h', + 'setjmp.h', 'signal.h', 'stdarg.h', 'stddef.h', 'stdint.h', + 'stdio.h', 'stdlib.h', 'string.h', 'strings.h', 'sys/stat.h', + 'sys/types.h', 'time.h', 'unistd.h' + conf.set('HAVE_@0@'.format(hdr.underscorify().to_upper()), cc.has_header(hdr)) +endforeach + +code = '''#include <time.h> +int a = sizeof(struct timespec); +''' +conf.set('HAVE_STRUCT_TIMESPEC', cc.compiles(code, name : 'struct timepec')) + +foreach func: 'calloc', 'exit', 'fprintf', 'free', 'longjmp', 'siglongjmp', + 'malloc', 'memcpy', 'memset', 'printf', 'setjmp', 'signal', + 'strsignal', 'strcmp', 'clock_gettime' + conf.set('HAVE_@0@'.format(func.to_upper()), cc.has_function(func)) +endforeach + +code = '__thread int tls;' +conf.set('HAVE_GCC_THREAD_LOCAL_STORAGE', cc.compiles(code, name : '__thread')) + +code = '''#include <time.h> +clockid_t t = CLOCK_REALTIME;''' +conf.set('HAVE_CLOCK_REALTIME', cc.compiles(code, name : 'CLOCK_REALTIME')) + +configure_file(output : 'config.h', configuration : conf) + +cmocka_includes = include_directories('.'), include_directories('include') +libcmocka = library('cmocka', 'src/cmocka.c', + c_args : '-DHAVE_CONFIG_H', + include_directories : cmocka_includes, + install : meson.is_subproject(), + override_options : 'c_std=gnu99', + dependencies : cc.find_library('rt', required : false)) + +if meson.is_subproject() + cmocka_dep = declare_dependency(include_directories : cmocka_includes, + link_with : libcmocka) +else + install_headers('include/cmocka.h') + + pkgconfig = import('pkgconfig') + pkgconfig.generate(libraries : libcmocka, + version : meson.project_version(), + name : 'cmocka', + filebase : 'cmocka', + description : 'The cmocka unit testing library') +endif + +if get_option('unit_testing') + subdir('tests') +endif
View file
_service:tar_scm:cmocka-1.1.7.tar.xz/meson_options.txt
Added
@@ -0,0 +1,1 @@ +option('unit_testing', type: 'boolean', value: false)
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/src/CMakeLists.txt -> _service:tar_scm:cmocka-1.1.7.tar.xz/src/CMakeLists.txt
Changed
@@ -3,18 +3,6 @@ set(CMOCKA_PLATFORM_INCLUDE CACHE PATH "Path to include directory for cmocka_platform.h") mark_as_advanced(CMOCKA_PLATFORM_INCLUDE) -set(CMOCKA_SHARED_LIBRARY - cmocka - CACHE INTERNAL "cmocka shared library" -) - -if (BUILD_STATIC_LIB) - set(CMOCKA_STATIC_LIBRARY - cmocka-static - CACHE INTERNAL "cmocka static library" - ) -endif() - set(CMOCKA_LINK_LIBRARIES ${CMOCKA_REQUIRED_LIBRARIES} CACHE INTERNAL "cmocka link libraries" @@ -31,93 +19,88 @@ ) endif (WIN32) -add_library(${CMOCKA_SHARED_LIBRARY} SHARED ${cmocka_SRCS}) +add_library(cmocka ${cmocka_SRCS}) -target_include_directories(${CMOCKA_SHARED_LIBRARY} +target_include_directories(cmocka PRIVATE ${CMOCKA_PLATFORM_INCLUDE} ${cmocka_BINARY_DIR} PUBLIC - ${cmocka-header_SOURCE_DIR}) - + $<BUILD_INTERFACE:${cmocka-header_SOURCE_DIR}> + $<INSTALL_INTERFACE:include>) -target_compile_options(${CMOCKA_SHARED_LIBRARY} +target_compile_options(cmocka PRIVATE ${DEFAULT_C_COMPILE_FLAGS} -DHAVE_CONFIG_H) if (CMOCKA_PLATFORM_INCLUDE) - target_compile_options(${CMOCKA_SHARED_LIBRARY} + target_compile_options(cmocka PRIVATE -DCMOCKA_PLATFORM_INCLUDE) endif() -target_link_libraries(${CMOCKA_SHARED_LIBRARY} ${CMOCKA_LINK_LIBRARIES}) +target_link_libraries(cmocka PRIVATE ${CMOCKA_LINK_LIBRARIES}) set_property(TARGET - ${CMOCKA_SHARED_LIBRARY} + cmocka PROPERTY DEFINE_SYMBOL CMOCKA_EXPORTS - PROPERTY - LINKER_FLAGS - "${DEFAULT_LINK_FLAGS}") +) -if (NOT WIN32) - set_target_properties( - ${CMOCKA_SHARED_LIBRARY} - PROPERTIES +set_property(TARGET + cmocka + PROPERTY VERSION ${LIBRARY_VERSION} +) +set_property(TARGET + cmocka + PROPERTY SOVERSION - ${LIBRARY_SOVERSION} - ) -endif (NOT WIN32) - -install(TARGETS - ${CMOCKA_SHARED_LIBRARY} - ARCHIVE DESTINATION - ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION - ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION - ${CMAKE_INSTALL_BINDIR} - COMPONENT - ${PROJECT_NAME}) - -if (BUILD_STATIC_LIB) - add_library(${CMOCKA_STATIC_LIBRARY} STATIC ${cmocka_SRCS}) - - target_include_directories(${CMOCKA_STATIC_LIBRARY} + ${LIBRARY_SOVERSION}) + +set_property(TARGET + cmocka + PROPERTY + LINK_FLAGS + "${DEFAULT_LINK_FLAGS}") + +add_library(cmocka::cmocka ALIAS cmocka) + +install(TARGETS cmocka + EXPORT cmocka-config + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${PROJECT_NAME}) + +install(EXPORT cmocka-config + NAMESPACE cmocka:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cmocka) + +if (UNIT_TESTING) + # Internal library + add_library(cmocka-static STATIC ${cmocka_SRCS}) + + target_include_directories(cmocka-static PRIVATE ${CMOCKA_PLATFORM_INCLUDE} ${cmocka_BINARY_DIR} PUBLIC ${cmocka-header_SOURCE_DIR}) - target_compile_options(${CMOCKA_STATIC_LIBRARY} + + target_compile_options(cmocka-static PRIVATE ${DEFAULT_C_COMPILE_FLAGS} -DHAVE_CONFIG_H) if (CMOCKA_PLATFORM_INCLUDE) - target_compile_options(${CMOCKA_STATIC_LIBRARY} + target_compile_options(cmocka-static PRIVATE -DCMOCKA_PLATFORM_INCLUDE) endif() - set_property(TARGET - ${CMOCKA_STATIC_LIBRARY} - PROPERTY - DEFINE_SYMBOL - CMOCKA_EXPORTS - PROPERTY - LINK_FLAGS - "${DEFAULT_LINK_FLAGS}") - - if (WITH_STATIC_LIB) - install(TARGETS - ${CMOCKA_STATIC_LIBRARY} - ARCHIVE DESTINATION - ${CMAKE_INSTALL_LIBDIR} - COMPONENT - ${PROJECT_NAME}) - endif() -endif (BUILD_STATIC_LIB) + target_link_libraries(cmocka-static PRIVATE ${CMOCKA_LINK_LIBRARIES}) + + add_library(cmocka::static ALIAS cmocka-static) +endif()
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/src/cmocka.c -> _service:tar_scm:cmocka-1.1.7.tar.xz/src/cmocka.c
Changed
@@ -42,6 +42,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <stdbool.h> #include <time.h> #include <float.h> @@ -70,7 +71,9 @@ #define MALLOC_ALLOC_PATTERN 0xBA #define MALLOC_FREE_PATTERN 0xCD /* Alignment of allocated blocks. NOTE: This must be base2. */ +#ifndef MALLOC_ALIGNMENT #define MALLOC_ALIGNMENT sizeof(size_t) +#endif /* Printf formatting for source code locations. */ #define SOURCE_LOCATION_FORMAT "%s:%u" @@ -108,37 +111,17 @@ /* - * Declare and initialize the pointer member of ValuePointer variable name - * with ptr. + * Declare and initialize a LargestIntegralType variable name + * with value the conversion of ptr. */ #define declare_initialize_value_pointer_pointer(name, ptr) \ - ValuePointer name ; \ - name.value = 0; \ - name.x.pointer = (void*)(ptr) + LargestIntegralType name ; \ + name = (LargestIntegralType) (uintptr_t) ptr -/* - * Declare and initialize the value member of ValuePointer variable name - * with val. - */ -#define declare_initialize_value_pointer_value(name, val) \ - ValuePointer name ; \ - name.value = val - -/* Cast a LargestIntegralType to pointer_type via a ValuePointer. */ +/* Cast a LargestIntegralType to pointer_type. */ #define cast_largest_integral_type_to_pointer( \ pointer_type, largest_integral_type) \ - ((pointer_type)((ValuePointer*)&(largest_integral_type))->x.pointer) - -/* Used to cast LargetIntegralType to void* and vice versa. */ -typedef union ValuePointer { - LargestIntegralType value; - struct { -#if defined(WORDS_BIGENDIAN) && (WORDS_SIZEOF_VOID_P == 4) - unsigned int padding; -#endif - void *pointer; - } x; -} ValuePointer; + ((pointer_type)(uintptr_t)(largest_integral_type)) /* Doubly linked list node. */ typedef struct ListNode { @@ -273,8 +256,6 @@ static int cm_error_message_enabled = 1; static CMOCKA_THREAD char *cm_error_message; -void cm_print_error(const char * const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2); - /* * Keeps track of the calling context returned by setenv() so that the fail() * method can jump out of a test. @@ -414,6 +395,9 @@ cm_print_error(SOURCE_LOCATION_FORMAT ": Skipped!\n", file, line); global_skip_test = 1; exit_test(1); + + /* Unreachable */ + exit(-1); } /* Initialize a SourceLocation structure. */ @@ -720,9 +704,16 @@ SymbolMapValue * const map_value = (SymbolMapValue*)value; const LargestIntegralType children = cast_ptr_to_largest_integral_type(cleanup_value_data); assert_non_null(value); - list_free(&map_value->symbol_values_list_head, - children ? free_symbol_map_value : free_value, - (void *) ((uintptr_t)children - 1)); + if (children == 0) { + list_free(&map_value->symbol_values_list_head, + free_value, + NULL); + } else { + list_free(&map_value->symbol_values_list_head, + free_symbol_map_value, + (void *)((uintptr_t)children - 1)); + } + free(map_value); } @@ -901,7 +892,7 @@ child_node = child_node->next, ++leftover_count) { const FuncOrderingValue *const o = (const FuncOrderingValue*) child_node->value; - cm_print_error(error_message, "%s", o->function); + cm_print_error("%s: %s", error_message, o->function); cm_print_error(SOURCE_LOCATION_FORMAT ": note: remaining item was declared here\n", o->location.file, o->location.line); @@ -933,7 +924,7 @@ if (!list_empty(child_list)) { if (number_of_symbol_names == 1) { const ListNode *child_node; - cm_print_error(error_message, "%s", value->symbol_name); + cm_print_error("%s: %s", error_message, value->symbol_name); for (child_node = child_list->next; child_node != child_list; child_node = child_node->next) { @@ -1146,10 +1137,10 @@ absLeft = (left >= 0.f) ? left : -left; absRight = (right >= 0.f) ? right : -right; - largest = (absRight > absLeft) ? absRight : absLeft; + largest = (absRight > absLeft) ? absRight : absLeft; relDiff = largest * FLT_EPSILON; - if (diff > relDiff) { + if (diff > relDiff) { return 0; } return 1; @@ -1181,6 +1172,73 @@ return not_equal; } +/* Returns 1 if the specified double values are equal, else returns 0. */ +static int double_compare(const double left, + const double right, + const double epsilon) { + double absLeft; + double absRight; + double largest; + double relDiff; + + double diff = left - right; + diff = (diff >= 0.f) ? diff : -diff; + + /* + * Check if the numbers are really close -- needed + * when comparing numbers near zero. + */ + if (diff <= epsilon) { + return 1; + } + + absLeft = (left >= 0.f) ? left : -left; + absRight = (right >= 0.f) ? right : -right; + + largest = (absRight > absLeft) ? absRight : absLeft; + relDiff = largest * FLT_EPSILON; + + if (diff > relDiff) { + return 0; + } + + return 1; +} + +/* + * Returns 1 if the specified double values are equal. If the values are not + * equal an error is displayed and 0 is returned. + */ +static int double_values_equal_display_error(const double left, + const double right, + const double epsilon) { + const int equal = double_compare(left, right, epsilon); + + if (!equal) { + cm_print_error(DoublePrintfFormat " != " + DoublePrintfFormat "\n", left, right); + } + + return equal; +} + +/* + * Returns 1 if the specified double values are different. If the values are + * equal an error is displayed and 0 is returned. + */ +static int double_values_not_equal_display_error(const double left, + const double right, + const double epsilon) { + const int not_equal = (double_compare(left, right, epsilon) == 0); + + if (!not_equal) { + cm_print_error(DoublePrintfFormat " == " + DoublePrintfFormat "\n", left, right); + } + + return not_equal; +} + /* Returns 1 if the specified values are equal. If the values are not equal * an error is displayed and 0 is returned. */ static int values_equal_display_error(const LargestIntegralType left, @@ -1410,7 +1468,7 @@ check_integer_set->size_of_set = number_of_values; _expect_check( function, parameter, file, line, check_function, - check_data.value, &check_integer_set->event, count); + check_data, &check_integer_set->event, count); } @@ -1473,7 +1531,7 @@ check_integer_range->minimum = minimum; check_integer_range->maximum = maximum; _expect_check(function, parameter, file, line, check_function, - check_data.value, &check_integer_range->event, count); + check_data, &check_integer_range->event, count); } @@ -1552,7 +1610,7 @@ declare_initialize_value_pointer_pointer(string_pointer, discard_const(string)); _expect_check(function, parameter, file, line, check_string, - string_pointer.value, NULL, count); + string_pointer, NULL, count); } @@ -1574,7 +1632,7 @@ declare_initialize_value_pointer_pointer(string_pointer, discard_const(string)); _expect_check(function, parameter, file, line, check_not_string, - string_pointer.value, NULL, count); + string_pointer, NULL, count); } /* CheckParameterValue callback to check whether a parameter equals an area of @@ -1607,7 +1665,7 @@ check_data->memory = mem; check_data->size = size; _expect_check(function, parameter, file, line, check_function, - check_data_pointer.value, &check_data->event, count); + check_data_pointer, &check_data->event, count); } @@ -1793,6 +1851,26 @@ } } +void _assert_double_equal(const double a, + const double b, + const double epsilon, + const char * const file, + const int line) { + if (!double_values_equal_display_error(a, b, epsilon)) { + _fail(file, line); + } +} + +void _assert_double_not_equal(const double a, + const double b, + const double epsilon, + const char * const file, + const int line) { + if (!double_values_not_equal_display_error(a, b, epsilon)) { + _fail(file, line); + } +} + void _assert_int_equal( const LargestIntegralType a, const LargestIntegralType b, const char * const file, const int line) { @@ -2194,11 +2272,14 @@ break; } exit_test(1); + + /* Unreachable */ + exit(-1); } #ifndef _WIN32 -static void exception_handler(int sig) { +CMOCKA_NORETURN static void exception_handler(int sig) { const char *sig_strerror = ""; #ifdef HAVE_STRSIGNAL @@ -2208,6 +2289,9 @@ cm_print_error("Test failed with exception: %s(%d)", sig_strerror, sig); exit_test(1); + + /* Unreachable */ + exit(-1); } #else /* _WIN32 */ @@ -2260,8 +2344,10 @@ } /* Standard output and error print methods. */ -void vprint_message(const char* const format, va_list args) { - char buffer1024; +void vprint_message(const char* const format, va_list args) +{ + char buffer4096; + vsnprintf(buffer, sizeof(buffer), format, args); printf("%s", buffer); fflush(stdout); @@ -2271,8 +2357,10 @@ } -void vprint_error(const char* const format, va_list args) { - char buffer1024; +void vprint_error(const char* const format, va_list args) +{ + char buffer4096; + vsnprintf(buffer, sizeof(buffer), format, args); fprintf(stderr, "%s", buffer); fflush(stderr); @@ -2434,13 +2522,16 @@ } } -static void cmprintf_group_start_standard(const size_t num_tests) +static void cmprintf_group_start_standard(const char *group_name, + const size_t num_tests) { - print_message("========== Running %u test(s).\n", - (unsigned)num_tests); + print_message("========== %s: Running %zu test(s).\n", + group_name, + num_tests); } -static void cmprintf_group_finish_standard(size_t total_executed, +static void cmprintf_group_finish_standard(const char *group_name, + size_t total_executed, size_t total_passed, size_t total_failed, size_t total_errors, @@ -2449,12 +2540,16 @@ { size_t i; - print_message("========== %u test(s) run.\n", (unsigned)total_executed); + print_message("========== %s: %zu test(s) run.\n", + group_name, + total_executed); print_error(" PASSED %u test(s).\n", (unsigned)(total_passed)); if (total_skipped) { - print_error(" SKIPPED %"PRIdS " test(s), listed below:\n", total_skipped); + print_error(" SKIPPED %s: %zu test(s), listed below:\n", + group_name, + total_skipped); for (i = 0; i < total_executed; i++) { struct CMUnitTestState *cmtest = &cm_testsi; @@ -2462,11 +2557,13 @@ print_error(" SKIPPED %s\n", cmtest->test->name); } } - print_error("\n %u SKIPPED TEST(S)\n", (unsigned)(total_skipped)); + print_error("\n %zu SKIPPED TEST(S)\n", total_skipped); } if (total_failed) { - print_error(" FAILED %"PRIdS " test(s), listed below:\n", total_failed); + print_error(" FAILED %s: %zu test(s), listed below:\n", + group_name, + total_failed); for (i = 0; i < total_executed; i++) { struct CMUnitTestState *cmtest = &cm_testsi; @@ -2474,8 +2571,8 @@ print_error(" FAILED %s\n", cmtest->test->name); } } - print_error("\n %u FAILED TEST(S)\n", - (unsigned)(total_failed + total_errors)); + print_error("\n %zu FAILED TEST(S)\n", + (total_failed + total_errors)); } } @@ -2510,6 +2607,12 @@ static void cmprintf_group_start_tap(const size_t num_tests) { + static bool version_printed = false; + if (!version_printed) { + print_message("TAP version 13\n"); + version_printed = true; + } + print_message("1..%u\n", (unsigned)num_tests); } @@ -2526,7 +2629,7 @@ } static void cmprintf_tap(enum cm_printf_type type, - uint32_t test_number, + size_t test_number, const char *test_name, const char *error_message) { @@ -2567,7 +2670,7 @@ } break; case PRINTF_TEST_SKIPPED: - print_message("not ok %u # SKIP %s\n", (unsigned)test_number, test_name); + print_message("ok %u # SKIP %s\n", (unsigned)test_number, test_name); break; case PRINTF_TEST_ERROR: print_message("not ok %u - %s %s\n", @@ -2602,7 +2705,8 @@ } } -static void cmprintf_group_start(const size_t num_tests) +static void cmprintf_group_start(const char *group_name, + const size_t num_tests) { enum cm_message_output output; @@ -2610,7 +2714,7 @@ switch (output) { case CM_OUTPUT_STDOUT: - cmprintf_group_start_standard(num_tests); + cmprintf_group_start_standard(group_name, num_tests); break; case CM_OUTPUT_SUBUNIT: break; @@ -2637,17 +2741,21 @@ switch (output) { case CM_OUTPUT_STDOUT: - cmprintf_group_finish_standard(total_executed, - total_passed, - total_failed, - total_errors, - total_skipped, - cm_tests); + cmprintf_group_finish_standard(group_name, + total_executed, + total_passed, + total_failed, + total_errors, + total_skipped, + cm_tests); break; case CM_OUTPUT_SUBUNIT: break; case CM_OUTPUT_TAP: - cmprintf_group_finish_tap(group_name, total_executed, total_passed, total_skipped); + cmprintf_group_finish_tap(group_name, + total_executed, + total_passed, + total_skipped); break; case CM_OUTPUT_XML: cmprintf_group_finish_xml(group_name, @@ -2743,7 +2851,7 @@ diff = cm_tspecdiff(clock1, clock0); - ret = diff.tv_sec; + ret = (double) diff.tv_sec; ret += (double) diff.tv_nsec / (double) 1E9; return ret; @@ -3010,7 +3118,7 @@ } } - cmprintf_group_start(total_tests); + cmprintf_group_start(group_name, total_tests); rc = 0; @@ -3129,7 +3237,7 @@ libc_free(cm_tests); fail_if_blocks_allocated(group_check_point, "cmocka_group_tests"); - return total_failed + total_errors; + return (int)(total_failed + total_errors); } /**************************************************************************** @@ -3371,7 +3479,7 @@ int _run_group_tests(const UnitTest * const tests, const size_t number_of_tests) { UnitTestFunction setup = NULL; - const char *setup_name; + const char *setup_name = NULL; size_t num_setups = 0; UnitTestFunction teardown = NULL; const char *teardown_name = NULL;
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/src/cmocka.def -> _service:tar_scm:cmocka-1.1.7.tar.xz/src/cmocka.def
Changed
@@ -1,5 +1,7 @@ LIBRARY cmocka EXPORTS + _assert_double_equal + _assert_double_not_equal _assert_float_equal _assert_float_not_equal _assert_in_range
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/tests/CMakeLists.txt -> _service:tar_scm:cmocka-1.1.7.tar.xz/tests/CMakeLists.txt
Changed
@@ -1,6 +1,10 @@ project(tests C) set(TEST_EXCEPTION_HANDLER TRUE) +if (WIN32) + # FIXME: The exception handler doesn't work on Windows + set(TEST_EXCEPTION_HANDLER FALSE) +endif() if (CMAKE_BUILD_TYPE) string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) if (CMAKE_BUILD_TYPE_LOWER STREQUAL "undefinedsanitizer") @@ -16,6 +20,7 @@ test_group_fixtures test_groups test_float_macros + test_double_macros test_assert_macros test_assert_macros_fail test_basics @@ -26,8 +31,10 @@ test_ordering_fail test_returns test_returns_fail + test_string test_wildcard test_skip_filter + test_cmockery ) if (TEST_EXCEPTION_HANDLER) @@ -38,20 +45,17 @@ add_cmocka_test(${_CMOCKA_TEST} SOURCES ${_CMOCKA_TEST}.c COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} - LINK_LIBRARIES ${CMOCKA_STATIC_LIBRARY} + LINK_LIBRARIES cmocka::static LINK_OPTIONS ${DEFAULT_LINK_FLAGS}) target_include_directories(${_CMOCKA_TEST} PRIVATE ${cmocka_BINARY_DIR}) + + add_cmocka_test_environment(${_CMOCKA_TEST}) endforeach() ### Special Cases if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)") set_source_files_properties(test_cmockery.c PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations") endif() -add_cmocka_test(test_cmockery - SOURCES test_cmockery.c - COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} - LINK_LIBRARIES ${CMOCKA_STATIC_LIBRARY} - LINK_OPTIONS ${DEFAULT_LINK_FLAGS}) ### Exceptions @@ -68,7 +72,7 @@ test_assert_macros_fail PROPERTIES PASS_REGULAR_EXPRESSION - "\\ FAILED \\ 1 test" + "\\ FAILED \\ tests: 1 test" ) # test_ordering ensure proper failures @@ -76,7 +80,7 @@ test_ordering_fail PROPERTIES PASS_REGULAR_EXPRESSION - "\\ FAILED \\ 7 test" + "\\ FAILED \\ tests: 7 test" ) # test_returns_fail ensure proper failures @@ -84,22 +88,15 @@ test_returns_fail PROPERTIES PASS_REGULAR_EXPRESSION - "\\ FAILED \\ 3 test" + "\\ FAILED \\ alloc_tests: 3 test" ) # test_exception_handler if (TEST_EXCEPTION_HANDLER) - if (WIN32) - set_tests_properties(test_exception_handler - PROPERTIES - PASS_REGULAR_EXPRESSION - "EXCEPTION_ACCESS_VIOLATION occurred at") - else() - set_tests_properties(test_exception_handler - PROPERTIES - PASS_REGULAR_EXPRESSION - "Test failed with exception: (Segmentation fault|Segmentation Fault|11|Illegal instruction)") - endif (WIN32) + set_tests_properties(test_exception_handler + PROPERTIES + PASS_REGULAR_EXPRESSION + "Test failed with exception") endif (TEST_EXCEPTION_HANDLER) set_tests_properties( @@ -124,6 +121,7 @@ ) add_test(test_setup_fail_1_failed ${TARGET_SYSTEM_EMULATOR} test_setup_fail) +add_cmocka_test_environment(test_setup_fail_1_failed) set_tests_properties( test_setup_fail_1_failed PROPERTIES @@ -132,6 +130,7 @@ ) add_test (test_setup_fail_1_passed ${TARGET_SYSTEM_EMULATOR} test_setup_fail) +add_cmocka_test_environment(test_setup_fail_1_passed) set_tests_properties( test_setup_fail_1_passed PROPERTIES @@ -140,6 +139,7 @@ ) add_test (test_setup_fail_match_failed ${TARGET_SYSTEM_EMULATOR} test_setup_fail) +add_cmocka_test_environment(test_setup_fail_match_failed) set_tests_properties( test_setup_fail_match_failed PROPERTIES @@ -148,6 +148,7 @@ ) add_test (test_setup_fail_match_passed ${TARGET_SYSTEM_EMULATOR} test_setup_fail) +add_cmocka_test_environment(test_setup_fail_match_passed) set_tests_properties( test_setup_fail_match_passed PROPERTIES @@ -171,23 +172,26 @@ xml) set(test_basics_tap_out - "^1\\.\\.2" + "^TAP version 13" + "1\\.\\.2" "ok 1 - null_test_success" "ok 2 - int_test_success" "# ok - tests") set(test_assert_macros_fail_tap_out - "^1\\.\\.1" + "^TAP version 13" + "1\\.\\.1" "not ok 1 - test_assert_return_code_fail" "#^\n\r+\n\r#^\n\r+\n\r# not ok - tests") set(test_groups_tap_out - "^1\\.\\.1" + "^TAP version 13" + "1\\.\\.1" "ok 1 - null_test_success" "# ok - test_group1" "1\\.\\.1" "ok 1 - int_test_success" "# ok - test_group2") set(test_skip_tap_out - "not ok 1 # SKIP") + "ok 1 # SKIP") set(test_setup_fail_tap_out "not ok 1 - int_test_ignored Could not run test: Test setup failed") @@ -234,10 +238,12 @@ foreach(_OUTPUT_TEST ${OUTPUT_TESTS}) set(TEST_NAME ${_OUTPUT_TEST}_${_TEST_OUTPUT_FMT}) add_test(${TEST_NAME} ${TARGET_SYSTEM_EMULATOR} ${_OUTPUT_TEST}) + add_cmocka_test_environment(${TEST_NAME}) set_property( TEST ${TEST_NAME} + APPEND PROPERTY ENVIRONMENT CMOCKA_MESSAGE_OUTPUT=${_TEST_OUTPUT_FMT} )
View file
_service:tar_scm:cmocka-1.1.7.tar.xz/tests/meson.build
Added
@@ -0,0 +1,30 @@ +tests = { + 'alloc': false, + 'group_setup_assert': true, + 'group_setup_fail': true, + 'fixtures': false, + 'group_fixtures': false, + 'groups': false, + 'float_macros': false, + 'assert_macros': false, + 'assert_macros_fail': true, + 'basics': false, + 'skip': false, + 'strmatch': false, + 'setup_fail': true, + 'ordering': false, + 'ordering_fail': true, + 'returns': false, + 'returns_fail': true, + 'wildcard': false, + 'skip_filter': false, + 'cmockery': false +} + +foreach name, should_fail: tests + exe = executable(name, + 'test_@0@.c'.format(name), + include_directories: cmocka_includes, + link_with: libcmocka) + test(name, exe, should_fail: should_fail) +endforeach
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/tests/test_assert_macros.c -> _service:tar_scm:cmocka-1.1.7.tar.xz/tests/test_assert_macros.c
Changed
@@ -19,7 +19,7 @@ **************************************/ static void test_assert_return_code(void **state) { - struct stat sb; + struct stat sb = {0}; int rc; (void)state; /* unused */
View file
_service:tar_scm:cmocka-1.1.7.tar.xz/tests/test_double_macros.c
Added
@@ -0,0 +1,40 @@ +/* + * Copyright 2019 Arnaud Gelas <arnaud.gelas@sensefly.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* Use the unit test allocators */ +#define UNIT_TESTING 1 + +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> + +/* A test case that does check if double is equal. */ +static void double_test_success(void **state) +{ + (void)state; /* unused */ + + assert_double_equal(0.5, 1. / 2., 0.000001); + assert_double_not_equal(0.5, 0.499, 0.000001); +} + +int main(void) { + const struct CMUnitTest tests = { + cmocka_unit_test(double_test_success), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +}
View file
_service:tar_scm:cmocka-1.1.5.tar.xz/tests/test_exception_handler.c -> _service:tar_scm:cmocka-1.1.7.tar.xz/tests/test_exception_handler.c
Changed
@@ -3,20 +3,14 @@ #include <setjmp.h> #include <cmocka.h> -#include <stdlib.h> - -struct test_segv { - int x; - int y; -}; +#include <signal.h> static void test_segfault_recovery(void **state) { - struct test_segv *s = NULL; - - (void) state; /* unused */ + (void)state; /* unused */ - s->x = 1; + /* Raise segmentation fault */ + raise(SIGSEGV); } static void test_segfault_recovery1(void **state) @@ -35,11 +29,11 @@ } int main(void) { - const struct CMUnitTest tests = { + const struct CMUnitTest exception_tests = { cmocka_unit_test(test_segfault_recovery1), cmocka_unit_test(test_segfault_recovery2), cmocka_unit_test(test_segfault_recovery3), }; - return cmocka_run_group_tests(tests, NULL, NULL); + return cmocka_run_group_tests(exception_tests, NULL, NULL); }
View file
_service:tar_scm:cmocka-1.1.7.tar.xz/tests/test_string.c
Added
@@ -0,0 +1,40 @@ +/* + * Copyright 2020 Andreas Schneider <asn@cryptomilk.org> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdarg.h> +#include <stddef.h> +#include <stdint.h> +#include <setjmp.h> +#include <cmocka.h> + +static void torture_string_equal(void **state) +{ + assert_string_equal("wurst", "wurst"); +} + +static void torture_string_not_equal(void **state) +{ + assert_string_not_equal("wurst", "brot"); +} + +int main(void) { + const struct CMUnitTest tests = { + cmocka_unit_test(torture_string_equal), + cmocka_unit_test(torture_string_not_equal), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +}
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2