Skip to content

Commit

Permalink
Update tests to match latest testdata changes
Browse files Browse the repository at this point in the history
Signed-off-by: Sumera Priyadarsini <[email protected]>

Update unwind table tests to match latest testdata changes

Signed-off-by: Sumera Priyadarsini <[email protected]>
  • Loading branch information
Sylfrena committed Feb 22, 2024
1 parent 1ed80d3 commit df28890
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 59 deletions.
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")
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
9 changes: 5 additions & 4 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 @@ -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

0 comments on commit df28890

Please sign in to comment.