Skip to content

rafael-santiago/cutest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cutest

Cutest is an acronym that can be understood as C unit test.

This library brings a bunch of macros in order to guide the implementation of unit tests for C projects.

Cutest brings a minimal memory leak detection system (fully working in Linux, Windows, FreeBSD, Solaris, NetBSD, MINIX and OpenBSD). You can also use cutest to test kernel mode stuff in Linux, FreeBSD, NetBSD and Windows.

All supported platforms by this library and other general features are listed on Table 1.

On Cutest is also possible customize the logs generated by your tests if you want to.

Table 1: Places where I have been running it. A.k.a. supported platforms. In additional, the compiler/linker options to be passed when using cutest as your unit testing library.

Operating System Has GNU Backtracing? Thread safe? Compiler/Linker flags to use (besides -lcutest) Kernel mode
Linux Yes Yes -ldl, -lpthread Yes
FreeBSD Yes Yes -lexecinfo, -lpthread Yes
NetBSD Yes Yes -lexecinfo, -lpthread Yes
OpenBSD Yes Yes -lexecinfo, -lpthread No
MINIX Yes No -lexecinfo No
Solaris No Yes -DNO_CUTEST_BACKTRACING, -lpthread No
Windows Yes Yes Yes

Of course, that it should run in a bunch of UNIX boxes, however I prefer listing the places where I actually watched it running and working pretty fine. If there is a specific non-listed platform that you want to use cutest, let me know, maybe I can adjust the library's build to accomplish your requirements ;)

Remark: When using cutest to test kernel mode code you do not need compiler flags because all is available in one single header file. For more details read the documentation.

How to build it

To build cutest is necessary to use my own build system called hefesto. Being Hefesto installed in your system all you need to emit on a shell inside the cutest's src sub-directory is:

hefesto

After the build a file named libcutest.a that stands for the library will be generated under the path src/lib. You should use this file and the header src/cutest.h to develop your further unit tests.

Note that the build was written based on GCC. So, you need to have the gcc/mingw installed (and well exported) in your system before going ahead.

Maybe you should read the documentation before starting.

Tip: In case of trying to compile it under a UNIX environment with no support for PTHREADS before calling hefesto you need to edit the file src/.ivk and add the following C Macro definition -DHAS_NO_PTHREAD to --cflags option:

--cflags=-DHAS_NO_PTHREAD

Note for Visual Studio users

If you want to build cutest under MSVC you need to invoke Hefesto as follows:

> hefesto --toolset=msvc-c-lib

The command above will build lib/libcutestmt.lib.

If you want to build lib/libcutestmtd.lib, use:

> hefesto --toolset=msvc-c-lib --compile-model=debug

On 64-bit environments 64-bit lib artifacts will be built, for 32-bit, use:

>hefesto --toolset=msvc-c-lib --cpu-arch=x86

After run one of the commands listed above, a file named libcutest.lib will be generated inside src/lib path. Note that use cutest on MSVC is a little bit tricky. It envolves composite the cutest with your current msvcrt.lib (it explains why the cutest.lib is so huge).

Important: When linking your test artifact. You need to add the following link option: /NODEFAULTLIB:MSVCRT,MSVCRTD.

I have tested it over Microsoft Visual Studio 2019.