/
build_properties.go
328 lines (306 loc) · 12.5 KB
/
build_properties.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
// Copyright 2018 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"
"regexp"
"strconv"
"strings"
"time"
"chromiumos/tast/common/testexec"
"chromiumos/tast/local/arc"
"chromiumos/tast/testing"
)
// buildPropertiesTestParameters contains all the data needed to run a single test iteration.
type buildPropertiesTestParameters struct {
arcBootType string
hardwareType string
}
func init() {
testing.AddTest(&testing.Test{
Func: BuildProperties,
LacrosStatus: testing.LacrosVariantUnneeded,
Desc: "Checks important Android properties such as first_api_level",
Contacts: []string{"niwa@chromium.org", "risan@chromium.org", "arc-eng@google.com"},
SoftwareDeps: []string{"chrome"},
Fixture: "arcBooted",
Timeout: 4 * time.Minute,
Attr: []string{"group:mainline"},
// Val is the property representing ARC boot type, which is different for container/VM.
Params: []testing.Param{{
ExtraSoftwareDeps: []string{"android_p"},
Val: buildPropertiesTestParameters{
arcBootType: "ro.vendor.arc_boot_type",
hardwareType: "cheets",
},
}, {
Name: "vm",
ExtraSoftwareDeps: []string{"android_vm"},
Val: buildPropertiesTestParameters{
arcBootType: "vendor.arc.boot_type",
hardwareType: "bertha",
},
}},
})
}
// createPropertiesMatcher returns a function that takes 3 strings and checks if Android properties are set up correctly.
// The returned function first gets a value of the referenceProperty, then for each partition, gets a value of the variant
// of the referenceProperty. For example, when referenceProperty is "ro.build.X", prefixToReplace is "ro.build.",
// replacementFormat is "ro.%s.build.", and partitions is ["P1", "P2"], the returned function checks if the value of
// "ro.build.X" is equal to "ro.P1.build.X" and "ro.P2.build.X".
func createPropertiesMatcher(s *testing.State, allProperties map[string]bool, partitions []string, getProperty func(string) string) func(string, string, string) {
return func(referenceProperty, prefixToReplace, replacementFormat string) {
referenceValue := getProperty(referenceProperty)
for _, partition := range partitions {
// Generate the property name to check. For example, when referenceProperty is ro.build.X, prefixToReplace is ro.build.,
// and replacementFormat is ro.%s.build., propertyForPartition will be ro.<partition>.build.X.
propertyForPartition := strings.Replace(referenceProperty, prefixToReplace, fmt.Sprintf(replacementFormat, partition), 1)
if !allProperties[propertyForPartition] {
// The partition doesn't have the referenceProperty equivalent.
continue
}
if valueForPartition := getProperty(propertyForPartition); valueForPartition != referenceValue {
s.Errorf("Unexpected %v property: got %q; want %q (%v)", propertyForPartition, valueForPartition, referenceValue, referenceProperty)
}
}
}
}
func BuildProperties(ctx context.Context, s *testing.State) {
const (
propertyBoard = "ro.product.board"
propertyDevice = "ro.product.device"
propertyFirstAPILevel = "ro.product.first_api_level"
propertyModel = "ro.product.model"
propertySDKVersion = "ro.build.version.sdk"
propertySerialNo = "ro.serialno"
propertyBootSerialNo = "ro.boot.serialno"
propertyBootHardware = "ro.boot.hardware"
)
a := s.FixtValue().(*arc.PreData).ARC
getProperty := func(propertyName string) string {
var value string
if err := testing.Poll(ctx, func(ctx context.Context) error {
out, err := a.Command(ctx, "getprop", propertyName).Output()
if err != nil {
return err
}
value = strings.TrimSpace(string(out))
return nil
}, &testing.PollOptions{Timeout: 10 * time.Second}); err != nil {
s.Fatalf("Failed to get %q: %v", propertyName, err)
}
return value
}
getAllPropertiesMap := func() map[string]bool {
// Returns a list of existing property names as a map.
out, err := a.Command(ctx, "getprop").Output(testexec.DumpLogOnError)
if err != nil {
s.Log("Failed to read properties: ", err)
}
properties := make(map[string]bool)
// Trying to match:
// [ro.build.version.preview_sdk]: [0]
// [ro.build.version.release]: [9]
re := regexp.MustCompile(`\[([^\]]+)\]: .*`)
for _, line := range strings.Split(string(out), "\n") {
property := re.FindStringSubmatch(line)
if len(property) < 2 {
continue
}
properties[property[1]] = true
}
return properties
}
// On each ARC boot, ARC detects its boot type (first boot, first boot after
// OTA, or regular boot) and sets the results as a property. Check that the
// property is actually set.
param := s.Param().(buildPropertiesTestParameters)
propertyBootType := param.arcBootType
bootType := getProperty(propertyBootType)
// '3' is from the ArcBootType enum in platform2/arc/setup/arc_setup.h (ARC container) and
// device/google/bertha/arc-boot-type-detector/main.cc (ARCVM).
if bootTypeInt, err := strconv.Atoi(bootType); err != nil || bootTypeInt <= 0 || bootTypeInt > 3 {
s.Errorf("%v property is %q; should contain an ArcBootType enum number",
propertyBootType, bootType)
}
// On unibuild boards, system.raw.img's build.prop contains some template
// values such as ro.product.board="{metrics-tag}". This check makes sure
// that such variables are expanded at runtime.
board := getProperty(propertyBoard)
if strings.Contains(board, "{") {
s.Errorf("%v property is %q; should not contain unexpanded values",
propertyBoard, board)
}
// On R, we set a placeholder board name during Android build (ag/11322572).
// Also make sure the placeholder is not used as-is so we can detect issues
// like b/157193348#comment5.
if strings.HasPrefix(board, "bertha_") {
s.Errorf("%v property is %q; should not start with bertha_",
propertyBoard, board)
}
// Read ro.product.device, drop _cheets suffix, and drop more suffices
// following '-', like -arcnext or -kernelnext to get the canonical key
// to map the device name to the first API level.
//
// The hyphen subpart conventionally denotes a variance of the same base
// board that shares the first API level, and moreover they can be truncated
// (to -kerneln or -ker etc) and becomes hard to match exactly.
device := getProperty(propertyDevice)
deviceRegexp := regexp.MustCompile(`^([^-]+).*_cheets$`)
match := deviceRegexp.FindStringSubmatch(device)
if match == nil {
s.Errorf("%v property is %q; should have _cheets suffix",
propertyDevice, device)
}
device = match[1]
expectedFirstAPILevel := getProperty(propertySDKVersion)
if device == "hatch" && strings.HasSuffix(board, "-arc-r") {
// TODO(b/159985784): Remove the hack once we bring up a board truly
// setting first_api_level=30.
//
// Correct value for hatch-arc-r is the same for hatch (28, obtained
// from the map), but it is currently put under a special experiment
// to test behaviors of devices of first API level 30. See b/159114376.
expectedFirstAPILevel = "30"
} else if overwrite, ok := expectedFirstAPILevelMap[device]; ok {
expectedFirstAPILevel = strconv.Itoa(overwrite)
}
firstAPILevel := getProperty(propertyFirstAPILevel)
if _, skip := skipFirstAPILevelCheckMap[device]; !skip && firstAPILevel != expectedFirstAPILevel {
if props, err := a.Command(ctx, "getprop").Output(testexec.DumpLogOnError); err != nil {
s.Log("Failed to read properties: ", err)
} else if err := ioutil.WriteFile(filepath.Join(s.OutDir(), "props.txt"), props, 0644); err != nil {
s.Log("Failed to dump properties: ", err)
}
s.Errorf("Unexpected %v property (see props.txt for details): got %q; want %q", propertyFirstAPILevel,
firstAPILevel, expectedFirstAPILevel)
}
// Verify that ro.serialno and ro.boot.serialno has same value and not empty.
arcSerialNo := getProperty(propertySerialNo)
arcBootSerialNo := getProperty(propertyBootSerialNo)
if arcSerialNo != arcBootSerialNo {
s.Errorf("ro.serialno - %v & ro.boot.serialno - %v are not same", arcBootSerialNo, arcSerialNo)
} else if arcSerialNo == "" {
s.Error("Serial numbers ro.serialno & ro.boot.serialno are not set")
}
// Verify that these important properties without a partition name still exist.
propertySuffixes := []string{"fingerprint", "id", "tags", "version.incremental"}
for _, propertySuffix := range propertySuffixes {
property := fmt.Sprintf("ro.build.%s", propertySuffix)
value := getProperty(property)
if value == "" {
s.Errorf("property %v is not set", property)
}
// Check that ro.build.fingerprint doesn't contain '_bertha' even when the device uses ARCVM (b/152775858)
if propertySuffix == "fingerprint" && !strings.Contains(value, "_cheets") {
s.Errorf("%v property is %q; should contain _cheets", property, value)
}
}
partitions := []string{"system", "system_ext", "product", "odm", "vendor", "bootimage"}
allProperties := getAllPropertiesMap()
propertiesMatcher := createPropertiesMatcher(s, allProperties, partitions, getProperty)
// Starting R, the images have ro.[property.]{system,system_ext,product,odm,vendor,bootimage}.*
// properties by default to allow vendors to customize the values. ARC doesn't need the
// customization and uses the same value for all of them. This verifies that all properties
// share the same value. On P, the images have only ro.{system,vendor,bootimage} ones.
for property := range allProperties {
if prefix := "ro.build."; strings.HasPrefix(property, prefix) {
// Verify that ro.build.X has the same value as ro.<partition>.build.X.
propertiesMatcher(property, prefix, "ro.%s.build.")
} else if prefix := "ro.product."; strings.HasPrefix(property, prefix) {
// Verify that ro.product.X has the same value as ro.<partition>.product.X.
propertiesMatcher(property, prefix, "ro.%s.product.")
// Verify that ro.product.X has the same value as ro.product.<partition>.X.
propertiesMatcher(property, prefix, "ro.product.%s.")
}
}
// Check if propertyBootHardware is properly set. This is important because some of our code
// rely on the value. For example, platform2/metrics/process_meter.cc looks for "bertha" to
// detect ARCVM's crosvm process
hardware := getProperty(propertyBootHardware)
hardwareExpected := param.hardwareType
if hardware != hardwareExpected {
s.Errorf("%v property is %q; should be %q", propertyBootHardware, hardware, hardwareExpected)
}
}
// expectedFirstAPILevelMap is a map of device name -> expected first API level.
// First API level is expected to be the same as current SDK version if the
// device name doesn't exist in this map.
var expectedFirstAPILevelMap = map[string]int{
// Boards initially shipped with ARC N (sorted alphabetically.)
"asuka": arc.SDKN,
"banon": arc.SDKN,
"bob": arc.SDKN,
"caroline": arc.SDKN,
"cave": arc.SDKN,
"celes": arc.SDKN,
"chell": arc.SDKN,
"coral": arc.SDKN,
"cyan": arc.SDKN,
"edgar": arc.SDKN,
"elm": arc.SDKN,
"eve": arc.SDKN,
"fievel": arc.SDKN,
"fizz": arc.SDKN,
"gandof": arc.SDKN,
"hana": arc.SDKN,
"jerry": arc.SDKN,
"kefka": arc.SDKN,
"kevin": arc.SDKN,
"kevin64": arc.SDKN,
"lars": arc.SDKN,
"lulu": arc.SDKN,
"mighty": arc.SDKN,
"minnie": arc.SDKN,
"nami": arc.SDKN,
"nautilus": arc.SDKN,
"paine": arc.SDKN,
"pyro": arc.SDKN,
"reef": arc.SDKN,
"reks": arc.SDKN,
"relm": arc.SDKN,
"samus": arc.SDKN,
"sand": arc.SDKN,
"scarlet": arc.SDKN,
"sentry": arc.SDKN,
"setzer": arc.SDKN,
"snappy": arc.SDKN,
"soraka": arc.SDKN,
"terra": arc.SDKN,
"tiger": arc.SDKN,
"ultima": arc.SDKN,
"wizpig": arc.SDKN,
"yuna": arc.SDKN,
// Boards initially shipped with ARC P (sorted alphabetically.)
"asurada": arc.SDKP,
"atlas": arc.SDKP,
"dedede": arc.SDKP,
"drallion": arc.SDKP,
"grunt": arc.SDKP,
"hatch": arc.SDKP,
"jacuzzi": arc.SDKP,
"kalista": arc.SDKP,
"keeby": arc.SDKP,
"kukui": arc.SDKP,
"nocturne": arc.SDKP,
"octopus": arc.SDKP,
"puff": arc.SDKP,
"rammus": arc.SDKP,
"sarien": arc.SDKP,
"strongbad": arc.SDKP,
"trogdor": arc.SDKP,
"volteer": arc.SDKP,
"zork": arc.SDKP,
// Note: This test is public. Do not add new boards unless the board's
// overlay already exists in src/overlay/overlay-<board>/.
}
// skipFirstAPILevelCheckMap is the set of devices to skip the first API level check.
// These devices are for dev purposes only and are not being shipped.
var skipFirstAPILevelCheckMap = map[string]struct{}{
"betty": {},
"novato": {},
}