Skip to content

Commit

Permalink
Extend bpf tests to cover golang 1.19
Browse files Browse the repository at this point in the history
Summary: TSIA

Test Plan: Ran all tests.

Reviewers: #stirling, jamesbartlett, oazizi

Reviewed By: #stirling, oazizi

Signed-off-by: Vihang Mehta <[email protected]>

Differential Revision: https://phab.corp.pixielabs.ai/D12008

GitOrigin-RevId: 6f08ade3be19324c19082b5ed0c513950fad2b6c
  • Loading branch information
vihangm authored and copybaranaut committed Aug 4, 2022
1 parent e0f435c commit c48c4a7
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 10 deletions.
159 changes: 154 additions & 5 deletions src/stirling/obj_tools/dwarf_reader_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ constexpr std::string_view kTestGo1_16Binary =
"src/stirling/obj_tools/testdata/go/test_go_1_16_binary";
constexpr std::string_view kTestGo1_17Binary =
"src/stirling/obj_tools/testdata/go/test_go_1_17_binary";
constexpr std::string_view kTestGoBinary =
"src/stirling/obj_tools/testdata/go/test_go_binary_/"
"test_go_binary";
constexpr std::string_view kTestGo1_18Binary =
"src/stirling/obj_tools/testdata/go/test_go_1_18_binary";
constexpr std::string_view kTestGo1_19Binary =
"src/stirling/obj_tools/testdata/go/test_go_1_19_binary";
constexpr std::string_view kGoGRPCServer =
"src/stirling/testing/demo_apps/go_grpc_tls_pl/server/golang_1_16_grpc_tls_server_binary";
constexpr std::string_view kCppBinary = "src/stirling/obj_tools/testdata/cc/test_exe";
Expand Down Expand Up @@ -60,21 +61,23 @@ auto CreateDwarfReader(const std::filesystem::path& path, bool indexing) {
return DwarfReader::CreateWithoutIndexing(path);
}

// TODO(chengruizhe): Make binary path a parameter in the TEST_P for go 1.16, 1.17, and 1.18.
// TODO(chengruizhe): Make binary path a parameter in the TEST_P for go 1.16, 1.17, 1.18, and 1.19.
class DwarfReaderTest : public ::testing::TestWithParam<DwarfReaderTestParam> {
protected:
DwarfReaderTest()
: kCppBinaryPath(px::testing::BazelRunfilePath(kCppBinary)),
kGo1_16BinaryPath(px::testing::BazelRunfilePath(kTestGo1_16Binary)),
kGo1_17BinaryPath(px::testing::BazelRunfilePath(kTestGo1_17Binary)),
kGo1_18BinaryPath(px::testing::BazelRunfilePath(kTestGoBinary)),
kGo1_18BinaryPath(px::testing::BazelRunfilePath(kTestGo1_18Binary)),
kGo1_19BinaryPath(px::testing::BazelRunfilePath(kTestGo1_19Binary)),
kGoServerBinaryPath(px::testing::BazelRunfilePath(kGoGRPCServer)),
kGoBinaryUnconventionalPath(px::testing::BazelRunfilePath(kGoBinaryUnconventional)) {}

const std::string kCppBinaryPath;
const std::string kGo1_16BinaryPath;
const std::string kGo1_17BinaryPath;
const std::string kGo1_18BinaryPath;
const std::string kGo1_19BinaryPath;
const std::string kGoServerBinaryPath;
const std::string kGoBinaryUnconventionalPath;
};
Expand Down Expand Up @@ -116,6 +119,14 @@ TEST_F(DwarfReaderTest, SourceLanguage) {
EXPECT_THAT(dwarf_reader->compiler(), ::testing::HasSubstr("go"));
EXPECT_THAT(dwarf_reader->compiler(), ::testing::HasSubstr("regabi"));
}

{
ASSERT_OK_AND_ASSIGN(std::unique_ptr<DwarfReader> dwarf_reader,
DwarfReader::CreateWithoutIndexing(kGo1_19BinaryPath));
EXPECT_EQ(dwarf_reader->source_language(), llvm::dwarf::DW_LANG_Go);
EXPECT_THAT(dwarf_reader->compiler(), ::testing::HasSubstr("go"));
EXPECT_THAT(dwarf_reader->compiler(), ::testing::HasSubstr("regabi"));
}
}

