From 67ceacc0f9c708201dd76daa5e3cf42283cf88f4 Mon Sep 17 00:00:00 2001 From: Sumera Priyadarsini Date: Sun, 28 Jan 2024 23:24:22 +0530 Subject: [PATCH 1/3] Update tests to match latest testdata changes Signed-off-by: Sumera Priyadarsini Update unwind table tests to match latest testdata changes Signed-off-by: Sumera Priyadarsini --- pkg/elfreader/executable_test.go | 4 ++-- pkg/runtime/elf_symbols_test.go | 13 +------------ pkg/runtime/nodejs/nodejs_test.go | 12 +----------- pkg/stack/unwind/executable_test.go | 6 +++--- pkg/stack/unwind/unwind_table_test.go | 10 +++++----- test/integration/integration.go | 21 --------------------- test/integration/native/native_test.go | 9 +++++---- testdata | 2 +- 8 files changed, 18 insertions(+), 59 deletions(-) diff --git a/pkg/elfreader/executable_test.go b/pkg/elfreader/executable_test.go index 739704f478..445de7fe0b 100644 --- a/pkg/elfreader/executable_test.go +++ b/pkg/elfreader/executable_test.go @@ -21,13 +21,13 @@ import ( ) func TestASLRDisabled(t *testing.T) { - aslrEnabled, err := IsASLRElegible("../../testdata/out/x86/basic-cpp") + aslrEnabled, err := IsASLRElegible("../../testdata/out/amd64/basic-cpp") require.NoError(t, err) require.False(t, aslrEnabled) } func TestASLREnabled(t *testing.T) { - aslrEnabled, err := IsASLRElegible("../../testdata/out/x86/basic-cpp-plt-pie") + aslrEnabled, err := IsASLRElegible("../../testdata/out/amd64/basic-cpp-plt-pie") require.NoError(t, err) require.True(t, aslrEnabled) } diff --git a/pkg/runtime/elf_symbols_test.go b/pkg/runtime/elf_symbols_test.go index e092f3f961..26c92435c8 100644 --- a/pkg/runtime/elf_symbols_test.go +++ b/pkg/runtime/elf_symbols_test.go @@ -25,20 +25,9 @@ import ( const testdata = "../../testdata" -// TODO(kakkoyun): Change upstream to use GOARCH. -func arch() string { - ar := runtime.GOARCH - switch ar { - case "amd64": - return "x86" - default: - return ar - } -} - //nolint:unparam func testBinaryPath(p string) string { - return path.Join(testdata, "vendored", arch(), p) + return path.Join(testdata, "vendored", runtime.GOARCH, p) } func Benchmark_isSymbolNameInSection(b *testing.B) { diff --git a/pkg/runtime/nodejs/nodejs_test.go b/pkg/runtime/nodejs/nodejs_test.go index bbfac607aa..14d5f0247d 100644 --- a/pkg/runtime/nodejs/nodejs_test.go +++ b/pkg/runtime/nodejs/nodejs_test.go @@ -26,19 +26,9 @@ import ( const testdata = "../../../testdata" -func arch() string { - ar := runtime.GOARCH - switch ar { - case "amd64": - return "x86" - default: - return ar - } -} - //nolint:unparam func testBinaryPath(p string) string { - return path.Join(testdata, "vendored", arch(), p) + return path.Join(testdata, "vendored", runtime.GOARCH, p) } func Test_scanVersionBytes(t *testing.T) { diff --git a/pkg/stack/unwind/executable_test.go b/pkg/stack/unwind/executable_test.go index 7d4b65ac74..2d714cf5fb 100644 --- a/pkg/stack/unwind/executable_test.go +++ b/pkg/stack/unwind/executable_test.go @@ -56,7 +56,7 @@ func TestHasFramePointersInCApplication(t *testing.T) { reg, runtime.NewCompilerInfoManager(reg, objFilePool), ) - hasFp, err := fpCache.hasFramePointers("../../../testdata/out/x86/basic-cpp") + hasFp, err := fpCache.hasFramePointers("../../../testdata/out/amd64/basic-cpp") require.NoError(t, err) require.False(t, hasFp) } @@ -75,13 +75,13 @@ func TestHasFramePointersCache(t *testing.T) { // Ensure that the cached results are correct. { - hasFp, err := fpCache.HasFramePointers("../../../testdata/out/x86/basic-cpp") + hasFp, err := fpCache.HasFramePointers("../../../testdata/out/amd64/basic-cpp") require.NoError(t, err) require.False(t, hasFp) } { - hasFp, err := fpCache.HasFramePointers("../../../testdata/out/x86/basic-cpp") + hasFp, err := fpCache.HasFramePointers("../../../testdata/out/amd64/basic-cpp") require.NoError(t, err) require.False(t, hasFp) } diff --git a/pkg/stack/unwind/unwind_table_test.go b/pkg/stack/unwind/unwind_table_test.go index 8809da4742..89a30adc89 100644 --- a/pkg/stack/unwind/unwind_table_test.go +++ b/pkg/stack/unwind/unwind_table_test.go @@ -24,17 +24,17 @@ import ( // TODO(Sylfrena): Add equivalent test for arm64. func TestBuildUnwindTable(t *testing.T) { - fdes, _, err := ReadFDEs("../../../testdata/out/x86/basic-cpp") + fdes, _, err := ReadFDEs("../../../testdata/out/amd64/basic-cpp") require.NoError(t, err) unwindTable, err := BuildUnwindTable(fdes) require.NoError(t, err) - require.Len(t, unwindTable, 38) + require.Len(t, unwindTable, 2762) - require.Equal(t, uint64(0x401020), unwindTable[0].Loc) - require.Equal(t, uint64(0x40118e), unwindTable[len(unwindTable)-1].Loc) + require.Equal(t, uint64(0x20b6e0), unwindTable[0].Loc) + require.Equal(t, uint64(0x224357), unwindTable[len(unwindTable)-1].Loc) - require.Equal(t, frame.DWRule{Rule: frame.RuleOffset, Offset: -8}, unwindTable[0].RA) + require.Equal(t, frame.DWRule{Rule: frame.RuleUndefined, Offset: 0}, unwindTable[0].RA) require.Equal(t, frame.DWRule{Rule: frame.RuleCFA, Reg: 0x7, Offset: 8}, unwindTable[0].CFA) require.Equal(t, frame.DWRule{Rule: frame.RuleUnknown, Reg: 0x0, Offset: 0}, unwindTable[0].RBP) } diff --git a/test/integration/integration.go b/test/integration/integration.go index 26baa4fe16..041bb930d3 100644 --- a/test/integration/integration.go +++ b/test/integration/integration.go @@ -17,11 +17,9 @@ package integration import ( "context" "errors" - "fmt" "net/http" "os" "path/filepath" - goruntime "runtime" "strconv" "strings" "time" @@ -150,25 +148,6 @@ func WaitForServer(url string) error { return errors.New("timed out waiting for HTTP server to start") } -const ( - Arm64 = "arm64" - Amd64 = "x86" -) - -// Choose host architecture. -func ChooseArch() (string, error) { - var arch string - switch goruntime.GOARCH { - case "arm64": - arch = Arm64 - case "amd64": - arch = Amd64 - default: - return "", fmt.Errorf("unsupported architecture: %s", goruntime.GOARCH) - } - return arch, nil -} - func NewTestProfiler( logger log.Logger, reg *prometheus.Registry, diff --git a/test/integration/native/native_test.go b/test/integration/native/native_test.go index 9db10a3cbc..dbc29695f9 100644 --- a/test/integration/native/native_test.go +++ b/test/integration/native/native_test.go @@ -22,6 +22,7 @@ import ( "os" "os/exec" "path/filepath" + goruntime "runtime" "strconv" "strings" "testing" @@ -194,8 +195,8 @@ func TestCPUProfiler(t *testing.T) { }) require.NoError(t, err) - arch, err := integration.ChooseArch() - require.NoError(t, err) + arch := goruntime.GOARCH + // Test unwinding without frame pointers. noFramePointersCmd := exec.Command(filepath.Join(testdataPath, fmt.Sprintf("out/%s/basic-cpp-no-fp-with-debuginfo", arch))) require.NoError(t, noFramePointersCmd.Start()) @@ -207,7 +208,7 @@ func TestCPUProfiler(t *testing.T) { // Test unwinding JIT without frame pointers in the AoT code. // TODO(sylfrena): Remove if condition once toy jit is added for arm64 var jitPid int - if arch == integration.Amd64 { + if arch == "amd64" { jitCmd := exec.Command(filepath.Join(testdataPath, fmt.Sprintf("out/%s/basic-cpp-jit-no-fp", arch))) err = jitCmd.Start() require.NoError(t, err) @@ -309,7 +310,7 @@ func TestCPUProfiler(t *testing.T) { }) t.Run("mixed mode unwinding", func(t *testing.T) { - if arch == integration.Amd64 { + if arch == "amd64" { sample := profileStore.SampleForProcess(jitPid, false) require.NotNil(t, sample) diff --git a/testdata b/testdata index 766941752c..559ba46173 160000 --- a/testdata +++ b/testdata @@ -1 +1 @@ -Subproject commit 766941752c489b83012676dbb628333fb360c357 +Subproject commit 559ba46173f520c430a595e2f9f9d8f8e15d0d04 From 6c46e1ec1f136e6a33d7802ca306d8b982ca2ddd Mon Sep 17 00:00:00 2001 From: Sumera Priyadarsini Date: Thu, 22 Feb 2024 16:58:31 +0530 Subject: [PATCH 2/3] Get compiler label check to pass --- test/integration/native/native_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/native/native_test.go b/test/integration/native/native_test.go index dbc29695f9..e04f3fcfb4 100644 --- a/test/integration/native/native_test.go +++ b/test/integration/native/native_test.go @@ -258,7 +258,7 @@ func TestCPUProfiler(t *testing.T) { // Test expected metadata. require.Equal(t, string(sample.Labels["comm"]), "basic-cpp-no-fp-with-debuginfo"[:15]) // comm is limited to 16 characters including NUL. require.True(t, strings.Contains(string(sample.Labels["executable"]), "basic-cpp-no-fp-with-debuginfo")) - require.True(t, strings.HasPrefix(string(sample.Labels["compiler"]), "GCC")) + require.True(t, strings.HasPrefix(string(sample.Labels["compiler"]), "\x00clang")) require.NotEmpty(t, string(sample.Labels["kernel_release"])) require.NotEmpty(t, string(sample.Labels["cgroup_name"])) metadataPid, err := strconv.Atoi(string(sample.Labels["pid"])) From 608cd0a8ab5081de7f3f9f20152e8bae928386a3 Mon Sep 17 00:00:00 2001 From: Sumera Priyadarsini Date: Thu, 22 Feb 2024 17:34:56 +0530 Subject: [PATCH 3/3] Update makefile --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f4d7cb565c..bcb57eafdb 100644 --- a/Makefile +++ b/Makefile @@ -140,9 +140,7 @@ $(OUT_BIN_EH_FRAME): go/deps $(GO_ENV) CGO_CFLAGS="$(CGO_CFLAGS_DYN)" CGO_LDFLAGS="$(CGO_LDFLAGS_DYN)" $(GO) build $(SANITIZERS) $(GO_BUILD_FLAGS) -o $@ ./cmd/eh-frame write-dwarf-unwind-tables: build - make -C testdata validate EH_FRAME_BIN=../dist/eh-frame - make -C testdata validate-compact EH_FRAME_BIN=../dist/eh-frame - make -C testdata validate-final EH_FRAME_BIN=../dist/eh-frame + make -C testdata generate test-dwarf-unwind-tables: write-dwarf-unwind-tables $(CMD_GIT) diff --exit-code testdata/