| 1 |
################################################################################ |
| 2 |
# This file is part of the bladeRF project: |
| 3 |
# http://www.github.com/nuand/bladeRF |
| 4 |
|
| 5 |
# Copyright (C) 2023 Nuand LLC |
| 6 |
|
| 7 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 |
# of this software and associated documentation files (the "Software"), to deal |
| 9 |
# in the Software without restriction, including without limitation the rights |
| 10 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 |
# copies of the Software, and to permit persons to whom the Software is |
| 12 |
# furnished to do so, subject to the following conditions: |
| 13 |
|
| 14 |
# The above copyright notice and this permission notice shall be included in |
| 15 |
# all copies or substantial portions of the Software. |
| 16 |
|
| 17 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 |
# THE SOFTWARE. |
| 24 |
################################################################################ |
| 25 |
|
| 26 |
################################################################################ |
| 27 |
# Runs testbench simulations or executes "do" files. |
| 28 |
# Exit Status: The script exits with the status code indicating success (0) or failure (1). |
| 29 |
################################################################################ |
| 30 |
set status 0 |
| 31 |
|
| 32 |
if {$argc == 0 || $1 == "-h" || $1 == "--help"} { |
| 33 |
# If "-h" is passed, print the usage information and exit |
| 34 |
puts "Usage: do test.do vsim <testbench_name> \[testbench parameters\] <time_in_microseconds>" |
| 35 |
puts " do test.do do <file_name> \[additional_parameters\]" |
| 36 |
puts "" |
| 37 |
puts "Arguments:" |
| 38 |
puts " vsim: Run a testbench simulation." |
| 39 |
puts " do: Execute a 'do' file with parameters." |
| 40 |
puts " -h: Print this help message." |
| 41 |
return |
| 42 |
} |
| 43 |
|
| 44 |
set params "" |
| 45 |
for {set i 2} {$i <= 9} {incr i} { |
| 46 |
if {[info exists $i]} { |
| 47 |
append params [eval set $i] |
| 48 |
append params " " |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
if { $1 == "vsim" } { |
| 53 |
set testbench [lindex $params 0] |
| 54 |
set tb_args [lrange $params 1 end-1] |
| 55 |
set time_us [lindex $params end] |
| 56 |
set assertion_log log.txt |
| 57 |
|
| 58 |
vsim $testbench -assertfile $assertion_log {*}$tb_args; run ${time_us}us; |
| 59 |
|
| 60 |
set f [open $assertion_log] |
| 61 |
set file_content [read $f] |
| 62 |
close $f |
| 63 |
|
| 64 |
if {[catch {exec grep -c Failure << $file_content} result]} { |
| 65 |
set fail_count 0 |
| 66 |
} else { |
| 67 |
set fail_count $result |
| 68 |
} |
| 69 |
echo "fail_count:" $fail_count |
| 70 |
if { $fail_count > 0 } { |
| 71 |
set status 1 |
| 72 |
echo "\nSee log.txt for failure\n" |
| 73 |
} else { |
| 74 |
exec rm $assertion_log |
| 75 |
} |
| 76 |
} else { |
| 77 |
onerror {set status 1} |
| 78 |
set do_file $1 |
| 79 |
do $do_file {*}$params |
| 80 |
} |
| 81 |
|
| 82 |
quit -code $status |