Skip to content

Commit

Permalink
More robust test cleanup (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorbel1 authored Feb 14, 2023
1 parent baa105c commit e57a1bc
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 42 deletions.
2 changes: 1 addition & 1 deletion test/bus_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ Future<void> main() async {
];
await SimCompare.checkFunctionalVector(mod, vectors);

CosimTestingInfrastructure.cleanupCosim(dirName);
await CosimTestingInfrastructure.cleanupCosim(dirName);
});
}
2 changes: 1 addition & 1 deletion test/cosim_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,6 @@ Future<void> main() async {
expect(File('tmp_cosim/simple_push_n_check_w_waves/waves.vcd').existsSync(),
isTrue);

CosimTestingInfrastructure.cleanupCosim(dirName);
await CosimTestingInfrastructure.cleanupCosim(dirName);
});
}
19 changes: 14 additions & 5 deletions test/cosim_test_infra.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,23 @@ class CosimTestingInfrastructure {

if (cleanupAfterSimulationEnds) {
// wait a second to do it so that the SV simulator can shut down
unawaited(Simulator.simulationEnded.then((_) =>
Future<void>.delayed(const Duration(seconds: 1))
.then((_) => cleanupCosim(testName))));
unawaited(Simulator.simulationEnded.then((_) => cleanupCosim(testName)));
}
}

/// Deletes temporary files created by [connectCosim].
static void cleanupCosim(String testName) {
Directory('$_tmpCosimDir/$testName').deleteSync(recursive: true);
static Future<void> cleanupCosim(String testName) async {
await delayedDeleteDirectory('$_tmpCosimDir/$testName');
}

/// Deletes a directory at [directoryPath] (recursively) after
/// [delay] seconds.
static Future<void> delayedDeleteDirectory(String directoryPath,
{int delay = 1}) async {
await Future<void>.delayed(const Duration(seconds: 1));
final dir = Directory(directoryPath);
if (dir.existsSync()) {
dir.deleteSync(recursive: true);
}
}
}
6 changes: 3 additions & 3 deletions test/example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
/// Author: Max Korbel <max.korbel@intel.com>
///
import 'dart:io';

import 'package:rohd/rohd.dart';
import 'package:rohd_cosim/rohd_cosim.dart';
import 'package:test/test.dart';

import '../example/main.dart' as counter;
import 'cosim_test_infra.dart';

void main() {
tearDown(() async {
Expand All @@ -24,6 +23,7 @@ void main() {

test('counter example', () async {
await counter.main(noPrint: true);
Directory('./example/tmp_cosim').deleteSync(recursive: true);
await CosimTestingInfrastructure.delayedDeleteDirectory(
'./example/tmp_cosim');
});
}
2 changes: 1 addition & 1 deletion test/ff_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ Future<void> main() async {
];
await SimCompare.checkFunctionalVector(mod, vectors);

CosimTestingInfrastructure.cleanupCosim(dirName);
await CosimTestingInfrastructure.cleanupCosim(dirName);
});
}
2 changes: 1 addition & 1 deletion test/finish_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ Future<void> main() async {
// expect the unexpected
expect(unexpectedEnd, isTrue);

CosimTestingInfrastructure.cleanupCosim(dirName);
await CosimTestingInfrastructure.cleanupCosim(dirName);
});
}
15 changes: 8 additions & 7 deletions test/hier_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import 'package:rohd/src/utilities/simcompare.dart';
import 'package:rohd_cosim/rohd_cosim.dart';
import 'package:test/test.dart';

import 'cosim_test_infra.dart';

