blob: 3f1ec2e878269d6179cfa398ad65792bc5a80753 [file]
// Copyright 2020 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 wilco
import (
"context"
"encoding/json"
"time"
"github.com/golang/protobuf/ptypes/empty"
"chromiumos/tast/common/policy"
"chromiumos/tast/ctxutil"
"chromiumos/tast/remote/policyutil"
"chromiumos/tast/rpc"
ps "chromiumos/tast/services/cros/policy"
"chromiumos/tast/services/cros/wilco"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: APIGetStatefulPartitionAvailableCapacity,
LacrosStatus: testing.LacrosVariantUnknown,
Desc: "Test sending GetStatefulPartitionAvailableCapacity gRPC requests from Wilco DTC VM to the Wilco DTC Support Daemon",
Contacts: []string{
"lamzin@google.com", // wilco_dtc_supportd maintainer
"chromeos-wilco@google.com",
"rbock@google.com", // test author
},
Attr: []string{"group:enrollment"},
SoftwareDeps: []string{"reboot", "vm_host", "wilco", "chrome"},
ServiceDeps: []string{"tast.cros.wilco.WilcoService", "tast.cros.policy.PolicyService"},
Timeout: 10 * time.Minute,
})
}
// APIGetStatefulPartitionAvailableCapacity tests GetStatefulPartitionAvailableCapacity gRPC API.
// TODO(b/189457904): remove once wilco.APIGetStatefulPartitionAvailableCapacityEnrolled will be stable enough.
func APIGetStatefulPartitionAvailableCapacity(ctx context.Context, s *testing.State) {
defer func(ctx context.Context) {
if err := policyutil.EnsureTPMAndSystemStateAreResetRemote(ctx, s.DUT()); err != nil {
s.Error("Failed to reset TPM: ", err)
}
}(ctx)
ctx, cancel := ctxutil.Shorten(ctx, 3*time.Minute)
defer cancel()
if err := policyutil.EnsureTPMAndSystemStateAreResetRemote(ctx, s.DUT()); err != nil {
s.Fatal("Failed to reset TPM: ", err)
}
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)
wc := wilco.NewWilcoServiceClient(cl.Conn)
pc := ps.NewPolicyServiceClient(cl.Conn)
pb := policy.NewBlob()
pb.AddPolicy(&policy.DeviceWilcoDtcAllowed{Val: true})
// wilco_dtc and wilco_dtc_supportd only run for affiliated users
pb.DeviceAffiliationIds = []string{"default"}
pb.UserAffiliationIds = []string{"default"}
pJSON, err := json.Marshal(pb)
if err != nil {
s.Fatal("Failed to serialize policies: ", err)
}
if _, err := pc.EnrollUsingChrome(ctx, &ps.EnrollUsingChromeRequest{
PolicyJson: pJSON,
}); err != nil {
s.Fatal("Failed to enroll using chrome: ", err)
}
defer pc.StopChromeAndFakeDMS(ctx, &empty.Empty{})
if _, err := wc.TestGetStatefulPartitionAvailableCapacity(ctx, &empty.Empty{}); err != nil {
s.Error("Get stateful partition available capacity test failed: ", err)
}
}