1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 04:45:24 +03:00
betaflight/src/test/unit/atomic_unittest_c.c
Petr Ledvina f564cdf952 Fix atomic in unittests (#4240)
Add unittest support for ATOMIC_BLOCK

- BASEPRI emulation on UNIT_TEST target
- documentation cleanup / fixed missspelings
- ATOMIC_BARRIER implemented for CLang, using blocks
- ATOMIC_BARRIER is using macros to separate barriers

gcc specific unittest for ATOMIC_BARRIER

ATOMIC_BARRIER clang unittest

quick hack to enable CLangs -flocks + ATOMIC_BARRIER tests
Needs cleanup

* Enable test

* Add libBlocksRuntime dependency to Travis
2017-09-27 13:12:37 +01:00

37 lines
1.1 KiB
C

#include "build/atomic.h"
struct barrierTrace {
int enter, leave;
};
int testAtomicBarrier_C(struct barrierTrace *b0, struct barrierTrace *b1, struct barrierTrace sample[][2])
{
int sIdx = 0;
// replace barrier macros to track barrier invocation
// pass known struct as barrier variable, keep track inside it
#undef ATOMIC_BARRIER_ENTER
#undef ATOMIC_BARRIER_LEAVE
#define ATOMIC_BARRIER_ENTER(ptr, refStr) do {(ptr)->enter++; } while(0)
#define ATOMIC_BARRIER_LEAVE(ptr, refStr) do {(ptr)->leave++; } while(0)
b0->enter = 0; b0->leave = 0;
b1->enter = 0; b1->leave = 0;
sample[sIdx][0]=*b0; sample[sIdx][1]=*b1; sIdx++;
do {
ATOMIC_BARRIER(*b0);
ATOMIC_BARRIER(*b1);
sample[sIdx][0]=*b0; sample[sIdx][1]=*b1; sIdx++;
do {
ATOMIC_BARRIER(*b0);
sample[sIdx][0]=*b0; sample[sIdx][1]=*b1; sIdx++;
} while(0);
sample[sIdx][0]=*b0; sample[sIdx][1]=*b1; sIdx++;
} while(0);
sample[sIdx][0]=*b0; sample[sIdx][1]=*b1; sIdx++;
return sIdx;
// ATOMIC_BARRIER is broken in rest of this file
#undef ATOMIC_BARRIER_ENTER
#undef ATOMIC_BARRIER_LEAVE
}