Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 18 | "fmt" |
| 19 | "strings" |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 20 | "testing" |
| 21 | |
| 22 | "android/soong/android" |
| 23 | ) |
| 24 | |
| 25 | var prepareForAsanTest = android.FixtureAddFile("asan/Android.bp", []byte(` |
| 26 | cc_library_shared { |
| 27 | name: "libclang_rt.asan-aarch64-android", |
| 28 | } |
| 29 | |
| 30 | cc_library_shared { |
| 31 | name: "libclang_rt.asan-arm-android", |
| 32 | } |
| 33 | `)) |
| 34 | |
| 35 | func TestAsan(t *testing.T) { |
| 36 | bp := ` |
| 37 | cc_binary { |
| 38 | name: "bin_with_asan", |
| 39 | host_supported: true, |
| 40 | shared_libs: [ |
| 41 | "libshared", |
| 42 | "libasan", |
| 43 | ], |
| 44 | static_libs: [ |
| 45 | "libstatic", |
| 46 | "libnoasan", |
| 47 | ], |
| 48 | sanitize: { |
| 49 | address: true, |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | cc_binary { |
| 54 | name: "bin_no_asan", |
| 55 | host_supported: true, |
| 56 | shared_libs: [ |
| 57 | "libshared", |
| 58 | "libasan", |
| 59 | ], |
| 60 | static_libs: [ |
| 61 | "libstatic", |
| 62 | "libnoasan", |
| 63 | ], |
| 64 | } |
| 65 | |
| 66 | cc_library_shared { |
| 67 | name: "libshared", |
| 68 | host_supported: true, |
| 69 | shared_libs: ["libtransitive"], |
| 70 | } |
| 71 | |
| 72 | cc_library_shared { |
| 73 | name: "libasan", |
| 74 | host_supported: true, |
| 75 | shared_libs: ["libtransitive"], |
| 76 | sanitize: { |
| 77 | address: true, |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | cc_library_shared { |
| 82 | name: "libtransitive", |
| 83 | host_supported: true, |
| 84 | } |
| 85 | |
| 86 | cc_library_static { |
| 87 | name: "libstatic", |
| 88 | host_supported: true, |
| 89 | } |
| 90 | |
| 91 | cc_library_static { |
| 92 | name: "libnoasan", |
| 93 | host_supported: true, |
| 94 | sanitize: { |
| 95 | address: false, |
| 96 | } |
| 97 | } |
| 98 | ` |
| 99 | |
| 100 | result := android.GroupFixturePreparers( |
| 101 | prepareForCcTest, |
| 102 | prepareForAsanTest, |
| 103 | ).RunTestWithBp(t, bp) |
| 104 | |
| 105 | check := func(t *testing.T, result *android.TestResult, variant string) { |
| 106 | asanVariant := variant + "_asan" |
| 107 | sharedVariant := variant + "_shared" |
| 108 | sharedAsanVariant := sharedVariant + "_asan" |
| 109 | staticVariant := variant + "_static" |
| 110 | staticAsanVariant := staticVariant + "_asan" |
| 111 | |
| 112 | // The binaries, one with asan and one without |
| 113 | binWithAsan := result.ModuleForTests("bin_with_asan", asanVariant) |
| 114 | binNoAsan := result.ModuleForTests("bin_no_asan", variant) |
| 115 | |
| 116 | // Shared libraries that don't request asan |
| 117 | libShared := result.ModuleForTests("libshared", sharedVariant) |
| 118 | libTransitive := result.ModuleForTests("libtransitive", sharedVariant) |
| 119 | |
| 120 | // Shared library that requests asan |
| 121 | libAsan := result.ModuleForTests("libasan", sharedAsanVariant) |
| 122 | |
| 123 | // Static library that uses an asan variant for bin_with_asan and a non-asan variant |
| 124 | // for bin_no_asan. |
| 125 | libStaticAsanVariant := result.ModuleForTests("libstatic", staticAsanVariant) |
| 126 | libStaticNoAsanVariant := result.ModuleForTests("libstatic", staticVariant) |
| 127 | |
| 128 | // Static library that never uses asan. |
| 129 | libNoAsan := result.ModuleForTests("libnoasan", staticVariant) |
| 130 | |
| 131 | // expectSharedLinkDep verifies that the from module links against the to module as a |
| 132 | // shared library. |
| 133 | expectSharedLinkDep := func(from, to android.TestingModule) { |
| 134 | t.Helper() |
| 135 | fromLink := from.Description("link") |
| 136 | toLink := to.Description("strip") |
| 137 | |
| 138 | if g, w := fromLink.OrderOnly.Strings(), toLink.Output.String(); !android.InList(w, g) { |
| 139 | t.Errorf("%s should link against %s, expected %q, got %q", |
| 140 | from.Module(), to.Module(), w, g) |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | // expectStaticLinkDep verifies that the from module links against the to module as a |
| 145 | // static library. |
| 146 | expectStaticLinkDep := func(from, to android.TestingModule) { |
| 147 | t.Helper() |
| 148 | fromLink := from.Description("link") |
| 149 | toLink := to.Description("static link") |
| 150 | |
| 151 | if g, w := fromLink.Implicits.Strings(), toLink.Output.String(); !android.InList(w, g) { |
| 152 | t.Errorf("%s should link against %s, expected %q, got %q", |
| 153 | from.Module(), to.Module(), w, g) |
| 154 | } |
| 155 | |
| 156 | } |
| 157 | |
| 158 | // expectInstallDep verifies that the install rule of the from module depends on the |
| 159 | // install rule of the to module. |
| 160 | expectInstallDep := func(from, to android.TestingModule) { |
| 161 | t.Helper() |
| 162 | fromInstalled := from.Description("install") |
| 163 | toInstalled := to.Description("install") |
| 164 | |
| 165 | // combine implicits and order-only dependencies, host uses implicit but device uses |
| 166 | // order-only. |
| 167 | got := append(fromInstalled.Implicits.Strings(), fromInstalled.OrderOnly.Strings()...) |
| 168 | want := toInstalled.Output.String() |
| 169 | if !android.InList(want, got) { |
| 170 | t.Errorf("%s installation should depend on %s, expected %q, got %q", |
| 171 | from.Module(), to.Module(), want, got) |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | expectSharedLinkDep(binWithAsan, libShared) |
| 176 | expectSharedLinkDep(binWithAsan, libAsan) |
| 177 | expectSharedLinkDep(libShared, libTransitive) |
| 178 | expectSharedLinkDep(libAsan, libTransitive) |
| 179 | |
| 180 | expectStaticLinkDep(binWithAsan, libStaticAsanVariant) |
| 181 | expectStaticLinkDep(binWithAsan, libNoAsan) |
| 182 | |
| 183 | expectInstallDep(binWithAsan, libShared) |
| 184 | expectInstallDep(binWithAsan, libAsan) |
| 185 | expectInstallDep(binWithAsan, libTransitive) |
| 186 | expectInstallDep(libShared, libTransitive) |
| 187 | expectInstallDep(libAsan, libTransitive) |
| 188 | |
| 189 | expectSharedLinkDep(binNoAsan, libShared) |
| 190 | expectSharedLinkDep(binNoAsan, libAsan) |
| 191 | expectSharedLinkDep(libShared, libTransitive) |
| 192 | expectSharedLinkDep(libAsan, libTransitive) |
| 193 | |
| 194 | expectStaticLinkDep(binNoAsan, libStaticNoAsanVariant) |
| 195 | expectStaticLinkDep(binNoAsan, libNoAsan) |
| 196 | |
| 197 | expectInstallDep(binNoAsan, libShared) |
| 198 | expectInstallDep(binNoAsan, libAsan) |
| 199 | expectInstallDep(binNoAsan, libTransitive) |
| 200 | expectInstallDep(libShared, libTransitive) |
| 201 | expectInstallDep(libAsan, libTransitive) |
| 202 | } |
| 203 | |
| 204 | t.Run("host", func(t *testing.T) { check(t, result, result.Config.BuildOSTarget.String()) }) |
| 205 | t.Run("device", func(t *testing.T) { check(t, result, "android_arm64_armv8-a") }) |
| 206 | } |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 207 | |
| 208 | type MemtagNoteType int |
| 209 | |
| 210 | const ( |
| 211 | None MemtagNoteType = iota + 1 |
| 212 | Sync |
| 213 | Async |
| 214 | ) |
| 215 | |
| 216 | func (t MemtagNoteType) str() string { |
| 217 | switch t { |
| 218 | case None: |
| 219 | return "none" |
| 220 | case Sync: |
| 221 | return "sync" |
| 222 | case Async: |
| 223 | return "async" |
| 224 | default: |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 225 | panic("type_note_invalid") |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
| 229 | func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 230 | t.Helper() |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 231 | note_async := "note_memtag_heap_async" |
| 232 | note_sync := "note_memtag_heap_sync" |
| 233 | |
| 234 | found := None |
| 235 | implicits := m.Rule("ld").Implicits |
| 236 | for _, lib := range implicits { |
| 237 | if strings.Contains(lib.Rel(), note_async) { |
| 238 | found = Async |
| 239 | break |
| 240 | } else if strings.Contains(lib.Rel(), note_sync) { |
| 241 | found = Sync |
| 242 | break |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | if found != expected { |
| 247 | t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str()) |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | var prepareForTestWithMemtagHeap = android.GroupFixturePreparers( |
| 252 | android.FixtureModifyMockFS(func(fs android.MockFS) { |
| 253 | templateBp := ` |
| 254 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 255 | name: "unset_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 256 | gtest: false, |
| 257 | } |
| 258 | |
| 259 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 260 | name: "no_memtag_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 261 | gtest: false, |
| 262 | sanitize: { memtag_heap: false }, |
| 263 | } |
| 264 | |
| 265 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 266 | name: "set_memtag_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 267 | gtest: false, |
| 268 | sanitize: { memtag_heap: true }, |
| 269 | } |
| 270 | |
| 271 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 272 | name: "set_memtag_set_async_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 273 | gtest: false, |
| 274 | sanitize: { memtag_heap: true, diag: { memtag_heap: false } }, |
| 275 | } |
| 276 | |
| 277 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 278 | name: "set_memtag_set_sync_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 279 | gtest: false, |
| 280 | sanitize: { memtag_heap: true, diag: { memtag_heap: true } }, |
| 281 | } |
| 282 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 283 | cc_test { |
| 284 | name: "unset_memtag_set_sync_test_%[1]s", |
| 285 | gtest: false, |
| 286 | sanitize: { diag: { memtag_heap: true } }, |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | cc_binary { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 290 | name: "unset_binary_%[1]s", |
| 291 | } |
| 292 | |
| 293 | cc_binary { |
| 294 | name: "no_memtag_binary_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 295 | sanitize: { memtag_heap: false }, |
| 296 | } |
| 297 | |
| 298 | cc_binary { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 299 | name: "set_memtag_binary_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 300 | sanitize: { memtag_heap: true }, |
| 301 | } |
| 302 | |
| 303 | cc_binary { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 304 | name: "set_memtag_set_async_binary_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 305 | sanitize: { memtag_heap: true, diag: { memtag_heap: false } }, |
| 306 | } |
| 307 | |
| 308 | cc_binary { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 309 | name: "set_memtag_set_sync_binary_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 310 | sanitize: { memtag_heap: true, diag: { memtag_heap: true } }, |
| 311 | } |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 312 | |
| 313 | cc_binary { |
| 314 | name: "unset_memtag_set_sync_binary_%[1]s", |
| 315 | sanitize: { diag: { memtag_heap: true } }, |
| 316 | } |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 317 | ` |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 318 | subdirNoOverrideBp := fmt.Sprintf(templateBp, "no_override") |
| 319 | subdirOverrideDefaultDisableBp := fmt.Sprintf(templateBp, "override_default_disable") |
| 320 | subdirSyncBp := fmt.Sprintf(templateBp, "override_default_sync") |
| 321 | subdirAsyncBp := fmt.Sprintf(templateBp, "override_default_async") |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 322 | |
| 323 | fs.Merge(android.MockFS{ |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 324 | "subdir_no_override/Android.bp": []byte(subdirNoOverrideBp), |
| 325 | "subdir_override_default_disable/Android.bp": []byte(subdirOverrideDefaultDisableBp), |
| 326 | "subdir_sync/Android.bp": []byte(subdirSyncBp), |
| 327 | "subdir_async/Android.bp": []byte(subdirAsyncBp), |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 328 | }) |
| 329 | }), |
| 330 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 331 | variables.MemtagHeapExcludePaths = []string{"subdir_override_default_disable"} |
| 332 | // "subdir_override_default_disable" is covered by both include and override_default_disable paths. override_default_disable wins. |
| 333 | variables.MemtagHeapSyncIncludePaths = []string{"subdir_sync", "subdir_override_default_disable"} |
| 334 | variables.MemtagHeapAsyncIncludePaths = []string{"subdir_async", "subdir_override_default_disable"} |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 335 | }), |
| 336 | ) |
| 337 | |
| 338 | func TestSanitizeMemtagHeap(t *testing.T) { |
| 339 | variant := "android_arm64_armv8-a" |
| 340 | |
| 341 | result := android.GroupFixturePreparers( |
| 342 | prepareForCcTest, |
| 343 | prepareForTestWithMemtagHeap, |
| 344 | ).RunTest(t) |
| 345 | ctx := result.TestContext |
| 346 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 347 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_no_override", variant), None) |
| 348 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_async", variant), None) |
| 349 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_disable", variant), None) |
| 350 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_sync", variant), None) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 351 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 352 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_no_override", variant), None) |
| 353 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_async", variant), None) |
| 354 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_disable", variant), None) |
| 355 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_sync", variant), None) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 356 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 357 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_no_override", variant), Async) |
| 358 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_async", variant), Async) |
| 359 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_disable", variant), Async) |
| 360 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 361 | |
Liz Kammer | 7b920b4 | 2021-06-22 16:57:27 -0400 | [diff] [blame] | 362 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_no_override", variant), Sync) |
| 363 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_async", variant), Sync) |
| 364 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_disable", variant), Sync) |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 365 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 366 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 367 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_no_override", variant), Async) |
| 368 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_async", variant), Async) |
| 369 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_disable", variant), Async) |
| 370 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_sync", variant), Async) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 371 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 372 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_no_override", variant), Async) |
| 373 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_async", variant), Async) |
| 374 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_disable", variant), Async) |
| 375 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_sync", variant), Async) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 376 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 377 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_no_override", variant), Sync) |
| 378 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_async", variant), Sync) |
| 379 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_disable", variant), Sync) |
| 380 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 381 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 382 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_no_override", variant), Sync) |
| 383 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_async", variant), Sync) |
| 384 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_disable", variant), Sync) |
| 385 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_sync", variant), Sync) |
| 386 | |
| 387 | // should sanitize: { diag: { memtag: true } } result in Sync instead of None here? |
| 388 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_no_override", variant), None) |
| 389 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_async", variant), Sync) |
| 390 | // should sanitize: { diag: { memtag: true } } result in Sync instead of None here? |
| 391 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_disable", variant), None) |
| 392 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_sync", variant), Sync) |
| 393 | |
| 394 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_no_override", variant), Sync) |
| 395 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_async", variant), Sync) |
| 396 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_disable", variant), Sync) |
| 397 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_sync", variant), Sync) |
| 398 | |
| 399 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_no_override", variant), None) |
| 400 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_async", variant), Async) |
| 401 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_disable", variant), None) |
| 402 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_sync", variant), Sync) |
| 403 | |
| 404 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_no_override", variant), Sync) |
| 405 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_async", variant), Sync) |
| 406 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_disable", variant), Sync) |
| 407 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) { |
| 411 | variant := "android_arm64_armv8-a" |
| 412 | |
| 413 | result := android.GroupFixturePreparers( |
| 414 | prepareForCcTest, |
| 415 | prepareForTestWithMemtagHeap, |
| 416 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 417 | variables.SanitizeDevice = []string{"memtag_heap"} |
| 418 | }), |
| 419 | ).RunTest(t) |
| 420 | ctx := result.TestContext |
| 421 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 422 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_no_override", variant), None) |
| 423 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_async", variant), None) |
| 424 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_disable", variant), None) |
| 425 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_sync", variant), None) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 426 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 427 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_no_override", variant), None) |
| 428 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_async", variant), None) |
| 429 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_disable", variant), None) |
| 430 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_sync", variant), None) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 431 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 432 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_no_override", variant), Async) |
| 433 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_async", variant), Async) |
| 434 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_disable", variant), Async) |
| 435 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 436 | |
Liz Kammer | 7b920b4 | 2021-06-22 16:57:27 -0400 | [diff] [blame] | 437 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_no_override", variant), Sync) |
| 438 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_async", variant), Sync) |
| 439 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_disable", variant), Sync) |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 440 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 441 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 442 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_no_override", variant), Async) |
| 443 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_async", variant), Async) |
| 444 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_disable", variant), Async) |
| 445 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_sync", variant), Async) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 446 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 447 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_no_override", variant), Async) |
| 448 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_async", variant), Async) |
| 449 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_disable", variant), Async) |
| 450 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_sync", variant), Async) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 451 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 452 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_no_override", variant), Sync) |
| 453 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_async", variant), Sync) |
| 454 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_disable", variant), Sync) |
| 455 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 456 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 457 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_no_override", variant), Sync) |
| 458 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_async", variant), Sync) |
| 459 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_disable", variant), Sync) |
| 460 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_sync", variant), Sync) |
| 461 | |
| 462 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_no_override", variant), Sync) |
| 463 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_async", variant), Sync) |
| 464 | // should sanitize: { diag: { memtag: true } } result in Sync instead of None here? |
| 465 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_disable", variant), None) |
| 466 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_sync", variant), Sync) |
| 467 | |
| 468 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_no_override", variant), Sync) |
| 469 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_async", variant), Sync) |
| 470 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_disable", variant), Sync) |
| 471 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_sync", variant), Sync) |
| 472 | |
| 473 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_no_override", variant), Async) |
| 474 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_async", variant), Async) |
| 475 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_disable", variant), None) |
| 476 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_sync", variant), Sync) |
| 477 | |
| 478 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_no_override", variant), Sync) |
| 479 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_async", variant), Sync) |
| 480 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_disable", variant), Sync) |
| 481 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) { |
| 485 | variant := "android_arm64_armv8-a" |
| 486 | |
| 487 | result := android.GroupFixturePreparers( |
| 488 | prepareForCcTest, |
| 489 | prepareForTestWithMemtagHeap, |
| 490 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 491 | variables.SanitizeDevice = []string{"memtag_heap"} |
| 492 | variables.SanitizeDeviceDiag = []string{"memtag_heap"} |
| 493 | }), |
| 494 | ).RunTest(t) |
| 495 | ctx := result.TestContext |
| 496 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 497 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_no_override", variant), None) |
| 498 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_async", variant), None) |
| 499 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_disable", variant), None) |
| 500 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_sync", variant), None) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 501 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 502 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_no_override", variant), None) |
| 503 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_async", variant), None) |
| 504 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_disable", variant), None) |
| 505 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_sync", variant), None) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 506 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 507 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_no_override", variant), Sync) |
| 508 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_async", variant), Sync) |
| 509 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_disable", variant), Sync) |
| 510 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 511 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 512 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_no_override", variant), Sync) |
| 513 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_async", variant), Sync) |
| 514 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_disable", variant), Sync) |
| 515 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 516 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 517 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_no_override", variant), Async) |
| 518 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_async", variant), Async) |
| 519 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_disable", variant), Async) |
| 520 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_sync", variant), Async) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 521 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 522 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_no_override", variant), Async) |
| 523 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_async", variant), Async) |
| 524 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_disable", variant), Async) |
| 525 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_sync", variant), Async) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 526 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 527 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_no_override", variant), Sync) |
| 528 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_async", variant), Sync) |
| 529 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_disable", variant), Sync) |
| 530 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 531 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 532 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_no_override", variant), Sync) |
| 533 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_async", variant), Sync) |
| 534 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_disable", variant), Sync) |
| 535 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_sync", variant), Sync) |
| 536 | |
| 537 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_no_override", variant), Sync) |
| 538 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_async", variant), Sync) |
| 539 | // should sanitize: { diag: { memtag: true } } result in Sync instead of None here? |
| 540 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_disable", variant), None) |
| 541 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_sync", variant), Sync) |
| 542 | |
| 543 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_no_override", variant), Sync) |
| 544 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_async", variant), Sync) |
| 545 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_disable", variant), Sync) |
| 546 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_sync", variant), Sync) |
| 547 | |
| 548 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_no_override", variant), Sync) |
| 549 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_async", variant), Sync) |
| 550 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_disable", variant), None) |
| 551 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_sync", variant), Sync) |
| 552 | |
| 553 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_no_override", variant), Sync) |
| 554 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_async", variant), Sync) |
| 555 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_disable", variant), Sync) |
| 556 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 557 | } |