clibs / cmocka Goto Github PK
View Code? Open in Web Editor NEWAn elegant unit testing framework for C with support for mock objects.
License: Apache License 2.0
An elegant unit testing framework for C with support for mock objects.
License: Apache License 2.0
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?
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
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".
This issue was reported by cppcheck 1.75.
Cmocka version 1.0.1
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".
Coverity is reporting possible dereferencing of null pointer in _function_called. The variable expected_call is dereferenced although it appears that it may be NULL.
Coverity error reader_ _libs_test_cmocka_cmocka-src_src_cmocka.c.html.zip
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.
Is it possible to run unit tests on Oracle Pro*C code?
If it is possible,
.pc
file or the compiled .c
file.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?
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:
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
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
Hi guys,
I want to add the builder platform of cmocka to my project. how to build the arm64 library to OS? thanks~
This error is due to the below line in cmocka.h file,
/* Perform an unsigned cast to uintmax_t. */
#define cast_to_uintmax_type(value)
((uintmax_t)(value))
Is there a patch to solve this build issue? This build issue comes when I tried to build cmockalib.
While checking memory leaks, buffer overflows using test_free, test_malloc, etc getting segmentation fault in the following case.
#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
#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.
Is there any mocking i missed or is it not yet supported by Cmocka ?
I currently use 1.1.1 version here
could you please update the package/add versioning support?
Thanks
Is this the same project as https://gitlab.com/cmocka/cmocka/tree/master ?
If so, perhaps you replace the contents of README.md
with a note saying that the project has moved.
Dear cmocka expert:
because some tools depend on "cmocka" dependency in my environment, After installing cmocka tool, when i try to compile my build again, the error is shown as title. Could you help me solving this issue? thank you in advance.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.