Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue-133] simcompare calculate signaltowidth instead of manual input #211

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/src/utilities/simcompare.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,24 @@ abstract class SimCompare {

/// Executes [vectors] against the Icarus Verilog simulator.
static bool iverilogVector(
String generatedVerilog,
String topModule,
Module module,
List<Vector> vectors, {
String? moduleName,
bool dontDeleteTmpFiles = false,
bool dumpWaves = false,
Map<String, int> signalToWidthMap = const {},
List<String> iverilogExtraArgs = const [],
bool allowWarnings = false,
}) {
String signalDeclaration(String signalName) {
if (signalToWidthMap.containsKey(signalName)) {
final width = signalToWidthMap[signalName]!;
return '[${width - 1}:0] $signalName';
final signal = module.signals.firstWhere((e) => e.name == signalName);
if (signal.width != 1) {
return '[${signal.width - 1}:0] $signalName';
} else {
return signalName;
}
}

final topModule = moduleName ?? module.definitionName;
final allSignals = <String>{
for (final e in vectors) ...e.inputValues.keys,
for (final e in vectors) ...e.expectedOutputValues.keys,
Expand All @@ -174,6 +174,7 @@ abstract class SimCompare {
final moduleConnections = allSignals.map((e) => '.$e($e)').join(', ');
final moduleInstance = '$topModule dut($moduleConnections);';
final stimulus = vectors.map((e) => e.toTbVerilog()).join('\n');
final generatedVerilog = module.generateSynth();

// so that when they run in parallel, they dont step on each other
final uniqueId =
Expand Down
3 changes: 1 addition & 2 deletions test/assignment_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ void main() {
];
await SimCompare.checkFunctionalVector(exampleModule, vectors);
final simResult = SimCompare.iverilogVector(
exampleModule.generateSynth(),
exampleModule.runtimeType.toString(),
exampleModule,
vectors,
allowWarnings: true, // since always_comb has no sensitivities
);
Expand Down
89 changes: 11 additions & 78 deletions test/bus_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,51 +270,6 @@ void main() {
});

group('simcompare', () {
final signalToWidthMap = {
'a': 8,
'b': 8,
'a_bar': 8,
'a_and_b': 8,
'a_b_joined': 16,
'a_plus_b': 8,

// Slicing
'a_shrunk1': 3,
'a_shrunk2': 2,
'a_shrunk3': 1,
'a_neg_shrunk1': 3,
'a_neg_shrunk2': 2,
'a_neg_shrunk3': 1,
// Reverse Slicing
'a_rsliced1': 5,
'a_rsliced2': 2,
'a_rsliced3': 1,
'a_r_neg_sliced1': 5,
'a_r_neg_sliced2': 2,
'a_r_neg_sliced3': 1,

// getRange
'a_range1': 3,
'a_range2': 2,
'a_range3': 1,
'a_range4': 3,
'a_neg_range1': 3,
'a_neg_range2': 2,
'a_neg_range3': 1,
'a_neg_range4': 3,

// operator[]
'a_operator_indexing1': 1,
'a_operator_indexing2': 1,
'a_operator_indexing3': 1,
'a_operator_neg_indexing1': 1,
'a_operator_neg_indexing2': 1,
'a_operator_neg_indexing3': 1,

// Logic bus value Reversed
'a_reversed': 8,
'expression_bit_select': 4,
};
test('NotGate bus', () async {
final gtm = BusTestModule(Logic(width: 8), Logic(width: 8));
await gtm.build();
Expand All @@ -325,9 +280,7 @@ void main() {
Vector({'a': 1}, {'a_bar': 0xfe}),
];
await SimCompare.checkFunctionalVector(gtm, vectors);
final simResult = SimCompare.iverilogVector(
gtm.generateSynth(), gtm.runtimeType.toString(), vectors,
signalToWidthMap: signalToWidthMap);
final simResult = SimCompare.iverilogVector(gtm, vectors);
expect(simResult, equals(true));
});

Expand All @@ -343,9 +296,7 @@ void main() {
];

await SimCompare.checkFunctionalVector(gtm, vectors);
final simResult = SimCompare.iverilogVector(
gtm.generateSynth(), gtm.runtimeType.toString(), vectors,
signalToWidthMap: signalToWidthMap);
final simResult = SimCompare.iverilogVector(gtm, vectors);
expect(simResult, equals(true));
});

Expand All @@ -362,9 +313,7 @@ void main() {
];

await SimCompare.checkFunctionalVector(gtm, vectors);
final simResult = SimCompare.iverilogVector(
gtm.generateSynth(), gtm.runtimeType.toString(), vectors,
signalToWidthMap: signalToWidthMap);
final simResult = SimCompare.iverilogVector(gtm, vectors);
expect(simResult, equals(true));
});

Expand Down Expand Up @@ -401,9 +350,7 @@ void main() {
Vector({'a': 0xba}, {'a_neg_shrunk3': 0})
];
await SimCompare.checkFunctionalVector(gtm, vectors);
final simResult = SimCompare.iverilogVector(
gtm.generateSynth(), gtm.runtimeType.toString(), vectors,
signalToWidthMap: signalToWidthMap);
final simResult = SimCompare.iverilogVector(gtm, vectors);
expect(simResult, equals(true));
});

