1#!/usr/bin/env perl
2# Makes the test run with tracing enabled by default, can be overridden
3# with --notrace
4unshift(@ARGV, "--trace");
5if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
6# DESCRIPTION: Verilator: Verilog Test driver/expect definition
7#
8# Copyright 2019 by Todd Strader. This program is free software; you
9# can redistribute it and/or modify it under the terms of either the GNU
10# Lesser General Public License Version 3 or the Perl Artistic License
11# Version 2.0.
12# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
13
14scenarios(
15    vlt => 1,
16    xsim => 1,
17    );
18
19$Self->{sim_time} = $Self->{benchmark} * 100 if $Self->{benchmark};
20
21my $secret_prefix = "secret";
22my $secret_dir = "$Self->{obj_dir}/$secret_prefix";
23mkdir $secret_dir;
24
25while (1) {
26    # Always compile the secret file with Verilator no matter what simulator
27    #   we are testing with
28    run(logfile => "$secret_dir/vlt_compile.log",
29        cmd => ["perl",
30                "$ENV{VERILATOR_ROOT}/bin/verilator",
31                "--prefix",
32                "Vt_lib_prot_secret",
33                "-cc",
34                "-Mdir",
35                $secret_dir,
36                "--protect-lib",
37                $secret_prefix,
38                "--protect-key",
39                "secret-key",
40                "t/t_lib_prot_secret.v"],
41        verilator_run => 1,
42        );
43    last if $Self->{errors};
44
45    run(logfile => "$secret_dir/secret_gcc.log",
46        cmd=>[$ENV{MAKE},
47              "-C",
48              $secret_dir,
49              "-f",
50              "Vt_lib_prot_secret.mk"]);
51    last if $Self->{errors};
52
53    compile(
54        verilator_flags2 => ["$secret_dir/secret.sv",
55                             "-LDFLAGS",
56                             "$secret_prefix/libsecret.a"],
57        xsim_flags2 => ["$secret_dir/secret.sv"],
58        );
59
60    execute(
61        check_finished => 1,
62        xsim_run_flags2 => ["--sv_lib",
63                            "$secret_dir/libsecret",
64                            "--dpi_absolute"],
65        );
66
67    if ($Self->{vlt} && $Self->{trace}) {
68        # We can see the ports of the secret module
69        file_grep("$Self->{obj_dir}/simx.vcd", qr/accum_in/);
70        # but we can't see what's inside
71        file_grep_not("$Self->{obj_dir}/simx.vcd", qr/secret_/);
72    }
73
74    ok(1);
75    last;
76}
771;
78