Skip to content

Commit

Permalink
TO REMOVE. Temporary test.
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
MiguelCompany committed Oct 18, 2023
1 parent a713065 commit 1bbee0e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/thread-sanitizer-v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
--return-code-on-test-failure \
--ctest-args \
--timeout 30 \
-V -E DDSSQLFilterValueTests
-V -R SystemInfoTests.TSanTemporaryTest
continue-on-error: true

- name: Upload Logs
Expand Down
39 changes: 39 additions & 0 deletions test/unittest/utils/SystemInfoTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,45 @@ TEST_F(SystemInfoTests, EnvironmentFileTest)
EXPECT_EQ(0, eprosima::SystemInfo::get_environment_file().compare(value));
}

// A temporary test to ensure tsan reports are generated
TEST_F(SystemInfoTests, TSanTemporaryTest)
{
// For data-race test
uint32_t n = 0;

// For lock-order inversion test
std::mutex mtx_a;
std::mutex mtx_b;

auto thr_job_1 = [&]()
{
// Both threads will write on n without locking, so a data-race shall be reported
n = n + 1;

// This thread takes A then B, while the other takes B then A, so a lock order inversion shall be reported
std::lock_guard<std::mutex> guard_a(mtx_a);
std::lock_guard<std::mutex> guard_b(mtx_b);
};

auto thr_job_2 = [&]()
{
// Both threads will write on n without locking, so a data-race shall be reported
n = n + 1;

// This thread takes B then A, while the other takes A then B, so a lock order inversion shall be reported
std::lock_guard<std::mutex> guard_b(mtx_b);
std::lock_guard<std::mutex> guard_a(mtx_a);
};

// Start both threads
std::thread thr_1(thr_job_1);
std::thread thr_2(thr_job_2);

// Wait for both threads
thr_1.join();
thr_2.join();
}

#if defined(_WIN32) || defined(__unix__)
/**
* This test checks the file watchers
Expand Down

0 comments on commit 1bbee0e

Please sign in to comment.