/
deqp.go
179 lines (160 loc) · 5.91 KB
/
deqp.go
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// 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 arc
import (
"context"
"fmt"
"io/ioutil"
"path/filepath"
"strings"
"time"
"chromiumos/tast/common/android/adb"
"chromiumos/tast/common/testexec"
"chromiumos/tast/ctxutil"
"chromiumos/tast/errors"
"chromiumos/tast/local/arc"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/graphics"
"chromiumos/tast/testing"
)
const (
apkCTS9 = "ArcDEQPAndroidCTS-9.0r9_20191126.apk"
apkCTS11 = "ArcDEQPAndroidCTS-11.0r1_20200924.apk"
testCaseDataDir = "deqp_tests"
packageName = "com.drawelements.deqp"
activityName = "android.app.NativeActivity"
)
// deqpTests contain the filenames of the tests cases we want to run the
// dEQP on. These caselist files have been obtained by the official Android
// CTS suites: https://source.android.com/compatibility/cts/downloads.html
var deqpTests = []string{
filepath.Join(testCaseDataDir, "gles3-multisample.txt"),
filepath.Join(testCaseDataDir, "gles31-multisample.txt"),
}
func init() {
testing.AddTest(&testing.Test{
Func: DEQP,
LacrosStatus: testing.LacrosVariantUnknown,
Desc: "Runs a subset of the DEQP test suite via the android CTS-provided apk binary",
Contacts: []string{"morg@chromium.org", "arc-eng@google.com"},
Data: deqpTests,
// "no_qemu" disables the test on betty. b/168566159#comment3
SoftwareDeps: []string{"chrome", "no_qemu"},
Fixture: "arcBooted",
Params: []testing.Param{{
ExtraAttr: []string{"group:mainline", "informational"},
ExtraSoftwareDeps: []string{"android_p"},
ExtraData: []string{apkCTS9},
Val: apkCTS9,
Timeout: 5 * time.Minute,
}, {
Name: "vm",
ExtraAttr: []string{"group:mainline", "informational"},
ExtraSoftwareDeps: []string{"android_vm"},
ExtraData: []string{apkCTS11},
Val: apkCTS11,
Timeout: 5 * time.Minute,
}},
})
}
func runSingleDEQPTest(ctx context.Context, a *arc.ARC, tconn *chrome.TestConn, name string) error {
fileName := filepath.Join("/sdcard/testcases", name)
testing.ContextLog(ctx, "Starting dEQP app for ", fileName)
act, err := arc.NewActivity(a, packageName, activityName)
if err != nil {
return errors.Wrapf(err, "failed to create new activity for %v", name)
}
defer act.Close()
// TODO: Escape the name and fileName strings so that there are no whitespaces in filenames.
cmdLineArg := fmt.Sprintf("deqp --deqp-log-filename=/sdcard/%s-results.qpa --deqp-caselist-file=%s", name, fileName)
if err := act.Start(ctx, tconn,
arc.WithWaitForLaunch(),
arc.WithForceStop(),
arc.WithExtraString("cmdLine", cmdLineArg),
); err != nil {
return errors.Wrapf(err, "failed to start activity for %v", name)
}
return act.WaitForFinished(ctx, ctxutil.MaxTimeout)
}
// pushCaseListFilesToAndroid pushes each individual caselist file to the Android device via adb push.
func pushCaseListFilesToAndroid(ctx context.Context, s *testing.State, a *arc.ARC) error {
for _, testFile := range deqpTests {
testName := filepath.Base(testFile)
if err := a.PushFile(ctx, s.DataPath(testFile), filepath.Join("/sdcard/testcases", testName)); err != nil {
return err
}
}
return nil
}
// DEQP is the main tast test entry point.
func DEQP(ctx context.Context, s *testing.State) {
a := s.FixtValue().(*arc.PreData).ARC
cr := s.FixtValue().(*arc.PreData).Chrome
apk := s.Param().(string)
tconn, err := cr.TestAPIConn(ctx)
if err != nil {
s.Fatal("Failed to create Test API connection: ", err)
}
s.Log("Installing dEQP APK")
if err := a.Install(ctx, s.DataPath(apk), adb.InstallOptionGrantPermissions); err != nil {
s.Fatal("Failed installing app: ", err)
}
// Grant apk permissions to manage external storage. This is required
// for Android 11 devices.
if apk == apkCTS11 {
cmd := a.Command(ctx, "appops", "set", packageName, "MANAGE_EXTERNAL_STORAGE", "allow")
if err := cmd.Run(testexec.DumpLogOnError); err != nil {
s.Fatal("Failed to set app permissions: ", err)
}
}
// We need to push each file to the device because on ARCVM we do not expose the guest
// filesystem to the host.
s.Log("Pushing testcase files to Android device")
if err := pushCaseListFilesToAndroid(ctx, s, a); err != nil {
s.Fatal("Failed pushing testcase lists to Android: ", err)
}
failedTests := false
totalTests := 0
totalFailedTests := 0
for _, testFile := range deqpTests {
testName := filepath.Base(testFile)
c, err := ioutil.ReadFile(s.DataPath(testFile))
if err != nil {
s.Fatalf("Failed to read %s: %v", testFile, err)
}
if len(strings.TrimSpace(string(c))) == 0 {
s.Logf("Testcase %v is empty. Skipping", testFile)
continue
}
if err := runSingleDEQPTest(ctx, a, tconn, testName); err != nil {
s.Fatalf("Test %s has failed: %v ", testName, err)
}
logFileOnGuest := filepath.Join("/sdcard", testName+"-results.qpa")
logFileOnHost := filepath.Join(s.OutDir(), testName+"-results.qpa")
if err := a.PullFile(ctx, logFileOnGuest, logFileOnHost); err != nil {
s.Fatalf("Failed to obtain test results for %s: %v", testName, err)
}
stats, nonFailed, err := graphics.ParseDEQPOutput(logFileOnHost)
if err != nil {
s.Logf("Failed to parse results for %s: %v", logFileOnHost, err)
s.Logf("The test for %s will be considered failed", testName)
failedTests = true
}
testsRun := 0
s.Logf("Parsing %v results", testName)
for r, c := range stats {
if c > 0 && graphics.DEQPOutcomeIsFailure(r) {
failedTests = true
}
testsRun += int(c)
}
s.Logf("%v: %v", testName, stats)
s.Logf("Tests run: %v. Tests considered failed: %v", testsRun, testsRun-len(nonFailed))
totalTests += testsRun
totalFailedTests += testsRun - len(nonFailed)
}
if failedTests {
s.Fatalf("Some dEQP tests did not pass: %v(failed)/%v(total)", totalFailedTests, totalTests)
}
}