File: 49_largeish.t

package info (click to toggle)
libverilog-perl 3.482-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,728 kB
  • sloc: perl: 8,685; yacc: 3,387; cpp: 2,266; lex: 1,502; makefile: 8; fortran: 3
file content (127 lines) | stat: -rwxr-xr-x 3,718 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/perl -w
# DESCRIPTION: Perl ExtUtils: Type 'make test' to test this package
#
# Copyright 2000-2024 by Wilson Snyder.  This program is free software;
# you can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License Version 2.0.

use strict;
use Test::More;
use Time::HiRes qw(gettimeofday tv_interval);
use Data::Dumper; $Data::Dumper::Indent = 1;

BEGIN { plan tests => 4 }
BEGIN { require "./t/test_utils.pl"; }

use Verilog::SigParser;
use Verilog::Preproc;
use Verilog::Getopt;
use Verilog::Netlist;
use POSIX qw();

######################################################################

our $nets = 10*1000;
our $Opt_Sym_Size = 30;
our $Opt_Spaced_Out = 0;   # Lots of stuff that preprocessor can rip out
our $Opt_Dir = $ENV{HARNESS_TEST_DIR}||"test_dir";  # Move to scratch disk for very large tests

prep("${Opt_Dir}/largeish_1.v",1);
prep("${Opt_Dir}/largeish_2.v",1+($nets/10));
prep("${Opt_Dir}/largeish_3.v",1+$nets);

per_net_test('sigparser', 100000);
per_net_test('netlist', 100000);

unlink(glob("${Opt_Dir}/largeish_*"));   # Fat, so don't keep around

######################################################################

sub prep {
    my $filename = shift;
    my $count = shift;

    my $fh = IO::File->new(">$filename");
    print $fh "module largeish;\n";
    my $wirefmt = " wire n%0".($Opt_Sym_Size-1)."d;\n";  # Each net is constant sized
    for (my $i=0; $i<$count; $i++) {
	printf $fh $wirefmt, $i;
	print $fh " "x1023,"\n" if $Opt_Spaced_Out;
    }
    print $fh "endmodule\n";

    printf "Wrote $filename: %6.3f MB\n", (-s $filename)/1024/1024;
}

sub per_net_test {
    my $pack = shift;
    my $limit = shift;

    my (@mem, @time, @size, @names, @secPerB);
    $names[1] = "${Opt_Dir}/largeish_1.v";
    $names[2] = "${Opt_Dir}/largeish_2.v";
    $names[3] = "${Opt_Dir}/largeish_3.v";

    $mem[0]  = get_memory_usage();
    $time[0] = [gettimeofday];

    for (my $i=1; $i<4; $i++) {
	read_test($pack, $names[$i]);
	$size[$i] = -s $names[$i];
	$mem[$i]  = get_memory_usage();
	$time[$i] = [gettimeofday];
    }

    for (my $i=2; $i<4; $i++) {
	my $deltamem = $mem[$i]-$mem[0];
	my $deltatime = tv_interval($time[$i-1],$time[$i]);
	my $mpn = $deltamem / $size[$i];
	$secPerB[$i] = $deltatime / ($size[$i]/1024/1024);
	printf "For $pack $names[$i]: File %1.3f MB, %1.3f s, %1.3f MB, Alloced %1.3f MB, %1.1f Alloc/FileB %1.1f s/MB\n"
	 , $size[$i]/1024/1024, $deltatime, $mem[$i]/1024/1024, $deltamem/1024/1024, $mpn, $secPerB[$i];
    }

    ok(1, "run complete");

    my $slope = $secPerB[3] / ($secPerB[2]||1);
  SKIP: {
      if ($slope > 0.5 && $slope < 2) {
	  ok(1, "complexity");
      } else {
	  if (!$ENV{VERILATOR_AUTHOR_SITE} || $ENV{HARNESS_FAST}) {
	      # It's somewhat sensitive unless there's a lot of loops,
	      # and lots of loops is too slow for users to deal with.
	      skip("waived, author only test",1);
	  } else {
	      warn "%Warning: ",$slope," non O(n) based on input file size, slope=$slope\n";
	      ok(0, "complexity");
	  }
	}
    }
}

sub read_test {
    my $pack = shift;
    my $filename = shift;

    if ($pack eq 'sigparser') {
	my $go = Verilog::Getopt->new();
	my $pp = Verilog::Preproc->new(keep_comments=>1);
	my $parser = Verilog::SigParser->new();
	#my $parser = Verilog::Parser->new();
	#$pp->debug(99);
	$pp->open($filename);
	##Preproc_Only_Test:  while (defined($pp->getline())) {}
	$parser->parse_preproc_file($pp);

	$pp->open($filename);
	while (defined($pp->getline())) {}

    }
    elsif ($pack eq 'netlist') {
	my $nl = Verilog::Netlist->new();
	$nl->read_file(filename=>$filename);
	$nl->delete;
    }
    else { die; }
}