From 827f9ac45cafe2c8c2ec33ff5d756d5235f9d4eb Mon Sep 17 00:00:00 2001 From: Shuhao Wu Date: Thu, 18 Jul 2024 01:05:34 -0400 Subject: [PATCH 1/2] Clangd in vscode --- .clangd | 9 +++++++++ .vscode/extensions.json | 6 ++++++ .vscode/settings.json | 7 +++++++ 3 files changed, 22 insertions(+) create mode 100644 .clangd create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..8d77a72 --- /dev/null +++ b/.clangd @@ -0,0 +1,9 @@ +--- +CompileFlags: + CompilationDatabase: build/debug +--- +If: + PathMatch: tests/.* + +CompileFlags: + CompilationDatabase: build/test diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..ba6e025 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "ms-vscode.cpptools", + "llvm-vs-code-extensions.vscode-clangd" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0f1da25 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "C_Cpp.intelliSenseEngine": "disabled", + "editor.formatOnSave": true, + "[cpp]": { + "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd" + } +} From 50152899f5abf3d2e8dc6b5f628aa4827d774a31 Mon Sep 17 00:00:00 2001 From: Shuhao Wu Date: Thu, 18 Jul 2024 23:04:17 -0400 Subject: [PATCH 2/2] Fixed a tracing test bug The thread sometimes can start after the app has stopped. So in setup test we need to make sure the thread started. --- tests/tracing/helpers/mock_threads.cc | 3 +++ tests/tracing/helpers/mock_threads.h | 5 +++++ tests/tracing/single_threaded_test.cc | 12 +++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/tracing/helpers/mock_threads.cc b/tests/tracing/helpers/mock_threads.cc index 0dc96b1..5bca023 100644 --- a/tests/tracing/helpers/mock_threads.cc +++ b/tests/tracing/helpers/mock_threads.cc @@ -1,5 +1,7 @@ #include "mock_threads.h" +#include + #include "utils.h" using namespace std::chrono_literals; @@ -38,6 +40,7 @@ void MockRegularThread::RunOneIteration(std::function& } void MockRegularThread::Run() { + started_ = true; while (!StopRequested()) { { std::unique_lock lock(mutex_); diff --git a/tests/tracing/helpers/mock_threads.h b/tests/tracing/helpers/mock_threads.h index 4256755..fd0b7a9 100644 --- a/tests/tracing/helpers/mock_threads.h +++ b/tests/tracing/helpers/mock_threads.h @@ -14,6 +14,7 @@ extern const char* kCyclicThreadName; class MockRegularThread : public cactus_rt::Thread { static cactus_rt::ThreadConfig MakeConfig(); + std::atomic_bool started_ = false; std::condition_variable cv_; std::mutex mutex_; std::optional> f_ = std::nullopt; @@ -28,6 +29,10 @@ class MockRegularThread : public cactus_rt::Thread { return Tracer(); } + inline bool Started() const noexcept { + return started_; + } + protected: void Run() final; }; diff --git a/tests/tracing/single_threaded_test.cc b/tests/tracing/single_threaded_test.cc index 2134985..c9976b0 100644 --- a/tests/tracing/single_threaded_test.cc +++ b/tests/tracing/single_threaded_test.cc @@ -2,7 +2,9 @@ #include #include +#include #include +#include #include "helpers/assert_helpers.h" #include "helpers/mock_sink.h" @@ -37,6 +39,9 @@ class SingleThreadTracingTest : public ::testing::Test { app_.RegisterThread(regular_thread_); app_.StartTraceSession(sink_); // TODO: make each test manually start the trace session! app_.Start(); + while (!regular_thread_->Started()) { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); // Not that efficient but OK + } } void TearDown() override { @@ -266,9 +271,12 @@ TEST_F(SingleThreadTracingTest, StopTracingAndNoEventsAreRecorded) { auto traces = sink_->LoggedTraces(); auto packets = GetPacketsFromTraces(traces); - ASSERT_EQ(packets.size(), 1); + ASSERT_EQ(packets.size(), 2); AssertIsProcessTrackDescriptor(*packets[0], kAppName); + const auto process_track_uuid = packets[0]->track_descriptor().uuid(); + + AssertIsThreadTrackDescriptor(*packets[1], kRegularThreadName, process_track_uuid); } TEST_F(SingleThreadTracingTest, RestartTracingStartsNewSession) { @@ -310,8 +318,6 @@ TEST_F(SingleThreadTracingTest, RestartTracingStartsNewSession) { AssertIsThreadTrackDescriptor(*packets2[1], kRegularThreadName, process_track_uuid); auto thread_track_uuid = packets2[1]->track_descriptor().uuid(); - std::cout << "packets2: " << packets2[2]->ShortDebugString() << "\n"; - // Event1 is emitted as interned data because that thread is still active and the event name got interned previously. auto event_names = GetInternedEventNames(*packets2[2]); ASSERT_EQ(event_names.size(), 1);