Skip to content

Commit f9bf682

Browse files
Add e2e restart test
1 parent 9bb8661 commit f9bf682

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed
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: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
"strconv"
20+
"strings"
21+
"testing"
22+
23+
"github.com/google/android-cuttlefish/e2etests/orchestration/common"
24+
25+
hoclient "github.com/google/android-cuttlefish/frontend/src/libhoclient"
26+
)
27+
28+
const baseURL = "http://0.0.0.0:2080"
29+
30+
func TestRestart(t *testing.T) {
31+
adbH := common.NewAdbHelper()
32+
if err := adbH.StartServer(); err != nil {
33+
t.Fatal(err)
34+
}
35+
srv := hoclient.NewHostOrchestratorClient(baseURL)
36+
t.Cleanup(func() {
37+
if err := common.CollectHOLogs(baseURL); err != nil {
38+
log.Printf("failed to collect HO logs: %s", err)
39+
}
40+
})
41+
imageDir, err := common.PrepareArtifact(srv, "../artifacts/images.zip")
42+
if err != nil {
43+
t.Fatal(err)
44+
}
45+
hostPkgDir, err := common.PrepareArtifact(srv, "../artifacts/cvd-host_package.tar.gz")
46+
if err != nil {
47+
t.Fatal(err)
48+
}
49+
cvd, err := common.CreateCVDFromImageDirs(srv, hostPkgDir, imageDir)
50+
if err != nil {
51+
t.Fatal(err)
52+
}
53+
if err := adbH.Connect(cvd.ADBSerial); err != nil {
54+
t.Fatal(err)
55+
}
56+
if err := adbH.WaitForDevice(cvd.ADBSerial); err != nil {
57+
t.Fatal(err)
58+
}
59+
60+
// Restart the device
61+
if err := srv.Restart(cvd.Group, cvd.Name); err != nil {
62+
t.Fatal(err)
63+
}
64+
65+
// Verify the device comes back online
66+
if err := adbH.WaitForDevice(cvd.ADBSerial); err != nil {
67+
t.Fatal(err)
68+
}
69+
70+
// Verify the device was actually restarted by checking its uptime
71+
uptimeStr, err := adbH.ExecShellCommand(cvd.ADBSerial, []string{"cat", "/proc/uptime"})
72+
if err != nil {
73+
t.Fatal(err)
74+
}
75+
uptime, err := strconv.ParseFloat(strings.Fields(uptimeStr)[0], 64)
76+
if err != nil {
77+
t.Fatal(err)
78+
}
79+
if uptime > 120 {
80+
t.Fatalf("Device does not seem to have restarted. Uptime: %f", uptime)
81+
}
82+
}

0 commit comments

Comments
 (0)