]> git.saurik.com Git - redis.git/blame - tests/test_helper.tcl
Ingore jemalloc make distclean error in Makefile, caused by make clean against a...
[redis.git] / tests / test_helper.tcl
CommitLineData
98578b57
PN
1# Redis test suite. Copyright (C) 2009 Salvatore Sanfilippo antirez@gmail.com
2# This softare is released under the BSD License. See the COPYING file for
3# more information.
4
5set tcl_precision 17
ab72b483 6source tests/support/redis.tcl
7source tests/support/server.tcl
8source tests/support/tmpfile.tcl
9source tests/support/test.tcl
10source tests/support/util.tcl
98578b57
PN
11
12set ::host 127.0.0.1
47bebf15 13set ::port 16379
e59a64b8 14set ::traceleaks 0
c4669d25 15set ::valgrind 0
322ea972 16set ::verbose 0
6e0e5bed
PN
17set ::denytags {}
18set ::allowtags {}
7d04fc75 19set ::external 0; # If "1" this means, we are running against external instance
9f1ae9ab 20set ::file ""; # If set, runs only the tests in this comma separated list
6f8a32d5 21set ::curfile ""; # Hold the filename of the current suite
5e1d2d30 22set ::diskstore 0; # Don't touch this by hand. The test itself will toggle it.
98578b57
PN
23
24proc execute_tests name {
6f8a32d5
PN
25 set path "tests/$name.tcl"
26 set ::curfile $path
27 source $path
98578b57
PN
28}
29
1c4114be
PN
30# Setup a list to hold a stack of server configs. When calls to start_server
31# are nested, use "srv 0 pid" to get the pid of the inner server. To access
32# outer servers, use "srv -1 pid" etcetera.
33set ::servers {}
f2dd4769
PN
34proc srv {args} {
35 set level 0
36 if {[string is integer [lindex $args 0]]} {
37 set level [lindex $args 0]
38 set property [lindex $args 1]
39 } else {
40 set property [lindex $args 0]
41 }
1c4114be
PN
42 set srv [lindex $::servers end+$level]
43 dict get $srv $property
44}
45
46# Provide easy access to the client for the inner server. It's possible to
47# prepend the argument list with a negative level to access clients for
48# servers running in outer blocks.
98578b57 49proc r {args} {
1c4114be
PN
50 set level 0
51 if {[string is integer [lindex $args 0]]} {
52 set level [lindex $args 0]
53 set args [lrange $args 1 end]
54 }
55 [srv $level "client"] {*}$args
56}
57
941c9fa2
PN
58proc reconnect {args} {
59 set level [lindex $args 0]
60 if {[string length $level] == 0 || ![string is integer $level]} {
61 set level 0
62 }
63
64 set srv [lindex $::servers end+$level]
65 set host [dict get $srv "host"]
66 set port [dict get $srv "port"]
67 set config [dict get $srv "config"]
68 set client [redis $host $port]
69 dict set srv "client" $client
70
71 # select the right db when we don't have to authenticate
72 if {![dict exists $config "requirepass"]} {
73 $client select 9
74 }
75
76 # re-set $srv in the servers list
77 set ::servers [lreplace $::servers end+$level 1 $srv]
78}
79
5eedc9c6
PN
80proc redis_deferring_client {args} {
81 set level 0
82 if {[llength $args] > 0 && [string is integer [lindex $args 0]]} {
83 set level [lindex $args 0]
84 set args [lrange $args 1 end]
85 }
86
87 # create client that defers reading reply
88 set client [redis [srv $level "host"] [srv $level "port"] 1]
89
90 # select the right db and read the response (OK)
91 $client select 9
92 $client read
93 return $client
94}
95
1c4114be
PN
96# Provide easy access to INFO properties. Same semantic as "proc r".
97proc s {args} {
98 set level 0
99 if {[string is integer [lindex $args 0]]} {
100 set level [lindex $args 0]
101 set args [lrange $args 1 end]
102 }
103 status [srv $level "client"] [lindex $args 0]
98578b57
PN
104}
105
f166bb1d 106proc cleanup {} {
69bfffb4 107 puts "Cleanup: warning may take some time..."
c4669d25 108 catch {exec rm -rf {*}[glob tests/tmp/redis.conf.*]}
109 catch {exec rm -rf {*}[glob tests/tmp/server.*]}
f166bb1d
PN
110}
111
9f1ae9ab 112proc execute_everything {} {
faa2a80f 113 if 0 {
3fe40d6e 114 # Use this when hacking on new tests.
115 set ::verbose 1
116 execute_tests "unit/first"
117 return
118 }
119
206d6271 120 execute_tests "unit/printver"
98578b57
PN
121 execute_tests "unit/auth"
122 execute_tests "unit/protocol"
123 execute_tests "unit/basic"
124 execute_tests "unit/type/list"
125 execute_tests "unit/type/set"
126 execute_tests "unit/type/zset"
127 execute_tests "unit/type/hash"
128 execute_tests "unit/sort"
129 execute_tests "unit/expire"
130 execute_tests "unit/other"
c20c189d 131 execute_tests "unit/cas"
5a4f9f27 132 execute_tests "unit/quit"
85ecc65e 133 execute_tests "integration/replication"
53cbf66c 134 execute_tests "integration/aof"
4589a823 135 execute_tests "unit/pubsub"
17daf16f 136 execute_tests "unit/slowlog"
9f1ae9ab
PN
137}
138
139proc main {} {
140 cleanup
141
142 if {[string length $::file] > 0} {
143 foreach {file} [split $::file ,] {
144 execute_tests $file
145 }
146 } else {
147 execute_everything
148 }
e39c8b50
PN
149
150 cleanup
6f8a32d5
PN
151 puts "\n[expr $::num_tests] tests, $::num_passed passed, $::num_failed failed\n"
152 if {$::num_failed > 0} {
153 set curheader ""
154 puts "Failures:"
155 foreach {test} $::tests_failed {
156 set header [lindex $test 0]
157 append header " ("
158 append header [join [lindex $test 1] ","]
159 append header ")"
160
161 if {$curheader ne $header} {
162 set curheader $header
163 puts "\n$curheader:"
164 }
165
166 set name [lindex $test 2]
167 set msg [lindex $test 3]
168 puts "- $name: $msg"
169 }
170
171 puts ""
e39c8b50 172 exit 1
98578b57 173 }
98578b57
PN
174}
175
73bd6c58
PN
176# parse arguments
177for {set j 0} {$j < [llength $argv]} {incr j} {
178 set opt [lindex $argv $j]
179 set arg [lindex $argv [expr $j+1]]
180 if {$opt eq {--tags}} {
181 foreach tag $arg {
182 if {[string index $tag 0] eq "-"} {
183 lappend ::denytags [string range $tag 1 end]
184 } else {
185 lappend ::allowtags $tag
186 }
187 }
188 incr j
4b918769 189 } elseif {$opt eq {--valgrind}} {
190 set ::valgrind 1
9f1ae9ab
PN
191 } elseif {$opt eq {--file}} {
192 set ::file $arg
193 incr j
7d04fc75 194 } elseif {$opt eq {--host}} {
195 set ::external 1
196 set ::host $arg
197 incr j
198 } elseif {$opt eq {--port}} {
199 set ::port $arg
200 incr j
6f8a32d5
PN
201 } elseif {$opt eq {--verbose}} {
202 set ::verbose 1
73bd6c58
PN
203 } else {
204 puts "Wrong argument: $opt"
205 exit 1
206 }
207}
208
436f18b6
PN
209if {[catch { main } err]} {
210 if {[string length $err] > 0} {
211 # only display error when not generated by the test suite
212 if {$err ne "exception"} {
6f8a32d5 213 puts $::errorInfo
436f18b6
PN
214 }
215 exit 1
216 }
217}