blob: 57ead9de95bfc404c0a87ff47cb6ab975eca5941 [file] [log] [blame]
// 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"
"github.com/golang/protobuf/ptypes/empty"
"chromiumos/tast/remote/firmware"
"chromiumos/tast/remote/firmware/reporters"
"chromiumos/tast/common/servo"
"chromiumos/tast/rpc"
fwService "chromiumos/tast/services/cros/firmware"
"chromiumos/tast/testing"
"chromiumos/tast/testing/hwdep"
)
func init() {
testing.AddTest(&testing.Test{
Func: CodelabRPC,
Desc: "Demonstrates common functionality for remote firmware tests",
Contacts: []string{
"me@chromium.org", // Test author
"my-team@chromium.org", // Backup mailing list
},
Data: []string{firmware.ConfigFile},
Attr: []string{"group:firmware", "firmware_experimental"},
HardwareDeps: hwdep.D(hwdep.ChromeEC()),
ServiceDeps: []string{"tast.cros.firmware.BiosService"},
Vars: []string{"servo"},
})
}
// CodelabRPC demonstrates using an RPC to run a subroutine on the DUT.
func CodelabRPC(ctx context.Context, s *testing.State) {
r := reporters.New(s.DUT())
board, err := r.Board(ctx)
if err != nil {
s.Fatal("Failed to report board: ", err)
}
model, err := r.Model(ctx)
if err != nil {
s.Fatal("Failed to report model: ", err)
}
s.Logf("Reported board=%s, model=%s", board, model)
cfg, err := firmware.NewConfig(s.DataPath(firmware.ConfigFile), board, model)
if err != nil {
s.Fatal("Failed to create config: ", err)
}
s.Log("This DUT's mode-switcher type is: ", cfg.ModeSwitcherType)
// Set up Servo
dut := s.DUT()
servoSpec, _ := s.Var("servo")
pxy, err := servo.NewProxy(ctx, servoSpec, dut.KeyFile(), dut.KeyDir())
if err != nil {
s.Fatal("Failed to connect to servo: ", err)
}
defer pxy.Close(ctx)
// Get the DUT's ec_board via Servo
ecBoard, err := pxy.Servo().GetString(ctx, servo.ECBoard)
if err != nil {
s.Fatal("Getting ec_board control from servo: ", err)
}
s.Log("EC Board: ", ecBoard)
// Connect to RPC
cl, err := rpc.Dial(ctx, dut, s.RPCHint())
if err != nil {
s.Fatal("Failed to connect to RPC service on the DUT: ", err)
}
defer cl.Close(ctx)
// Get current GBB flags via RPC
bios := fwService.NewBiosServiceClient(cl.Conn)
flags, err := bios.GetGBBFlags(ctx, &empty.Empty{})
if err != nil {
s.Fatal("Failed to get GBB flags: ", err)
}
s.Log("Clear GBB flags: ", flags.Clear)
s.Log("Set GBB flags: ", flags.Set)
}