Git Product home page Git Product logo

cmocka's Introduction

CMOCKA

Mirror of https://gitlab.com/cmocka/cmocka

INSTALLATION

$ clib install cmocka

cmocka is a fork for Google's cmockery unit testing framework to fix bugs and support it in future. See https://code.google.com/p/cmockery/

For information about how to use the cmocka unit testing framework see doc/index.html.

COMPILING

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.

LICENSE

Apache

cmocka's People

Contributors

aleksandr-vin avatar ammrat13 avatar ansasaki avatar arisada avatar cryptomilk avatar dimkr avatar dsch avatar evanmiller avatar evelikov avatar ffontaine avatar fjouault avatar flrl avatar jajanusz avatar jhrozek avatar jktjkt avatar joelsoncarl avatar jonathonreinhart avatar jwerle avatar koalatux avatar kopasiak avatar lespocky avatar neocturne avatar obnoxxx avatar paoloteti avatar pbrezina avatar perror avatar pszewczyk avatar sdroege avatar stevebyan avatar wolfram-ladurner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cmocka's Issues

The input parameter types of the function are inconsistent

When I visit the web url www.cmocka.org, I found the supported parameter types of function assert_int_equal are integers.
so I thought what if I want to compare two long integer datas.
I looked into the cmocka source code and found that actually function assert_int_equal supports LargestIntegralType which covers long integer.
so I suggest to use
void assert_int_equal (LargestIntegralType a, LargestIntegralType b) instead of void assert_int_equal (int a, int b) during introduce assert macros api on website www.cmocka.org to tell user what we exactly support?

functions for testing floating point numbers.

For numerical applications we sometimes need to test if floating point numbers are correct.

two few useful functions are

int assert_double_close(double a, double b, double rtol, double atol);

int assert_double_allclose(double *a, double * b, int size, double rtol, double atol);

The behaviour of these functions can be modelled after the testing functions in numpy:

https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.testing.assert_allclose.html

I'd like to start working on a PR, if there are no other considerations that these functions were not included in cmocka.

Segmentation fault on freeing memory allocated by strdup

While checking memory leaks, buffer overflows using test_free, test_malloc, etc getting segmentation fault in the following case.

  • Mocked Dynamic Memory handling functions like below
#ifdef UNITTEST
    extern void* _test_malloc(const size_t size, const char* file, const int line);
    extern void* _test_calloc(size_t nmemb, const size_t size, const char* file, const int line);
    extern void* _test_realloc(void *ptr, const size_t size, const char* file, const int line);
    extern void _test_free(void *ptr, const char* file, const int line);

    #define malloc(size) _test_malloc(size, __FILE__, __LINE__)
    #define calloc(nmemb,size) _test_calloc(nmemb, size, __FILE__, __LINE__)
    #define realloc(ptr,size) _test_realloc(ptr, size, __FILE__, __LINE__)
    #define free(ptr) _test_free(ptr, __FILE__, __LINE__)
#endif
  • Segmentation fault is thrown in the code when test_free tried to deallocate the memory allocated by strdup.
  • Below is the Call stack when run through GDB
#0  strlen () at ../sysdeps/i386/strlen.S:35
#1  0xf7bc3166 in _IO_vfprintf_internal (s=0xffffc7d0, format=0xf7d2c21e "%s:%u: error: Guard block of %p size=%lu is corrupt\n%s:%u: note: allocated here at %p\n", ap=0xffffcd58 "e-4c") at vfprintf.c:1643
#2  0xf7be5baf in _IO_vsnprintf (string=0xffffc8fc "src/config.c:49: error: Guard block of 0x8063010 size=943077171 is corrupt\n", maxlen=<optimized out>,
    format=0xf7d2c21e "%s:%u: error: Guard block of %p size=%lu is corrupt\n%s:%u: note: allocated here at %p\n", args=0xffffcd44 "\377\204\005\b1") at vsnprintf.c:114
#3  0xf7d28421 in vcm_print_error (format=0xf7d2c21e "%s:%u: error: Guard block of %p size=%lu is corrupt\n%s:%u: note: allocated here at %p\n", args=0xffffcd44 "\377\204\005\b1")
    at /home/sowri/cmocka-1.0.1_32/src/cmocka.c:1535
