Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests based on latest testdata changes #2520

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
4 changes: 2 additions & 2 deletions pkg/elfreader/executable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Sylfrena marked this conversation as resolved.
Show resolved Hide resolved
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)
}
13 changes: 1 addition & 12 deletions pkg/runtime/elf_symbols_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 1 addition & 11 deletions pkg/runtime/nodejs/nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/stack/unwind/executable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/stack/unwind/unwind_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
21 changes: 0 additions & 21 deletions test/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ package integration
import (
"context"
"errors"
"fmt"
"net/http"
"os"
"path/filepath"
goruntime "runtime"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions test/integration/native/native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"os/exec"
"path/filepath"
goruntime "runtime"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -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())
Expand All @@ -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)
Expand Down Expand Up @@ -257,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"]))
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion testdata
Submodule testdata updated 227 files
Loading