mirror of
https://github.com/meekrosoft/fff
synced 2026-01-23 00:15:59 +01:00
Squashed commit of the following:
commit e5a5749971eb9274679699020a54c91d4053ed79 Author: James Fraser <wulfgar.pro@gmail.com> Date: Sun Feb 3 19:57:31 2019 +1100 PR #47: Minor review fixes to tests files. commit e9f11b9ec8de8f8d1f0de7b6959c575e15894526 Author: James Fraser <wulfgar.pro@gmail.com> Date: Sun Feb 3 19:57:04 2019 +1100 PR #47: Minor review fixes. commit0a7fbeceecAuthor: Pauli Salmenrinne <pauli.salmenrinne@pexraytech.com> Date: Tue Jan 22 15:11:10 2019 +0200 Add example for the weak linking commit647737304dAuthor: susundberg <susundberg@gmail.com> Date: Wed Mar 21 13:14:05 2018 +0200 Add "FFF_FUNCTION_ATTRIBUTES" definition that can be used to declare attributes for functions. More specifically, allow __weak__ attribute.
This commit is contained in:
26
README.md
26
README.md
@@ -21,6 +21,7 @@
|
||||
- [How do I fake a function that returns a value by reference?](#how-do-i-fake-a-function-that-returns-a-value-by-reference)
|
||||
- [How do I fake a function with a function pointer parameter?](#how-do-i-fake-a-function-with-a-function-pointer-parameter)
|
||||
- [How do I reuse a fake across multiple test-suites?](#how-do-i-reuse-a-fake-across-multiple-test-suites)
|
||||
- [Specifying GCC Function Attributes](#specifying-gcc-function-attributes)
|
||||
- [Find out more...](#find-out-more)
|
||||
- [Benefits](#benefits)
|
||||
- [Under the hood](#under-the-hood)
|
||||
@@ -603,6 +604,26 @@ DEFINE_FAKE_VALUE_FUNC_VARARG(int, value_function_vargs, const char *, int, ...)
|
||||
DEFINE_FAKE_VOID_FUNC_VARARG(void_function_vargs, const char *, int, ...);
|
||||
|
||||
```
|
||||
## Specifying GCC Function Attributes
|
||||
|
||||
You can specify GCC function attributes for your fakes using the `FFF_GCC_FUNCTION_ATTRIBUTES` directive.
|
||||
|
||||
### Weak Functions
|
||||
|
||||
One usful attribute is the _weak_ attribute that marks a function such that it can be overridden by a non-weak variant at link time. Using weak functions in combination with FFF can help simplify your testing approach.
|
||||
|
||||
For example:
|
||||
* Define a library of fake functions, e.g. libfake.a.
|
||||
* Link a binary (you might have many) that defines a subset of real variants of the fake functions to the aforementioned fake library.
|
||||
* This has the benefit of allowing a binary to selectively use a subset of the required fake functions while testing the real variants without the need for many different make targets.
|
||||
|
||||
You can mark all fakes with the weak attribute like so:
|
||||
```
|
||||
#define FFF_GCC_FUNCTION_ATTRIBUTES __attribute__((weak))
|
||||
#include "fff.h"
|
||||
```
|
||||
|
||||
See the example project that demonstrates the above approach: _./examples/weak_linking_.
|
||||
|
||||
## Find out more...
|
||||
|
||||
@@ -621,8 +642,9 @@ So whats the point?
|
||||
|
||||
## Under the Hood
|
||||
* The fff.h header file is generated by a ruby script
|
||||
* There are tests under src/test
|
||||
* There is an example for testing an embedded UI and a hardware driver under src/examples
|
||||
* There are tests under _./test_
|
||||
* There is an example for testing an embedded UI and a hardware driver under _./examples_
|
||||
* There is an example of weak_linking under _./examples_
|
||||
|
||||
|
||||
## Cheat Sheet
|
||||
|
||||
Reference in New Issue
Block a user