You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/06/12 11:40:55 UTC

[plc4x] 02/02: test(plc4go): improve logging of driver test runner and test transport

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 66915585b23395cef14a935ea582266b123abcd8
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon Jun 12 13:40:44 2023 +0200

    test(plc4go): improve logging of driver test runner and test transport
---
 plc4go/spi/testutils/DriverTestRunner.go |  6 +++++-
 plc4go/spi/transports/test/Transport.go  | 12 +++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/plc4go/spi/testutils/DriverTestRunner.go b/plc4go/spi/testutils/DriverTestRunner.go
index d7900b8ab1..fa7f841e61 100644
--- a/plc4go/spi/testutils/DriverTestRunner.go
+++ b/plc4go/spi/testutils/DriverTestRunner.go
@@ -478,7 +478,7 @@ const (
 )
 
 func RunDriverTestsuite(t *testing.T, driver plc4go.PlcDriver, testPath string, parser XmlParser, _options ...config.WithOption) {
-	t.Log("Extract testsuite _options")
+	t.Log("Extract testsuite options")
 	var rootTypeParser func(utils.ReadBufferByteBased) (any, error)
 	skippedTestCasesMap := map[string]bool{}
 	for _, withOption := range _options {
@@ -494,18 +494,22 @@ func RunDriverTestsuite(t *testing.T, driver plc4go.PlcDriver, testPath string,
 			}
 		}
 	}
+	t.Log("Read the test-specification as XML file")
 	// Read the test-specification as XML file
 	rootNode := ParseDriverTestsuiteXml(t, testPath)
 
+	t.Log("Parse the contents of the test-specification")
 	// Parse the contents of the test-specification
 	testsuite := ParseDriverTestsuite(t, *rootNode, parser, rootTypeParser)
 
 	// We don't want to await completion of connection initialization
 	if connectionConnectAwaiter, ok := driver.(ConnectionConnectAwaiter); ok {
+		t.Log("We don't wait for setup and disconnect")
 		connectionConnectAwaiter.SetAwaitSetupComplete(false)
 		connectionConnectAwaiter.SetAwaitDisconnectComplete(false)
 	}
 
+	t.Log("Initialize the driver manager")
 	// Initialize the driver manager
 	driverManager := plc4go.NewPlcDriverManager(_options...)
 	transport := test.NewTransport(converter.WithOptionToInternal(_options...)...)
diff --git a/plc4go/spi/transports/test/Transport.go b/plc4go/spi/transports/test/Transport.go
index 5f11bd346d..c81c3bc00b 100644
--- a/plc4go/spi/transports/test/Transport.go
+++ b/plc4go/spi/transports/test/Transport.go
@@ -23,6 +23,7 @@ import (
 	"bufio"
 	"bytes"
 	"context"
+	"encoding/hex"
 	"math"
 	"net/url"
 
@@ -126,13 +127,16 @@ func (m *TransportInstance) GetNumBytesAvailableInBuffer() (uint32, error) {
 }
 
 func (m *TransportInstance) FillBuffer(until func(pos uint, currentByte byte, reader *bufio.Reader) bool) error {
+	m.log.Trace().Msg("Fill the buffer")
 	nBytes := uint32(1)
 	for {
+		m.log.Trace().Msgf("Peeking %d bytes", nBytes)
 		_bytes, err := m.PeekReadableBytes(nBytes)
 		if err != nil {
 			return errors.Wrap(err, "Error while peeking")
 		}
 		if keepGoing := until(uint(nBytes-1), _bytes[len(_bytes)-1], bufio.NewReader(bytes.NewReader(m.readBuffer))); !keepGoing {
+			m.log.Trace().Msgf("Stopped after %d bytes", nBytes)
 			return nil
 		}
 		nBytes++
@@ -147,15 +151,17 @@ func (m *TransportInstance) PeekReadableBytes(numBytes uint32) ([]byte, error) {
 		err = errors.New("not enough bytes available")
 	}
 	if availableBytes == 0 {
+		m.log.Trace().Msg("No bytes available")
 		return nil, err
 	}
 	return m.readBuffer[0:availableBytes], err
 }
 
 func (m *TransportInstance) Read(numBytes uint32) ([]byte, error) {
-	m.log.Trace().Msgf("Read num bytes %d", numBytes)
+	m.log.Trace().Msgf("Read num bytes %d (of %d available)", numBytes, len(m.readBuffer))
 	data := m.readBuffer[0:int(numBytes)]
 	m.readBuffer = m.readBuffer[int(numBytes):]
+	m.log.Trace().Msgf("New buffer size %d", len(m.readBuffer))
 	return data, nil
 }
 
@@ -167,13 +173,13 @@ func (m *TransportInstance) Write(data []byte) error {
 	if m.writeInterceptor != nil {
 		m.writeInterceptor(m, data)
 	}
-	m.log.Trace().Msgf("Write data %#x", data)
+	m.log.Trace().Msgf("Write data\n%s", hex.Dump(data))
 	m.writeBuffer = append(m.writeBuffer, data...)
 	return nil
 }
 
 func (m *TransportInstance) FillReadBuffer(data []byte) {
-	m.log.Trace().Msgf("FillReadBuffer with %#x", data)
+	m.log.Trace().Msgf("fill read buffer with \n%s (%d bytes). (Adding to %d bytes existing)", hex.Dump(data), len(data), len(m.readBuffer))
 	m.readBuffer = append(m.readBuffer, data...)
 }