Skip to content

Commit b94ee29

Browse files
committed
wip
1 parent 1a5bfbc commit b94ee29

15 files changed

+438
-4
lines changed

β€Ž.vscode/launch.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,20 @@
106106
]
107107
},
108108
{
109-
"name": "-p com46",
109+
"name": "G0B1 -p com6",
110110
"type": "go",
111111
"request": "launch",
112112
"mode": "auto",
113113
"program": "${workspaceFolder}/cmd/trice",
114114
"env": {},
115115
"args": ["log",
116116
"-port",
117-
"com46",
117+
"com6",
118+
"-pf=cobs",
118119
"-i",
119-
"${workspaceFolder}/../NAi2Development/SD3Modbus/SD3-HW-RevA-Lib_Modbus-STM32-HAL-FreeRTOS/til.json",
120+
"${workspaceFolder}/examples/G0B1_inst/til.json",
120121
"-li",
121-
"${workspaceFolder}/../NAi2Development/SD3Modbus/SD3-HW-RevA-Lib_Modbus-STM32-HAL-FreeRTOS/li.json"
122+
"${workspaceFolder}/examples/G0B1_inst/li.json"
122123
]
123124
},
124125
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "trice.h"
2+
3+
void TriceCheckSpecial( int n ) {
4+
5+
static int8_t b8[24] = { 0, -1, -2, 0x33, 4, 5, 6, 7, 8, 9, 10, 11, 0, -1, -2, 0x33, 4, 5, 6, 7, 8, 9, 10, 11 };
6+
static int16_t b16[] = { 0, -1, -2, 0x3344 };
7+
static int32_t b32[] = { 0, -1, -2, 0x33445555};
8+
static int64_t b64[4] = { 0, -1, -2, 0x3344555566666666 };
9+
10+
switch(n){
11+
case __LINE__: TRice("Hello World!\n"); //exp: feed3322 Hello World!
12+
break; case __LINE__: TRICE8_F(ID(0), "info:FunctionNameWa", b8, sizeof(b8) /sizeof(int8_t) ); //exp: feed3322 FunctionNameWa(00)(ff)(fe)(33)(04)(05)(06)(07)(08)(09)(0a)(0b)(00)(ff)(fe)(33)(04)(05)(06)(07)(08)(09)(0a)(0b)
13+
break; case __LINE__: TRice8F("info:FunctionNameWb", b8, sizeof(b8) /sizeof(int8_t) ); //exp: feed3322 FunctionNameWb(00)(ff)(fe)(33)(04)(05)(06)(07)(08)(09)(0a)(0b)(00)(ff)(fe)(33)(04)(05)(06)(07)(08)(09)(0a)(0b)
14+
break; case __LINE__: Trice8F("info:FunctionNameWc", b8, sizeof(b8) /sizeof(int8_t) ); //exp: be16 FunctionNameWc(00)(ff)(fe)(33)(04)(05)(06)(07)(08)(09)(0a)(0b)(00)(ff)(fe)(33)(04)(05)(06)(07)(08)(09)(0a)(0b)
15+
break; case __LINE__: trice8F("info:FunctionNameWd", b8, sizeof(b8) /sizeof(int8_t) ); //exp: FunctionNameWd(00)(ff)(fe)(33)(04)(05)(06)(07)(08)(09)(0a)(0b)(00)(ff)(fe)(33)(04)(05)(06)(07)(08)(09)(0a)(0b)
16+
break; case __LINE__: TRICE16_F(ID(0), "info:FunctionNameXa", b16, sizeof(b16)/sizeof(int16_t) ); //exp: feed3322 FunctionNameXa(0000)(ffff)(fffe)(3344)
17+
break; case __LINE__: TRice16F("info:FunctionNameXb", b16, sizeof(b16)/sizeof(int16_t) ); //exp: feed3322 FunctionNameXb(0000)(ffff)(fffe)(3344)
18+
break; case __LINE__: Trice16F("info:FunctionNameXc", b16, sizeof(b16)/sizeof(int16_t) ); //exp: be16 FunctionNameXc(0000)(ffff)(fffe)(3344)
19+
break; case __LINE__: trice16F("info:FunctionNameXd", b16, sizeof(b16)/sizeof(int16_t) ); //exp: FunctionNameXd(0000)(ffff)(fffe)(3344)
20+
break; case __LINE__: TRICE32_F(ID(0), "info:FunctionNameYa", b32, sizeof(b32)/sizeof(int32_t) ); //exp: feed3322 FunctionNameYa(00000000)(ffffffff)(fffffffe)(33445555)
21+
break; case __LINE__: TRice32F("rpc:FunctionNameYb", b32, sizeof(b32)/sizeof(int32_t) ); //exp: feed3322 FunctionNameYb(00000000)(ffffffff)(fffffffe)(33445555)
22+
break; case __LINE__: Trice32F("rpc:FunctionNameYc", b32, sizeof(b32)/sizeof(int32_t) ); //exp: be16 FunctionNameYc(00000000)(ffffffff)(fffffffe)(33445555)
23+
break; case __LINE__: trice32F("call:FunctionNameYd", b32, sizeof(b32)/sizeof(int32_t) ); //exp: call:FunctionNameYd(00000000)(ffffffff)(fffffffe)(33445555)
24+
break; case __LINE__: TRICE64_F(ID(0), "info:FunctionNameZa", b64, sizeof(b64)/sizeof(int64_t) ); //exp: feed3322 FunctionNameZa(0000000000000000)(ffffffffffffffff)(fffffffffffffffe)(3344555566666666)
25+
break; case __LINE__: TRice64F("call:FunctionNameZb", b64, sizeof(b64)/sizeof(int64_t) ); //exp: feed3322 call FunctionNameZb(0000000000000000)(ffffffffffffffff)(fffffffffffffffe)(3344555566666666)
26+
break; case __LINE__: Trice64F("RPC:FunctionNameZc", b64, sizeof(b64)/sizeof(int64_t) ); //exp: be16 RPC:FunctionNameZc(0000000000000000)(ffffffffffffffff)(fffffffffffffffe)(3344555566666666)
27+
break; case __LINE__: trice64F("Rpc:FunctionNameZd", b64, sizeof(b64)/sizeof(int64_t) ); //exp: Rpc:FunctionNameZd(0000000000000000)(ffffffffffffffff)(fffffffffffffffe)(3344555566666666)
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package cgot
2+
3+
// For some reason inside the trice_test.go an 'import "C"' is not possible.
4+
5+
// void TriceCheckSpecial( int n );
6+
import "C"
7+
import (
8+
"fmt"
9+
"strings"
10+
"testing"
11+
12+
"github.com/spf13/afero"
13+
"github.com/tj/assert"
14+
)
15+
16+
func targetSpecialActivity(n int) {
17+
C.TriceCheckSpecial(C.int(n))
18+
}
19+
20+
// triceLogSpecialTest creates a list of expected results from path.Join(triceDir, "./_test/tf/TargetActivity.c").
21+
// It loops over the result list and executes for each result the compiled C-code.
22+
// It passes the received binary data as buffer to the triceLog function of type logF.
23+
// This function is test package specific defined. The file cgoPackage.go is
24+
// copied into all specific test packages and compiled there together with the
25+
// triceConfig.h, which holds the test package specific target code configuration.
26+
// limit is the count of executed test lines starting from the beginning. -1 ist for all.
27+
func triceLogSpecialTest(t *testing.T, triceLog logF, limit int) {
28+
29+
osFSys := &afero.Afero{Fs: afero.NewOsFs()}
30+
31+
// CopyFileIntoFSys(t, mmFSys, "til.json", osFSys, td+"./til.json") // needed for the trice log
32+
out := make([]byte, 32768)
33+
setTriceBuffer(out)
34+
35+
result := getExpectedResults(osFSys, "./TargetActivity.c")
36+
37+
var count int
38+
for i, r := range result {
39+
40+
count++
41+
if limit >= 0 && count >= limit {
42+
return
43+
}
44+
45+
fmt.Println(i, r)
46+
47+
// target activity
48+
targetSpecialActivity(r.line) // triceCheck would compile but not wat we want here
49+
50+
triceTransfer() // This is only for deferred modes needed, but direct modes contain this as empty function.
51+
52+
length := triceOutDepth()
53+
bin := out[:length] // bin contains the binary trice data of trice message i in r.line
54+
55+
buf := fmt.Sprint(bin)
56+
buffer := buf[1 : len(buf)-1]
57+
58+
act := triceLog(t, osFSys, buffer)
59+
triceClearOutBuffer()
60+
61+
assert.Equal(t, r.exps, strings.TrimSuffix(act, "\n"))
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cgot
2+
3+
import (
4+
"bytes"
5+
"io"
6+
"path"
7+
"testing"
8+
9+
"github.com/rokath/trice/internal/args"
10+
"github.com/spf13/afero"
11+
"github.com/tj/assert"
12+
)
13+
14+
func TestLogs(t *testing.T) {
15+
// triceLog is the log function for executing the trice logging on binary log data in buffer as space separated numbers.
16+
// It uses the inside fSys specified til.json and returns the log output.
17+
triceLog := func(t *testing.T, fSys *afero.Afero, buffer string) string {
18+
var o bytes.Buffer
19+
assert.Nil(t, args.Handler(io.Writer(&o), fSys, []string{"trice", "log", "-pf=none", "-i", path.Join(triceDir, "/_test/testdata/til.json"), "-p=BUFFER", "-args", buffer, "-hs=off", "-prefix=off", "-li=off", "-color=none", "-ts0", "time: ", "-ts16", "time: %04x", "-ts32", "time:%08x"}))
20+
return o.String()
21+
}
22+
triceLogSpecialTest(t, triceLog, -1)
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*! \file triceConfig.h
2+
\author Thomas.Hoehenleitner [at] seerose.net
3+
*******************************************************************************/
4+
5+
#ifndef TRICE_CONFIG_H_
6+
#define TRICE_CONFIG_H_
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
#define TRICE_CLEAN 1
13+
14+
#define TRICE_BUFFER TRICE_STACK_BUFFER
15+
#define TRICE_DIRECT_OUTPUT 1
16+
#define TRICE_DIRECT_AUXILIARY32 1
17+
18+
#define TRICE_CGO 1
19+
#define TRICE_CYCLE_COUNTER 0
20+
21+
#ifdef __cplusplus
22+
}
23+
#endif
24+
25+
#endif /* TRICE_CONFIG_H_ */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Attention
2+
3+
* Do **not** edit `generated_cgoPackage.go`. Change instead file `../testdata/cgoPackage.go` and execute `../updateTestData.sh` afterwards. This influences _all_ cgot packages tests.
4+
* For individual modifications use file `cgo_test.go` or create an additional file.

0 commit comments

Comments
Β (0)