Skip to content

Commit 37d2e42

Browse files
committed
updated vqm2blif test script to now allow input flags and provide usage information. The script now also supports creating a new set of golden netlists (instead of testing).
1 parent 0e7383c commit 37d2e42

File tree

1 file changed

+169
-24
lines changed

1 file changed

+169
-24
lines changed

utils/vqm2blif/test/scripts/test_vqm2blif.sh

Lines changed: 169 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@
2626

2727
# Finally, the generated blif files have the extension ".test.blif", so please do not name any other files with this extension
2828

29+
## usefule functions ##
30+
# prints information regarding how to use the script
31+
print_usage()
32+
{
33+
echo "Usage: test_vqm2blif.sh [-h | --help] [-vqm2blif_location] V [-netlists] N [-arch] A [-create_golden]"
34+
echo ""
35+
echo "Evaluating the vqm2blif program."
36+
echo ""
37+
echo "Positional Arguments:"
38+
echo "V Location of the vqm2blif program executable"
39+
echo "N Location of the folder containing the netlists"
40+
echo "A Location of the architecture file to use"
41+
echo ""
42+
echo "Optional Arguments:"
43+
echo "-h, --help show the usage of the test script"
44+
echo "-vqm2blif_location specify the vqm2blif program executable (defalt: \$VTR_ROOT/build/utils/vqm2blif/vqm2blif"
45+
echo "-netlists specify the netlists used to evalute the vqm2blif program (default: \$VTR_ROOT/utils/vqm2blif/test/netlists/"
46+
echo "-arch specify the architecture file that will be used to evalute the vqm2blif program"
47+
echo " (default: \$VTR_ROOT/vtr_flow/arch/titan/stratixiv_arch.timing.xml)"
48+
echo "-create_golden creates a set of \"golden\" .blif netlists using the vqm2blif program. The generated netlists will have the same"
49+
echo " name as the provided .vqm netlists with the extension \"golden.blif\". The generated netlists can be found in the same"
50+
echo " location as provided .vqm netlists."
51+
}
52+
2953

3054
# has useful utilities
3155
source "$(dirname "$0")/../../../../.github/scripts/common.sh"
@@ -34,6 +58,9 @@ source "$(dirname "$0")/../../../../.github/scripts/common.sh"
3458
# location of the VTR project root directory
3559
VTR_ROOT_DIR="$(dirname "$0")/../../../../"
3660

61+
# location of the vqm program directory
62+
VQM_PROGRAM="$VTR_ROOT_DIR/build/utils/vqm2blif/vqm2blif"
63+
3764
# location of the deafult architecture file used when testing the vqm2blif program
3865
ARCH_FILE="$(dirname "$0")/../../../../vtr_flow/arch/titan/stratixiv_arch.timing.xml"
3966

@@ -44,27 +71,81 @@ TEST_FOLDER="$(dirname "$0")/../netlists/"
4471
# file extensions of the created blif netlists (these files will be compared to the golden netlists)
4572
VQM_OUTPUT_EXT=".test.blif"
4673

74+
# file extension for the generated golden blif netlists
75+
VQM_GOLDEN_OUTPUT_EXT=".golden.blif"
76+
4777
# variable to keep track of the test status
4878
# initially the status is successful
49-
TEST_STATUS=0
50-
51-
# check if the user provided a different folder for the test netlist locations
52-
# if they did, the update the test folder
53-
if ! [ -z $1 ]; then
54-
55-
# update the test folder to the user input
56-
TEST_FOLDER=$1
79+
TEST_STATUS=0
5780

58-
fi
59-
60-
# check if the user provided a different architecture file to use.
61-
# if they did, then update the architecture file.
62-
if ! [ -z $2 ]; then
63-
64-
# upadte the architecture file to the user input
65-
ARCH_FILE=$2
81+
# variable to determine whether the user wanted to generate a set of golden netlists (initially we assume the golden netlists are not being generated)
82+
GEN_GOLDEN=0
6683

