-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathmain_test.go
More file actions
92 lines (79 loc) · 2.22 KB
/
main_test.go
File metadata and controls
92 lines (79 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// 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 (
"fmt"
"path"
"path/filepath"
"regexp"
"testing"
"github.com/google/android-cuttlefish/e2etests/cvd/common"
)
func anyFileExists(pattern string) bool {
matches, err := filepath.Glob(pattern)
if err != nil {
return false
}
return len(matches) > 0
}
func TestMetrics(t *testing.T) {
c := e2etests.TestContext{}
c.SetUp(t)
defer c.TearDown()
if err := c.CVDFetch(e2etests.FetchArgs{
DefaultBuildBranch: "aosp-android-latest-release",
DefaultBuildTarget: "aosp_cf_x86_64_only_phone-userdebug",
}); err != nil {
t.Fatal(err)
}
if err := c.CVDCreate(e2etests.CreateArgs{}); err != nil {
t.Fatal(err)
}
var metricsdir string
err := func() error {
output, err := c.RunCmd(c.TargetBin(), "fleet")
if err != nil {
return fmt.Errorf("failed to run `cvd fleet`")
}
re := regexp.MustCompile(`"metrics_dir" : "(.*)",`)
matches := re.FindStringSubmatch(output)
if len(matches) != 2 {
return fmt.Errorf("failed to find metrics directory.")
}
metricsdir = matches[1]
if !e2etests.DirectoryExists(metricsdir) {
return fmt.Errorf("failed to find directory %s", metricsdir)
}
patterns := []string{
"device_instantiation*.txtpb",
"device_boot_start*.txtpb",
"device_boot_complete*.txtpb",
}
for _, p := range patterns {
if !anyFileExists(path.Join(metricsdir, p)) {
return fmt.Errorf("failed to find a file matching `%s`", p)
}
}
return nil
}()
if err != nil {
t.Fatal(err)
}
if err := c.CVDStop(); err != nil {
t.Fatal(err)
}
if !anyFileExists(path.Join(metricsdir, "device_stop*.txtpb")) {
t.Errorf("failed to find `device_stop*.txtpb` file.")
}
}