summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorNiels de Vos <ndevos@redhat.com>2015-02-18 14:47:01 +0100
committerKaleb KEITHLEY <kkeithle@redhat.com>2015-03-05 13:51:37 -0800
commitbc2e58a436002e1627a225663bc7b11dddc1172f (patch)
treef586bcf41d82dcbb6979741ca299ff1291f9a8f7 /doc
parent0bef7717d3100734c6c5a4ba85de7a39e76774db (diff)
testing: Switch to cmocka the successor of cmockery2
This uses https://cmocka.org/ as the unit testing framework. With this change, unit testing is made optional as well. We assume there is no cmocka available while building. cmocka will be enabled by default later on. For now, to build with cmocka run: $ ./configure --enable-cmocka This change is based on the work of Andreas (replacing cmockery2 with cmocka) and Kaleb (make cmockery2 an optional build dependency). The only modifications I made, are additional #defines in unittest.h for making sure the unit tests function as expected. Change-Id: Iea4cbcdaf09996b49ffcf3680c76731459cb197e BUG: 1067059 Merged-change: http://review.gluster.org/9762/ Signed-off-by: Andreas Schneider <asn@samba.org> Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com> Signed-off-by: Niels de Vos <ndevos@redhat.com> Change-Id: Ia2e955481c102d5dce17695a9205395a6030e985 Reviewed-on: http://review.gluster.org/9738 Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/hacker-guide/en-US/markdown/unittest.md19
1 files changed, 11 insertions, 8 deletions
diff --git a/doc/hacker-guide/en-US/markdown/unittest.md b/doc/hacker-guide/en-US/markdown/unittest.md
index 42dc210959e..5c6c0a8a039 100644
--- a/doc/hacker-guide/en-US/markdown/unittest.md
+++ b/doc/hacker-guide/en-US/markdown/unittest.md
@@ -14,10 +14,13 @@
* Maintainable
* Trustworthy (when you see its result, you don’t need to debug the code just to be sure)
-## Cmockery2
-GlusterFS unit test framework is based on [Cmockery2][]. Cmockery provides developers with methods to isolate and test modules written in C language. It also provides integration with Jenkins by providing JUnit XML compliant unit test results.
+## cmocka
+GlusterFS unit test framework is based on [cmocka][]. cmocka provides
+developers with methods to isolate and test modules written in C language. It
+also provides integration with Jenkins by providing JUnit XML compliant unit
+test results.
-Before continuing, you may want to familiarize yourself with Cmockery2 by reading the [usage guide][cmockery2usage].
+cmocka
## Running Unit Tests
To execute the unit tests, all you need is to type `make check`. Here is a step-by-step example assuming you just cloned a GlusterFS tree:
@@ -90,7 +93,7 @@ Expected assertion ((void *)0) != ptr occurred
Add the following to your C file:
```c
-#include <cmockery/pbc.h>
+#include <cmocka_pbc.h>
```
```c
@@ -171,7 +174,7 @@ int divide (int n, int d)
Cmockery2 provides its own memory allocation functions which check for buffer overrun and memory leaks. The following header file must be included **last** to be able to override any of the memory allocation functions:
```c
-#include <cmockery/cmockery_override.h>
+#include <cmocka.h>
```
This file will only take effect with the `UNIT_TESTING` CFLAG is set.
@@ -204,7 +207,7 @@ TESTS += xxx_unittest
Where `xxx` is the name of your C file. For example, look at `libglusterfs/src/Makefile.am`.
-Copy the simple unit test from `cmockery2/src/example/run_tests.c` to `unittest/xxx_unittest.c`. If you would like to see an example of a unit test, please refer to `libglusterfs/src/unittest/mem_pool_unittest.c`.
+Copy the simple unit test from the [cmocka API][cmockaapi] to `unittest/xxx_unittest.c`. If you would like to see an example of a unit test, please refer to `libglusterfs/src/unittest/mem_pool_unittest.c`.
#### Mocking
You may see that the linker will complain about missing functions needed by the C file you would like to test. Identify the required functions, then place their stubs in a file called `unittest/xxx_mock.c`, then include this file in `Makefile.am` in `xxx_unittest_SOURCES`. This will allow you to you Cmockery2's mocking functions.
@@ -220,6 +223,6 @@ $ gdb libglusterfs/src/mem_pool_unittest
```
-[Cmockery2]: https://github.com/lpabon/cmockery2
+[cmocka]: https://cmocka.org
[definitionofunittest]: http://artofunittesting.com/definition-of-a-unit-test/
-[cmockery2usage]: https://github.com/lpabon/cmockery2/blob/master/doc/usage.md
+[cmockapi]: https://api.cmocka.org