Modelsim Bug 3

Modelsim version: 6.3c
Operating System: Linux 2.6.8-3-686
Reported: 2007-06-11

I was running modelsim (vsim) using the "coverage save -onexit .." command. Unfortunately, it turns out that the vsim shell can exit before the vsimk (the actual simulator) is done, and consequently it's possible that the coverage file is still being created/written after your vsim call has returned.

This is a serious problem for batch coverage scripts, especially mine which was essentially doing this loop:

foreach test do
	Run vsim and save coverage to new coverage database
	Merge new coverage database into full coverage database
Often times the merge would start running while the new database wasn't finished, or even created. I'd often see errors about the file not existing, or various errors about the codebases not matching, etc..

Modelsim didn't quite believe this was happening until I was able to verify it with this simple batch script:

# For shorter than 1 second sleeps
sub usleep($) { select(undef,undef,undef,shift); }

# Handle each test
my @run = (
  "coverage save -onexit new.ucdb",
  "onerror {resume}",
  "run -all",
  "quit -f");
my $run = join(' ; ',@run);
my $cmd = "vsim -coverage -c -do '$run' tb -pli +test=test/t.00000000";
$cmd .= " > /dev/null";

print "Do: $cmd\n";
print "Done simulating - check new.ucdb\n\n";

foreach ( 1..5 ) {
  system("ls -l new.ucdb");
  system("fuser new.ucdb");
  usleep .1;
And they realized that vsim and vsimk were not running in the normal parent/child arrangement (with an exec and wait), but by closing down through mutual agreement via a socket. It seems that agreement is happening too soon.