blob: c1ca03408bdc8e27251baaad970f88d1570c03b2 [file] [log] [blame]
Colin Crossaf98f582021-05-12 17:27:32 -07001// Copyright 2021 Google Inc. All rights reserved.
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
15package cc
16
17import (
Liz Kammerbb8d84f2021-06-21 12:53:03 -040018 "fmt"
19 "strings"
Colin Crossaf98f582021-05-12 17:27:32 -070020 "testing"
21
22 "android/soong/android"
23)
24
25var prepareForAsanTest = android.FixtureAddFile("asan/Android.bp", []byte(`
26 cc_library_shared {
Colin Crossfc0df952022-02-10 11:41:18 -080027 name: "libclang_rt.asan",
Colin Crossaf98f582021-05-12 17:27:32 -070028 }
29`))
30
31func TestAsan(t *testing.T) {
32 bp := `
33 cc_binary {
34 name: "bin_with_asan",
35 host_supported: true,
36 shared_libs: [
37 "libshared",
38 "libasan",
39 ],
40 static_libs: [
41 "libstatic",
42 "libnoasan",
43 ],
44 sanitize: {
45 address: true,
46 }
47 }
48
49 cc_binary {
50 name: "bin_no_asan",
51 host_supported: true,
52 shared_libs: [
53 "libshared",
54 "libasan",
55 ],
56 static_libs: [
57 "libstatic",
58 "libnoasan",
59 ],
60 }
61
62 cc_library_shared {
63 name: "libshared",
64 host_supported: true,
65 shared_libs: ["libtransitive"],
66 }
67
68 cc_library_shared {
69 name: "libasan",
70 host_supported: true,
71 shared_libs: ["libtransitive"],
72 sanitize: {
73 address: true,
74 }
75 }
76
77 cc_library_shared {
78 name: "libtransitive",
79 host_supported: true,
80 }
81
82 cc_library_static {
83 name: "libstatic",
84 host_supported: true,
85 }
86
87 cc_library_static {
88 name: "libnoasan",
89 host_supported: true,
90 sanitize: {
91 address: false,
92 }
93 }
94 `
95
96 result := android.GroupFixturePreparers(
97 prepareForCcTest,
98 prepareForAsanTest,
99 ).RunTestWithBp(t, bp)
100
101 check := func(t *testing.T, result *android.TestResult, variant string) {
102 asanVariant := variant + "_asan"
103 sharedVariant := variant + "_shared"
104 sharedAsanVariant := sharedVariant + "_asan"
105 staticVariant := variant + "_static"
106 staticAsanVariant := staticVariant + "_asan"
107
108 // The binaries, one with asan and one without
109 binWithAsan := result.ModuleForTests("bin_with_asan", asanVariant)
110 binNoAsan := result.ModuleForTests("bin_no_asan", variant)
111
112 // Shared libraries that don't request asan
113 libShared := result.ModuleForTests("libshared", sharedVariant)
114 libTransitive := result.ModuleForTests("libtransitive", sharedVariant)
115
116 // Shared library that requests asan
117 libAsan := result.ModuleForTests("libasan", sharedAsanVariant)
118
119 // Static library that uses an asan variant for bin_with_asan and a non-asan variant
120 // for bin_no_asan.
121 libStaticAsanVariant := result.ModuleForTests("libstatic", staticAsanVariant)
122 libStaticNoAsanVariant := result.ModuleForTests("libstatic", staticVariant)
123
124 // Static library that never uses asan.
125 libNoAsan := result.ModuleForTests("libnoasan", staticVariant)
126
127 // expectSharedLinkDep verifies that the from module links against the to module as a
128 // shared library.
129 expectSharedLinkDep := func(from, to android.TestingModule) {
130 t.Helper()
131 fromLink := from.Description("link")
132 toLink := to.Description("strip")
133
134 if g, w := fromLink.OrderOnly.Strings(), toLink.Output.String(); !android.InList(w, g) {
135 t.Errorf("%s should link against %s, expected %q, got %q",
136 from.Module(), to.Module(), w, g)
137 }
138 }
139
140 // expectStaticLinkDep verifies that the from module links against the to module as a
141 // static library.
142 expectStaticLinkDep := func(from, to android.TestingModule) {
143 t.Helper()
144 fromLink := from.Description("link")
145 toLink := to.Description("static link")
146
147 if g, w := fromLink.Implicits.Strings(), toLink.Output.String(); !android.InList(w, g) {
148 t.Errorf("%s should link against %s, expected %q, got %q",
149 from.Module(), to.Module(), w, g)
150 }
151
152 }
153
154 // expectInstallDep verifies that the install rule of the from module depends on the
155 // install rule of the to module.
156 expectInstallDep := func(from, to android.TestingModule) {
157 t.Helper()
158 fromInstalled := from.Description("install")
159 toInstalled := to.Description("install")
160
161 // combine implicits and order-only dependencies, host uses implicit but device uses
162 // order-only.
163 got := append(fromInstalled.Implicits.Strings(), fromInstalled.OrderOnly.Strings()...)
164 want := toInstalled.Output.String()
165 if !android.InList(want, got) {
166 t.Errorf("%s installation should depend on %s, expected %q, got %q",
167 from.Module(), to.Module(), want, got)
168 }
169 }
170
171 expectSharedLinkDep(binWithAsan, libShared)
172 expectSharedLinkDep(binWithAsan, libAsan)
173 expectSharedLinkDep(libShared, libTransitive)
174 expectSharedLinkDep(libAsan, libTransitive)
175
176 expectStaticLinkDep(binWithAsan, libStaticAsanVariant)
177 expectStaticLinkDep(binWithAsan, libNoAsan)
178
179 expectInstallDep(binWithAsan, libShared)
180 expectInstallDep(binWithAsan, libAsan)
181 expectInstallDep(binWithAsan, libTransitive)
182 expectInstallDep(libShared, libTransitive)
183 expectInstallDep(libAsan, libTransitive)
184
185 expectSharedLinkDep(binNoAsan, libShared)
186 expectSharedLinkDep(binNoAsan, libAsan)
187 expectSharedLinkDep(libShared, libTransitive)
188 expectSharedLinkDep(libAsan, libTransitive)
189
190 expectStaticLinkDep(binNoAsan, libStaticNoAsanVariant)
191 expectStaticLinkDep(binNoAsan, libNoAsan)
192
193 expectInstallDep(binNoAsan, libShared)
194 expectInstallDep(binNoAsan, libAsan)
195 expectInstallDep(binNoAsan, libTransitive)
196 expectInstallDep(libShared, libTransitive)
197 expectInstallDep(libAsan, libTransitive)
198 }
199
200 t.Run("host", func(t *testing.T) { check(t, result, result.Config.BuildOSTarget.String()) })
201 t.Run("device", func(t *testing.T) { check(t, result, "android_arm64_armv8-a") })
202}
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400203
204type MemtagNoteType int
205
206const (
207 None MemtagNoteType = iota + 1
208 Sync
209 Async
210)
211
212func (t MemtagNoteType) str() string {
213 switch t {
214 case None:
215 return "none"
216 case Sync:
217 return "sync"
218 case Async:
219 return "async"
220 default:
Liz Kammerd56ddb52021-06-21 17:37:39 -0400221 panic("type_note_invalid")
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400222 }
223}
224
225func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) {
Liz Kammerd56ddb52021-06-21 17:37:39 -0400226 t.Helper()
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400227 note_async := "note_memtag_heap_async"
228 note_sync := "note_memtag_heap_sync"
229
230 found := None
231 implicits := m.Rule("ld").Implicits
232 for _, lib := range implicits {
233 if strings.Contains(lib.Rel(), note_async) {
234 found = Async
235 break
236 } else if strings.Contains(lib.Rel(), note_sync) {
237 found = Sync
238 break
239 }
240 }
241
242 if found != expected {
243 t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str())
244 }
245}
246
247var prepareForTestWithMemtagHeap = android.GroupFixturePreparers(
248 android.FixtureModifyMockFS(func(fs android.MockFS) {
249 templateBp := `
250 cc_test {
Liz Kammerd56ddb52021-06-21 17:37:39 -0400251 name: "unset_test_%[1]s",
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400252 gtest: false,
253 }
254
255 cc_test {
Liz Kammerd56ddb52021-06-21 17:37:39 -0400256 name: "no_memtag_test_%[1]s",
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400257 gtest: false,
258 sanitize: { memtag_heap: false },
259 }
260
261 cc_test {
Liz Kammerd56ddb52021-06-21 17:37:39 -0400262 name: "set_memtag_test_%[1]s",
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400263 gtest: false,
264 sanitize: { memtag_heap: true },
265 }
266
267 cc_test {
Liz Kammerd56ddb52021-06-21 17:37:39 -0400268 name: "set_memtag_set_async_test_%[1]s",
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400269 gtest: false,
270 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
271 }
272
273 cc_test {
Liz Kammerd56ddb52021-06-21 17:37:39 -0400274 name: "set_memtag_set_sync_test_%[1]s",
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400275 gtest: false,
276 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
277 }
278
Liz Kammerd56ddb52021-06-21 17:37:39 -0400279 cc_test {
280 name: "unset_memtag_set_sync_test_%[1]s",
281 gtest: false,
282 sanitize: { diag: { memtag_heap: true } },
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400283 }
284
285 cc_binary {
Liz Kammerd56ddb52021-06-21 17:37:39 -0400286 name: "unset_binary_%[1]s",
287 }
288
289 cc_binary {
290 name: "no_memtag_binary_%[1]s",
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400291 sanitize: { memtag_heap: false },
292 }
293
294 cc_binary {
Liz Kammerd56ddb52021-06-21 17:37:39 -0400295 name: "set_memtag_binary_%[1]s",
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400296 sanitize: { memtag_heap: true },
297 }
298
299 cc_binary {
Liz Kammerd56ddb52021-06-21 17:37:39 -0400300 name: "set_memtag_set_async_binary_%[1]s",
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400301 sanitize: { memtag_heap: true, diag: { memtag_heap: false } },
302 }
303
304 cc_binary {
Liz Kammerd56ddb52021-06-21 17:37:39 -0400305 name: "set_memtag_set_sync_binary_%[1]s",
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400306 sanitize: { memtag_heap: true, diag: { memtag_heap: true } },
307 }
Liz Kammerd56ddb52021-06-21 17:37:39 -0400308
309 cc_binary {
310 name: "unset_memtag_set_sync_binary_%[1]s",
311 sanitize: { diag: { memtag_heap: true } },
312 }
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400313 `
Liz Kammerd56ddb52021-06-21 17:37:39 -0400314 subdirNoOverrideBp := fmt.Sprintf(templateBp, "no_override")
315 subdirOverrideDefaultDisableBp := fmt.Sprintf(templateBp, "override_default_disable")
316 subdirSyncBp := fmt.Sprintf(templateBp, "override_default_sync")
317 subdirAsyncBp := fmt.Sprintf(templateBp, "override_default_async")
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400318
319 fs.Merge(android.MockFS{
Liz Kammerd56ddb52021-06-21 17:37:39 -0400320 "subdir_no_override/Android.bp": []byte(subdirNoOverrideBp),
321 "subdir_override_default_disable/Android.bp": []byte(subdirOverrideDefaultDisableBp),
322 "subdir_sync/Android.bp": []byte(subdirSyncBp),
323 "subdir_async/Android.bp": []byte(subdirAsyncBp),
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400324 })
325 }),
326 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
Liz Kammerd56ddb52021-06-21 17:37:39 -0400327 variables.MemtagHeapExcludePaths = []string{"subdir_override_default_disable"}
328 // "subdir_override_default_disable" is covered by both include and override_default_disable paths. override_default_disable wins.
329 variables.MemtagHeapSyncIncludePaths = []string{"subdir_sync", "subdir_override_default_disable"}
330 variables.MemtagHeapAsyncIncludePaths = []string{"subdir_async", "subdir_override_default_disable"}
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400331 }),
332)
333
334func TestSanitizeMemtagHeap(t *testing.T) {
335 variant := "android_arm64_armv8-a"
336
337 result := android.GroupFixturePreparers(
338 prepareForCcTest,
339 prepareForTestWithMemtagHeap,
340 ).RunTest(t)
341 ctx := result.TestContext
342
Liz Kammerd56ddb52021-06-21 17:37:39 -0400343 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_no_override", variant), None)
344 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_async", variant), None)
345 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_disable", variant), None)
346 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_sync", variant), None)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400347
Liz Kammerd56ddb52021-06-21 17:37:39 -0400348 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_no_override", variant), None)
349 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_async", variant), None)
350 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_disable", variant), None)
351 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_sync", variant), None)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400352
Liz Kammerd56ddb52021-06-21 17:37:39 -0400353 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_no_override", variant), Async)
354 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_async", variant), Async)
355 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_disable", variant), Async)
356 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_sync", variant), Sync)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400357
Liz Kammer7b920b42021-06-22 16:57:27 -0400358 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_no_override", variant), Sync)
359 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_async", variant), Sync)
360 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_disable", variant), Sync)
Liz Kammerd56ddb52021-06-21 17:37:39 -0400361 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_sync", variant), Sync)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400362
Liz Kammerd56ddb52021-06-21 17:37:39 -0400363 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_no_override", variant), Async)
364 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_async", variant), Async)
365 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_disable", variant), Async)
366 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_sync", variant), Async)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400367
Liz Kammerd56ddb52021-06-21 17:37:39 -0400368 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_no_override", variant), Async)
369 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_async", variant), Async)
370 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_disable", variant), Async)
371 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_sync", variant), Async)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400372
Liz Kammerd56ddb52021-06-21 17:37:39 -0400373 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_no_override", variant), Sync)
374 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_async", variant), Sync)
375 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_disable", variant), Sync)
376 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_sync", variant), Sync)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400377
Liz Kammerd56ddb52021-06-21 17:37:39 -0400378 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_no_override", variant), Sync)
379 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_async", variant), Sync)
380 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_disable", variant), Sync)
381 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_sync", variant), Sync)
382
383 // should sanitize: { diag: { memtag: true } } result in Sync instead of None here?
384 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_no_override", variant), None)
385 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_async", variant), Sync)
386 // should sanitize: { diag: { memtag: true } } result in Sync instead of None here?
387 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_disable", variant), None)
388 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_sync", variant), Sync)
389
390 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_no_override", variant), Sync)
391 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_async", variant), Sync)
392 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_disable", variant), Sync)
393 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_sync", variant), Sync)
394
395 checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_no_override", variant), None)
396 checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_async", variant), Async)
397 checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_disable", variant), None)
398 checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_sync", variant), Sync)
399
400 checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_no_override", variant), Sync)
401 checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_async", variant), Sync)
402 checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_disable", variant), Sync)
403 checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_sync", variant), Sync)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400404}
405
406func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) {
407 variant := "android_arm64_armv8-a"
408
409 result := android.GroupFixturePreparers(
410 prepareForCcTest,
411 prepareForTestWithMemtagHeap,
412 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
413 variables.SanitizeDevice = []string{"memtag_heap"}
414 }),
415 ).RunTest(t)
416 ctx := result.TestContext
417
Liz Kammerd56ddb52021-06-21 17:37:39 -0400418 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_no_override", variant), None)
419 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_async", variant), None)
420 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_disable", variant), None)
421 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_sync", variant), None)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400422
Liz Kammerd56ddb52021-06-21 17:37:39 -0400423 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_no_override", variant), None)
424 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_async", variant), None)
425 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_disable", variant), None)
426 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_sync", variant), None)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400427
Liz Kammerd56ddb52021-06-21 17:37:39 -0400428 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_no_override", variant), Async)
429 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_async", variant), Async)
430 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_disable", variant), Async)
431 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_sync", variant), Sync)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400432
Liz Kammer7b920b42021-06-22 16:57:27 -0400433 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_no_override", variant), Sync)
434 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_async", variant), Sync)
435 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_disable", variant), Sync)
Liz Kammerd56ddb52021-06-21 17:37:39 -0400436 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_sync", variant), Sync)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400437
Liz Kammerd56ddb52021-06-21 17:37:39 -0400438 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_no_override", variant), Async)
439 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_async", variant), Async)
440 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_disable", variant), Async)
441 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_sync", variant), Async)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400442
Liz Kammerd56ddb52021-06-21 17:37:39 -0400443 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_no_override", variant), Async)
444 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_async", variant), Async)
445 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_disable", variant), Async)
446 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_sync", variant), Async)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400447
Liz Kammerd56ddb52021-06-21 17:37:39 -0400448 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_no_override", variant), Sync)
449 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_async", variant), Sync)
450 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_disable", variant), Sync)
451 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_sync", variant), Sync)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400452
Liz Kammerd56ddb52021-06-21 17:37:39 -0400453 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_no_override", variant), Sync)
454 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_async", variant), Sync)
455 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_disable", variant), Sync)
456 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_sync", variant), Sync)
457
458 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_no_override", variant), Sync)
459 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_async", variant), Sync)
460 // should sanitize: { diag: { memtag: true } } result in Sync instead of None here?
461 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_disable", variant), None)
462 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_sync", variant), Sync)
463
464 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_no_override", variant), Sync)
465 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_async", variant), Sync)
466 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_disable", variant), Sync)
467 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_sync", variant), Sync)
468
469 checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_no_override", variant), Async)
470 checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_async", variant), Async)
471 checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_disable", variant), None)
472 checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_sync", variant), Sync)
473
474 checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_no_override", variant), Sync)
475 checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_async", variant), Sync)
476 checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_disable", variant), Sync)
477 checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_sync", variant), Sync)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400478}
479
480func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) {
481 variant := "android_arm64_armv8-a"
482
483 result := android.GroupFixturePreparers(
484 prepareForCcTest,
485 prepareForTestWithMemtagHeap,
486 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
487 variables.SanitizeDevice = []string{"memtag_heap"}
488 variables.SanitizeDeviceDiag = []string{"memtag_heap"}
489 }),
490 ).RunTest(t)
491 ctx := result.TestContext
492
Liz Kammerd56ddb52021-06-21 17:37:39 -0400493 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_no_override", variant), None)
494 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_async", variant), None)
495 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_disable", variant), None)
496 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_sync", variant), None)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400497
Liz Kammerd56ddb52021-06-21 17:37:39 -0400498 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_no_override", variant), None)
499 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_async", variant), None)
500 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_disable", variant), None)
501 checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_sync", variant), None)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400502
Liz Kammerd56ddb52021-06-21 17:37:39 -0400503 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_no_override", variant), Sync)
504 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_async", variant), Sync)
505 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_disable", variant), Sync)
506 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_sync", variant), Sync)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400507
Liz Kammerd56ddb52021-06-21 17:37:39 -0400508 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_no_override", variant), Sync)
509 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_async", variant), Sync)
510 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_disable", variant), Sync)
511 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_sync", variant), Sync)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400512
Liz Kammerd56ddb52021-06-21 17:37:39 -0400513 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_no_override", variant), Async)
514 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_async", variant), Async)
515 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_disable", variant), Async)
516 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_sync", variant), Async)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400517
Liz Kammerd56ddb52021-06-21 17:37:39 -0400518 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_no_override", variant), Async)
519 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_async", variant), Async)
520 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_disable", variant), Async)
521 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_sync", variant), Async)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400522
Liz Kammerd56ddb52021-06-21 17:37:39 -0400523 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_no_override", variant), Sync)
524 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_async", variant), Sync)
525 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_disable", variant), Sync)
526 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_sync", variant), Sync)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400527
Liz Kammerd56ddb52021-06-21 17:37:39 -0400528 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_no_override", variant), Sync)
529 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_async", variant), Sync)
530 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_disable", variant), Sync)
531 checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_sync", variant), Sync)
532
533 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_no_override", variant), Sync)
534 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_async", variant), Sync)
535 // should sanitize: { diag: { memtag: true } } result in Sync instead of None here?
536 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_disable", variant), None)
537 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_sync", variant), Sync)
538
539 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_no_override", variant), Sync)
540 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_async", variant), Sync)
541 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_disable", variant), Sync)
542 checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_sync", variant), Sync)
543
544 checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_no_override", variant), Sync)
545 checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_async", variant), Sync)
546 checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_disable", variant), None)
547 checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_sync", variant), Sync)
548
549 checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_no_override", variant), Sync)
550 checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_async", variant), Sync)
551 checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_disable", variant), Sync)
552 checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_sync", variant), Sync)
Liz Kammerbb8d84f2021-06-21 12:53:03 -0400553}