#4  0xf7d28957 in cm_print_error (format=0xf7d2c21e "%s:%u: error: Guard block of %p size=%lu is corrupt\n%s:%u: note: allocated here at %p\n")
    at /home/sowri/cmocka-1.0.1_32/src/cmocka.c:1825
#5  0xf7d2a75b in _test_free (ptr=0x8063010, file=0x80584ff "src/config.c", line=49) at /home/sowri/cmocka-1.0.1_32/src/cmocka.c:1643
#6  0x0804a2b3 in config_reset (cfg=0x8060e20 <g_config>) at src/config.c:49
#7  0x0804cd0c in config_load (config_file=0x8058feb "/cfg/fwcm-updaterd.conf") at src/config.c:352
#8  0x0804f9e4 in test_config_load (state=0x80621a0) at unittest/config_ut.c:323
#9  0xf7d2aa9f in cmocka_run_one_test_or_fixture (function_name=0x805948b "test_config_load", test_func=0x804ee80 <test_config_load>, setup_func=setup_func@entry=0x0, teardown_func=0x0, state=<optimized out>, heap_check_point=0x0)
    at /home/sowri/omc/cmocka-1.0.1_32/src/cmocka.c:2305
#10 0xf7d2b2c3 in cmocka_run_one_tests (test_state=0x8062198) at /home/sowri/omc/cmocka-1.0.1_32/src/cmocka.c:2413
#11 _cmocka_run_group_tests (group_name=0x805949c "tests", tests=0xffffd040, num_tests=3, group_setup=0x0, group_teardown=0x0) at /home/sowri//cmocka-1.0.1_32/src/cmocka.c:2518
#12 0x08052818 in main () at unittest/config_ut.c:85

But when i have replaced strdup with custom strdup to do the same, its working perfectly, No SEG-FAULT been observed. It seems Cmocka is not tracking the memory block allocated by the strdup.

Work-Around:

  • I can mock strdup with Custom implementation while running the Test case but looking for straight Forward solution.

Is there any mocking i missed or is it not yet supported by Cmocka ?

build error on linux

cmake -DUNIT_TESTING=On ../cmocka-1.1.1
CMake Error at cmake/Modules/MacroEnsureOutOfSourceBuild.cmake:13 (message):
cmocka requires an out of source build. Please create a separate build
directory and run 'cmake /path/to/cmocka [options]' there.
Call Stack (most recent call first):
CMakeLists.txt:41 (macro_ensure_out_of_source_build)

CMake Error at cmake/Modules/MacroEnsureOutOfSourceBuild.cmake:14 (message):
Remove the file CMakeCache.txt in /home/dnewbrk/dev/jrl/cmocka-1.1.1 first.
Call Stack (most recent call first):
CMakeLists.txt:41 (macro_ensure_out_of_source_build)

-- Configuring incomplete, errors occurred!
See also "/home/.../dev/.../cmocka-1.1.1/CMakeFiles/CMakeOutput.log".

Needs updating

I currently use 1.1.1 version here

could you please update the package/add versioning support?

Thanks

Calling cmocka group tests repeatedly causing invalid XML files.

In our testing scripts, some CMOCKA group tests are called repeatedly (sometimes like 100+ times). This is making our Jenkins job fail with some tests having invalid JUNIT (xml) files [root of XML having nested testsuites tag]. Is there a way to workaround this issue? Any information in this area is greatly appreciated.
Failed XML file format:

?xml version="1.0" encoding="UTF-8" ?>
testsuites>
testsuite name="debug test" time="0.000" tests="1" failures="0" errors="0" skipped="0" >
testcase name="EVT003: debug" time="0.000" >
/testcase>
/testsuite>
/testsuites>
testsuites>
testsuite name="debug test" time="0.000" tests="1" failures="0" errors="0" skipped="0" >
testcase name="EVT003: debug" time="0.000" >
/testcase>
/testsuite>
/testsuites>

... so on

Compilation broken under Ubuntu 16.04

Compiling on Ubuntu 16.04 following these steps:

$ git clone https://github.com/clibs/cmocka.git
$ mkdir -p cmocka/build
$ cd cmocka/build
$ cmake ../
$ make

The compilation is broken with a bunch of errors like this:

error: ISO C does not support ‘__FUNCTION__’ predefined identifier [-Wpedantic]

This repo is outdated for 3 years... Is this the proper cmoka repository?

