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:53 UTC

[plc4x] branch develop updated (4c0e1cb532 -> 66915585b2)

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

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


    from 4c0e1cb532 test(plc4go): hook in testing logger were not done yet
     new 9dd16ed55a feat(plc4go): ensure right logger is used when creating a transport instance
     new 66915585b2 test(plc4go): improve logging of driver test runner and test transport

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 plc4go/internal/ads/Driver.go            |  2 +-
 plc4go/internal/cbus/Driver.go           |  2 +-
 plc4go/internal/eip/Driver.go            |  2 +-
 plc4go/internal/modbus/AsciiDriver.go    |  2 +-
 plc4go/internal/modbus/RtuDriver.go      |  2 +-
 plc4go/internal/modbus/TcpDriver.go      |  2 +-
 plc4go/internal/s7/Driver.go             |  2 +-
 plc4go/spi/testutils/DriverTestRunner.go |  6 +++++-
 plc4go/spi/transports/test/Transport.go  | 12 +++++++++---
 9 files changed, 21 insertions(+), 11 deletions(-)


[plc4x] 01/02: feat(plc4go): ensure right logger is used when creating a transport instance

Posted by sr...@apache.org.
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 9dd16ed55a1f5c3bc971ff630180cd1aec56f651
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon Jun 12 13:31:16 2023 +0200

    feat(plc4go): ensure right logger is used when creating a transport instance
---
 plc4go/internal/ads/Driver.go         | 2 +-
 plc4go/internal/cbus/Driver.go        | 2 +-
 plc4go/internal/eip/Driver.go         | 2 +-
 plc4go/internal/modbus/AsciiDriver.go | 2 +-
 plc4go/internal/modbus/RtuDriver.go   | 2 +-
 plc4go/internal/modbus/TcpDriver.go   | 2 +-
 plc4go/internal/s7/Driver.go          | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/plc4go/internal/ads/Driver.go b/plc4go/internal/ads/Driver.go
