~simonkberg/nginx/debian-1.6.2-5

« back to all changes in this revision

Viewing changes to debian/modules/nginx-lua/t/047-match-jit.t

  • Committer: root
  • Date: 2015-01-12 11:50:11 UTC
  • Revision ID: root@server205.kberg.eu-20150112115011-jh2tdvt9ey1itt3g
import from anonscm.debian.org

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim:set ft= ts=4 sw=4 et fdm=marker:
 
2
use lib 'lib';
 
3
use Test::Nginx::Socket::Lua;
 
4
 
 
5
#worker_connections(1014);
 
6
#master_on();
 
7
#workers(2);
 
8
#log_level('warn');
 
9
 
 
10
repeat_each(2);
 
11
 
 
12
plan tests => repeat_each() * (blocks() * 2 + 5);
 
13
 
 
14
#no_diff();
 
15
no_long_string();
 
16
run_tests();
 
17
 
 
18
__DATA__
 
19
 
 
20
=== TEST 1: matched with j
 
21
--- config
 
22
    location /re {
 
23
        content_by_lua '
 
24
            m = ngx.re.match("hello, 1234", "([0-9]+)", "j")
 
25
            if m then
 
26
                ngx.say(m[0])
 
27
            else
 
28
                ngx.say("not matched!")
 
29
            end
 
30
        ';
 
31
    }
 
32
--- request
 
33
    GET /re
 
34
--- response_body
 
35
1234
 
36
--- error_log
 
37
pcre JIT compiling result: 1
 
38
 
 
39
 
 
40
 
 
41
=== TEST 2: not matched with j
 
42
--- config
 
43
    location /re {
 
44
        content_by_lua '
 
45
            m = ngx.re.match("hello, world", "([0-9]+)", "j")
 
46
            if m then
 
47
                ngx.say(m[0])
 
48
            else
 
49
                ngx.say("not matched!")
 
50
            end
 
51
        ';
 
52
    }
 
53
--- request
 
54
    GET /re
 
55
--- response_body
 
56
not matched!
 
57
--- error_log
 
58
pcre JIT compiling result: 1
 
59
 
 
60
 
 
61
 
 
62
=== TEST 3: matched with jo
 
63
--- config
 
64
    location /re {
 
65
        content_by_lua '
 
66
            m = ngx.re.match("hello, 1234", "([0-9]+)", "jo")
 
67
            if m then
 
68
                ngx.say(m[0])
 
69
            else
 
70
                ngx.say("not matched!")
 
71
            end
 
72
        ';
 
73
    }
 
74
--- request
 
75
    GET /re
 
76
--- response_body
 
77
1234
 
78
 
 
79
--- grep_error_log eval
 
80
qr/pcre JIT compiling result: \d+/
 
81
 
 
82
--- grep_error_log_out eval
 
83
["pcre JIT compiling result: 1\n", ""]
 
84
 
 
85
 
 
86
 
 
87
=== TEST 4: not matched with jo
 
88
--- config
 
89
    location /re {
 
90
        content_by_lua '
 
91
            m = ngx.re.match("hello, world", "([0-9]+)", "jo")
 
92
            if m then
 
93
                ngx.say(m[0])
 
94
            else
 
95
                ngx.say("not matched!")
 
96
            end
 
97
        ';
 
98
    }
 
99
--- request
 
100
    GET /re
 
101
--- response_body
 
102
not matched!
 
103
 
 
104
--- grep_error_log eval
 
105
qr/pcre JIT compiling result: \d+/
 
106
 
 
107
--- grep_error_log_out eval
 
108
["pcre JIT compiling result: 1\n", ""]
 
109
 
 
110
 
 
111
 
 
112
=== TEST 5: bad pattern
 
113
--- config
 
114
    location /re {
 
115
        content_by_lua '
 
116
            local m, err = ngx.re.match("hello\\nworld", "(abc", "j")
 
117
            if m then
 
118
                ngx.say(m[0])
 
119
 
 
120
            else
 
121
                if err then
 
122
                    ngx.say("error: ", err)
 
123
 
 
124
                else
 
125
                    ngx.say("not matched: ", m)
 
126
                end
 
127
            end
 
128
        ';
 
129
    }
 
130
--- request
 
131
    GET /re
 
132
--- response_body
 
133
error: pcre_compile() failed: missing ) in "(abc"
 
134
--- no_error_log
 
135
[error]
 
136
 
 
137
 
 
138
 
 
139
=== TEST 6: just hit match limit
 
140
--- http_config
 
141
    lua_regex_match_limit 2940;
 
142
--- config
 
143
    location /re {
 
144
        content_by_lua_file html/a.lua;
 
145
    }
 
146
 
 
147
--- user_files
 
148
>>> a.lua
 
149
local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
 
150
 
 
151
s = string.rep([[ABCDEFG]], 21)
 
152
 
 
153
local start = ngx.now()
 
154
 
 
155
local res, err = ngx.re.match(s, re, "jo")
 
156
 
 
157
--[[
 
158
ngx.update_time()
 
159
local elapsed = ngx.now() - start
 
160
ngx.say(elapsed, " sec elapsed.")
 
161
]]
 
162
 
 
163
if not res then
 
164
    if err then
 
165
        ngx.say("error: ", err)
 
166
        return
 
167
    end
 
168
    ngx.say("failed to match")
 
169
    return
 
170
end
 
171
 
 
172
--- request
 
173
    GET /re
 
174
--- response_body
 
175
error: pcre_exec() failed: -8
 
176
 
 
177
 
 
178
 
 
179
=== TEST 7: just not hit match limit
 
180
--- http_config
 
181
    lua_regex_match_limit 2950;
 
182
--- config
 
183
    location /re {
 
184
        content_by_lua_file html/a.lua;
 
185
    }
 
186
 
 
187
--- user_files
 
188
>>> a.lua
 
189
local re = [==[(?i:([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:=|<=>|r?like|sounds\s+like|regexp)([\s'\"`´’‘\(\)]*)?\2|([\s'\"`´’‘\(\)]*)?([\d\w]+)([\s'\"`´’‘\(\)]*)?(?:!=|<=|>=|<>|<|>|\^|is\s+not|not\s+like|not\s+regexp)([\s'\"`´’‘\(\)]*)?(?!\6)([\d\w]+))]==]
 
190
 
 
191
s = string.rep([[ABCDEFG]], 21)
 
192
 
 
193
local start = ngx.now()
 
194
 
 
195
local res, err = ngx.re.match(s, re, "jo")
 
196
 
 
197
--[[
 
198
ngx.update_time()
 
199
local elapsed = ngx.now() - start
 
200
ngx.say(elapsed, " sec elapsed.")
 
201
]]
 
202
 
 
203
if not res then
 
204
    if err then
 
205
        ngx.say("error: ", err)
 
206
        return
 
207
    end
 
208
    ngx.say("failed to match")
 
209
    return
 
210
end
 
211
 
 
212
--- request
 
213
    GET /re
 
214
--- response_body
 
215
failed to match
 
216