test_helper.tcl 4.6 KB
Newer Older
1 2 3 4 5
# Redis test suite. Copyright (C) 2009 Salvatore Sanfilippo antirez@gmail.com
# This softare is released under the BSD License. See the COPYING file for
# more information.

set tcl_precision 17
6 7 8 9 10
source tests/support/redis.tcl
source tests/support/server.tcl
source tests/support/tmpfile.tcl
source tests/support/test.tcl
source tests/support/util.tcl
11 12

set ::host 127.0.0.1
13
set ::port 16379
14
set ::traceleaks 0
15
set ::valgrind 0
P
Pieter Noordhuis 已提交
16 17
set ::denytags {}
set ::allowtags {}
18
set ::external 0; # If "1" this means, we are running against external instance
19
set ::file ""; # If set, runs only the tests in this comma separated list
20 21

proc execute_tests name {
22
    source "tests/$name.tcl"
23 24
}

25 26 27 28
# Setup a list to hold a stack of server configs. When calls to start_server
# are nested, use "srv 0 pid" to get the pid of the inner server. To access
# outer servers, use "srv -1 pid" etcetera.
set ::servers {}
29 30 31 32 33 34 35 36
proc srv {args} {
    set level 0
    if {[string is integer [lindex $args 0]]} {
        set level [lindex $args 0]
        set property [lindex $args 1]
    } else {
        set property [lindex $args 0]
    }
37 38 39 40 41 42 43
    set srv [lindex $::servers end+$level]
    dict get $srv $property
}

# Provide easy access to the client for the inner server. It's possible to
# prepend the argument list with a negative level to access clients for
# servers running in outer blocks.
44
proc r {args} {
45 46 47 48 49 50 51 52
    set level 0
    if {[string is integer [lindex $args 0]]} {
        set level [lindex $args 0]
        set args [lrange $args 1 end]
    }
    [srv $level "client"] {*}$args
}

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
proc redis_deferring_client {args} {
    set level 0
    if {[llength $args] > 0 && [string is integer [lindex $args 0]]} {
        set level [lindex $args 0]
        set args [lrange $args 1 end]
    }

    # create client that defers reading reply
    set client [redis [srv $level "host"] [srv $level "port"] 1]

    # select the right db and read the response (OK)
    $client select 9
    $client read
    return $client
}

69 70 71 72 73 74 75 76
# Provide easy access to INFO properties. Same semantic as "proc r".
proc s {args} {
    set level 0
    if {[string is integer [lindex $args 0]]} {
        set level [lindex $args 0]
        set args [lrange $args 1 end]
    }
    status [srv $level "client"] [lindex $args 0]
77 78
}

79
proc cleanup {} {
80 81
    catch {exec rm -rf {*}[glob tests/tmp/redis.conf.*]}
    catch {exec rm -rf {*}[glob tests/tmp/server.*]}
82 83
}

84
proc execute_everything {} {
85 86 87 88 89 90 91 92 93 94
    execute_tests "unit/auth"
    execute_tests "unit/protocol"
    execute_tests "unit/basic"
    execute_tests "unit/type/list"
    execute_tests "unit/type/set"
    execute_tests "unit/type/zset"
    execute_tests "unit/type/hash"
    execute_tests "unit/sort"
    execute_tests "unit/expire"
    execute_tests "unit/other"
A
antirez 已提交
95
    execute_tests "unit/cas"
96
    execute_tests "integration/replication"
97
    execute_tests "integration/aof"
98
#    execute_tests "integration/redis-cli"
P
Pieter Noordhuis 已提交
99
    execute_tests "unit/pubsub"
100 101

    # run tests with VM enabled
102
    set ::global_overrides {vm-enabled yes}
103 104 105 106 107 108 109 110 111
    execute_tests "unit/protocol"
    execute_tests "unit/basic"
    execute_tests "unit/type/list"
    execute_tests "unit/type/set"
    execute_tests "unit/type/zset"
    execute_tests "unit/type/hash"
    execute_tests "unit/sort"
    execute_tests "unit/expire"
    execute_tests "unit/other"
A
antirez 已提交
112
    execute_tests "unit/cas"
113 114 115 116 117 118 119 120 121 122 123 124
}

proc main {} {
    cleanup

    if {[string length $::file] > 0} {
        foreach {file} [split $::file ,] {
            execute_tests $file
        }
    } else {
        execute_everything
    }
125 126

    cleanup
127 128 129
    puts "\n[expr $::passed+$::failed] tests, $::passed passed, $::failed failed"
    if {$::failed > 0} {
        puts "\n*** WARNING!!! $::failed FAILED TESTS ***\n"
130
        exit 1
131 132 133
    }
}

134 135 136 137 138 139 140 141 142 143 144 145 146
# parse arguments
for {set j 0} {$j < [llength $argv]} {incr j} {
    set opt [lindex $argv $j]
    set arg [lindex $argv [expr $j+1]]
    if {$opt eq {--tags}} {
        foreach tag $arg {
            if {[string index $tag 0] eq "-"} {
                lappend ::denytags [string range $tag 1 end]
            } else {
                lappend ::allowtags $tag
            }
        }
        incr j
147 148 149
    } elseif {$opt eq {--file}} {
        set ::file $arg
        incr j
150 151 152 153 154 155 156
    } elseif {$opt eq {--host}} {
        set ::external 1
        set ::host $arg
        incr j
    } elseif {$opt eq {--port}} {
        set ::port $arg
        incr j
157 158 159 160 161 162
    } else {
        puts "Wrong argument: $opt"
        exit 1
    }
}

163 164 165 166 167 168 169 170 171
if {[catch { main } err]} {
    if {[string length $err] > 0} {
        # only display error when not generated by the test suite
        if {$err ne "exception"} {
            puts $err
        }
        exit 1
    }
}