class BottomMod extends ExternalSystemVerilogModule with Cosim {
@override
String get cosimHierarchy => 'submod';
Expand All @@ -31,19 +33,18 @@ void main() {
const hierStuffDir = './test/hier_stuff/';
const outDirPath = '$hierStuffDir/tmp_output/';

void cleanup() {
final outDir = Directory(outDirPath);
if (outDir.existsSync()) {
outDir.deleteSync(recursive: true);
}
Future<void> cleanup() async {
await CosimTestingInfrastructure.delayedDeleteDirectory(outDirPath);
}

setUp(cleanup);
setUp(() async {
await cleanup();
});

tearDown(() async {
await Simulator.reset();
await Cosim.reset();
cleanup();
await cleanup();
});

test('hier test', () async {
Expand Down
17 changes: 9 additions & 8 deletions test/pair_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import 'package:rohd/rohd.dart';
import 'package:rohd_cosim/rohd_cosim.dart';
import 'package:test/test.dart';

import 'cosim_test_infra.dart';

enum PairDirection { leftToRight, rightToLeft, misc }

class PairInterface extends Interface<PairDirection> {
Expand Down Expand Up @@ -71,19 +73,18 @@ void main() async {
const pairStuffDir = './test/pair_stuff/';
const outDirPath = '$pairStuffDir/tmp_output/';

void cleanup() {
final outDir = Directory(outDirPath);
if (outDir.existsSync()) {
outDir.deleteSync(recursive: true);
}
Future<void> cleanup() async {
await CosimTestingInfrastructure.delayedDeleteDirectory(outDirPath);
}

setUp(cleanup);
setUp(() async {
await cleanup();
});

tearDown(() async {
await Cosim.reset();
await Simulator.reset();
cleanup();
await Cosim.reset();
await cleanup();
});

test('pair test', () async {
Expand Down
20 changes: 9 additions & 11 deletions test/port_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@ import 'package:rohd/rohd.dart';
import 'package:rohd_cosim/rohd_cosim.dart';
import 'package:test/test.dart';

import 'cosim_test_infra.dart';
import 'port_stuff/port_launch.dart';

void main() async {
const portStuffDir = './test/port_stuff/';
String outDirPathOf(String outDirName) => '$portStuffDir/$outDirName/';

void cleanup(String outDirName) {
Future<void> cleanup(String outDirName) async {
final outDirPath = outDirPathOf(outDirName);
final outDir = Directory(outDirPath);
if (outDir.existsSync()) {
outDir.deleteSync(recursive: true);
}
await CosimTestingInfrastructure.delayedDeleteDirectory(outDirPath);
}

tearDown(() async {
Expand All @@ -46,7 +44,7 @@ void main() async {
bool failAsync = false,
bool hang = false,
}) async {
cleanup(outDirName);
await cleanup(outDirName);

final runEnv = {
'OUT_DIR': outDirName,
Expand Down Expand Up @@ -103,7 +101,7 @@ void main() async {

expect(stdoutContents, contains('PASS=1'));

cleanup(outDirName);
await cleanup(outDirName);
});

test('port test dart fail', () async {
Expand All @@ -123,7 +121,7 @@ void main() async {
// make sure error is communicated
expect(stdoutContents, contains('ERROR:'));

cleanup(outDirName);
await cleanup(outDirName);
});

test('port test with finish passes', () async {
Expand All @@ -134,7 +132,7 @@ void main() async {

expect(stdoutContents, contains('detected a failure from cocotb'));

cleanup(outDirName);
await cleanup(outDirName);
});

test('port test dart fail async', () async {
Expand All @@ -154,7 +152,7 @@ void main() async {
// make sure error is communicated
expect(stdoutContents, contains('ERROR:'));

cleanup(outDirName);
await cleanup(outDirName);
});

test('port test dart hang timeout', () async {
Expand All @@ -168,6 +166,6 @@ void main() async {
// make sure error is communicated
expect(stdoutContents, contains('ERROR:'));

cleanup(outDirName);
await cleanup(outDirName);
});
}
2 changes: 1 addition & 1 deletion test/sampling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ void main() {
);
}

CosimTestingInfrastructure.cleanupCosim(dirName);
await CosimTestingInfrastructure.cleanupCosim(dirName);
});
}
6 changes: 3 additions & 3 deletions test/timing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void main() {
VcdParser.confirmValue(vcdContents, 'reset', vcdTime, expectedResetValue);
}

CosimTestingInfrastructure.cleanupCosim(dirName);
await CosimTestingInfrastructure.cleanupCosim(dirName);
});

test('inject on edge shows up on same edge', () async {
Expand Down Expand Up @@ -128,7 +128,7 @@ void main() {
expect(VcdParser.confirmValue(vcdContents, 'reset', 20000, LogicValue.zero),
isTrue);

CosimTestingInfrastructure.cleanupCosim(dirName);
await CosimTestingInfrastructure.cleanupCosim(dirName);
});

test('initially driven signals show up properly', () async {
Expand All @@ -154,6 +154,6 @@ void main() {

await Simulator.run();

CosimTestingInfrastructure.cleanupCosim(dirName);
await CosimTestingInfrastructure.cleanupCosim(dirName);
});
}

0 comments on commit e57a1bc

Please sign in to comment.