Fix fuzzer when only explicit faults are used

This commit is contained in:
Raúl Marín 2024-05-14 16:25:12 +02:00
parent 3af24dacf8
commit 33885b27bf
2 changed files with 19 additions and 8 deletions

View File

@ -51,16 +51,17 @@ namespace ErrorCodes
ThreadFuzzer::ThreadFuzzer()
{
initConfiguration();
if (needsSetup())
setup();
if (!isEffective())
{
/// It has no effect - disable it
stop();
return;
}
setup();
}
template <typename T>
static void initFromEnv(T & what, const char * name)
{
@ -133,10 +134,16 @@ void ThreadFuzzer::initConfiguration()
}
bool ThreadFuzzer::needsSetup() const
{
return cpu_time_period_us != 0
&& (yield_probability > 0 || migrate_probability > 0 || (sleep_probability > 0 && sleep_time_us_max > 0));
}
bool ThreadFuzzer::isEffective() const
{
if (!isStarted())
return false;
if (needsSetup())
return true;
#if THREAD_FUZZER_WRAP_PTHREAD
# define CHECK_WRAPPER_PARAMS(RET, NAME, ...) \
@ -163,10 +170,13 @@ bool ThreadFuzzer::isEffective() const
# undef INIT_WRAPPER_PARAMS
#endif
return cpu_time_period_us != 0
&& (yield_probability > 0
|| migrate_probability > 0
|| (sleep_probability > 0 && sleep_time_us_max > 0));
if (explicit_sleep_probability > 0 && sleep_time_us_max > 0)
return true;
if (explicit_memory_exception_probability > 0)
return true;
return false;
}
void ThreadFuzzer::stop()

View File

@ -52,6 +52,7 @@ public:
}
bool isEffective() const;
bool needsSetup() const;
static void stop();
static void start();