Skip to content

Commit 3f6e5a1

Browse files
SuperStrongDinosaurrmuthiah
authored andcommitted
Add e2e restart test
1 parent e86956c commit 3f6e5a1

2 files changed

Lines changed: 111 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (C) 2026 The Android Open Source Project
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
load("@rules_go//go:def.bzl", "go_test")
16+
17+
go_test(
18+
name = "restart_test_test",
19+
srcs = ["main_test.go"],
20+
data = [
21+
"//orchestration/artifacts:cvd_host_package",
22+
"//orchestration/artifacts:images_zip",
23+
],
24+
deps = [
25+
"//orchestration/common",
26+
"@com_github_google_android_cuttlefish_frontend_src_libhoclient//:libhoclient",
27+
],
28+
)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright (C) 2026 The Android Open Source Project
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"log"
19+
"testing"
20+
21+
"github.com/google/android-cuttlefish/e2etests/orchestration/common"
22+
23+
hoclient "github.com/google/android-cuttlefish/frontend/src/libhoclient"
24+
)
25+
26+
const baseURL = "http://0.0.0.0:2080"
27+
28+
func TestRestart(t *testing.T) {
29+
adbH := common.NewAdbHelper()
30+
if err := adbH.StartServer(); err != nil {
31+
t.Fatal(err)
32+
}
33+
srv := hoclient.NewHostOrchestratorClient(baseURL)
34+
t.Cleanup(func() {
35+
if err := common.CollectHOLogs(baseURL); err != nil {
36+
log.Printf("failed to collect HO logs: %s", err)
37+
}
38+
})
39+
imageDir, err := common.PrepareArtifact(srv, "../artifacts/images.zip")
40+
if err != nil {
41+
t.Fatal(err)
42+
}
43+
hostPkgDir, err := common.PrepareArtifact(srv, "../artifacts/cvd-host_package.tar.gz")
44+
if err != nil {
45+
t.Fatal(err)
46+
}
47+
cvd, err := common.CreateCVDFromImageDirs(srv, hostPkgDir, imageDir)
48+
if err != nil {
49+
t.Fatal(err)
50+
}
51+
if err := adbH.Connect(cvd.ADBSerial); err != nil {
52+
t.Fatal(err)
53+
}
54+
if err := adbH.WaitForDevice(cvd.ADBSerial); err != nil {
55+
t.Fatal(err)
56+
}
57+
58+
// Get boot time before restart
59+
bootTimeBefore, err := adbH.ExecShellCommand(cvd.ADBSerial, []string{"uptime", "-s"})
60+
if err != nil {
61+
t.Fatal(err)
62+
}
63+
64+
// Restart the device
65+
if err := srv.Restart(cvd.Group, cvd.Name); err != nil {
66+
t.Fatal(err)
67+
}
68+
69+
// Verify the device comes back online
70+
if err := adbH.WaitForDevice(cvd.ADBSerial); err != nil {
71+
t.Fatal(err)
72+
}
73+
74+
// Get boot time after restart
75+
bootTimeAfter, err := adbH.ExecShellCommand(cvd.ADBSerial, []string{"uptime", "-s"})
76+
if err != nil {
77+
t.Fatal(err)
78+
}
79+
80+
if bootTimeBefore == bootTimeAfter {
81+
t.Fatalf("Device does not seem to have restarted. Boot time remained: %s", bootTimeBefore)
82+
}
83+
}

0 commit comments

Comments
 (0)