67-
fi
84+
# we process the command line inputs below
85+
while test $# -gt 0;
86+
do
87+
case "$1" in
88+
-h | --help)
89+
print_usage
90+
exit 0
91+
;;
92+
-vqm2blif_location)
93+
if ! [ -z $2 ]; then
94+
95+
# update the test folder to the user input
96+
VQM_PROGRAM=$2
97+
98+
else
99+
echo "Did not supply vqm program location"
100+
echo "-----------------------------------"
101+
print_usage
102+
exit 1
103+
fi
104+
shift
105+
shift
106+
;;
107+
-netlists)
108+
if ! [ -z $2 ]; then
109+
110+
# update the test folder to the user input
111+
TEST_FOLDER=$2
112+
113+
else
114+
echo "Did not supply the folder location for netlists"
115+
echo "-----------------------------------------------"
116+
print_usage
117+
exit 1
118+
fi
119+
shift
120+
shift
121+
;;
122+
-arch)
123+
if ! [ -z $2 ]; then
124+
125+
# update the test folder to the user input
126+
ARCH_FILE=$2
127+
128+
else
129+
echo "Did not supply architecture file location"
130+
echo "-----------------------------------------"
131+
print_usage
132+
exit 1
133+
fi
134+
shift
135+
shift
136+
;;
137+
-create_golden)
138+
GEN_GOLDEN=1
139+
shift
140+
;;
141+
*) # handle all other options
142+
echo "Invalid Argument Provided"
143+
echo "-------------------------"
144+
print_usage
145+
exit 1
146+
;;
147+
esac
148+
done
68149

69150

70151
echo "VQM2BLIF Program Check"
@@ -74,7 +155,11 @@ echo "----------------------"
74155
# start by going through the user supplied directory and identify all the .vqm files. We will recursively go throught the directory and identify these .vqm files. We assume that any file found is going to be a test file.
75156
find $TEST_FOLDER -name "*.vqm" -print0 | while read -d $'\0' vqm_file
76157
do
77-
158+
# "create_golden" related variables
159+
CREATE_GOLDEN_FILE_NAME=""
160+
CREATE_GOLDEN_OUTPUT=""
161+
162+
78163
# identify the directory of the current vqm file and its name
79164
CURR_DIR_NAME="$(dirname "$vqm_file")"
80165
CURR_VQM_FILE_NAME="$(basename "$vqm_file" .vqm)"
@@ -88,28 +173,66 @@ do
88173
GOLDEN_BLIF_OUTPUT="$(find "$CURR_DIR_NAME" -name *.blif)"
89174
GOLDEN_BLIF_OUTPUT_FILE_NAME="$(basename "$GOLDEN_BLIF_OUTPUT" .blif)"
90175

176+
# if the user chose the "create_golden" option, then we need to generate the file/location names for them
177+
if [ $GEN_GOLDEN -eq 1 ]; then
178+
179+
CREATE_GOLDEN_FILE_NAME="${CURR_VQM_FILE_NAME}${VQM_GOLDEN_OUTPUT_EXT}"
180+
CREATE_GOLDEN_OUTPUT="${CURR_DIR_NAME}/${CREATE_GOLDEN_FILE_NAME}"
181+
182+
fi
183+
91184
# uncomment for debugging
92185
#echo "Starting test $CURR_VQM_FILE_NAME"
93186

94187
# now we need to run the vqm to blif program.
95188
# we only care about any outputs related to errors, so ignore standard output.
96189
# We are running this process in a seperate sub shell to make sure that unwanted error messags are not reported in the terminal
97-
($VTR_ROOT_DIR/build/utils/vqm2blif/vqm2blif -vqm $vqm_file -arch $ARCH_FILE -out $VQM_OUTPUT || false) > /dev/null 2>&1
190+
# we have two cases, one for testing and one for generating a golden set of outputs
191+
if [ $GEN_GOLDEN -eq 0 ]; then
192+
193+
($VTR_ROOT_DIR/build/utils/vqm2blif/vqm2blif -vqm $vqm_file -arch $ARCH_FILE -out $VQM_OUTPUT || false) > /dev/null 2>&1
194+
195+
else
196+
197+
($VTR_ROOT_DIR/build/utils/vqm2blif/vqm2blif -vqm $vqm_file -arch $ARCH_FILE -out $CREATE_GOLDEN_OUTPUT || false) > /dev/null 2>&1
98198