// Tests that GetMatchingDIEs() returns empty vector when nothing is found.
Expand Down Expand Up @@ -161,6 +172,14 @@ TEST_P(DwarfReaderTest, Go1_18GetStructByteSize) {
EXPECT_OK_AND_EQ(dwarf_reader->GetStructByteSize("main.Vertex"), 16);
}

TEST_P(DwarfReaderTest, Go1_19GetStructByteSize) {
DwarfReaderTestParam p = GetParam();
ASSERT_OK_AND_ASSIGN(std::unique_ptr<DwarfReader> dwarf_reader,
CreateDwarfReader(kGo1_19BinaryPath, p.index));

EXPECT_OK_AND_EQ(dwarf_reader->GetStructByteSize("main.Vertex"), 16);
}

TEST_P(DwarfReaderTest, CppGetStructMemberInfo) {
DwarfReaderTestParam p = GetParam();
ASSERT_OK_AND_ASSIGN(std::unique_ptr<DwarfReader> dwarf_reader,
Expand Down Expand Up @@ -213,6 +232,19 @@ TEST_P(DwarfReaderTest, Go1_18GetStructMemberInfo) {
"bogus", llvm::dwarf::DW_TAG_member));
}

TEST_P(DwarfReaderTest, Go1_19GetStructMemberInfo) {
DwarfReaderTestParam p = GetParam();
ASSERT_OK_AND_ASSIGN(std::unique_ptr<DwarfReader> dwarf_reader,
CreateDwarfReader(kGo1_19BinaryPath, p.index));

EXPECT_OK_AND_EQ(
dwarf_reader->GetStructMemberInfo("main.Vertex", llvm::dwarf::DW_TAG_structure_type, "Y",
llvm::dwarf::DW_TAG_member),
(StructMemberInfo{8, TypeInfo{VarType::kBaseType, "float64"}}));
EXPECT_NOT_OK(dwarf_reader->GetStructMemberInfo("main.Vertex", llvm::dwarf::DW_TAG_structure_type,
"bogus", llvm::dwarf::DW_TAG_member));
}

