<commit_before>#!/bin/bash

SCRIPT_DIR=`dirname "${BASH_SOURCE[0]}"`
SV2V="$SCRIPT_DIR/../../bin/sv2v"

assertExists() {
    file=$1
    [ -f "$file" ]
    assertTrue "$file does not exist" $?
}

# USAGE: simulate <vcd-file> <log-file> <top-module> <file> [<file> ...]
simulate() {
    # arguments
    sim_vcd="$1"; shift
    sim_log="$1"; shift
    sim_top="$1"; shift
    # compile the files
    sim_prog="$SHUNIT_TMPDIR/simprog.exe"
    iverilog \
        -o "$sim_prog" \
        -g2005 \
        -DTEST_VCD="\"$sim_vcd\"" \
        -DTEST_TOP=$sim_top \
        "$SCRIPT_DIR/tb_dumper.v" \
        "$@"
    assertTrue "iverilog on $1 failed" $?
    # run the simulation
    $sim_prog > $sim_log
    assertTrue "simulating $1 failed" $?
    # remove the date from the VCD
    sed -i.orig -e "1,3d" "$sim_vcd"
    # remove the "opened file..." prompt from the log
    sed -i.orig -e "1,1d" "$sim_log"
}

assertConverts() {
    ac_file="$1"
    ac_temp="$SHUNIT_TMPDIR/ac-conv-temp.v"
    $SV2V "$ac_file" 2> /dev/null > "$ac_temp"
    assertTrue "1st conversion of $ac_file failed" $?
    $SV2V "$ac_temp" 2> /dev/null > /dev/null
    assertTrue "2nd conversion of $ac_file failed" $?
}

simpleTest() {
    sv="$1"
    ve="$2"
    if [ -z ${NO_SEPARATE_TBS} ]; then
        tb="$3"
    else
        tb="$SCRIPT_DIR/empty.v"
    fi

    assertNotNull "SystemVerilog file not specified" $sv
    assertNotNull "Verilog file not specified" $ve
    assertNotNull "Testbench not specified" $tb

    assertExists $sv
    assertExists $ve
    assertExists $tb

    assertConverts "$sv"
    assertConverts "$ve"
    assertConverts "$tb"

    # convert the SystemVerilog source file
    cv="$SHUNIT_TMPDIR/conv.v"
    $SV2V $sv 2> /dev/null > $cv
    assertTrue "conversion failed" $?
    assertExists $cv<commit_msg>added $bits and stability checks to test runner<commit_after>#!/bin/bash

SCRIPT_DIR=`dirname "${BASH_SOURCE[0]}"`
SV2V="$SCRIPT_DIR/../../bin/sv2v"

assertExists() {
    file=$1
    [ -f "$file" ]
    assertTrue "$file does not exist" $?
}

# USAGE: simulate <vcd-file> <log-file> <top-module> <file> [<file> ...]
simulate() {
    # arguments
    sim_vcd="$1"; shift
    sim_log="$1"; shift
    sim_top="$1"; shift
    # compile the files
    sim_prog="$SHUNIT_TMPDIR/simprog.exe"
    iverilog \
        -o "$sim_prog" \
        -g2005 \
        -DTEST_VCD="\"$sim_vcd\"" \
        -DTEST_TOP=$sim_top \
        "$SCRIPT_DIR/tb_dumper.v" \
        "$@"
    assertTrue "iverilog on $1 failed" $?
    # run the simulation
    $sim_prog > $sim_log
    assertTrue "simulating $1 failed" $?
    # remove the date from the VCD
    sed -i.orig -e "1,3d" "$sim_vcd"
    # remove the "opened file..." prompt from the log
    sed -i.orig -e "1,1d" "$sim_log"
}

assertConverts() {
    ac_file="$1"
    ac_tmpa="$SHUNIT_TMPDIR/ac-conv-tmpa.v"
    ac_tmpb="$SHUNIT_TMPDIR/ac-conv-tmpb.v"
    ac_tmpc="$SHUNIT_TMPDIR/ac-conv-tmpc.v"
    $SV2V "$ac_file" 2> /dev/null > "$ac_tmpa"
    assertTrue "1st conversion of $ac_file failed" $?
    $SV2V "$ac_tmpa" 2> /dev/null > "$ac_tmpb"
    assertTrue "2nd conversion of $ac_file failed" $?
    $SV2V "$ac_tmpb" 2> /dev/null > "$ac_tmpc"
    assertTrue "3rd conversion of $ac_file failed" $?
    diff "$ac_tmpb" "$ac_tmpc" > /dev/null
    assertTrue "conversion of $ac_file not stable after the second iteration" $?
    # using sed to remove quoted strings because "$bits" may be printed
    sed -E 's/"([^"]|\")+"//g' "$ac_tmpa" | grep "\$bits" > /dev/null
    assertFalse "conversion of $ac_file still contains \$bits" $?
}

simpleTest() {
    sv="$1"
    ve="$2"
    if [ -z ${NO_SEPARATE_TBS} ]; then
        tb="$3"
    else
        tb="$SCRIPT_DIR/empty.v"
    fi

    assertNotNull "SystemVerilog file not specified" $sv
    assertNotNull "Verilog file not specified" $ve
    assertNotNull "Testbench not specified" $tb

    assertExists $sv
    assertExists $ve
    assertExists $tb

    assertConverts "$sv"
    assertConverts "$ve"
    assertConverts "$tb"

    # convert the SystemVerilog source file
    cv="$SHUNIT_TMPDIR/conv.v"
    $SV2V $sv 2> /dev/null > $cv
    assertTrue "conversion failed" $?
    assertExists $cv
{'fraction_non_alphanumeric': 0.15469348659003831, 'fraction_numerical': 0.01460727969348659, 'mean_word_length': 2.739480752014324, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4849281', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1568, 'n_words': 374}