File: t_flag_csplit_groups.py

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 (131 lines) | stat: -rwxr-xr-x 5,183 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
128
129
130
131
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 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.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0

import vltest_bootstrap

test.scenarios('vlt_all')

test.top_filename = "t/t_flag_csplit.v"


def check_splits():
    got1 = False
    gotSyms1 = False
    for filename in test.glob_some(test.obj_dir + "/*.cpp"):
        if re.search(r'Syms__1', filename):
            gotSyms1 = True
        elif re.search(r'__1', filename):
            got1 = True
    if not got1:
        test.error("No __1 split file found")
    if not gotSyms1:
        test.error("No Syms__1 split file found")


def check_no_all_file():
    for filename in test.glob_some(test.obj_dir + "/*.cpp"):
        if re.search(r'__ALL.cpp', filename):
            test.error("__ALL.cpp file found: " + filename)


def check_cpp(filename):
    size = os.path.getsize(filename)
    if test.verbose:
        print("  File %6d  %s\n" % (size, filename))
    funcs = []
    with open(filename, 'r', encoding="utf8") as fh:
        for line in fh:
            m = re.search(r'^(void|IData)\s+(.*::.*){', line)
            if not m:
                continue
            func = m.group(2)
            func = re.sub(r'\(.*$', '', func)
            if test.verbose:
                print("\tFunc " + func)
            if (re.search(r'(::_eval_initial_loop$', func) or re.search(r'::__Vconfigure$', func)
                    or re.search(r'::trace$', func) or re.search(r'::traceInit$', func)
                    or re.search(r'::traceFull$', func) or re.search(r'::final$', func)
                    or re.search(r'::prepareClone$', func) or re.search(r'::atClone$', func)):
                continue
            funcs.append(func)

    if len(funcs) > 0:
        test.error("Split had multiple functions in $filename\n\t" + "\n\t".join(funcs))


def check_gcc_flags(filename):
    with open(filename, 'r', encoding="utf8") as fh:
        for line in fh:
            line = line.rstrip()
            if test.verbose:
                print(":log: " + line)
            if re.search(r'' + test.vm_prefix + r'\S*\.cpp', line):
                filetype = "slow" if re.search(r'(Slow|Syms)', line) else "fast"
                opt = "fast" if re.search(r'-O2', line) else "slow"
                if test.verbose:
                    print(filetype + ", " + opt + ", " + line)
                if filetype != opt:
                    test.error(filetype + " file compiled as if was " + opt + ": " + line)
            elif re.search(r'.cpp', line) and not re.search(r'-Os', line):
                test.error("library file not compiled with OPT_GLOBAL: " + line)


# This rule requires GNU make > 4.1 (or so, known broken in 3.81)
#%__Slow.o: %__Slow.cpp
#        $(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_SLOW) -c -o $@ $<
if not test.make_version or float(test.make_version) < 4.1:
    test.skip("Test requires GNU Make version >= 4.1")

test.compile(v_flags2=["--trace-vcd",
                       "--output-split 1",
                       "--output-groups 2",
                       "--output-split-cfuncs 1",
                       "--exe",
                       "--stats",
                       "../" + test.main_filename],
             verilator_make_gmake=False)  # yapf:disable

# We don't use the standard test_regress rules, as want to test the rules
# properly build
test.run(logfile=test.obj_dir + "/vlt_gcc.log",
         tee=test.verbose,
         cmd=[os.environ["MAKE"],
              "-C " + test.obj_dir,
              "-f "+test.vm_prefix+".mk",
              "-j 4",
              "VM_PREFIX="+test.vm_prefix,
              "TEST_OBJ_DIR="+test.obj_dir,
              "CPPFLAGS_DRIVER=-D"+test.name.upper(),
              ("CPPFLAGS_DRIVER2=-DTEST_VERBOSE=1" if test.verbose else ""),
              "OPT_FAST=-O2",
              "OPT_SLOW=-O0",
              "OPT_GLOBAL=-Os",
              ])  # yapf:disable

test.execute()

# Splitting should set VM_PARALLEL_BUILDS to 1 by default
test.file_grep(test.obj_dir + "/" + test.vm_prefix + "_classes.mk", r'VM_PARALLEL_BUILDS\s*=\s*1')
check_splits()
check_no_all_file()
check_gcc_flags(test.obj_dir + "/vlt_gcc.log")

# Check that only vm_classes_*.cpp are to be compiled
test.file_grep_not(test.obj_dir + "/" + test.vm_prefix + "_classes.mk", "sub")
test.file_grep(test.obj_dir + "/" + test.vm_prefix + "_classes.mk", "vm_classes_Slow_1")
test.file_grep(test.obj_dir + "/" + test.vm_prefix + "_classes.mk", "vm_classes_1")
test.file_grep_not(test.obj_dir + "/" + test.vm_prefix + "_classes.mk", "vm_classes_Slow_2")
test.file_grep_not(test.obj_dir + "/" + test.vm_prefix + "_classes.mk", "vm_classes_2")

# Check combine count
test.file_grep(test.stats, r'Node count, CFILE + (\d+)', (234 if test.vltmt else 214))
test.file_grep(test.stats, r'Makefile targets, VM_CLASSES_FAST + (\d+)', 2)
test.file_grep(test.stats, r'Makefile targets, VM_CLASSES_SLOW + (\d+)', 2)

test.passes()