OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [dejagnu/] [lib/] [util-defs.exp] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Copyright (C) 92, 93, 94, 95, 96, 97, 98, 1999 Free Software Foundation, Inc.
2
 
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 
17
# Please email any bugs, comments, and/or additions to this file to:
18
# bug-dejagnu@prep.ai.mit.edu
19
 
20
# This file was written by Rob Savoye. (rob@cygnus.com)
21
 
22
#
23
# Run a utility and test the result.
24
#
25
# Parameters:
26
# First one is the command
27
# Second one is command arguments
28
# Third one is the file name
29
# Fourth one is the regexp style pattern to match for a PASS
30
#
31
# Returns:
32
#  1 if the test failed,
33
#  0 if the test passes,
34
# -1 if there was an internal error.
35
#
36
 
37
proc util_test { args } {
38
    global verbose
39
    # get the parameters
40
    set cmd     [lindex $args 0]
41
    verbose     "Utility to execute is $cmd" 2
42
    set cmd_arg [lindex $args 1]
43
    verbose     "Command line arguments are $cmd_arg" 2
44
    set file    [lindex $args 2]
45
    verbose     "The file name to use is $file" 2
46
    set pattern [lindex $args 3]
47
    verbose     "The pattern to match is \"$pattern\"" 2
48
 
49
    if [info exists file] {
50
        if ![string match "" $file] {
51
            if ![file exists $file] {
52
                perror "$file doesn't exist"
53
                return -1
54
            }
55
        }
56
    }
57
 
58
    # Run the utility to be tested and analyze the results.
59
 
60
    set comp_output [util_start $cmd $cmd_arg $file]
61
 
62
    verbose "Output is \"$comp_output\"" 2
63
    verbose "Pattern is \"$pattern\"" 2
64
 
65
    if [regexp "$pattern" $comp_output] {
66
        verbose "Pattern matches." 2
67
        return 0
68
    }
69
 
70
    verbose "Pattern does not match." 2
71
    return 1
72
}
73
 
74
#
75
# Run the utility
76
#
77
# Return NULL or the output.
78
#
79
 
80
proc util_start { args } {
81
    global verbose
82
    set cmd     [lindex $args 0]
83
    set cmd_arg [lindex $args 1]
84
    set file    [lindex $args 2]
85
 
86
    if {[which $cmd] == 0} {
87
        perror "Can't find $cmd"
88
        return ""
89
    }
90
 
91
    if { $verbose > 0 } {
92
        verbose "Spawning \"$cmd $cmd_arg $file\""
93
    } else {
94
        send_log "Spawning \"$cmd $cmd_arg $file\"\n"
95
    }
96
    catch "exec $cmd $cmd_arg $file" comp_output
97
    if ![string match "" $comp_output] {
98
        send_log "$comp_output\n"
99
    }
100
    return $comp_output
101
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.