From f7aadf70d8b9aaa6cbba7a471808f272d7f8f2a9 Mon Sep 17 00:00:00 2001 From: Inseob Kim Date: Tue, 13 Apr 2021 10:15:31 +0900 Subject: [PATCH] Add flag test for cfi snapshot Test: soong test Change-Id: I651120b11f5b80c4b5f04172170afc533f24c54d --- cc/vendor_snapshot_test.go | 86 ++++++++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 23 deletions(-) diff --git a/cc/vendor_snapshot_test.go b/cc/vendor_snapshot_test.go index 1c3f1b482..ed9e9d6e2 100644 --- a/cc/vendor_snapshot_test.go +++ b/cc/vendor_snapshot_test.go @@ -424,6 +424,20 @@ func TestVendorSnapshotUse(t *testing.T) { srcs: ["client.cpp"], } + cc_library_shared { + name: "libclient_cfi", + vendor: true, + nocrt: true, + no_libcrt: true, + stl: "none", + system_shared_libs: [], + static_libs: ["libvendor"], + sanitize: { + cfi: true, + }, + srcs: ["client.cpp"], + } + cc_binary { name: "bin_without_snapshot", vendor: true, @@ -584,10 +598,18 @@ func TestVendorSnapshotUse(t *testing.T) { vendor: true, arch: { arm64: { + cfi: { + src: "libvendor.cfi.a", + export_include_dirs: ["include/libvendor_cfi"], + }, src: "libvendor.a", export_include_dirs: ["include/libvendor"], }, arm: { + cfi: { + src: "libvendor.cfi.a", + export_include_dirs: ["include/libvendor_cfi"], + }, src: "libvendor.a", export_include_dirs: ["include/libvendor"], }, @@ -726,29 +748,31 @@ func TestVendorSnapshotUse(t *testing.T) { depsBp := GatherRequiredDepsForTest(android.Android) mockFS := map[string][]byte{ - "deps/Android.bp": []byte(depsBp), - "framework/Android.bp": []byte(frameworkBp), - "framework/symbol.txt": nil, - "vendor/Android.bp": []byte(vendorProprietaryBp), - "vendor/bin": nil, - "vendor/bin32": nil, - "vendor/bin.cpp": nil, - "vendor/client.cpp": nil, - "vendor/include/libvndk/a.h": nil, - "vendor/include/libvendor/b.h": nil, - "vendor/libc++_static.a": nil, - "vendor/libc++demangle.a": nil, - "vendor/libgcc_striped.a": nil, - "vendor/libvndk.a": nil, - "vendor/libvendor.a": nil, - "vendor/libvendor.so": nil, - "vendor/lib32.a": nil, - "vendor/lib32.so": nil, - "vendor/lib64.a": nil, - "vendor/lib64.so": nil, - "vndk/Android.bp": []byte(vndkBp), - "vndk/include/libvndk/a.h": nil, - "vndk/libvndk.so": nil, + "deps/Android.bp": []byte(depsBp), + "framework/Android.bp": []byte(frameworkBp), + "framework/symbol.txt": nil, + "vendor/Android.bp": []byte(vendorProprietaryBp), + "vendor/bin": nil, + "vendor/bin32": nil, + "vendor/bin.cpp": nil, + "vendor/client.cpp": nil, + "vendor/include/libvndk/a.h": nil, + "vendor/include/libvendor/b.h": nil, + "vendor/include/libvendor_cfi/c.h": nil, + "vendor/libc++_static.a": nil, + "vendor/libc++demangle.a": nil, + "vendor/libgcc_striped.a": nil, + "vendor/libvndk.a": nil, + "vendor/libvendor.a": nil, + "vendor/libvendor.cfi.a": nil, + "vendor/libvendor.so": nil, + "vendor/lib32.a": nil, + "vendor/lib32.so": nil, + "vendor/lib64.a": nil, + "vendor/lib64.so": nil, + "vndk/Android.bp": []byte(vndkBp), + "vndk/include/libvndk/a.h": nil, + "vndk/libvndk.so": nil, } config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS) @@ -766,6 +790,9 @@ func TestVendorSnapshotUse(t *testing.T) { staticVariant := "android_vendor.30_arm64_armv8-a_static" binaryVariant := "android_vendor.30_arm64_armv8-a" + sharedCfiVariant := "android_vendor.30_arm64_armv8-a_shared_cfi" + staticCfiVariant := "android_vendor.30_arm64_armv8-a_static_cfi" + shared32Variant := "android_vendor.30_arm_armv7-a-neon_shared" binary32Variant := "android_vendor.30_arm_armv7-a-neon" @@ -808,6 +835,19 @@ func TestVendorSnapshotUse(t *testing.T) { t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g) } + // libclient_cfi uses libvendor.vendor_static.30.arm64's cfi variant + libclientCfiCcFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("cc").Args["cFlags"] + if !strings.Contains(libclientCfiCcFlags, "-Ivendor/include/libvendor_cfi") { + t.Errorf("flags for libclient_cfi must contain %#v, but was %#v.", + "-Ivendor/include/libvendor_cfi", libclientCfiCcFlags) + } + + libclientCfiLdFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("ld").Args["libFlags"] + libvendorCfiOutputPaths := getOutputPaths(ctx, staticCfiVariant, []string{"libvendor.vendor_static.30.arm64"}) + if !strings.Contains(libclientCfiLdFlags, libvendorCfiOutputPaths[0].String()) { + t.Errorf("libflags for libclientCfi must contain %#v, but was %#v", libvendorCfiOutputPaths[0], libclientCfiLdFlags) + } + // bin_without_snapshot uses libvndk.vendor_static.30.arm64 binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"] if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivendor/include/libvndk") {