index cfc2a33f3f..2bfbdf1294 100644
--- a/plc4go/internal/ads/Driver.go
+++ b/plc4go/internal/ads/Driver.go
@@ -62,7 +62,7 @@ func (m *Driver) GetConnectionWithContext(ctx context.Context, transportUrl url.
 	// Provide a default-port to the transport, which is used, if the user doesn't provide on in the connection string.
 	driverOptions["defaultTcpPort"] = []string{strconv.Itoa(int(adsModel.AdsConstants_ADSTCPDEFAULTPORT))}
 	// Have the transport create a new transport-instance.
-	transportInstance, err := transport.CreateTransportInstance(transportUrl, driverOptions)
+	transportInstance, err := transport.CreateTransportInstance(transportUrl, driverOptions, options.WithCustomLogger(m.log))
 	if err != nil {
 		m.log.Error().Stringer("transportUrl", &transportUrl).Msgf("We couldn't create a transport instance for port %#v", driverOptions["defaultTcpPort"])
 		ch := make(chan plc4go.PlcConnectionConnectResult, 1)
diff --git a/plc4go/internal/cbus/Driver.go b/plc4go/internal/cbus/Driver.go
index 27e38a0739..08fabaf5d3 100644
--- a/plc4go/internal/cbus/Driver.go
+++ b/plc4go/internal/cbus/Driver.go
@@ -66,7 +66,7 @@ func (m *Driver) GetConnectionWithContext(ctx context.Context, transportUrl url.
 	// Provide a default-port to the transport, which is used, if the user doesn't provide on in the connection string.
 	driverOptions["defaultTcpPort"] = []string{strconv.FormatUint(uint64(readWriteModel.CBusConstants_CBUSTCPDEFAULTPORT), 10)}
 	// Have the transport create a new transport-instance.
-	transportInstance, err := transport.CreateTransportInstance(transportUrl, driverOptions)
+	transportInstance, err := transport.CreateTransportInstance(transportUrl, driverOptions, options.WithCustomLogger(m.log))
 	if err != nil {
 		m.log.Error().Err(err).Stringer("transportUrl", &transportUrl).Msgf("We couldn't create a transport instance for port %#v", driverOptions["defaultTcpPort"])
 		return m.reportError(errors.Wrapf(err, "couldn't initialize transport configuration for given transport url %s", transportUrl.String()))
diff --git a/plc4go/internal/eip/Driver.go b/plc4go/internal/eip/Driver.go
index 5370638d9d..1d0c625f32 100644
--- a/plc4go/internal/eip/Driver.go
+++ b/plc4go/internal/eip/Driver.go
@@ -66,7 +66,7 @@ func (m *Driver) GetConnectionWithContext(ctx context.Context, transportUrl url.
 	// Provide a default-port to the transport, which is used, if the user doesn't provide on in the connection string.
 	driverOptions["defaultTcpPort"] = []string{"44818"}
 	// Have the transport create a new transport-instance.
-	transportInstance, err := transport.CreateTransportInstance(transportUrl, driverOptions)
+	transportInstance, err := transport.CreateTransportInstance(transportUrl, driverOptions, options.WithCustomLogger(m.log))
 	if err != nil {
 		m.log.Error().Stringer("transportUrl", &transportUrl).Msgf("We couldn't create a transport instance for port %#v", driverOptions["defaultTcpPort"])
 		ch := make(chan plc4go.PlcConnectionConnectResult, 1)
diff --git a/plc4go/internal/modbus/AsciiDriver.go b/plc4go/internal/modbus/AsciiDriver.go
index 4d77c1fb9d..e5c22d0f63 100644
--- a/plc4go/internal/modbus/AsciiDriver.go
+++ b/plc4go/internal/modbus/AsciiDriver.go
@@ -61,7 +61,7 @@ func (m AsciiDriver) GetConnectionWithContext(ctx context.Context, transportUrl
 	// Provide a default-port to the transport, which is used, if the user doesn't provide on in the connection string.
 	connectionOptions["defaultTcpPort"] = []string{"502"}
 	// Have the transport create a new transport-instance.
-	transportInstance, err := transport.CreateTransportInstance(transportUrl, connectionOptions)
+	transportInstance, err := transport.CreateTransportInstance(transportUrl, connectionOptions, options.WithCustomLogger(m.log))
 	if err != nil {
 		m.log.Error().Stringer("transportUrl", &transportUrl).Msgf("We couldn't create a transport instance for port %#v", connectionOptions["defaultTcpPort"])
 		ch := make(chan plc4go.PlcConnectionConnectResult, 1)
diff --git a/plc4go/internal/modbus/RtuDriver.go b/plc4go/internal/modbus/RtuDriver.go
index 7e285e0fc6..fb91955eb4 100644
--- a/plc4go/internal/modbus/RtuDriver.go
+++ b/plc4go/internal/modbus/RtuDriver.go
@@ -61,7 +61,7 @@ func (m RtuDriver) GetConnectionWithContext(ctx context.Context, transportUrl ur
 	// Provide a default-port to the transport, which is used, if the user doesn't provide on in the connection string.
 	driverOptions["defaultTcpPort"] = []string{"502"}
 	// Have the transport create a new transport-instance.
-	transportInstance, err := transport.CreateTransportInstance(transportUrl, driverOptions)
+	transportInstance, err := transport.CreateTransportInstance(transportUrl, driverOptions, options.WithCustomLogger(m.log))
 	if err != nil {
 		m.log.Error().Stringer("transportUrl", &transportUrl).Msgf("We couldn't create a transport instance for port %#v", driverOptions["defaultTcpPort"])
 		ch := make(chan plc4go.PlcConnectionConnectResult, 1)
diff --git a/plc4go/internal/modbus/TcpDriver.go b/plc4go/internal/modbus/TcpDriver.go
index ffacff0073..067b8f62ad 100644
--- a/plc4go/internal/modbus/TcpDriver.go
+++ b/plc4go/internal/modbus/TcpDriver.go
@@ -61,7 +61,7 @@ func (m TcpDriver) GetConnectionWithContext(ctx context.Context, transportUrl ur
 	// Provide a default-port to the transport, which is used, if the user doesn't provide on in the connection string.
 	driverOptions["defaultTcpPort"] = []string{"502"}
 	// Have the transport create a new transport-instance.
-	transportInstance, err := transport.CreateTransportInstance(transportUrl, driverOptions)
+	transportInstance, err := transport.CreateTransportInstance(transportUrl, driverOptions, options.WithCustomLogger(m.log))
 	if err != nil {
 		m.log.Error().Stringer("transportUrl", &transportUrl).Msgf("We couldn't create a transport instance for port %#v", driverOptions["defaultTcpPort"])
 		ch := make(chan plc4go.PlcConnectionConnectResult, 1)
diff --git a/plc4go/internal/s7/Driver.go b/plc4go/internal/s7/Driver.go
index 2fea12f057..56a9e9127b 100644
--- a/plc4go/internal/s7/Driver.go
+++ b/plc4go/internal/s7/Driver.go
@@ -66,7 +66,7 @@ func (m *Driver) GetConnectionWithContext(ctx context.Context, transportUrl url.
 	// Provide a default-port to the transport, which is used, if the user doesn't provide on in the connection string.
 	driverOptions["defaultTcpPort"] = []string{"102"}
 	// Have the transport create a new transport-instance.
-	transportInstance, err := transport.CreateTransportInstance(transportUrl, driverOptions)
+	transportInstance, err := transport.CreateTransportInstance(transportUrl, driverOptions, options.WithCustomLogger(m.log))
 	if err != nil {
 		m.log.Error().Stringer("transportUrl", &transportUrl).Msgf("We couldn't create a transport instance for port %#v", driverOptions["defaultTcpPort"])
 		ch := make(chan plc4go.PlcConnectionConnectResult, 1)


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

Posted by sr...@apache.org.
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...)
 }