TEST_P(DwarfReaderTest, CppGetStructMemberOffset) {
DwarfReaderTestParam p = GetParam();
ASSERT_OK_AND_ASSIGN(std::unique_ptr<DwarfReader> dwarf_reader,
Expand Down Expand Up @@ -250,6 +282,15 @@ TEST_P(DwarfReaderTest, Go1_18GetStructMemberOffset) {
EXPECT_NOT_OK(dwarf_reader->GetStructMemberOffset("main.Vertex", "bogus"));
}

TEST_P(DwarfReaderTest, Go1_19GetStructMemberOffset) {
DwarfReaderTestParam p = GetParam();
ASSERT_OK_AND_ASSIGN(std::unique_ptr<DwarfReader> dwarf_reader,
CreateDwarfReader(kGo1_19BinaryPath, p.index));

EXPECT_OK_AND_EQ(dwarf_reader->GetStructMemberOffset("main.Vertex", "Y"), 8);
EXPECT_NOT_OK(dwarf_reader->GetStructMemberOffset("main.Vertex", "bogus"));
}

// Inspired from a real life case.
TEST_P(DwarfReaderTest, GoUnconventionalGetStructMemberOffset) {
DwarfReaderTestParam p = GetParam();
Expand Down Expand Up @@ -408,6 +449,19 @@ TEST_P(DwarfReaderTest, Golang1_18ArgumentTypeByteSize) {
EXPECT_OK_AND_EQ(dwarf_reader->GetArgumentTypeByteSize("main.Vertex.Abs", "v"), 16);
}

TEST_P(DwarfReaderTest, Golang1_19ArgumentTypeByteSize) {
DwarfReaderTestParam p = GetParam();
ASSERT_OK_AND_ASSIGN(std::unique_ptr<DwarfReader> dwarf_reader,
CreateDwarfReader(kGo1_19BinaryPath, p.index));

// v is of type *Vertex.
EXPECT_OK_AND_EQ(dwarf_reader->GetArgumentTypeByteSize("main.(*Vertex).Scale", "v"), 8);
// f is of type float64.
EXPECT_OK_AND_EQ(dwarf_reader->GetArgumentTypeByteSize("main.(*Vertex).Scale", "f"), 8);
// v is of type Vertex.
EXPECT_OK_AND_EQ(dwarf_reader->GetArgumentTypeByteSize("main.Vertex.Abs", "v"), 16);
}

TEST_P(DwarfReaderTest, CppArgumentLocation) {
DwarfReaderTestParam p = GetParam();
ASSERT_OK_AND_ASSIGN(std::unique_ptr<DwarfReader> dwarf_reader,
Expand Down Expand Up @@ -490,6 +544,28 @@ TEST_P(DwarfReaderTest, Golang1_18ArgumentLocation) {
EXPECT_NOT_OK(dwarf_reader->GetArgumentLocation("main.Vertex.Abs", "v"));
}

TEST_P(DwarfReaderTest, Golang1_19ArgumentLocation) {
DwarfReaderTestParam p = GetParam();
ASSERT_OK_AND_ASSIGN(std::unique_ptr<DwarfReader> dwarf_reader,
CreateDwarfReader(kGo1_19BinaryPath, p.index));

EXPECT_OK_AND_EQ(dwarf_reader->GetArgumentLocation("main.(*Vertex).Scale", "v"),
(VarLocation{.loc_type = LocationType::kRegister, .offset = 0}));
EXPECT_OK_AND_EQ(dwarf_reader->GetArgumentLocation("main.(*Vertex).Scale", "f"),
(VarLocation{.loc_type = LocationType::kRegister, .offset = 17}));
EXPECT_OK_AND_EQ(dwarf_reader->GetArgumentLocation("main.(*Vertex).CrossScale", "v"),
(VarLocation{.loc_type = LocationType::kRegister, .offset = 0}));

// TODO(oazizi): Support multi-piece arguments that span multiple registers.
EXPECT_NOT_OK(dwarf_reader->GetArgumentLocation("main.(*Vertex).CrossScale", "v2"));

EXPECT_OK_AND_EQ(dwarf_reader->GetArgumentLocation("main.(*Vertex).CrossScale", "f"),
(VarLocation{.loc_type = LocationType::kRegister, .offset = 19}));

// TODO(oazizi): Support multi-piece arguments that span multiple registers.
EXPECT_NOT_OK(dwarf_reader->GetArgumentLocation("main.Vertex.Abs", "v"));
}

// Note the differences here and the results in CppArgumentStackPointerOffset.
// This needs more investigation. Appears as though there are issues with alignment and
// also the reference point of the offset.
Expand Down Expand Up @@ -758,6 +834,79 @@ TEST_P(DwarfReaderTest, Go1_18FunctionArgInfo) {
}
}

TEST_P(DwarfReaderTest, Go1_19FunctionArgInfo) {
DwarfReaderTestParam p = GetParam();

{
ASSERT_OK_AND_ASSIGN(std::unique_ptr<DwarfReader> dwarf_reader,
CreateDwarfReader(kGo1_19BinaryPath, p.index));

EXPECT_OK_AND_THAT(
dwarf_reader->GetFunctionArgInfo("main.(*Vertex).Scale"),
UnorderedElementsAre(
Pair("v", ArgInfo{TypeInfo{VarType::kPointer, "*main.Vertex"},
{LocationType::kRegister, 0, {RegisterName::kRAX}}}),
Pair("f", ArgInfo{TypeInfo{VarType::kBaseType, "float64"},
{LocationType::kRegisterFP, 0, {RegisterName::kXMM0}}})));
EXPECT_OK_AND_THAT(
dwarf_reader->GetFunctionArgInfo("main.(*Vertex).CrossScale"),
UnorderedElementsAre(
Pair("v", ArgInfo{TypeInfo{VarType::kPointer, "*main.Vertex"},
{LocationType::kRegister, 0, {RegisterName::kRAX}}}),
Pair("v2",
ArgInfo{
TypeInfo{VarType::kStruct, "main.Vertex"},
{LocationType::kRegisterFP, 0, {RegisterName::kXMM0, RegisterName::kXMM1}}}),
Pair("f", ArgInfo{TypeInfo{VarType::kBaseType, "float64"},
{LocationType::kRegisterFP, 16, {RegisterName::kXMM2}}})));
EXPECT_OK_AND_THAT(
dwarf_reader->GetFunctionArgInfo("main.Vertex.Abs"),
UnorderedElementsAre(
Pair("v",
ArgInfo{
TypeInfo{VarType::kStruct, "main.Vertex"},
{LocationType::kRegisterFP, 0, {RegisterName::kXMM0, RegisterName::kXMM1}}}),
Pair("~r0", ArgInfo{TypeInfo{VarType::kBaseType, "float64"},
{LocationType::kRegisterFP, 0, {RegisterName::kXMM0}},
true})));
EXPECT_OK_AND_THAT(dwarf_reader->GetFunctionArgInfo("main.MixedArgTypes"),
UnorderedElementsAre(
Pair("i1", ArgInfo{TypeInfo{VarType::kBaseType, "int"},
{LocationType::kRegister, 0, {RegisterName::kRAX}}}),
Pair("b1", ArgInfo{TypeInfo{VarType::kBaseType, "bool"},
{LocationType::kRegister, 8, {RegisterName::kRBX}}}),
Pair("b2", ArgInfo{TypeInfo{VarType::kStruct, "main.BoolWrapper"},
{LocationType::kRegister,
16,
{RegisterName::kRCX, RegisterName::kRDI,
RegisterName::kRSI, RegisterName::kR8}}}),
Pair("i2", ArgInfo{TypeInfo{VarType::kBaseType, "int"},
{LocationType::kRegister, 48, {RegisterName::kR9}}}),
Pair("i3", ArgInfo{TypeInfo{VarType::kBaseType, "int"},
{LocationType::kRegister, 56, {RegisterName::kR10}}}),
Pair("b3", ArgInfo{TypeInfo{VarType::kBaseType, "bool"},
{LocationType::kRegister, 64, {RegisterName::kR11}}}),
Pair("~r0", ArgInfo{TypeInfo{VarType::kBaseType, "int"},
{LocationType::kRegister, 0, {RegisterName::kRAX}},
true}),
Pair("~r1", ArgInfo{TypeInfo{VarType::kStruct, "main.BoolWrapper"},
{LocationType::kRegister,
8,
{RegisterName::kRBX, RegisterName::kRCX,
RegisterName::kRDI, RegisterName::kRSI}},
true})));
EXPECT_OK_AND_THAT(
dwarf_reader->GetFunctionArgInfo("main.GoHasNamedReturns"),
UnorderedElementsAre(
Pair("retfoo", ArgInfo{TypeInfo{VarType::kBaseType, "int"},
{LocationType::kRegister, 0, {RegisterName::kRAX}},
true}),
Pair("retbar", ArgInfo{TypeInfo{VarType::kBaseType, "bool"},
{LocationType::kRegister, 8, {RegisterName::kRBX}},
true})));
}
}

TEST_P(DwarfReaderTest, GoFunctionVarLocationConsistency) {
DwarfReaderTestParam p = GetParam();

Expand Down
15 changes: 14 additions & 1 deletion src/stirling/obj_tools/testdata/go/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,26 @@ go_cross(
target = ":test_go_binary",
)

go_cross(
name = "test_go_1_18_binary",
sdk_version = "1.18",
target = ":test_go_binary",
)

go_cross(
name = "test_go_1_19_binary",
sdk_version = "1.19",
target = ":test_go_binary",
)

filegroup(
name = "test_binaries",
testonly = True,
srcs = [
"sockshop_payments_service",
":test_go_1_16_binary",
":test_go_1_17_binary",
":test_go_binary",
":test_go_1_18_binary",
":test_go_1_19_binary",
],
)
2 changes: 2 additions & 0 deletions src/stirling/source_connectors/socket_tracer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,11 @@ pl_cc_test(
"//src/stirling/source_connectors/socket_tracer/protocols/http2/testing/go_grpc_client:golang_1_16_grpc_client",
"//src/stirling/source_connectors/socket_tracer/protocols/http2/testing/go_grpc_client:golang_1_17_grpc_client",
"//src/stirling/source_connectors/socket_tracer/protocols/http2/testing/go_grpc_client:golang_1_18_grpc_client",
"//src/stirling/source_connectors/socket_tracer/protocols/http2/testing/go_grpc_client:golang_1_19_grpc_client",
"//src/stirling/source_connectors/socket_tracer/protocols/http2/testing/go_grpc_server:golang_1_16_grpc_server_with_certs",
"//src/stirling/source_connectors/socket_tracer/protocols/http2/testing/go_grpc_server:golang_1_17_grpc_server_with_certs",
"//src/stirling/source_connectors/socket_tracer/protocols/http2/testing/go_grpc_server:golang_1_18_grpc_server_with_certs",
"//src/stirling/source_connectors/socket_tracer/protocols/http2/testing/go_grpc_server:golang_1_19_grpc_server_with_certs",
],
flaky = True,
shard_count = 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ struct Go1_18TLSClientServerContainers {
using GoTLSClientContainer = ::px::stirling::testing::Go1_18_TLSClientContainer;
};

struct Go1_19TLSClientServerContainers {
using GoTLSServerContainer = ::px::stirling::testing::Go1_19_TLSServerContainer;
using GoTLSClientContainer = ::px::stirling::testing::Go1_19_TLSClientContainer;
};

typedef ::testing::Types<Go1_16TLSClientServerContainers, Go1_17TLSClientServerContainers,
Go1_18TLSClientServerContainers>
Go1_18TLSClientServerContainers, Go1_19TLSClientServerContainers>
GoVersions;
TYPED_TEST_SUITE(GoTLSTraceTest, GoVersions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ INSTANTIATE_TEST_SUITE_P(SecurityModeTest, GRPCTraceTest,
// our knowledge, and to minimize test size to reduce flakiness.
TestParams{"1_16", true, true}, TestParams{"1_16", true, false},
TestParams{"1_17", false, true}, TestParams{"1_17", false, false},
TestParams{"1_18", false, true}, TestParams{"1_18", true, false}));
TestParams{"1_18", false, true}, TestParams{"1_18", true, false},
TestParams{"1_19", false, false}, TestParams{"1_19", true, true}));

} // namespace stirling
} // namespace px
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ struct Go1_18GRPCClientServerContainers {
using ClientContainer = ::px::stirling::testing::Go1_18_GRPCClientContainer;
};

// Use a typed test to run the test for Go 1.16 - Go 1.18.
struct Go1_19GRPCClientServerContainers {
using ServerContainer = ::px::stirling::testing::Go1_19_GRPCServerContainer;
using ClientContainer = ::px::stirling::testing::Go1_19_GRPCClientContainer;
};

// Use a typed test to run the test for Go 1.16 - Go 1.19.
typedef ::testing::Types<Go1_16GRPCClientServerContainers, Go1_17GRPCClientServerContainers,
Go1_18GRPCClientServerContainers>
Go1_18GRPCClientServerContainers, Go1_19GRPCClientServerContainers>
GoVersions;
TYPED_TEST_SUITE(HTTP2TraceTest, GoVersions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,19 @@ pl_cc_test_library(
"//src/stirling/testing/demo_apps/go_grpc_tls_pl/client:golang_1_16_grpc_tls_client.tar",
"//src/stirling/testing/demo_apps/go_grpc_tls_pl/client:golang_1_17_grpc_tls_client.tar",
"//src/stirling/testing/demo_apps/go_grpc_tls_pl/client:golang_1_18_grpc_tls_client.tar",
"//src/stirling/testing/demo_apps/go_grpc_tls_pl/client:golang_1_19_grpc_tls_client.tar",
"//src/stirling/testing/demo_apps/go_grpc_tls_pl/server:golang_1_16_grpc_tls_server.tar",
"//src/stirling/testing/demo_apps/go_grpc_tls_pl/server:golang_1_17_grpc_tls_server.tar",
"//src/stirling/testing/demo_apps/go_grpc_tls_pl/server:golang_1_18_grpc_tls_server.tar",
"//src/stirling/testing/demo_apps/go_grpc_tls_pl/server:golang_1_19_grpc_tls_server.tar",
"//src/stirling/testing/demo_apps/go_https/client:golang_1_16_https_client.tar",
"//src/stirling/testing/demo_apps/go_https/client:golang_1_17_https_client.tar",
"//src/stirling/testing/demo_apps/go_https/client:golang_1_18_https_client.tar",
"//src/stirling/testing/demo_apps/go_https/client:golang_1_19_https_client.tar",
"//src/stirling/testing/demo_apps/go_https/server:golang_1_16_https_server.tar",
"//src/stirling/testing/demo_apps/go_https/server:golang_1_17_https_server.tar",
"//src/stirling/testing/demo_apps/go_https/server:golang_1_18_https_server.tar",
"//src/stirling/testing/demo_apps/go_https/server:golang_1_19_https_server.tar",
"//src/stirling/testing/demo_apps/hipster_shop/productcatalogservice_client:productcatalogservice_client_image.tar",
],
deps = ["//src/common/testing/test_utils:cc_library"],
Expand Down
Loading

0 comments on commit c48c4a7

Please sign in to comment.