Skip to content

Commit

Permalink
The tests in folder "_test" now executable with `cd _test && go test …
Browse files Browse the repository at this point in the history
…./... && cd -`
  • Loading branch information
rokath committed Oct 22, 2024
1 parent 1d79e37 commit 32bf83b
Show file tree
Hide file tree
Showing 114 changed files with 283 additions and 283 deletions.
30 changes: 15 additions & 15 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"program": "${workspaceFolder}/cmd/trice",
"env": {},
"args": ["log",
"-idlist", "${workspaceFolder}/test/til.json",
"-idlist", "${workspaceFolder}/_test/til.json",
"-source", "RND",
"-rndLimit", "10",
"-rndMode", "ChaosMode",
Expand Down Expand Up @@ -158,9 +158,9 @@
"-pf",
"COBS",
"-idlist",
"${workspaceFolder}/test/testdata/til.json",
"${workspaceFolder}/_test/testdata/til.json",
"-li",
"${workspaceFolder}/test/testdata/li.json"
"${workspaceFolder}/_test/testdata/li.json"
]
},
{
Expand Down Expand Up @@ -202,9 +202,9 @@
"-d16",
"-s",
"-idlist",
"${workspaceFolder}/test/testdata/til.json",
"${workspaceFolder}/_test/testdata/til.json",
"-li",
"${workspaceFolder}/test/testdata/li.json"
"${workspaceFolder}/_test/testdata/li.json"
]
},
{
Expand Down Expand Up @@ -236,9 +236,9 @@
"-args",
"cb de 32 13 c0 0b 61 62 63 64 65 20 31 32 33 34 35 ad 00",
"-idlist",
"${workspaceFolder}/test/testdata/til.json",
"${workspaceFolder}/_test/testdata/til.json",
"-li",
"${workspaceFolder}/test/testdata/li.json"
"${workspaceFolder}/_test/testdata/li.json"
]
},
{
Expand All @@ -250,9 +250,9 @@
"env": {},
"args": ["log",
"-idlist",
"${workspaceFolder}/test/testdata/til.json",
"${workspaceFolder}/_test/testdata/til.json",
"-li",
"${workspaceFolder}/test/testdata/li.json",
"${workspaceFolder}/_test/testdata/li.json",
"-port",
"DUMP",
"-args",
Expand Down Expand Up @@ -291,9 +291,9 @@
"env": {},
"args": ["log",
"-idlist",
"${workspaceFolder}/test/testdata/til.json",
"${workspaceFolder}/_test/testdata/til.json",
"-li",
"${workspaceFolder}/test/testdata/li.json",
"${workspaceFolder}/_test/testdata/li.json",
"-port",
"COM6",
"-baud",
Expand All @@ -309,9 +309,9 @@
"env": {},
"args": ["log",
"-idlist",
"${workspaceFolder}/test/testdata/til.json",
"${workspaceFolder}/_test/testdata/til.json",
"-li",
"${workspaceFolder}/test/testdata/li.json",
"${workspaceFolder}/_test/testdata/li.json",
"-port",
"JLINK",
"-args",
Expand Down Expand Up @@ -412,9 +412,9 @@
"env": {},
"args": ["log",
"-idlist",
"${workspaceFolder}/test/testdata/til.json",
"${workspaceFolder}/_test/testdata/til.json",
"-locationInformation",
"${workspaceFolder}/test/testdata/li.json",
"${workspaceFolder}/_test/testdata/li.json",
"-p",
"com4",
"-baud",
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
![GitHub commits since latest release](https://img.shields.io/github/commits-since/rokath/trice/latest)
[![Go Report Card](https://goreportcard.com/badge/github.com/rokath/trice)](https://goreportcard.com/report/github.com/rokath/trice)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![test](https://github.com/shogo82148/actions-goveralls/workflows/test/badge.svg?branch=main)](https://coveralls.io/github/rokath/trice)
[![test](https://github.com/shogo82148/actions-goveralls/workflows/_test/badge.svg?branch=main)](https://coveralls.io/github/rokath/trice)
[![Coverage Status](https://coveralls.io/repos/github/rokath/trice/badge.svg?branch=master)](https://coveralls.io/github/rokath/trice?branch=master)

<!-- [![Sponsor rokath](https://github.com/sponsors/rokath/button)](https://github.com/sponsors/rokath) -->
Expand All @@ -36,14 +36,14 @@ even inside **↯ interrupts** in less than 1 µs❗

## Possible Use Cases

- Using *Trice* not only for **printf debugging** but also as **logging** technique is possible and gives the advantage to have very short messages (no strings) for transmission, but keep in mind that the file [til.json](./test/testdata/til.json) is the key to read all output if your devices in the field for 10 or more years.
- Optionally add [til.json](./test/testdata/til.json) as a (compressed) resource to your target image. One possibility is using [SRecord](http://srecord.sourceforge.net/download.html). Or simply provide a download link.
- Using *Trice* not only for **printf debugging** but also as **logging** technique is possible and gives the advantage to have very short messages (no strings) for transmission, but keep in mind that the file [til.json](./_test/testdata/til.json) is the key to read all output if your devices in the field for 10 or more years.
- Optionally add [til.json](./_test/testdata/til.json) as a (compressed) resource to your target image. One possibility is using [SRecord](http://srecord.sourceforge.net/download.html). Or simply provide a download link.
- You can see *Trice* also as a kind of **data compression** what could be interesting for [IoT](https://en.wikipedia.org/wiki/Internet_of_things) things, especially [NB-IoT](https://en.wikipedia.org/wiki/Narrowband_IoT), where you have very low data rates.
- Storing *Trice* messages in [FLASH memory](https://en.wikipedia.org/wiki/Flash_memory) for later log analysis saves memory because a typical `TRICE` occupies only 4 bytes independently of the format string length plus optional values.
- Also, it is possible to **encrypt** the *Trice* transfer packets to get a reasonable protection for many cases.
- This way you can deliver firmware images with encrypted *Trice* output, only readable with the appropriate key and [til.json](./test/testdata/til.json).
- This way you can deliver firmware images with encrypted *Trice* output, only readable with the appropriate key and [til.json](./_test/testdata/til.json).
- [XTEA](https://en.m.wikipedia.org/wiki/XTEA) is implemented as one option.
- You can even translate the [til.json](./test/testdata/til.json) file in **different languages**, so changing a language is just changing the [til.json](./test/testdata/til.json) file without touching the target binary.
- You can even translate the [til.json](./_test/testdata/til.json) file in **different languages**, so changing a language is just changing the [til.json](./_test/testdata/til.json) file without touching the target binary.
- With *Trice* it is easy to do **timing analysis** on distributed embedded systems. Host and target timestamps are supported.

## How it approximately works (UART example)
Expand Down Expand Up @@ -131,7 +131,7 @@ git clone https://github.com/rokath/trice.git
- [Logging with symbols - The Embedonomicon](https://docs.rust-embedded.org/embedonomicon/logging.html)
- [MCUViewer](https://github.com/klonyyy/MCUViewer)
- [Memfault Compact Log Library](https://docs.memfault.com/docs/mcu/compact-logs/#host-decoding)
- [Metal Serial Library](https://github.com/metal-ci/test/tree/master/doc/metal.serial.md)
- [Metal Serial Library](https://github.com/metal-ci/_test/tree/master/doc/metal.serial.md)
- [Minimal Structured Logging for Autonomous Vehikles](https://youtu.be/FyJI4Z6jD4w) (C++, closed source talk)
- [NanoLog](https://github.com/PlatformLab/NanoLog) (Linux C++)
- [Percepio Tracealyzer](https://percepio.com/tracealyzer/) (Visual Trace Diagnostics)
Expand Down
4 changes: 2 additions & 2 deletions _test/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ The `testdata\cgoPackage.go` file contains a variable `testLines = n`, which lim

## Test Internals

The `./trice/test/testdata/*.c` and `./trice/src/*.c` are compiled together with the actual cgot package into one singe Trice test binary. Calling its TestFunction(s) causes the activation of the Trice statement(s) inside *triceCheck.c*. The ususally into an embedded device compiled Trice code generates a few bytes according to the configuration into a buffer. These bytes are transmitted in real life over a (serial) port or RTT. In the test this buffer is then read out by the Trice tool handler function according to the used CLI switches and processed to a log string using the *til.json* file. This string in then compared to the expected string for the activated line.
The `./trice/_test/testdata/*.c` and `./trice/src/*.c` are compiled together with the actual cgot package into one singe Trice test binary. Calling its TestFunction(s) causes the activation of the Trice statement(s) inside *triceCheck.c*. The ususally into an embedded device compiled Trice code generates a few bytes according to the configuration into a buffer. These bytes are transmitted in real life over a (serial) port or RTT. In the test this buffer is then read out by the Trice tool handler function according to the used CLI switches and processed to a log string using the *til.json* file. This string in then compared to the expected string for the activated line.

Each `tf` is a **Go** package, which is not part of any **Go** application. They all named `cgot` and are only used independently for testing different configurations. The `tf/generated_cgoPackage.go` file is identical in all `tf`. Its master is `testdata/cgoPackage.go`. After editing the master, running the command `./updateTestData.sh` copies the master to all `tf` and renames it to `generated_cgoPackage.go`.

The test specific target code configuration is inside `tf/trice.Config.h` and the appropriate Trice tool CLI switches are in `tf/cgo_test.go`.

When running `go test ./test/tf`, a Trice tool test executable is build, using the Trice tool packages and the `tf` package `cgot`, and the function `TestLogs` is executed. Its internal closure `triceLog` contains the Trice tool CLI switches and is passed to the `ccgot` package function `triceLogTest` together with the number of testLines and the trice mode (`directTransfer` or `deferrerdTransfer`).
When running `go test ./_test/tf`, a Trice tool test executable is build, using the Trice tool packages and the `tf` package `cgot`, and the function `TestLogs` is executed. Its internal closure `triceLog` contains the Trice tool CLI switches and is passed to the `ccgot` package function `triceLogTest` together with the number of testLines and the trice mode (`directTransfer` or `deferrerdTransfer`).

During the test, the file `triceCheck.c` is scanned for lines like

Expand Down
4 changes: 2 additions & 2 deletions _test/_ERROR_dblB_di_cobs_rtt32__de_xtea_cobs_ua/cgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ func TestLogs(t *testing.T) {
// It uses the inside fSys specified til.json and returns the log output.
triceLog0 := func(t *testing.T, fSys *afero.Afero, buffer string) string {
var o bytes.Buffer
assert.Nil(t, args.Handler(io.Writer(&o), fSys, []string{"trice", "log", "-i", path.Join(triceDir, "/test/testdata/til.json"), "-p=BUFFER", "-args", buffer, "-hs=off", "-prefix=off", "-li=off", "-color=off", "-pf=COBS", "-d16", "-ts16", "time: %04x", "-ts32", "time:%08x"}))
assert.Nil(t, args.Handler(io.Writer(&o), fSys, []string{"trice", "log", "-i", path.Join(triceDir, "/_test/testdata/til.json"), "-p=BUFFER", "-args", buffer, "-hs=off", "-prefix=off", "-li=off", "-color=off", "-pf=COBS", "-d16", "-ts16", "time: %04x", "-ts32", "time:%08x"}))
return o.String()
}

// triceLog is the log function for executing the trice logging on binary log data in buffer as space separated numbers.
// It uses the inside fSys specified til.json and returns the log output.
triceLog1 := func(t *testing.T, fSys *afero.Afero, buffer string) string {
var o bytes.Buffer
assert.Nil(t, args.Handler(io.Writer(&o), fSys, []string{"trice", "log", "-i", path.Join(triceDir, "/test/testdata/til.json"), "-p=BUFFER", "-args", buffer, "-hs=off", "-prefix=off", "-li=off", "-color=off", "-pw=MySecret", "-pf=COBS", "-d16=false", "-ts16", "time: %04x", "-ts32", "time:%08x"}))
assert.Nil(t, args.Handler(io.Writer(&o), fSys, []string{"trice", "log", "-i", path.Join(triceDir, "/_test/testdata/til.json"), "-p=BUFFER", "-args", buffer, "-hs=off", "-prefix=off", "-li=off", "-color=off", "-pw=MySecret", "-pf=COBS", "-d16=false", "-ts16", "time: %04x", "-ts32", "time:%08x"}))
return o.String()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func getExpectedResults(fSys *afero.Afero, filename string) (result []results) {
// It uses the inside fSys specified til.json and returns the log output.
type logF func(t *testing.T, fSys *afero.Afero, buffer string) string

// triceLogTest creates a list of expected results from path.Join(triceDir, "./test/testdata/triceCheck.c").
// triceLogTest creates a list of expected results from path.Join(triceDir, "./_test/testdata/triceCheck.c").
// It loops over the result list and executes for each result the compiled C-code.
// It passes the received binary data as buffer to the triceLog function of type logF.
// This function is test package specific defined. The file cgoPackage.go is
Expand All @@ -155,7 +155,7 @@ func triceLogTest(t *testing.T, triceLog logF, limit int) {
out := make([]byte, 32768)
setTriceBuffer(out)

result := getExpectedResults(osFSys, path.Join(triceDir, "./test/testdata/triceCheck.c"))
result := getExpectedResults(osFSys, path.Join(triceDir, "./_test/testdata/triceCheck.c"))

var count int
for i, r := range result {
Expand Down Expand Up @@ -194,7 +194,7 @@ func triceLogTest2(t *testing.T, triceLog0, triceLog1 logF, limit int) {
out := make([]byte, 32768)
setTriceBuffer(out)

result := getExpectedResults(osFSys, path.Join(triceDir, "./test/testdata/triceCheck.c"))
result := getExpectedResults(osFSys, path.Join(triceDir, "./_test/testdata/triceCheck.c"))

var count int
for i, r := range result {
Expand Down
4 changes: 2 additions & 2 deletions _test/_ERROR_ringB_di_cobs_rtt32__de_xtea_cobs_ua/cgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ func TestLogs(t *testing.T) {
// It uses the inside fSys specified til.json and returns the log output.
triceLog0 := func(t *testing.T, fSys *afero.Afero, buffer string) string {
var o bytes.Buffer
assert.Nil(t, args.Handler(io.Writer(&o), fSys, []string{"trice", "log", "-i", path.Join(triceDir, "/test/testdata/til.json"), "-p=BUFFER", "-args", buffer, "-hs=off", "-prefix=off", "-li=off", "-color=off", "-pf=COBS", "-d16", "-ts16", "time: %04x", "-ts32", "time:%08x"}))
assert.Nil(t, args.Handler(io.Writer(&o), fSys, []string{"trice", "log", "-i", path.Join(triceDir, "/_test/testdata/til.json"), "-p=BUFFER", "-args", buffer, "-hs=off", "-prefix=off", "-li=off", "-color=off", "-pf=COBS", "-d16", "-ts16", "time: %04x", "-ts32", "time:%08x"}))
return o.String()
}

// triceLog is the log function for executing the trice logging on binary log data in buffer as space separated numbers.
// It uses the inside fSys specified til.json and returns the log output.
triceLog1 := func(t *testing.T, fSys *afero.Afero, buffer string) string {
var o bytes.Buffer
assert.Nil(t, args.Handler(io.Writer(&o), fSys, []string{"trice", "log", "-i", path.Join(triceDir, "/test/testdata/til.json"), "-p=BUFFER", "-args", buffer, "-hs=off", "-prefix=off", "-li=off", "-color=off", "-pw=MySecret", "-pf=COBS", "-d16=false", "-ts16", "time: %04x", "-ts32", "time:%08x"}))
assert.Nil(t, args.Handler(io.Writer(&o), fSys, []string{"trice", "log", "-i", path.Join(triceDir, "/_test/testdata/til.json"), "-p=BUFFER", "-args", buffer, "-hs=off", "-prefix=off", "-li=off", "-color=off", "-pw=MySecret", "-pf=COBS", "-d16=false", "-ts16", "time: %04x", "-ts32", "time:%08x"}))
return o.String()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func getExpectedResults(fSys *afero.Afero, filename string) (result []results) {
// It uses the inside fSys specified til.json and returns the log output.
type logF func(t *testing.T, fSys *afero.Afero, buffer string) string

// triceLogTest creates a list of expected results from path.Join(triceDir, "./test/testdata/triceCheck.c").
// triceLogTest creates a list of expected results from path.Join(triceDir, "./_test/testdata/triceCheck.c").
// It loops over the result list and executes for each result the compiled C-code.
// It passes the received binary data as buffer to the triceLog function of type logF.
// This function is test package specific defined. The file cgoPackage.go is
Expand All @@ -155,7 +155,7 @@ func triceLogTest(t *testing.T, triceLog logF, limit int) {
out := make([]byte, 32768)
setTriceBuffer(out)

result := getExpectedResults(osFSys, path.Join(triceDir, "./test/testdata/triceCheck.c"))
result := getExpectedResults(osFSys, path.Join(triceDir, "./_test/testdata/triceCheck.c"))

var count int
for i, r := range result {
Expand Down Expand Up @@ -194,7 +194,7 @@ func triceLogTest2(t *testing.T, triceLog0, triceLog1 logF, limit int) {
out := make([]byte, 32768)
setTriceBuffer(out)

result := getExpectedResults(osFSys, path.Join(triceDir, "./test/testdata/triceCheck.c"))
result := getExpectedResults(osFSys, path.Join(triceDir, "./_test/testdata/triceCheck.c"))

var count int
for i, r := range result {
Expand Down
4 changes: 2 additions & 2 deletions _test/_ERROR_ringB_di_xtea_cobs_rtt32__de_cobs_ua/cgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestLogs(t *testing.T) {
triceLog0 := func(t *testing.T, fSys *afero.Afero, buffer string) string {
var o bytes.Buffer
// trice -p jlink -args "-Device STM32F030R8 -if SWD -Speed 4000 -RTTChannel 0" -showID "deb:%04x" -hs off -pw MySecret -pf COBS -d16=true
assert.Nil(t, args.Handler(io.Writer(&o), fSys, []string{"trice", "log", "-i", path.Join(triceDir, "/test/testdata/til.json"), "-p=BUFFER", "-args", buffer, "-hs=off", "-prefix=off", "-li=off", "-color=off", "-pw=MySecret", "-pf=COBS", "-d16=true", "-ts16", "time: %04x", "-ts32", "time:%08x"}))
assert.Nil(t, args.Handler(io.Writer(&o), fSys, []string{"trice", "log", "-i", path.Join(triceDir, "/_test/testdata/til.json"), "-p=BUFFER", "-args", buffer, "-hs=off", "-prefix=off", "-li=off", "-color=off", "-pw=MySecret", "-pf=COBS", "-d16=true", "-ts16", "time: %04x", "-ts32", "time:%08x"}))
return o.String()
}

Expand All @@ -27,7 +27,7 @@ func TestLogs(t *testing.T) {
triceLog1 := func(t *testing.T, fSys *afero.Afero, buffer string) string {
var o bytes.Buffer
// trice l -p com4 -d16=false
assert.Nil(t, args.Handler(io.Writer(&o), fSys, []string{"trice", "log", "-i", path.Join(triceDir, "/test/testdata/til.json"), "-p=BUFFER", "-args", buffer, "-hs=off", "-prefix=off", "-li=off", "-color=off", "-pf=COBS", "-d16=false", "-ts16", "time: %04x", "-ts32", "time:%08x"}))
assert.Nil(t, args.Handler(io.Writer(&o), fSys, []string{"trice", "log", "-i", path.Join(triceDir, "/_test/testdata/til.json"), "-p=BUFFER", "-args", buffer, "-hs=off", "-prefix=off", "-li=off", "-color=off", "-pf=COBS", "-d16=false", "-ts16", "time: %04x", "-ts32", "time:%08x"}))
return o.String()
}

Expand Down
Loading

0 comments on commit 32bf83b

Please sign in to comment.