@@ -22,6 +22,8 @@ namespace {
2222 };
2323
2424 struct BlockTypesAllowed {
25+ BlockTypesAllowed (std::vector<BlockType> blockTypesToUse, std::vector<BusDef> busDefinitions, std::vector<std::string> customBlockPaths) :
26+ blockTypesToUse (blockTypesToUse), busDefinitions(busDefinitions), customBlockPaths(customBlockPaths) {}
2527 std::vector<BlockType> blockTypesToUse;
2628 std::vector<BusDef> busDefinitions;
2729 std::vector<std::string> customBlockPaths;
@@ -69,7 +71,7 @@ namespace {
6971 for (bool realistic : {false , true }) {
7072 // RunningConfig runningConfig = {5000, 100, 3, 50};
7173 RunningConfig runningConfig = {100 , 50 , 3 , 20 };
72- BlockTypesAllowed blockTypesAllowed = {
74+ BlockTypesAllowed blockTypesAllowed (
7375 {
7476 BlockType::AND,
7577 BlockType::OR,
@@ -87,28 +89,49 @@ namespace {
8789 BlockType::LIGHT,
8890 BlockType::SWITCH,
8991 BlockType::BUTTON
90- }, {}, {}
91- };
92+ },
93+ {},
94+ {}
95+ );
9296 testcases.push_back (TestcaseConfig { seed, realistic, runningConfig, blockTypesAllowed, u++ });
9397
94- blockTypesAllowed = {
95- {}, {}, {}
96- };
97- for (unsigned int i = 1 ; i <= 21 ; ++i) {
98- blockTypesAllowed.blockTypesToUse .push_back (BlockType (i));
99- }
100- blockTypesAllowed.busDefinitions .push_back (BusDef {2 , 1 , 1 , 2 });
101- blockTypesAllowed.busDefinitions .push_back (BusDef {4 , 1 , 1 , 4 });
102- blockTypesAllowed.busDefinitions .push_back (BusDef {2 , 1 , 2 , 4 });
103- blockTypesAllowed.busDefinitions .push_back (BusDef {8 , 1 , 1 , 8 });
104- blockTypesAllowed.busDefinitions .push_back (BusDef {4 , 1 , 2 , 8 });
105- blockTypesAllowed.busDefinitions .push_back (BusDef {2 , 1 , 4 , 8 });
106- blockTypesAllowed.busDefinitions .push_back (BusDef { 2 , 4 , 4 , 2 });
98+ blockTypesAllowed = BlockTypesAllowed (
99+ {
100+ BlockType::AND,
101+ BlockType::OR,
102+ BlockType::XOR,
103+ BlockType::NAND,
104+ BlockType::NOR,
105+ BlockType::XNOR,
106+ BlockType::BUFFER,
107+ BlockType::NOT,
108+ BlockType::TRISTATE_BUFFER,
109+ BlockType::JUNCTION,
110+ BlockType::JUNCTION_L,
111+ BlockType::JUNCTION_H,
112+ BlockType::JUNCTION_X,
113+ BlockType::LIGHT,
114+ BlockType::SWITCH,
115+ BlockType::BUTTON
116+ },
117+ {
118+ BusDef {2 , 1 , 1 , 2 },
119+ BusDef {4 , 1 , 1 , 4 },
120+ BusDef {2 , 1 , 2 , 4 },
121+ BusDef {8 , 1 , 1 , 8 },
122+ BusDef {4 , 1 , 2 , 8 },
123+ BusDef {2 , 1 , 4 , 8 },
124+ BusDef { 2 , 4 , 4 , 2 }
125+ },
126+ {
127+ " passthrough.cir" ,
128+ " full_adder.cir" ,
129+ " bus_tristate_2.cir" ,
130+ " nested_passthrough.cir" ,
131+ }
132+ );
133+ // a test case fails if you just have types, passthrough, nested_passthrough!
107134
108- blockTypesAllowed.customBlockPaths .push_back (" passthrough.cir" );
109- blockTypesAllowed.customBlockPaths .push_back (" full_adder.cir" );
110- blockTypesAllowed.customBlockPaths .push_back (" bus_tristate_2.cir" );
111- blockTypesAllowed.customBlockPaths .push_back (" nested_passthrough.cir" );
112135 testcases.push_back (TestcaseConfig { seed, realistic, runningConfig, blockTypesAllowed, u++ });
113136 }
114137 }
@@ -212,7 +235,7 @@ TEST_P(BasicFuzzingEvaluatorTest, FuzzInteractions) {
212235 allowedBlockTypes.push_back (customBlockType);
213236 }
214237 logInfo (" Fuzzing test with seed {}, realistic {}, {} edit operations, {} test operations, {} ticks between tests, {} states per test, {} allowed block types. config idx: {}" , " BasicFuzzingEvaluatorTest" , config.seed , runRealistic, numEditOperations, numTestOperations, numTicksBetweenTests, numStatesSetPerTest, allowedBlockTypes.size (), config.index );
215- for (int i = 0 ; i < numEditOperations; ++i) {
238+ for (int i = 0 ; i < numEditOperations || blockIds. empty () ; ++i) {
216239 int operation = gen () % 8 ; // 0,1: place, 2: remove, 3,4,5: connect, 6,7: disconnect
217240 if (operation <= 1 ) { // place block
218241 Orientation orientation (Rotation (gen () % 4 ), (gen () % 2 ) == 0 );
@@ -279,8 +302,7 @@ TEST_P(BasicFuzzingEvaluatorTest, FuzzInteractions) {
279302 // SAVE CIRCUIT TO FILE
280303 {
281304 CircuitFileManager& circuitFileManager = environment.getCircuitFileManager ();
282- const std::filesystem::path savePath =
283- DirectoryManager::getConfigDirectory () / " tmp" / (" BasicFuzzingCircuit_" + testcase_config_to_string (config) + " .cir" );
305+ const std::filesystem::path savePath = DirectoryManager::getConfigDirectory () / " tmp" / (" BasicFuzzingCircuit_" + testcase_config_to_string (config) + " .cir" );
284306 std::filesystem::create_directories (savePath.parent_path ());
285307 ASSERT_TRUE (circuitFileManager.saveToFile (savePath.string (), circuit->getUUID ()));
286308 logInfo (" Saved fuzzing circuit to " + savePath.string (), " BasicFuzzingEvaluatorTest" );
@@ -364,8 +386,28 @@ TEST_P(BasicFuzzingEvaluatorTest, FuzzInteractions) {
364386 block_id_t blockId = blockIds[gen () % blockIds.size ()];
365387 Position pos = blockIdToPosition.at (blockId);
366388 logic_state_t state = logic_state_t (gen () % 4 );
367- rSimulator->setState (pos, state);
368- tSimulator->setState (pos, state);
389+ const Block* block = circuit->getBlockContainer ().getBlock (pos);
390+ if ( // limit state sets to only settable blocks
391+ block->type () == BlockType::AND ||
392+ block->type () == BlockType::OR ||
393+ block->type () == BlockType::XOR ||
394+ block->type () == BlockType::NAND ||
395+ block->type () == BlockType::NOR ||
396+ block->type () == BlockType::XNOR ||
397+ block->type () == BlockType::BUFFER ||
398+ block->type () == BlockType::NOT ||
399+ // block->type() == BlockType::TRISTATE_BUFFER || // cant be set
400+ // block->type() == BlockType::JUNCTION ||
401+ // block->type() == BlockType::JUNCTION_L ||
402+ // block->type() == BlockType::JUNCTION_H ||
403+ // block->type() == BlockType::JUNCTION_X ||
404+ // block->type() == BlockType::LIGHT ||
405+ block->type () == BlockType::SWITCH ||
406+ block->type () == BlockType::BUTTON
407+ ) {
408+ rSimulator->setState (pos, state);
409+ tSimulator->setState (pos, state);
410+ }
369411 }
370412
371413 // compare states
0 commit comments