2
0
mirror of https://github.com/boostorg/atomic.git synced 2026-01-19 04:02:09 +00:00

Suppress TSAN for intentionally racy functions in tests.

This commit is contained in:
Andrey Semashev
2025-02-22 20:58:22 +03:00
parent fb96eeec40
commit de94875920
3 changed files with 29 additions and 0 deletions

View File

@@ -35,6 +35,7 @@
#include <functional>
#include <boost/config.hpp>
#include <boost/core/lightweight_test.hpp>
#include "test_config.hpp"
#include "test_clock.hpp"
/* helper class to let two instances of a function race against each
@@ -120,6 +121,7 @@ private:
std::thread second_thread_;
};
BOOST_ATOMIC_TEST_NO_SANITIZE_THREAD
bool racy_add(unsigned int volatile& value, std::size_t instance)
{
std::size_t shift = instance * 8;
@@ -142,6 +144,7 @@ bool racy_add(unsigned int volatile& value, std::size_t instance)
}
/* compute estimate for average time between races being observable, in usecs */
BOOST_ATOMIC_TEST_NO_SANITIZE_THREAD
double estimate_avg_race_time(void)
{
double sum = 0.0;

View File

@@ -39,6 +39,7 @@
#include <functional>
#include <boost/config.hpp>
#include <boost/core/lightweight_test.hpp>
#include "test_config.hpp"
#include "test_clock.hpp"
/* helper class to let two instances of a function race against each
@@ -124,6 +125,7 @@ private:
std::thread second_thread_;
};
BOOST_ATOMIC_TEST_NO_SANITIZE_THREAD
bool racy_add(unsigned int volatile& value, std::size_t instance)
{
std::size_t shift = instance * 8;
@@ -146,6 +148,7 @@ bool racy_add(unsigned int volatile& value, std::size_t instance)
}
/* compute estimate for average time between races being observable, in usecs */
BOOST_ATOMIC_TEST_NO_SANITIZE_THREAD
double estimate_avg_race_time(void)
{
double sum = 0.0;

23
test/test_config.hpp Normal file
View File

@@ -0,0 +1,23 @@
// Copyright (c) 2025 Andrey Semashev
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_ATOMIC_TEST_TEST_CONFIG_HPP_INCLUDED_
#define BOOST_ATOMIC_TEST_TEST_CONFIG_HPP_INCLUDED_
#include <boost/config.hpp>
#if defined(TSAN) && defined(__GNUC__)
// Suppresses TSAN for a marked function
#define BOOST_ATOMIC_TEST_NO_SANITIZE_THREAD __attribute__((no_sanitize("thread")))
#else // defined(TSAN) && defined(__GNUC__)
#define BOOST_ATOMIC_TEST_NO_SANITIZE_THREAD
#endif // defined(TSAN) && defined(__GNUC__)
#endif // BOOST_ATOMIC_TEST_TEST_CONFIG_HPP_INCLUDED_