Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion e2etests/orchestration/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func verifyZipFile(filename string) error {
func VerifyLogsEndpoint(srvURL, group, name string) error {
base := fmt.Sprintf("%s/cvds/%s/%s/logs/", srvURL, group, name)
urls := []string{
base,
base + "launcher.log",
base + "kernel.log",
}
Expand Down
25 changes: 25 additions & 0 deletions e2etests/orchestration/instance_logs_test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (C) 2026 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_go//go:def.bzl", "go_test")

go_test(
name = "instance_logs_test_test",
srcs = ["main_test.go"],
deps = [
"//orchestration/common",
"@com_github_google_android_cuttlefish_frontend//src/host_orchestrator/api/v1:api",
"@com_github_google_android_cuttlefish_frontend//src/libhoclient:libhoclient",
],
)
144 changes: 144 additions & 0 deletions e2etests/orchestration/instance_logs_test/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// Copyright (C) 2026 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"encoding/json"
"io"
"log"
"net/http"
"testing"
"time"

"github.com/google/android-cuttlefish/e2etests/orchestration/common"
hoapi "github.com/google/android-cuttlefish/frontend/src/host_orchestrator/api/v1"
hoclient "github.com/google/android-cuttlefish/frontend/src/libhoclient"
)

const baseURL = "http://0.0.0.0:2080"

func TestInstanceLogs(t *testing.T) {
srv := hoclient.NewHostOrchestratorClient(baseURL)
t.Cleanup(func() {
if err := common.CollectHOLogs(baseURL); err != nil {
log.Printf("failed to collect HO logs: %s", err)
}
})
config := `
{
"instances": [
{
"vm": {
"crosvm": {
"enable_sandbox": false
},
"memory_mb": 8192,
"setupwizard_mode": "OPTIONAL",
"cpus": 8
},
"disk": {
"default_build": "@ab/aosp-android-latest-release/aosp_cf_x86_64_only_phone-userdebug",
"download_img_zip": true
}
}
]
}
`
envConfig := make(map[string]interface{})
if err := json.Unmarshal([]byte(config), &envConfig); err != nil {
t.Fatal(err)
}
createReq := &hoapi.CreateCVDRequest{
EnvConfig: envConfig,
}
if _, err := srv.CreateCVD(createReq, &hoclient.AccessTokenBuildAPICreds{}); err != nil {
t.Fatal(err)
}
oneSecStreamChan := make(chan result)
twoSecsStreamChan := make(chan result)
go stream(1*time.Second, oneSecStreamChan)
go stream(2*time.Second, twoSecsStreamChan)
oneSecRes := <-oneSecStreamChan
twoSecsRes := <-twoSecsStreamChan

if oneSecRes.err != nil {
t.Fatal(oneSecRes.err)
}
if twoSecsRes.err != nil {
t.Fatal(twoSecsRes.err)
}
if oneSecRes.read == 0 {
t.Fatal("0 bytes read")
}
diff := twoSecsRes.read - oneSecRes.read
delta := 50
if diff <= delta {
t.Fatalf("expected stream delta bigger than: %d, got: %d", delta, diff)
}

// Verifies stream stops when device is deleted
stopStreamChan := make(chan result)
start := time.Now()
go stream(1*time.Minute, stopStreamChan)
go func() {
if err := srv.Reset(); err != nil {
log.Printf("reset failed %v", err)
}
}()
res := <-stopStreamChan
if res.err != nil {
t.Fatal(res.err)
}
duration := time.Since(start)
if duration >= 1*time.Minute {
t.Fatal("stream not stopped in less than 1 minute after `cvd reset`")
}
}

type result struct {
read int
err error
}

func stream(duration time.Duration, ch chan result) {
ticker := time.NewTicker(duration)
defer ticker.Stop()
resp, err := http.Get("http://0.0.0.0:2080/cvds/cvd_1/1/logs/logcat/:stream")
if err != nil {
ch <- result{err: err}
return
}
defer resp.Body.Close()
read := 0
buffer := make([]byte, 1024)
for {
select {
case <-ticker.C:
ch <- result{read: read}
return
default:
n, err := resp.Body.Read(buffer)
if err != nil {
if err == io.EOF {
ch <- result{read: read}
} else {
ch <- result{err: err}
}
return
}
read += n
}
}
}
3 changes: 3 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
go.work
go.work.sum

/src/host_orchestrator/host_orchestrator
/src/cvdserver_bootstrapper/cvdserver_bootstrapper
/src/operator/operator
8 changes: 0 additions & 8 deletions frontend/go.work

This file was deleted.

5 changes: 3 additions & 2 deletions frontend/src/host_orchestrator/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/google/android-cuttlefish/frontend/src/host_orchestrator

go 1.17
go 1.23

require (
github.com/google/android-cuttlefish/frontend/src/liboperator v0.0.0-20240822182916-7bea0dafdbde
Expand All @@ -12,10 +12,11 @@ require (
)

require (
github.com/fsnotify/fsnotify v1.10.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.3.0 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/grpc v1.40.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/host_orchestrator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fsnotify/fsnotify v1.10.1 h1:b0/UzAf9yR5rhf3RPm9gf3ehBPpf0oZKIjtpKrx59Ho=
github.com/fsnotify/fsnotify v1.10.1/go.mod h1:TLheqan6HD6GBK6PrDWyDPBaEV8LspOxvPSjC+bVfgo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
Expand Down Expand Up @@ -51,6 +53,8 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
Expand Down Expand Up @@ -83,6 +87,8 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
Loading
Loading