/
remote_serial_port.go
77 lines (65 loc) · 2.01 KB
/
remote_serial_port.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2021 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package firmware
import (
"context"
"time"
commonSerial "chromiumos/tast/common/firmware/serial"
"chromiumos/tast/remote/firmware/serial"
"chromiumos/tast/rpc"
pb "chromiumos/tast/services/cros/firmware"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: RemoteSerialPort,
Desc: "Test RemoteSerialPort",
Timeout: 1 * time.Minute,
Contacts: []string{
"aluo@chromium.org", // Test Author
"chromeos-firmware@google.com", // CrOS Firmware Developers
},
ServiceDeps: []string{"tast.cros.firmware.SerialPortService"},
Attr: []string{"group:firmware", "firmware_smoke"},
})
}
func RemoteSerialPort(ctx context.Context, s *testing.State) {
rpcClient, err := rpc.Dial(ctx, s.DUT(), s.RPCHint())
if err != nil {
s.Fatal("Error dialing rpc: ", err)
}
defer rpcClient.Close(ctx)
pty1, pty2, cancel, done, err := commonSerial.CreateDUTPTYPair(ctx, s.DUT())
if err != nil {
s.Fatal("Error creating pty: ", err)
}
defer func() {
cancel()
<-done
}()
s.Logf("Created ptys: %s %s", pty1, pty2)
serviceClient := pb.NewSerialPortServiceClient(rpcClient.Conn)
o1 := serial.NewRemotePortOpener(serviceClient, pty1, 115200, 200*time.Millisecond)
o2 := serial.NewRemotePortOpener(serviceClient, pty2, 115200, 200*time.Millisecond)
s.Log("Opening remote ports should work")
p1, err := o1.OpenPort(ctx)
if err != nil {
s.Fatal("Open port 1: ", err)
}
defer p1.Close(ctx)
p2, err := o2.OpenPort(ctx)
if err != nil {
s.Fatal("Open port 2: ", err)
}
defer p2.Close(ctx)
if err = commonSerial.DoTestRead(ctx, s.Log, p1, p2); err != nil {
s.Fatal("TestRead failed: ", err)
}
if err = commonSerial.DoTestWrite(ctx, s.Log, p1, p2); err != nil {
s.Fatal("TestWrite failed: ", err)
}
if err = commonSerial.DoTestFlush(ctx, s.Log, p1, p2); err != nil {
s.Fatal("TestFlush failed: ", err)
}
}