$PERL
=
"$^X -Iblib/arch -Iblib/lib -IPreproc/blib/arch -IPreproc/blib/lib"
;
mkdir
'test_dir'
,0777;
unlink
"test_dir/verilog"
;
if
(!
$ENV
{HARNESS_ACTIVE}) {
use
lib
"Preproc/blib/lib"
;
use
lib
"Preproc/blib/arch"
;
}
sub
run_system {
my
$command
=
shift
;
print
"\t$command\n"
;
system
"$command"
;
my
$status
= $?;
(
$status
== 0) or
die
"%Error: Command Failed $command, $status, stopped"
;
}
sub
run_system_no_die {
my
$command
=
shift
;
print
"\t$command\n"
;
system
"$command"
;
return
$?;
}
sub
wholefile {
my
$file
=
shift
;
my
$fh
= IO::File->new (
$file
) or
die
"%Error: $! $file"
;
my
$wholefile
=
join
(
''
,
$fh
->getlines());
$fh
->
close
();
return
$wholefile
;
}
sub
files_identical {
my
$fn1
=
shift
;
my
$fn2
=
shift
;
my
$f1
= IO::File->new (
$fn1
) or
die
"%Error: $! $fn1,"
;
my
$f2
= IO::File->new (
$fn2
) or
die
"%Error: $! $fn2,"
;
my
@l1
=
$f1
->getlines();
my
@l2
=
$f2
->getlines();
my
$nl
=
$#l1
;
$nl
=
$#l2
if
(
$#l2
>
$nl
);
for
(
my
$l
=0;
$l
<=
$nl
;
$l
++) {
$l1
[
$l
] =~ s/\r\n/\n/g
if
defined
$l1
[
$l
];
$l2
[
$l
] =~ s/\r\n/\n/g
if
defined
$l2
[
$l
];
if
((
$l1
[
$l
]||
""
) ne (
$l2
[
$l
]||
""
)) {
next
if
(
$l1
[
$l
]||
""
) =~ /Generated by vrename on/;
warn
(
"%Warning: Line "
.(
$l
+1).
" mismatches; $fn1 $fn2\n"
.
"GOT: "
.(
$l1
[
$l
]||
"*EOF*\n"
)
.
"EXP: "
.(
$l2
[
$l
]||
"*EOF*\n"
));
if
(
$ENV
{HARNESS_UPDATE_GOLDEN}) {
warn
"%Warning: HARNESS_UPDATE_GOLDEN set: cp $fn1 $fn2\n"
;
copy(
$fn1
,
$fn2
);
}
else
{
warn
"To update reference: HARNESS_UPDATE_GOLDEN=1 "
.
join
(
" "
,$0,
@ARGV
).
"\n"
;
}
return
0;
}
}
return
1;
}
sub
get_memory_usage {
my
$fh
= IO::File->new(
"</proc/self/statm"
);
return
0
if
!
$fh
;
my
$stat
=
$fh
->getline ||
""
;
my
@stats
=
split
/\s+/,
$stat
;
return
(
$stats
[0]||0)*4096;
}
1;