Expand Down Expand Up @@ -440,9 +387,7 @@ void main() {
Vector({'a': 0xaf}, {'a_r_neg_sliced3': 1})
];
await SimCompare.checkFunctionalVector(gtm, vectors);
final simResult = SimCompare.iverilogVector(
gtm.generateSynth(), gtm.runtimeType.toString(), vectors,
signalToWidthMap: signalToWidthMap);
final simResult = SimCompare.iverilogVector(gtm, vectors);
expect(simResult, equals(true));
});

Expand All @@ -455,9 +400,7 @@ void main() {
Vector({'a': 0xf5}, {'a_reversed': 0xaf}),
];
await SimCompare.checkFunctionalVector(gtm, vectors);
final simResult = SimCompare.iverilogVector(
gtm.generateSynth(), gtm.runtimeType.toString(), vectors,
signalToWidthMap: signalToWidthMap);
final simResult = SimCompare.iverilogVector(gtm, vectors);
expect(simResult, equals(true));
});

Expand Down Expand Up @@ -502,9 +445,7 @@ void main() {
Vector({'a': bin('11000101')}, {'a_neg_range4': bin('110')}),
];
await SimCompare.checkFunctionalVector(gtm, vectors);
final simResult = SimCompare.iverilogVector(
gtm.generateSynth(), gtm.runtimeType.toString(), vectors,
signalToWidthMap: signalToWidthMap);
final simResult = SimCompare.iverilogVector(gtm, vectors);
expect(simResult, equals(true));
});

Expand All @@ -519,9 +460,7 @@ void main() {
Vector({'a': 0xaa, 'b': 0x55}, {'a_b_joined': 0x55aa}),
];
await SimCompare.checkFunctionalVector(gtm, vectors);
final simResult = SimCompare.iverilogVector(
gtm.generateSynth(), gtm.runtimeType.toString(), vectors,
signalToWidthMap: signalToWidthMap);
final simResult = SimCompare.iverilogVector(gtm, vectors);
expect(simResult, equals(true));
});

Expand All @@ -534,9 +473,7 @@ void main() {
Vector({'a': 0xf5}, {'a1': 0}),
];
await SimCompare.checkFunctionalVector(gtm, vectors);
final simResult = SimCompare.iverilogVector(
gtm.generateSynth(), gtm.runtimeType.toString(), vectors,
signalToWidthMap: signalToWidthMap);
final simResult = SimCompare.iverilogVector(gtm, vectors);
expect(simResult, equals(true));
});

Expand All @@ -551,9 +488,7 @@ void main() {
Vector({'a': 6, 'b': 7}, {'a_plus_b': 13}),
];
await SimCompare.checkFunctionalVector(gtm, vectors);
final simResult = SimCompare.iverilogVector(
gtm.generateSynth(), gtm.runtimeType.toString(), vectors,
signalToWidthMap: signalToWidthMap);
final simResult = SimCompare.iverilogVector(gtm, vectors);
expect(simResult, equals(true));
});

Expand All @@ -564,9 +499,7 @@ void main() {
Vector({'a': 1, 'b': 1}, {'expression_bit_select': 2}),
];
await SimCompare.checkFunctionalVector(gtm, vectors);
final simResult = SimCompare.iverilogVector(
gtm.generateSynth(), gtm.runtimeType.toString(), vectors,
signalToWidthMap: signalToWidthMap);
final simResult = SimCompare.iverilogVector(gtm, vectors);
expect(simResult, equals(true));
});
});
Expand Down
3 changes: 1 addition & 2 deletions test/collapse_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ void main() {
Vector({'a': 0, 'b': 0}, {'c': 0, 'd': 0, 'e': 0, 'f': 0}),
];
await SimCompare.checkFunctionalVector(mod, vectors);
final simResult = SimCompare.iverilogVector(
mod.generateSynth(), mod.runtimeType.toString(), vectors);
final simResult = SimCompare.iverilogVector(mod, vectors);
expect(simResult, equals(true));
});

