Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion _test/testdata/triceCheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ static int64_t DoubleToInt64(double f);
static void exampleOfManualSerialization(void);
static void exampleOfManualJSONencoding(void);
static void dynString(int n);
static int Test_triceAssertOrReturnValue(int flag);
static int Test_TriceAssertOrReturnValue(int flag);
static int Test_TRiceAssertOrReturnValue(int flag);
#endif // #ifndef TRICE_CHECK_MIN

// clang-format off
Expand Down Expand Up @@ -141,17 +144,35 @@ void TriceCheck(int n) {
break; case __LINE__: triceAssertTrue("ASSERT:flag not true!\n", 0 ); //exp: "time: default: ASSERT:flag not true!\n"
break; case __LINE__: TriceAssertTrue("ASSERT:flag not true!\n", 0 ); //exp: "time: be16default: ASSERT:flag not true!\n"
break; case __LINE__: TRiceAssertTrue("ASSERT:flag not true!\n", 0 ); //exp: "time:feed3322default: ASSERT:flag not true!\n"
break; case __LINE__: triceAssert("ASSERT:flag not true!\n", 0 ); //exp: "time: default: ASSERT:flag not true!\n"
break; case __LINE__: TriceAssert("ASSERT:flag not true!\n", 0 ); //exp: "time: be16default: ASSERT:flag not true!\n"
break; case __LINE__: TRiceAssert("ASSERT:flag not true!\n", 0 ); //exp: "time:feed3322default: ASSERT:flag not true!\n"
break; case __LINE__: triceAssertFalse("ASSERT:flag not false!\n", !0 ); //exp: "time: default: ASSERT:flag not false!\n"
break; case __LINE__: TriceAssertFalse("ASSERT:flag not false!\n", !0 ); //exp: "time: be16default: ASSERT:flag not false!\n"
break; case __LINE__: TRiceAssertFalse("ASSERT:flag not false!\n", !0 ); //exp: "time:feed3322default: ASSERT:flag not false!\n"

break; case __LINE__: Test_triceAssertOrReturnValue(0); //exp: "time: default: ASSERT:flag not true!\n"
break; case __LINE__: Test_TriceAssertOrReturnValue(0); //exp: "time: be16default: ASSERT:flag not true!\n"
break; case __LINE__: Test_TRiceAssertOrReturnValue(0); //exp: "time:feed3322default: ASSERT:flag not true!\n"

// The following 6 asserts are expected to be silent, so we add some output just for the testing here.
// The following asserts are expected to be silent, so we add some output just for the testing here.
break; case __LINE__: triceAssertTrue("ASSERT:flag not true!\n", !0 ); TRice("ok\n"); //exp: "time:feed3322default: ok\n"
break; case __LINE__: TriceAssertTrue("ASSERT:flag not true!\n", !0 ); TRice("ok\n"); //exp: "time:feed3322default: ok\n"
break; case __LINE__: TRiceAssertTrue("ASSERT:flag not true!\n", !0 ); TRice("ok\n"); //exp: "time:feed3322default: ok\n"
break; case __LINE__: triceAssert("ASSERT:flag not true!\n", !0 ); TRice("ok\n"); //exp: "time:feed3322default: ok\n"
break; case __LINE__: TriceAssert("ASSERT:flag not true!\n", !0 ); TRice("ok\n"); //exp: "time:feed3322default: ok\n"
break; case __LINE__: TRiceAssert("ASSERT:flag not true!\n", !0 ); TRice("ok\n"); //exp: "time:feed3322default: ok\n"
break; case __LINE__: triceAssertFalse("ASSERT:flag not false!\n", 0 ); TRice("ok\n"); //exp: "time:feed3322default: ok\n"
break; case __LINE__: TriceAssertFalse("ASSERT:flag not false!\n", 0 ); TRice("ok\n"); //exp: "time:feed3322default: ok\n"
break; case __LINE__: TRiceAssertFalse("ASSERT:flag not false!\n", 0 ); TRice("ok\n"); //exp: "time:feed3322default: ok\n"

break; case __LINE__: triceAssertOrReturn("ASSERT:flag not true!\n", !0 ); TRice("ok\n"); //exp: "time:feed3322default: ok\n"
break; case __LINE__: TriceAssertOrReturn("ASSERT:flag not true!\n", !0 ); TRice("ok\n"); //exp: "time:feed3322default: ok\n"
break; case __LINE__: TRiceAssertOrReturn("ASSERT:flag not true!\n", !0 ); TRice("ok\n"); //exp: "time:feed3322default: ok\n"

break; case __LINE__: if(Test_triceAssertOrReturnValue(1) == 1) { TRice("ok\n"); } //exp: "time:feed3322default: ok\n"
break; case __LINE__: if(Test_TriceAssertOrReturnValue(1) == 1) { TRice("ok\n"); } //exp: "time:feed3322default: ok\n"
break; case __LINE__: if(Test_TRiceAssertOrReturnValue(1) == 1) { TRice("ok\n"); } //exp: "time:feed3322default: ok\n"

break; case __LINE__: trice("sig:trice without stamp and with 0 to 12 values (most common use cases)\n" );
break; case __LINE__: trice("rd:trice\n" ); //exp: "time: default: rd:trice\n"
Expand Down Expand Up @@ -2760,6 +2781,24 @@ static void dynString(int n) {
TRICE_N(id(0), "wr:%s\n", s, N_dynString);
}

static int Test_triceAssertOrReturnValue(int flag) {
triceAssertOrReturnValue("ASSERT:flag not true!\n", flag != 0, 0);

return 1;
}

static int Test_TriceAssertOrReturnValue(int flag) {
TriceAssertOrReturnValue("ASSERT:flag not true!\n", flag != 0, 0);

return 1;
}

static int Test_TRiceAssertOrReturnValue(int flag) {
TRiceAssertOrReturnValue("ASSERT:flag not true!\n", flag != 0, 0);

return 1;
}

#endif // #ifndef TRICE_CHECK_MIN

#endif // #if !TRICE_OFF
4 changes: 1 addition & 3 deletions build_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ fi
# ARM Clang uses the ARM GNU toolchain libraries and finds them over C_INCLUDE_PATH.

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# which returns s.th. like /...-arm-none-eabi/bin//arm-none-eabi-gcc # 2 slashes
# <--- 22 chars --->
loc=$(which arm-none-eabi-gcc) && export C_INCLUDE_PATH=${loc:0:${#loc}-22}arm-none-eabi/include
loc=$(arm-none-eabi-gcc -print-file-name=include) && export C_INCLUDE_PATH="${loc}:/usr/include/newlib/"
export MAKE_JOBS="-j"

elif [[ "$OSTYPE" == "darwin"* ]]; then
Expand Down
8 changes: 4 additions & 4 deletions internal/id/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func ProcessAliases() {
suffix := `\b` // Word boundary after macro name

// Core TRICE pattern (without closing \b)
baseTricePattern := `(?i)\bTRICE(?:0|_0|AssertTrue|AssertFalse|(?:8|16|32|64)*(?:_*[0-9SNBF]*)*)`
baseTricePattern := `(?i)\bTRICE(?:0|_0|Assert\w*|(?:8|16|32|64)*(?:_*[0-9SNBF]*)*)`

// Combine static and dynamic aliases
merged := append(TriceAliases, TriceSAliases...)
Expand Down Expand Up @@ -239,9 +239,9 @@ func evaluateTriceParameterCount(t TriceFmt, line int, rest string) (err error)
return fmt.Errorf("line %d %v should have exactly two parameters and not %d", line, t, cnt)
}
default:
if strings.Contains(t.Type, "Assert") { // matches triceAssertTrue and triceAssertFalse
if fsc != 0 || cnt != 1 {
return fmt.Errorf("line %d %v should have no format specifiers and eactly one parameter, the boolean value (fsc=%d, cnt=%d)", line, t, fsc, cnt)
if strings.Contains(t.Type, "Assert") { // matches triceAssert*
if fsc != 0 || cnt < 1 {
return fmt.Errorf("line %d %v should have no format specifiers and one or more parameters, the boolean value is need (fsc=%d, cnt=%d)", line, t, fsc, cnt)
}
return
}
Expand Down
9 changes: 7 additions & 2 deletions internal/trexDecoder/trexDecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,13 @@ func (p *trexDec) sprintTrice(b []byte) (n int) {
}

p.pFmt, p.u = decoder.UReplaceN(p.Trice.Strg)
p.Trice.Type = strings.TrimSuffix(p.Trice.Type, "AssertTrue")
p.Trice.Type = strings.TrimSuffix(p.Trice.Type, "AssertFalse")

// remove Assert if found
before, _, found := strings.Cut(p.Trice.Type, "Assert")
if found {
p.Trice.Type = strings.TrimSpace(before)
}

triceType, err := id.ConstructFullTriceInfo(p.Trice.Type, len(p.u))

if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions src/trice.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#include "trice.h"
#include "cobs.h"
#include "tcobs.h"

#if ((TRICE_DIRECT_XTEA_ENCRYPT == 1) || (TRICE_DEFERRED_XTEA_ENCRYPT == 1))
#include "xtea.h"
#endif

#if !TRICE_OFF

Expand Down Expand Up @@ -923,6 +926,18 @@ unsigned TriceOutDepth(void) {
TRICE_CNTC(0); \
TRICE_LEAVE

void triceAssertFail(int idN) {
TRICE_ASSERT(id(idN));
}

void TriceAssertFail(int idN) {
TRICE_ASSERT(Id(idN));
}

void TRiceAssertFail(int idN) {
TRICE_ASSERT(ID(idN));
}

void triceAssertTrue(int idN, const char* msg, int flag) {
TRICE_UNUSED(msg)
if (!flag) {
Expand Down
16 changes: 16 additions & 0 deletions src/trice.h
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,22 @@ void triceAssertFalse(int idN, const char* msg, int flag);
void TriceAssertFalse(int idN, const char* msg, int flag);
void TRiceAssertFalse(int idN, const char* msg, int flag);

void triceAssertFail(int idN);
void TriceAssertFail(int idN);
void TRiceAssertFail(int idN);

#define triceAssert(idN, msg, flag) triceAssertTrue(idN, msg, flag)
#define TriceAssert(idN, msg, flag) TriceAssertTrue(idN, msg, flag)
#define TRiceAssert(idN, msg, flag) TRiceAssertTrue(idN, msg, flag)

#define triceAssertOrReturn(idN, msg, flag) do {if (!(flag)) {triceAssertFail(idN); return;}} while(0)
#define TriceAssertOrReturn(idN, msg, flag) do {if (!(flag)) {TriceAssertFail(idN); return;}} while(0)
#define TRiceAssertOrReturn(idN, msg, flag) do {if (!(flag)) {TRiceAssertFail(idN); return;}} while(0)

#define triceAssertOrReturnValue(idN, msg, flag, value) do {if (!(flag)) {triceAssertFail(idN); return (value);}} while(0)
#define TriceAssertOrReturnValue(idN, msg, flag, value) do {if (!(flag)) {TriceAssertFail(idN); return (value);}} while(0)
#define TRiceAssertOrReturnValue(idN, msg, flag, value) do {if (!(flag)) {TRiceAssertFail(idN); return (value);}} while(0)

typedef void (*Write8AuxiliaryFn_t)(const uint8_t* enc, size_t encLen);
extern Write8AuxiliaryFn_t UserNonBlockingDirectWrite8AuxiliaryFn;
extern Write8AuxiliaryFn_t UserNonBlockingDeferredWrite8AuxiliaryFn;
Expand Down
60 changes: 54 additions & 6 deletions src/triceOff.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,60 @@
#define Trice0(...)
#define TRice0(...)

#define triceAssertTrue(x, y, ...) TRICE_UNUSED(x) TRICE_UNUSED(y)
#define TriceAssertTrue(x, y, ...) TRICE_UNUSED(x) TRICE_UNUSED(y)
#define TRiceAssertTrue(x, y, ...) TRICE_UNUSED(x) TRICE_UNUSED(y)
#define triceAssertFalse(x, y, ...) TRICE_UNUSED(x) TRICE_UNUSED(y)
#define TriceAssertFalse(x, y, ...) TRICE_UNUSED(x) TRICE_UNUSED(y)
#define TRiceAssertFalse(x, y, ...) TRICE_UNUSED(x) TRICE_UNUSED(y)
#define triceAssertTrue(...)
#define TriceAssertTrue(...)
#define TRiceAssertTrue(...)
#define triceAssertFalse(...)
#define TriceAssertFalse(...)
#define TRiceAssertFalse(...)

#define triceAssertFail(...)
#define TriceAssertFail(...)
#define TRiceAssertFail(...)

#define triceAssert(...)
#define TriceAssert(...)
#define TRiceAssert(...)

// ----- Arity detection helpers (C99) -----
#define _TRICE_PP_NARG_IMPL( \
_1,_2,_3,_4,_5,_6,_7,_8,_9,_10, \
_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
N, ...) N
#define _TRICE_PP_NARG(...) \
_TRICE_PP_NARG_IMPL(__VA_ARGS__, \
20,19,18,17,16,15,14,13,12,11, \
10,9,8,7,6,5,4,3,2,1,0)

#define _TRICE_PP_CAT(a,b) a##b
#define _TRICE_PP_OVERLOAD(name, count) _TRICE_PP_CAT(name, count)
#define _TRICE_PP_DISPATCH(name, ...) \
_TRICE_PP_OVERLOAD(name, _TRICE_PP_NARG(__VA_ARGS__))(__VA_ARGS__)

// triceAssertOrReturn
#define triceAssertOrReturn2(msg, flag) do {if (!(flag)) {return;}} while(0)
#define TriceAssertOrReturn2(msg, flag) do {if (!(flag)) {return;}} while(0)
#define TRiceAssertOrReturn2(msg, flag) do {if (!(flag)) {return;}} while(0)
#define triceAssertOrReturn3(idN, msg, flag) do {if (!(flag)) {return;}} while(0)
#define TriceAssertOrReturn3(idN, msg, flag) do {if (!(flag)) {return;}} while(0)
#define TRiceAssertOrReturn3(idN, msg, flag) do {if (!(flag)) {return;}} while(0)

#define triceAssertOrReturn(...) _TRICE_PP_DISPATCH(triceAssertOrReturn, __VA_ARGS__)
#define TriceAssertOrReturn(...) _TRICE_PP_DISPATCH(TriceAssertOrReturn, __VA_ARGS__)
#define TRiceAssertOrReturn(...) _TRICE_PP_DISPATCH(TRiceAssertOrReturn, __VA_ARGS__)

// triceAssertOrReturnValue
#define triceAssertOrReturnValue3(msg, flag, value) do {if (!(flag)) {return (value);}} while(0)
#define TriceAssertOrReturnValue3(msg, flag, value) do {if (!(flag)) {return (value);}} while(0)
#define TRiceAssertOrReturnValue3(msg, flag, value) do {if (!(flag)) {return (value);}} while(0)
#define triceAssertOrReturnValue4(idN, msg, flag, value) do {if (!(flag)) {return (value);}} while(0)
#define TriceAssertOrReturnValue4(idN, msg, flag, value) do {if (!(flag)) {return (value);}} while(0)
#define TRiceAssertOrReturnValue4(idN, msg, flag, value) do {if (!(flag)) {return (value);}} while(0)

#define triceAssertOrReturnValue(...) _TRICE_PP_DISPATCH(triceAssertOrReturnValue, __VA_ARGS__)
#define TriceAssertOrReturnValue(...) _TRICE_PP_DISPATCH(TriceAssertOrReturnValue, __VA_ARGS__)
#define TRiceAssertOrReturnValue(...) _TRICE_PP_DISPATCH(TRiceAssertOrReturnValue, __VA_ARGS__)


// All following macros are defined without ID and as variadic, to avoid editor warnings for TRICE_CLEAN == 1 or TRICE_OFF == 1

Expand Down