Test with MPI

How can I set up a test that uses multiple MPI processes using CMake and cmocka?
I did it for the sequential case but I'm not able to test with MPI

"The following configuration files were considered but not accepted"

Hi!

I'm sorry if this is has an obvious answer, but I haven't played with C/C++ enough to know for sure; still learning. :)
Also sorry if this has an answer written somewhere; I can be a mole sometimes.

I'm running into an issue trying to setup cmocka for a project, using CMAKE, Ninja, and espressif; all for an ESP32. I'll share what I can, but some things are private for company reasons.

Some information that might help:

  • Linux Kernel 6.8.0
  • Pop!_OS 22.04 LTS (Ubuntu 22.04 derivative)
  • cmake version 3.22.1
  • GNU Make 4.3
  • ninja 1.10.1
  • ESP-IDF v4.4.7-92-g718cdd6c65

I run into this issue when trying to build:

CMake Error at CMakeLists.txt:16 (find_package):
  Could not find a configuration file for package "cmocka" that is compatible
  with requested version "1.1.5".

  The following configuration files were considered but not accepted:

    /usr/local/lib/cmake/cmocka/cmocka-config.cmake, version: 1.1.5 (64bit)

As you can see, I have compiled cmocka, and I have just taken it from the master branch; it compiled without issue.

I have the following CMakeList.txt:

# The following four lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

# (Not part of the boilerplate)
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common main/esp-protocols-master/components/esp_modem main/components)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(ThisIsAProjectName)

# Add CMocka CMake modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmocka)

if (UNIT_TESTING)
    find_package(cmocka 1.1.5 REQUIRED)
    include(AddCMockaTest)
    add_subdirectory(tests)
endif()

Have I missed anything? Have I missed anything in the documentation? I can't seem to find anything about this.

If you need more information, please ask, and I'll supply it if I can.

Edit

I forgot, but I use a build script (simply called build.sh) to build a bin file, which looks like this:

#!/bin/bash

#/opt/esp/python_env/idf4.4_py3.8_env/bin/python -m pip install --upgrade idf-component-manager
~/.espressif/python_env/idf4.4_py3.10_env/bin/python -m pip install --upgrade idf-component-manager

echo Delete Build folder...
rm -r -f ./build

echo Version.txt contains version
cat ./version.txt

echo Running cmake...
cmake ./ -G "Ninja" -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DESP_PLATFORM=1 -DCCACHE_ENABLE=0 -DCMOCKA_PATH="/var/projekter/cmocka" -DUNIT_TESTING=ON -B ./build

echo Run Ninja in Debug folder...
cd build
/usr/bin/ninja

build error

hi,

when i tried to build the cmocka library i got the following error message
make -DCMAKE_INSTALL_PREFIX=/home/mkarthig/repo/mkarthig/5601/sw/y/build/netconfdevel/ -DCMAKE_BUILD_TYPE=Debug -DUNIT_TESTING=ON ..
-- Check if the system is big endian
-- Searching 16 bit integer
CMake Error at /usr/local/share/cmake-3.7/Modules/TestBigEndian.cmake:41 (message):
no suitable type found
Call Stack (most recent call first):
ConfigureChecks.cmake:142 (test_big_endian)
CMakeLists.txt:43 (include)

-- Configuring incomplete, errors occurred!
See also "/home/mkarthig/repo/mkarthig/5601/sw/y/build/netconfdevel/cmocka-master/build/CMakeFiles/CMakeOutput.log".
See also "/home/mkarthig/repo/mkarthig/5601/sw/y/build/netconfdevel/cmocka-master/build/CMakeFiles/CMakeError.log".

Executing cmocka unit tests on Oracle Proc*C code

Is it possible to run unit tests on Oracle Pro*C code?

If it is possible,

  • Should we run tests on the .pc file or the compiled .c file.
  • Can anyone please explain the steps to do so?

I tried googling this with no results.

For example, creating a simple database connection and returning via cn.pc file as follows:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<sqlca.h>

char *p="username/password@SID";

void main()
{  
    EXEC SQL CONNECT :p;

    if(sqlca.sqlcode==0)
    {  
       printf("Database connection successful to %s",p);
    }
    else
    {   printf("\n connection to  %s   failed ",p);
    }

}

How should a test_cn.c file be coded for this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.