1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-23 00:00:01 +01:00
VILLASnode/go/pkg/node/node_test.go
Steffen Vogel 7eec1bb753 update Steffens mail address
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
2022-12-16 23:44:07 +01:00

95 lines
1.8 KiB
Go

/** Unit tests for using libvillas in Go code.
*
* @author Steffen Vogel <post@steffenvogel.de>
* @copyright 2014-2022, Institute for Automation of Complex Power Systems, EONERC
* @license Apache 2.0
*********************************************************************************/
package node_test
import (
"testing"
"time"
"git.rwth-aachen.de/acs/public/villas/node/go/pkg/config"
"git.rwth-aachen.de/acs/public/villas/node/go/pkg/node"
"github.com/google/uuid"
)
func TestNode(t *testing.T) {
cfg := &config.LoopbackNode{
Node: config.Node{
Name: "lo1",
Type: "loopback",
},
In: config.NodeLoopbackIn{
Hooks: []interface{}{
&config.PrintHook{
Hook: config.Hook{
Type: "print",
},
},
},
Signals: []config.Signal{
{
Name: "sig1",
},
{
Name: "sig2",
},
{
Name: "sig3",
},
},
},
}
n, err := node.NewNode(cfg, uuid.New())
if err != nil {
t.Fatalf("Failed to create node: %s", err)
}
defer n.Close()
if err := n.Check(); err != nil {
t.Fatalf("Failed to check node: %s", err)
}
if err := n.Prepare(); err != nil {
t.Fatalf("Failed to prepare node: %s", err)
}
if err := n.Start(); err != nil {
t.Fatalf("Failed to start node: %s", err)
}
defer n.Stop()
t.Logf("%s", n.NameFull())
smps_send := []node.Sample{
{
Sequence: 1234,
TimestampOrigin: time.Now(),
Data: []float64{1.1, 2.2, 3.3},
},
{
Sequence: 1235,
TimestampOrigin: time.Now(),
Data: []float64{4.4, 5.5, 6.6},
},
}
t.Logf("Sent: %+#v", smps_send)
cnt_written := n.Write(smps_send)
if cnt_written != len(smps_send) {
t.Fatalf("Failed to send all samples")
}
smps_received := n.Read(cnt_written)
if len(smps_received) != cnt_written {
t.Fatalf("Failed to receive samples back")
}
t.Logf("Received: %+#v", smps_received)
}