199+
fi
200+
201+
# if we errored during the program execution
99202
if [ $? -ne 0 ]; then
100203

101204
echo "ERROR: The vqm2blif program failed while converting \"$CURR_VQM_FILE_NAME.vqm\". Please refer to the failure messages below:"
102205
echo "-----------------------------------------------------------------------------------------------------------------------"
103206

104207
$VTR_ROOT_DIR/build/utils/vqm2blif/vqm2blif -vqm $vqm_file -arch $ARCH_FILE -out $VQM_OUTPUT
105208

209+
# once again, we cover the cases of testing and creating a golden set of outputs
210+
if [ $GEN_GOLDEN -eq 0]; then
211+
212+
$VTR_ROOT_DIR/build/utils/vqm2blif/vqm2blif -vqm $vqm_file -arch $ARCH_FILE -out $VQM_OUTPUT
213+
214+
else
215+
216+
$VTR_ROOT_DIR/build/utils/vqm2blif/vqm2blif -vqm $vqm_file -arch $ARCH_FILE -out $CREATE_GOLDEN_OUTPUT
217+
218+
fi
219+
106220
exit 1
107221
fi
108222

109223
#uncomment for debugging
110224
#echo "Comparing $CURR_VQM_FILE_NAME output"
111225

112-
NUM_OF_DIFFERENCES="$(diff $GOLDEN_BLIF_OUTPUT $VQM_OUTPUT | grep "^>" | wc -l)"
226+
# variable to keep track of the total number of differences between a generated nelist and its "golden" counterpart
227+
NUM_OF_DIFFERENCES=0
228+
229+
# we only need to calculate the number of differences, if we are testing the vqm2blif program
230+
# this is not needed when we are just generating a golden set of outputs
231+
if [ $GEN_GOLDEN -eq 0 ]; then
232+
233+
NUM_OF_DIFFERENCES="$(diff $GOLDEN_BLIF_OUTPUT $VQM_OUTPUT | grep "^>" | wc -l)"
234+
235+
fi
113236

114237
#uncomment for debugging
115238
#echo "Number of differences: $NUM_OF_DIFFERENCES"
@@ -125,6 +248,7 @@ do
125248
diff $GOLDEN_BLIF_OUTPUT $VQM_OUTPUT
126249

127250
exit 1
251+
128252
fi
129253

130254
# uncomment for debugging
@@ -142,14 +266,35 @@ if [ $? -eq 1 ]; then
142266
# if we are here then the test failed, so update the test status with an error code
143267
TEST_STATUS=1
144268

269+
# delete the blif files generated if there was an error
270+
# this is for the case where golden blif files are generated
271+
find $TEST_FOLDER -name "*$VQM_OUTPUT_EXT" -type f -delete
272+
145273
else
146274

147-
# if we are here then the test passed, so report to the user (no need to update the test status)
148-
echo "VQM2BLIF Checks Successfully Passed!"
275+
# if we are here then the test passed or the golden blif netlists were successfully generated, so report to the user (no need to update the test status)
276+
277+
if [ $GEN_GOLDEN -eq 0 ]; then
278+
279+
# case where we are testing
280+
echo "VQM2BLIF Checks Successfully Passed!"
281+
282+
else
283+
284+
# case where we are generating a set of golden blif outputs
285+
echo "VQM2BLIF has Successfully created all golden blif netlists!"
286+
287+
fi
149288
fi
150289

151-
#find all the newly created blif files above (used for verification) and delete them (don't need them anymore)
152-
find $TEST_FOLDER -name "*$VQM_OUTPUT_EXT" -type f -delete
290+
# find all the newly created blif files above (used for verification) and delete them (don't need them anymore)
291+
# we only delete the generated blif files if we are testing, when we are generating a new set of golden blif outputs, we do not want to delete them
292+
293+
if [ $GEN_GOLDEN -eq 0 ]; then
294+
295+
find $TEST_FOLDER -name "*$VQM_OUTPUT_EXT" -type f -delete
296+
297+
fi
153298

154299
# exit with the status of the test (failure=1 and pass=0)
155300
exit $TEST_STATUS

0 commit comments

Comments
 (0)