Skip to content

Commit 78488dc

Browse files
committed
some unit test fuzzer fixes (busses still dont work)
1 parent 035dbda commit 78488dc

File tree

2 files changed

+67
-99
lines changed

2 files changed

+67
-99
lines changed

src/backend/evaluator/layers/junctionMergeEvalLayer.cpp

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -285,71 +285,6 @@ void JunctionMergeEvalLayer::run() {
285285
}
286286
nextState.getGateIdReverseRemapping().erase(iterPair2.first, iterPair2.second);
287287
assert(connectionPointRemapping.size() == connectionPointReverseRemapping.size());
288-
289-
290-
// if (nextState.getGate(junctionId) != nullptr) nextState.removeGate(junctionId);
291-
// if (nextState.getGate(junctionId) == nullptr) {
292-
// assert(currentState.getRemovedGates().contains(junctionId));
293-
// } else {
294-
// if (currentState.getGate(junctionId) == nullptr) {
295-
// nextState.removeGate(junctionId); // if it was added this layer remove it
296-
// }
297-
// }
298-
// auto iterPair = nextState.getGateIdReverseRemapping().equal_range(junctionId);
299-
// if (iterPair.first != iterPair.second) {
300-
// for (auto reverseRemappingIter = iterPair.first; reverseRemappingIter != iterPair.second; reverseRemappingIter++) {
301-
// auto addedGatesIter = currentState.getAddedGates().find(reverseRemappingIter->second);
302-
// if (addedGatesIter != currentState.getAddedGates().end()) {
303-
// assert(nextState.getGateIdRemapping().contains(reverseRemappingIter->second));
304-
// assert(nextState.getGateIdRemapping().at(reverseRemappingIter->second) == reverseRemappingIter->second);
305-
// if (!isJunctionType(addedGatesIter->second)) continue;
306-
// bool suc1 = nextState.getGateIdRemapping().erase(reverseRemappingIter->second);
307-
// assert(suc1);
308-
// if (nextState.getGate(junctionId) != nullptr) nextState.removeGate(junctionId);
309-
// connectionPointsToScan.insert(EvalConnectionPoint(reverseRemappingIter->second, 0));
310-
// } else {
311-
// bool suc1 = nextState.getGateIdRemapping().erase(reverseRemappingIter->second);
312-
// assert(suc1);
313-
// if (currentState.getRemovedGates().contains(reverseRemappingIter->second)) continue;
314-
// if (nextState.getGate(junctionId) != nullptr) nextState.removeGate(junctionId);
315-
// connectionPointsToScan.insert(EvalConnectionPoint(reverseRemappingIter->second, 0));
316-
// }
317-
// }
318-
// nextState.getGateIdReverseRemapping().erase(iterPair.first, iterPair.second);
319-
// if (currentState.getAddedGates().contains(junctionId)) { // if the gate was added back after being deleted then add the id remapping back
320-
// // assert(currentState.getRemovedGates().contains(junctionId));
321-
// assert(!nextState.getGateIdReverseRemapping().contains(junctionId));
322-
// if (currentState.getAddedGates().contains(junctionId)) nextState.getGateIdReverseRemapping().emplace(junctionId, junctionId);
323-
// assert(nextState.getGateIdReverseRemapping().size() == nextState.getGateIdRemapping().size());
324-
// }
325-
// }
326-
// auto iterPair2 = connectionPointReverseRemapping.equal_range(junctionId);
327-
// for (auto reverseRemappingIter = iterPair2.first; reverseRemappingIter != iterPair2.second; reverseRemappingIter++) {
328-
// const EvalGate* curGate = currentState.getGate(reverseRemappingIter->second.gateId);
329-
// assert(curGate);
330-
// if (!(isJunctionType(curGate->type) || isConnectionEndIdSinglePin(curGate->type, reverseRemappingIter->second.connectionEndId))) {
331-
// logError("This is a bug and should not happen. Tho it should not break anything I dont want it to happen!");
332-
// }
333-
// connectionPointRemapping.erase(reverseRemappingIter->second);
334-
// const EvalGate* gate = nextState.getGate(reverseRemappingIter->second.gateId);
335-
// if (gate) {
336-
// while (true) {
337-
// auto iter = gate->connections.find(reverseRemappingIter->second.connectionEndId);
338-
// if (iter == gate->connections.end()) break;
339-
// EvalConnectionPoint otherConnectionPoint = *iter->second.begin();
340-
// unsigned int weight = nextState.getConnectionWeight(EvalConnection(reverseRemappingIter->second, otherConnectionPoint));
341-
// assert(weight != 0);
342-
// nextState.removeConnection(EvalConnection(reverseRemappingIter->second, otherConnectionPoint), weight);
343-
// }
344-
// connectionPointsToScan.insert(reverseRemappingIter->second);
345-
// } else {
346-
// connectionPointsToScan.erase(reverseRemappingIter->second);
347-
// }
348-
// }
349-
// connectionPointReverseRemapping.erase(iterPair2.first, iterPair2.second);
350-
// assert(connectionPointRemapping.size() == connectionPointReverseRemapping.size());
351-
352-
353288
}
354289
// nextState.visualize();
355290
while (!connectionPointsToScan.empty()) {
@@ -399,15 +334,6 @@ void JunctionMergeEvalLayer::run() {
399334
if (pair.first == connectionPoint) continue;
400335
nextState.addConnection(EvalConnection(connectionPoint, pair.first), pair.second);
401336
}
402-
// const EvalGate* gate = currentState.getGate(connectionPoint.gateId);
403-
// auto connectionIter = gate->connections.find(connectionPoint.connectionEndId);
404-
// if (connectionIter == gate->connections.end()) continue;
405-
// for (EvalConnectionPoint otherConnectionPoint : connectionIter->second) {
406-
// // if (connectionPoint == pair.first) continue;
407-
// unsigned int weight = currentState.getConnectionWeight(EvalConnection(connectionPoint, otherConnectionPoint));
408-
// assert(weight);
409-
// nextState.addConnection(EvalConnection(connectionPoint, otherConnectionPoint), weight);
410-
// }
411337
continue;
412338
}
413339

tests/evaluator/fuzzing/basic.cpp

Lines changed: 67 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)