27 for (
int i = 0;
i < 100000; ++
i) {
30 for (
int i = 0;
i < 10; ++
i) {
39 for (
int i = 0;
i < 100000; ++
i) {
40 if (
i > 0 && (
i % 100) == 0) {
49 for (
int i = 0;
i < 10; ++
i) {
55 for (
bool bug : {
false,
true}) {
68 std::vector<std::thread>
threads(numThreads);
69 for (
int t = 0;
t < numThreads; ++
t) {
71 baseline.fetch_add(1);
82 int newval =
test.load() + 1;
94 for (
auto&
t : threads) {
100 if (
test.load() == baseline.load()) {
169 template <
typename T>
173 template <
typename T,
template <
typename>
class Atom = std::atomic>
213 std::vector<PerThread>
t_;
223 DEFINE_int64(max_steps, 1000000,
"Max. number of shared steps for the test");
224 DEFINE_int64(num_reps, 1,
"Number of test repetitions");
225 DEFINE_int64(num_ops, 1000,
"Number of increments per repetition");
226 DEFINE_int64(liveness_thresh, 1000000,
"Liveness threshold");
227 DEFINE_int64(log_begin, 0,
"Step number to start logging. No logging if <= 0");
228 DEFINE_int64(log_length, 1000,
"Length of step by step log (if log_begin > 0)");
229 DEFINE_int64(log_freq, 100000,
"Log every so many steps");
234 #define AUX_THR(x) (aux_->t_[tid_].x) 235 #define AUX_UPDATE() (aux_->lastUpdate_ = aux_->step_ + 1) 238 #define AUX_ACT(act) \ 240 AUX_THR(func_) = __func__; \ 241 AUX_THR(line_) = __LINE__; \ 242 AuxAct auxfn([&](bool success) { \ 249 DeterministicSchedule::setAuxAct(auxfn); \ 253 template <
typename T>
257 template <
typename T>
274 if (aux_->
step_ == 0) {
278 if (step > (
uint64_t)FLAGS_max_steps) {
282 (((FLAGS_log_begin > 0) && (step >= (
uint64_t)FLAGS_log_begin) &&
283 (step <= (
uint64_t)FLAGS_log_begin + FLAGS_log_length)) ||
284 ((step % FLAGS_log_freq) == 0));
291 std::stringstream ss;
295 ss <<
" counter =" << this->
counter_.load_direct();
298 ss <<
" count[" <<
tid_ <<
"] = " <<
AUX_THR(count_);
300 std::cerr << ss.str() << std::endl;
308 for (
auto&
t : aux_->
t_) {
316 return this->
counter_.load_direct();
340 CHECK_GT(FLAGS_num_threads, 0);
343 for (
int i = 0;
i < FLAGS_num_reps; ++
i) {
344 aux_ =
new AuxData(FLAGS_num_threads);
348 std::vector<std::thread>
threads(FLAGS_num_threads);
349 for (
int tid = 0; tid < FLAGS_num_threads; ++tid) {
352 for (
int j = tid; j < FLAGS_num_ops; j += FLAGS_num_threads) {
353 (FLAGS_bug) ? annotated.
incBug() : annotated.
inc();
357 for (
auto&
t : threads) {
360 std::cerr <<
"====== rep " <<
i <<
" completed in step " << aux_->
step_ 363 std::cerr << std::endl;
372 gflags::ParseCommandLineFlags(&argc, &argv,
true);
std::atomic< int64_t > sum(0)
#define FOLLY_TEST_DSCHED_VLOG(...)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
#define EXPECT_EQ(val1, val2)
DEFINE_int32(num_threads, 1,"Number of producers")
static std::thread thread(Func &&func, Args &&...args)
DEFINE_int64(threadtimeout_ms, 60000,"Idle time before ThreadPoolExecutor threads are joined")
std::unordered_set< std::pair< const IValidator *, const dynamic * > > seen
std::vector< std::thread::id > threads
static std::function< size_t(size_t)> uniform(uint64_t seed)
static void setAuxChk(AuxChk &aux)
std::function< void(uint64_t)> AuxChk
static map< string, int > m
AtomicCounter< T, DeterministicAtomic > Base
static std::function< size_t(size_t)> uniformSubset(uint64_t seed, size_t n=2, size_t m=64)
TEST(ProgramOptionsTest, Errors)
#define EXPECT_TRUE(condition)
DEFINE_bool(bug, false,"Introduce bug")
void auxLog(uint64_t step)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
AnnotatedAtomicCounter(int val)
folly::detail::CompressionCounter * counter_
static void join(std::thread &child)
int main(int argc, char **argv)
void doAuxLog(uint64_t step)
std::vector< PerThread > t_
static void clearAuxChk()
static FOLLY_TLS uint32_t tid_