| // Copyright 2019 The ChromiumOS Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package example |
| |
| import ( |
| "context" |
| |
| "github.com/golang/protobuf/ptypes/empty" |
| |
| "go.chromium.org/tast-tests/cros/services/cros/example" |
| "go.chromium.org/tast/core/rpc" |
| "go.chromium.org/tast/core/testing" |
| ) |
| |
| func init() { |
| testing.AddTest(&testing.Test{ |
| Func: GRPC, |
| LacrosStatus: testing.LacrosVariantUnneeded, |
| Desc: "Demonstrates how to use gRPC support to run Go code on DUT", |
| Contacts: []string{"tast-core@google.com", "seewaifu@google.com"}, |
| BugComponent: "b:1034522", // ChromeOS > Test > Harness > Tast > Examples |
| Attr: []string{"group:mainline", "informational", "group:hw_agnostic"}, |
| SoftwareDeps: []string{"chrome"}, |
| ServiceDeps: []string{"tast.cros.example.ChromeService"}, |
| }) |
| } |
| |
| func GRPC(ctx context.Context, s *testing.State) { |
| // Connect to the gRPC server on the DUT. |
| cl, err := rpc.Dial(ctx, s.DUT(), s.RPCHint()) |
| if err != nil { |
| s.Fatal("Failed to connect to the RPC service on the DUT: ", err) |
| } |
| defer cl.Close(ctx) |
| |
| cr := example.NewChromeServiceClient(cl.Conn) |
| |
| if _, err := cr.New(ctx, &empty.Empty{}); err != nil { |
| s.Fatal("Failed to start Chrome: ", err) |
| } |
| defer cr.Close(ctx, &empty.Empty{}) |
| |
| const expr = "chrome.i18n.getUILanguage()" |
| req := &example.EvalOnTestAPIConnRequest{Expr: expr} |
| res, err := cr.EvalOnTestAPIConn(ctx, req) |
| if err != nil { |
| s.Fatalf("Failed to eval %s: %v", expr, err) |
| } |
| s.Logf("Eval(%q) = %s", expr, res.ValueJson) |
| } |