Skip to content

Commit

Permalink
add RandomConfigs class with default values and applied to the Genera…
Browse files Browse the repository at this point in the history
…teStatement()
  • Loading branch information
hmeriann committed Aug 22, 2024
1 parent 98fb00d commit 922b9af
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/include/statement_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class StatementGenerator {
friend class ExpressionDepthChecker;
friend class AggregateChecker;
friend class WindowChecker;
friend class RandomsConfig;

public:
StatementGenerator(ClientContext &context);
Expand All @@ -55,6 +56,8 @@ class StatementGenerator {
bool RandomPercentage(idx_t percentage);
bool verification_enabled = false;
idx_t RandomValue(idx_t max);


string GetRandomAttachedDataBase();
unique_ptr<SQLStatement> GenerateStatement(StatementType type); // came from private

Expand Down
31 changes: 25 additions & 6 deletions src/statement_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,43 @@ std::shared_ptr<GeneratorContext> StatementGenerator::GetDatabaseState(ClientCon
return result;
}

class RandomsConfig {
public:
idx_t select_percentage = 60;
idx_t attach_percentage = 40;
idx_t attach_use_percentage = 50;
idx_t detach_percentage = 60;
idx_t set_percentage = 30;
idx_t delete_percentage = 40;

RandomsConfig(){

};

void getConfigFromFile() {
// read file and update default values
}
};

unique_ptr<SQLStatement> StatementGenerator::GenerateStatement() {
if (RandomPercentage(80)) {
RandomsConfig config = RandomsConfig();
if (RandomPercentage(config.select_percentage)) {
return GenerateStatement(StatementType::SELECT_STATEMENT);
}
if (RandomPercentage(40)) {
if (RandomPercentage(50)) {
if (RandomPercentage(config.attach_percentage)) {
if (RandomPercentage(config.attach_use_percentage)) {
// We call this directly so we have a higher chance to fuzz persistent databases
return GenerateAttachUse();
}
return GenerateStatement(StatementType::ATTACH_STATEMENT);
}
if (RandomPercentage(60)) {
if (RandomPercentage(config.detach_percentage)) {
return GenerateStatement(StatementType::DETACH_STATEMENT);
}
if (RandomPercentage(30)) {
if (RandomPercentage(config.set_percentage)) {
return GenerateStatement(StatementType::SET_STATEMENT);
}
if (RandomPercentage(40)) { //20
if (RandomPercentage(config.delete_percentage)) { //20
return GenerateStatement(StatementType::DELETE_STATEMENT);
}
return GenerateStatement(StatementType::CREATE_STATEMENT);
Expand Down

0 comments on commit 922b9af

Please sign in to comment.