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
21top_filename("t/t_lib_prot.v");
22my $secret_prefix = "secret";
23my $secret_dir = "$Self->{obj_dir}/$secret_prefix";
24mkdir $secret_dir;
25
26while (1) {
27    # Always compile the secret file with Verilator no matter what simulator
28    #   we are testing with
29    run(logfile => "$secret_dir/vlt_compile.log",
30        cmd => ["perl",
31                "$ENV{VERILATOR_ROOT}/bin/verilator",
32                "--prefix",
33                "Vt_lib_prot_secret",
34                "-cc",
35                "-Mdir",
36                $secret_dir,
37                "-GGATED_CLK=1",
38                "--protect-lib",
39                $secret_prefix,
40                "--protect-key",
41                "secret-key",
42                "t/t_lib_prot_secret.v"],
43        verilator_run => 1,
44        );
45    last if $Self->{errors};
46
47    run(logfile => "$secret_dir/secret_gcc.log",
48        cmd=>[$ENV{MAKE},
49              "-C",
50              $secret_dir,
51              "-f",
52              "Vt_lib_prot_secret.mk"]);
53    last if $Self->{errors};
54
55    compile(
56        verilator_flags2 => ["$secret_dir/secret.sv",
57                             "-GGATED_CLK=1",
58                             "-LDFLAGS",
59                             "$secret_prefix/libsecret.a"],
60        xsim_flags2 => ["$secret_dir/secret.sv"],
61        );
62
63    execute(
64        check_finished => 1,
65        xsim_run_flags2 => ["--sv_lib",
66                            "$secret_dir/libsecret",
67                            "--dpi_absolute"],
68        );
69
70    if ($Self->{vlt} && $Self->{trace}) {
71        # We can see the ports of the secret module
72        file_grep("$Self->{obj_dir}/simx.vcd", qr/accum_in/);
73        # but we can't see what's inside
74        file_grep_not("$Self->{obj_dir}/simx.vcd", qr/secret_/);
75    }
76
77    ok(1);
78    last;
79}
801;
81