Merge "Prevent NetworkTraceHandlerTest from touching BPF." am: 030b9fc4f1
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2521395 Change-Id: If193a1a789f8272ce067cc53c408cd6a67915dae Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
committed by
Automerger Merge Worker
commit
ab40aa6b74
@@ -136,10 +136,12 @@ void NetworkTraceHandler::OnSetup(const SetupArgs& args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void NetworkTraceHandler::OnStart(const StartArgs&) {
|
void NetworkTraceHandler::OnStart(const StartArgs&) {
|
||||||
|
if (mIsTest) return; // Don't touch non-hermetic bpf in test.
|
||||||
mStarted = sPoller.Start(mPollMs);
|
mStarted = sPoller.Start(mPollMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkTraceHandler::OnStop(const StopArgs&) {
|
void NetworkTraceHandler::OnStop(const StopArgs&) {
|
||||||
|
if (mIsTest) return; // Don't touch non-hermetic bpf in test.
|
||||||
if (mStarted) sPoller.Stop();
|
if (mStarted) sPoller.Stop();
|
||||||
mStarted = false;
|
mStarted = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,14 +33,6 @@ using ::perfetto::protos::Trace;
|
|||||||
using ::perfetto::protos::TracePacket;
|
using ::perfetto::protos::TracePacket;
|
||||||
using ::perfetto::protos::TrafficDirection;
|
using ::perfetto::protos::TrafficDirection;
|
||||||
|
|
||||||
// This handler makes OnStart and OnStop a no-op so that tracing is not really
|
|
||||||
// started on the device.
|
|
||||||
class HandlerForTest : public NetworkTraceHandler {
|
|
||||||
public:
|
|
||||||
void OnStart(const StartArgs&) override {}
|
|
||||||
void OnStop(const StopArgs&) override {}
|
|
||||||
};
|
|
||||||
|
|
||||||
class NetworkTraceHandlerTest : public testing::Test {
|
class NetworkTraceHandlerTest : public testing::Test {
|
||||||
protected:
|
protected:
|
||||||
// Starts a tracing session with the handler under test.
|
// Starts a tracing session with the handler under test.
|
||||||
@@ -52,7 +44,7 @@ class NetworkTraceHandlerTest : public testing::Test {
|
|||||||
|
|
||||||
perfetto::DataSourceDescriptor dsd;
|
perfetto::DataSourceDescriptor dsd;
|
||||||
dsd.set_name("test.network_packets");
|
dsd.set_name("test.network_packets");
|
||||||
HandlerForTest::Register(dsd);
|
NetworkTraceHandler::Register(dsd, /*isTest=*/true);
|
||||||
|
|
||||||
perfetto::TraceConfig cfg;
|
perfetto::TraceConfig cfg;
|
||||||
cfg.add_buffers()->set_size_kb(1024);
|
cfg.add_buffers()->set_size_kb(1024);
|
||||||
@@ -94,7 +86,7 @@ class NetworkTraceHandlerTest : public testing::Test {
|
|||||||
std::vector<TracePacket>* output,
|
std::vector<TracePacket>* output,
|
||||||
NetworkPacketTraceConfig config = {}) {
|
NetworkPacketTraceConfig config = {}) {
|
||||||
auto session = StartTracing(config);
|
auto session = StartTracing(config);
|
||||||
HandlerForTest::Trace([&](HandlerForTest::TraceContext ctx) {
|
NetworkTraceHandler::Trace([&](NetworkTraceHandler::TraceContext ctx) {
|
||||||
ctx.GetDataSourceLocked()->Write(input, ctx);
|
ctx.GetDataSourceLocked()->Write(input, ctx);
|
||||||
ctx.Flush();
|
ctx.Flush();
|
||||||
});
|
});
|
||||||
@@ -357,7 +349,7 @@ TEST_F(NetworkTraceHandlerTest, Interning) {
|
|||||||
|
|
||||||
auto session = StartTracing(config);
|
auto session = StartTracing(config);
|
||||||
|
|
||||||
HandlerForTest::Trace([&](HandlerForTest::TraceContext ctx) {
|
NetworkTraceHandler::Trace([&](NetworkTraceHandler::TraceContext ctx) {
|
||||||
ctx.GetDataSourceLocked()->Write(inputs[0], ctx);
|
ctx.GetDataSourceLocked()->Write(inputs[0], ctx);
|
||||||
ctx.GetDataSourceLocked()->Write(inputs[1], ctx);
|
ctx.GetDataSourceLocked()->Write(inputs[1], ctx);
|
||||||
ctx.GetDataSourceLocked()->Write(inputs[2], ctx);
|
ctx.GetDataSourceLocked()->Write(inputs[2], ctx);
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ class NetworkTraceHandler
|
|||||||
// Connects to the system Perfetto daemon and registers the trace handler.
|
// Connects to the system Perfetto daemon and registers the trace handler.
|
||||||
static void InitPerfettoTracing();
|
static void InitPerfettoTracing();
|
||||||
|
|
||||||
|
// When isTest is true, skip non-hermetic code.
|
||||||
|
NetworkTraceHandler(bool isTest = false) : mIsTest(isTest) {}
|
||||||
|
|
||||||
// perfetto::DataSource overrides:
|
// perfetto::DataSource overrides:
|
||||||
void OnSetup(const SetupArgs& args) override;
|
void OnSetup(const SetupArgs& args) override;
|
||||||
void OnStart(const StartArgs&) override;
|
void OnStart(const StartArgs&) override;
|
||||||
@@ -92,6 +95,7 @@ class NetworkTraceHandler
|
|||||||
|
|
||||||
static internal::NetworkTracePoller sPoller;
|
static internal::NetworkTracePoller sPoller;
|
||||||
bool mStarted;
|
bool mStarted;
|
||||||
|
bool mIsTest;
|
||||||
|
|
||||||
// Values from config, see proto for details.
|
// Values from config, see proto for details.
|
||||||
uint32_t mPollMs;
|
uint32_t mPollMs;
|
||||||
|
|||||||
Reference in New Issue
Block a user