Abort traces if duration_ms is too high to prevent overflow bugs
Prior to this change the guardrail for too-long traces was
triggered only for non-interactive traces.
However, turns out that if the duration_ms is accidentally too
high (e.g. 0xffffffff) that triggers subtle overflow bugs in the
watchdog logic of the traced_probes process.
This CL caps also the duration of the non-interactive traces.
Test: perfetto_unittests
Bug: 73051872
Change-Id: I76dbe5cfaf59c22e72d203da05c51d6200bd2ef0
diff --git a/src/tracing/core/service_impl_unittest.cc b/src/tracing/core/service_impl_unittest.cc
index c679c52..2a23b15 100644
--- a/src/tracing/core/service_impl_unittest.cc
+++ b/src/tracing/core/service_impl_unittest.cc
@@ -1353,4 +1353,25 @@
Eq("payload3"))))));
}
+TEST_F(TracingServiceImplTest, AbortIfTraceDurationIsTooLong) {
+ std::unique_ptr<MockConsumer> consumer = CreateMockConsumer();
+ consumer->Connect(svc.get());
+
+ std::unique_ptr<MockProducer> producer = CreateMockProducer();
+ producer->Connect(svc.get(), "mock_producer");
+ producer->RegisterDataSource("datasource");
+
+ TraceConfig trace_config;
+ trace_config.add_buffers()->set_size_kb(128);
+ trace_config.add_data_sources()->mutable_config()->set_name("datasource");
+ trace_config.set_duration_ms(0x7fffffff);
+
+ EXPECT_CALL(*producer, SetupDataSource(_, _)).Times(0);
+ consumer->EnableTracing(trace_config);
+
+ // The trace is aborted immediately, 5s here is just some slack for the thread
+ // ping-pongs for slow devices.
+ consumer->WaitForTracingDisabled(5000);
+}
+
} // namespace perfetto