Expand Down
20 changes: 5 additions & 15 deletions test/comb_math_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ void main() {

await SimCompare.checkFunctionalVector(mod, vectors);

final simResult = SimCompare.iverilogVector(
mod.generateSynth(), mod.runtimeType.toString(), vectors,
signalToWidthMap: {'codepoint': 21, 'bytes': 32});
final simResult = SimCompare.iverilogVector(mod, vectors);
expect(simResult, equals(true));
});

Expand All @@ -146,9 +144,7 @@ void main() {
}

await SimCompare.checkFunctionalVector(mod, vectors);
final simResult = SimCompare.iverilogVector(
mod.generateSynth(), mod.runtimeType.toString(), vectors,
signalToWidthMap: {'codepoint': 21, 'bytes': 32});
final simResult = SimCompare.iverilogVector(mod, vectors);
expect(simResult, equals(true));
});

Expand All @@ -161,9 +157,7 @@ void main() {
Vector({'a': 0xff}, {'b': bin('00001111')})
];
await SimCompare.checkFunctionalVector(mod, vectors);
final simResult = SimCompare.iverilogVector(
mod.generateSynth(), mod.runtimeType.toString(), vectors,
signalToWidthMap: {'a': 8, 'b': 8});
final simResult = SimCompare.iverilogVector(mod, vectors);
expect(simResult, equals(true));
});

Expand All @@ -176,9 +170,7 @@ void main() {
Vector({'a': 0xff}, {'b': bin('00001111')})
];
await SimCompare.checkFunctionalVector(mod, vectors);
final simResult = SimCompare.iverilogVector(
mod.generateSynth(), mod.runtimeType.toString(), vectors,
signalToWidthMap: {'a': 8, 'b': 8});
final simResult = SimCompare.iverilogVector(mod, vectors);
expect(simResult, equals(true));
});

Expand All @@ -191,9 +183,7 @@ void main() {
Vector({'a': 0xff}, {'b': bin('00001111')})
];
await SimCompare.checkFunctionalVector(mod, vectors);
final simResult = SimCompare.iverilogVector(
mod.generateSynth(), mod.runtimeType.toString(), vectors,
signalToWidthMap: {'a': 8, 'b': 8});
final simResult = SimCompare.iverilogVector(mod, vectors);
expect(simResult, equals(true));
});
}
8 changes: 2 additions & 6 deletions test/comb_mod_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ void main() {
Vector({'a': 3}, {'b': 5})
];
await SimCompare.checkFunctionalVector(mod, vectors);
final simResult = SimCompare.iverilogVector(
mod.generateSynth(), mod.runtimeType.toString(), vectors,
signalToWidthMap: {'a': 8, 'b': 8});
final simResult = SimCompare.iverilogVector(mod, vectors);
expect(simResult, equals(true));
});

Expand All @@ -82,9 +80,7 @@ void main() {
Vector({'a': 3}, {'b': 5})
];
await SimCompare.checkFunctionalVector(mod, vectors);
final simResult = SimCompare.iverilogVector(
mod.generateSynth(), mod.runtimeType.toString(), vectors,
signalToWidthMap: {'a': 8, 'b': 8});
final simResult = SimCompare.iverilogVector(mod, vectors);
expect(simResult, equals(true));
});
}
9 changes: 1 addition & 8 deletions test/comparison_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ void main() {
tearDown(Simulator.reset);

group('simcompare', () {
final signalToWidthMap = {
'a': 8,
'b': 8,
};

test('compares', () async {
final gtm = ComparisonTestModule(Logic(width: 8), Logic(width: 8));
await gtm.build();
Expand Down Expand Up @@ -107,9 +102,7 @@ void main() {
}),
];
await SimCompare.checkFunctionalVector(gtm, vectors);
final simResult = SimCompare.iverilogVector(
gtm.generateSynth(), gtm.runtimeType.toString(), vectors,
signalToWidthMap: signalToWidthMap);
final simResult = SimCompare.iverilogVector(gtm, vectors);
expect(simResult, equals(true));
});
});
Expand Down
Loading