Fix for ndk having sanitizers

Test: go test soong tests
Test: verify no NeuralNetworksTest_random_graph sdk variants in
    build.ninja when aosp_x86 is lunched
Bug: 302093869
Change-Id: I6429aa75518cca6974abcf7330236a6a07135ea1
This commit is contained in:
Liz Kammer 2023-09-26 16:48:04 -04:00
parent 2863e4535e
commit ba23cb6436
2 changed files with 126 additions and 3 deletions

View file

@ -1113,12 +1113,15 @@ func (sanitize *sanitize) isSanitizerExplicitlyDisabled(t SanitizerType) bool {
// indirectly (via a mutator) sets the bool ptr to true, and you can't // indirectly (via a mutator) sets the bool ptr to true, and you can't
// distinguish between the cases. It isn't needed though - both cases can be // distinguish between the cases. It isn't needed though - both cases can be
// treated identically. // treated identically.
func (sanitize *sanitize) isSanitizerEnabled(t SanitizerType) bool { func (s *sanitize) isSanitizerEnabled(t SanitizerType) bool {
if sanitize == nil { if s == nil {
return false
}
if proptools.Bool(s.Properties.SanitizeMutated.Never) {
return false return false
} }
sanitizerVal := sanitize.getSanitizerBoolPtr(t) sanitizerVal := s.getSanitizerBoolPtr(t)
return sanitizerVal != nil && *sanitizerVal == true return sanitizerVal != nil && *sanitizerVal == true
} }

View file

@ -16,6 +16,7 @@ package cc
import ( import (
"fmt" "fmt"
"reflect"
"runtime" "runtime"
"strings" "strings"
"testing" "testing"
@ -1273,3 +1274,122 @@ func TestCfi(t *testing.T) {
t.Errorf("non-CFI variant of baz not expected to contain CFI flags ") t.Errorf("non-CFI variant of baz not expected to contain CFI flags ")
} }
} }
func TestHwasan(t *testing.T) {
t.Parallel()
bp := `
cc_library_shared {
name: "shared_with_hwaddress",
static_libs: [
"static_dep_with_hwaddress",
"static_dep_no_hwaddress",
],
sanitize: {
hwaddress: true,
},
sdk_version: "current",
stl: "c++_shared",
}
cc_library_static {
name: "static_dep_with_hwaddress",
sanitize: {
hwaddress: true,
},
sdk_version: "current",
stl: "c++_shared",
}
cc_library_static {
name: "static_dep_no_hwaddress",
sdk_version: "current",
stl: "c++_shared",
}
`
androidArm := "android_arm_armv7-a-neon"
androidArm64 := "android_arm64_armv8-a"
androidX86 := "android_x86_silvermont"
sharedSuffix := "_shared"
hwasanSuffix := "_hwasan"
staticSuffix := "_static"
sdkSuffix := "_sdk"
sharedWithHwasanVariant := sharedSuffix + hwasanSuffix
sharedWithSdkVariant := sdkSuffix + sharedSuffix
staticWithHwasanVariant := staticSuffix + hwasanSuffix
staticWithSdkVariant := sdkSuffix + staticSuffix
testCases := []struct {
buildOs string
extraPreparer android.FixturePreparer
expectedVariants map[string][]string
}{
{
buildOs: androidArm64,
expectedVariants: map[string][]string{
"shared_with_hwaddress": []string{
androidArm64 + sharedWithHwasanVariant,
androidArm64 + sharedWithSdkVariant,
androidArm + sharedSuffix,
androidArm + sharedWithSdkVariant,
},
"static_dep_with_hwaddress": []string{
androidArm64 + staticSuffix,
androidArm64 + staticWithHwasanVariant,
androidArm64 + staticWithSdkVariant,
androidArm + staticSuffix,
androidArm + staticWithSdkVariant,
},
"static_dep_no_hwaddress": []string{
androidArm64 + staticSuffix,
androidArm64 + staticWithHwasanVariant,
androidArm64 + staticWithSdkVariant,
androidArm + staticSuffix,
androidArm + staticWithSdkVariant,
},
},
},
{
buildOs: androidX86,
extraPreparer: android.FixtureModifyConfig(func(config android.Config) {
config.Targets[android.Android] = []android.Target{
{
android.Android,
android.Arch{
ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, android.NativeBridgeDisabled, "", "", false},
}
}),
expectedVariants: map[string][]string{
"shared_with_hwaddress": []string{
androidX86 + sharedSuffix,
androidX86 + sharedWithSdkVariant,
},
"static_dep_with_hwaddress": []string{
androidX86 + staticSuffix,
androidX86 + staticWithSdkVariant,
},
"static_dep_no_hwaddress": []string{
androidX86 + staticSuffix,
androidX86 + staticWithSdkVariant,
},
},
},
}
for _, tc := range testCases {
preparer := android.GroupFixturePreparers(
prepareForCcTest,
android.OptionalFixturePreparer(tc.extraPreparer),
)
result := preparer.RunTestWithBp(t, bp)
for m, v := range tc.expectedVariants {
variants := result.ModuleVariantsForTests(m)
if !reflect.DeepEqual(variants, v) {
t.Errorf("Expected variants of %q to be %q, but got %q", m, v, variants)
}
}
}
}