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 { |
Colin Cross | fc0df95 | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 27 | name: "libclang_rt.asan", |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 28 | } |
| 29 | `)) |
| 30 | |
| 31 | func 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 203 | |
| 204 | type MemtagNoteType int |
| 205 | |
| 206 | const ( |
| 207 | None MemtagNoteType = iota + 1 |
| 208 | Sync |
| 209 | Async |
| 210 | ) |
| 211 | |
| 212 | func (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 Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 221 | panic("type_note_invalid") |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
| 225 | func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 226 | t.Helper() |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 227 | 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 | |
| 247 | var prepareForTestWithMemtagHeap = android.GroupFixturePreparers( |
| 248 | android.FixtureModifyMockFS(func(fs android.MockFS) { |
| 249 | templateBp := ` |
| 250 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 251 | name: "unset_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 252 | gtest: false, |
| 253 | } |
| 254 | |
| 255 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 256 | name: "no_memtag_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 257 | gtest: false, |
| 258 | sanitize: { memtag_heap: false }, |
| 259 | } |
| 260 | |
| 261 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 262 | name: "set_memtag_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 263 | gtest: false, |
| 264 | sanitize: { memtag_heap: true }, |
| 265 | } |
| 266 | |
| 267 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 268 | name: "set_memtag_set_async_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 269 | gtest: false, |
| 270 | sanitize: { memtag_heap: true, diag: { memtag_heap: false } }, |
| 271 | } |
| 272 | |
| 273 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 274 | name: "set_memtag_set_sync_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 275 | gtest: false, |
| 276 | sanitize: { memtag_heap: true, diag: { memtag_heap: true } }, |
| 277 | } |
| 278 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 279 | cc_test { |
| 280 | name: "unset_memtag_set_sync_test_%[1]s", |
| 281 | gtest: false, |
| 282 | sanitize: { diag: { memtag_heap: true } }, |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | cc_binary { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 286 | name: "unset_binary_%[1]s", |
| 287 | } |
| 288 | |
| 289 | cc_binary { |
| 290 | name: "no_memtag_binary_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 291 | sanitize: { memtag_heap: false }, |
| 292 | } |
| 293 | |
| 294 | cc_binary { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 295 | name: "set_memtag_binary_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 296 | sanitize: { memtag_heap: true }, |
| 297 | } |
| 298 | |
| 299 | cc_binary { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 300 | name: "set_memtag_set_async_binary_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 301 | sanitize: { memtag_heap: true, diag: { memtag_heap: false } }, |
| 302 | } |
| 303 | |
| 304 | cc_binary { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 305 | name: "set_memtag_set_sync_binary_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 306 | sanitize: { memtag_heap: true, diag: { memtag_heap: true } }, |
| 307 | } |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 308 | |
| 309 | cc_binary { |
| 310 | name: "unset_memtag_set_sync_binary_%[1]s", |
| 311 | sanitize: { diag: { memtag_heap: true } }, |
| 312 | } |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 313 | ` |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 314 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 318 | |
| 319 | fs.Merge(android.MockFS{ |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 320 | "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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 324 | }) |
| 325 | }), |
| 326 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 327 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 331 | }), |
| 332 | ) |
| 333 | |
| 334 | func 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 Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 343 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 347 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 348 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 352 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 353 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 357 | |
Liz Kammer | 7b920b4 | 2021-06-22 16:57:27 -0400 | [diff] [blame] | 358 | 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 Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 361 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 362 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 363 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 367 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 368 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 372 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 373 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 377 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 378 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | func 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 Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 418 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 422 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 423 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 427 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 428 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 432 | |
Liz Kammer | 7b920b4 | 2021-06-22 16:57:27 -0400 | [diff] [blame] | 433 | 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 Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 436 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 437 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 438 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 442 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 443 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 447 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 448 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 452 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 453 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | func 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 Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 493 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 497 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 498 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 502 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 503 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 507 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 508 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 512 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 513 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 517 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 518 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 522 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 523 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 527 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 528 | 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 Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 553 | } |