File: t_cover_lib_c.cpp

package info (click to toggle)
verilator 5.038-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 162,552 kB
  • sloc: cpp: 139,204; python: 20,931; ansic: 10,222; yacc: 6,000; lex: 1,925; makefile: 1,260; sh: 494; perl: 282; fortran: 22
file content (97 lines) | stat: -rw-r--r-- 3,649 bytes parent folder | download | duplicates (2)
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
// -*- mode: C++; c-file-style: "cc-mode" -*-
//*************************************************************************
//
// Copyright 2009-2017 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.
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
//
//*************************************************************************

#include "verilated_cov.h"

#include "svdpi.h"

#include <cstdio>
#include <cstring>
#include <iostream>

// These require the above. Comment prevents clang-format moving them
#include "TestCheck.h"

#include VM_PREFIX_INCLUDE

//======================================================================

double sc_time_stamp() { return 0; }

int errors = 0;

//======================================================================

const char* name() { return "main"; }

void hier_insert(VerilatedCovContext* covContextp, uint64_t* countp, const char* hierp,
                 const char* peri) {
    // This needs to be a function at one line number so all of the
    // line numbers for coverage are constant, otherwise instances won't combine.
    VL_COVER_INSERT(covContextp, name(), countp, "hier", hierp, "per_instance", peri);
}

int main() {
    uint32_t covers[1];
    uint64_t coverw[6];

    VerilatedCovContext* covContextp = Verilated::defaultContextp()->coveragep();

    VL_COVER_INSERT(covContextp, name(), &covers[0], "comment", "kept_one");
    VL_COVER_INSERT(covContextp, name(), &coverw[0], "comment", "kept_two");
    VL_COVER_INSERT(covContextp, name(), &coverw[1], "comment", "lost_three");

    hier_insert(covContextp, &coverw[2], "top.a0.pi", "0");
    hier_insert(covContextp, &coverw[3], "top.a1.pi", "0");
    hier_insert(covContextp, &coverw[4], "top.a0.npi", "1");
    hier_insert(covContextp, &coverw[5], "top.a1.npi", "1");

    covers[0] = 100;
    coverw[0] = 210;
    coverw[1] = 220;

    coverw[2] = 200;
    coverw[3] = 300;
    coverw[4] = 200;
    coverw[5] = 300;

#ifdef T_COVER_LIB
    TEST_CHECK_EQ(covContextp->defaultFilename(), "coverage.dat");
    covContextp->write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage1.dat");
    covContextp->forcePerInstance(true);
    covContextp->write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage1_per_instance.dat");
    covContextp->forcePerInstance(false);
    covContextp->clearNonMatch("kept_");
    covContextp->write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage2.dat");
    covContextp->zero();
    covContextp->write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage3.dat");
    covContextp->clear();
    Verilated::defaultContextp()->coverageFilename(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage4.dat");
    TEST_CHECK_EQ(covContextp->defaultFilename(), VL_STRINGIFY(TEST_OBJ_DIR) "/coverage4.dat");
    covContextp->write();  // Uses defaultFilename()
#elif defined(T_COVER_LIB_LEGACY)
    TEST_CHECK_EQ(VerilatedCov::defaultFilename(), "coverage.dat");
    VerilatedCov::write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage1.dat");
    VerilatedCov::clearNonMatch("kept_");
    VerilatedCov::write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage2.dat");
    VerilatedCov::zero();
    VerilatedCov::write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage3.dat");
    VerilatedCov::clear();
    Verilated::defaultContextp()->coverageFilename(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage4.dat");
    TEST_CHECK_EQ(VerilatedCov::defaultFilename(), VL_STRINGIFY(TEST_OBJ_DIR) "/coverage4.dat");
    VerilatedCov::write();  // Uses defaultFilename()
#else
#error
#endif

    printf("*-* All Finished *-*\n");
    return (errors ? 10 : 0);
}