annotate image_filter_webp.t @ 1236:93f749c1d5c5

Tests: fixed parallel tests execution with UDP. Previously, when checking ports availability, a UDP socket was always created first, then a TCP socket was created. On success, one of UDP and TCP sockets was closed (depending on the "udp" option) and the second one was used to busy this port in other scripts. This lead to the following problem: in an attempt to reopen a UDP socket used in a given testing script it could be stolen by another script as part of checking ports availability. To solve this problem, UDP and TCP ports were split into two non-overlapping ranges: TCP ports are only used in the range 8000-8499, and UDP ports - in the range 8500-8999. In addition, the order of creating sockets in UDP tests has been reversed: now a TCP socket used as a lock precedes a UDP socket.
author Andrey Zelenkov <zelenkov@nginx.com>
date Thu, 26 Oct 2017 18:00:21 +0300
parents 37c18a92115b
children 766bcbb632ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1072
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for image filter module, WebP support.
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http image_filter/)
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 ->write_file_expand('nginx.conf', <<'EOF');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 %%TEST_GLOBALS%%
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 daemon off;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 events {
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 }
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 http {
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 %%TEST_GLOBALS_HTTP%%
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 server {
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 listen 127.0.0.1:8080;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 server_name localhost;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 location /size {
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 image_filter size;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 alias %%TESTDIR%%/;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 }
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 location /test {
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 image_filter test;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 alias %%TESTDIR%%/;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 }
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 location /resize {
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 image_filter resize 1 1;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 alias %%TESTDIR%%/;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 }
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 location /quality {
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 image_filter rotate 90;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 image_filter_webp_quality 50;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 alias %%TESTDIR%%/;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 }
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 location /quality_var {
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 image_filter rotate 90;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 image_filter_webp_quality $arg_q;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 alias %%TESTDIR%%/;
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 }
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 }
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 }
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 EOF
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 $t->try_run('no WebP support')->plan(18);
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 $t->write_file('webp', pack("A4LA8", "RIFF", 0x22, "WEBPVP8 ") .
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 pack("N4", 0x16000000, 0x3001009d, 0x012a0100, 0x01000ec0) .
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 pack("N2n", 0xfe25a400, 0x03700000, 0x0000));
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 $t->write_file('webpl', pack("A4LA8", "RIFF", 0x1a, "WEBPVP8L") .
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 pack("N4n", 0x0d000000, 0x2f000000, 0x10071011, 0x118888fe, 0x0700));
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 $t->write_file('webpx', pack("A4LA8", "RIFF", 0x4a, "WEBPVP8X") .
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 pack("N4", 0x0a000000, 0x10000000, 0x00000000, 0x0000414c) .
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 pack("N4", 0x50480c00, 0x00001107, 0x1011fd0f, 0x4444ff03) .
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 pack("N4", 0x00005650, 0x38201800, 0x00001401, 0x009d012a) .
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 pack("N4n", 0x01000100, 0x0000fe00, 0x000dc000, 0xfee6b500, 0x0000));
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 $t->write_file('webperr', pack("A4LA8", "RIFF", 0x22, "WEBPERR ") .
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 pack("N4", 0x16000000, 0x3001009d, 0x012a0100, 0x01000ec0) .
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 pack("N2n", 0xfe25a400, 0x03700000, 0x0000));
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 $t->write_file('webptrunc', substr $t->read_file('webp'), 0, 29);
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 ###############################################################################
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 my $r = http_get('/test/webp');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 like($r, qr!Content-Type: image/webp!, 'content-type');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 like($r, qr/RIFF/, 'content');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 $r = http_get('/size/webp');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 like($r, qr/"type": "webp"/, 'size type');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 like($r, qr/"width": 1/, 'size width');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 like($r, qr/"height": 1/, 'size height');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 # lossless
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 $r = http_get('/size/webpl');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 like($r, qr/"type": "webp"/, 'lossless type');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 like($r, qr/"width": 1/, 'lossless width');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 like($r, qr/"height": 1/, 'lossless height');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 # extended
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 $r = http_get('/size/webpx');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 like($r, qr/"type": "webp"/, 'extended type');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 like($r, qr/"width": 1/, 'extended width');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 like($r, qr/"height": 1/, 'extended height');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 # transforms, libgd may have no WebP support
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 like(http_get('/quality/webp'), qr/RIFF|415/, 'quality');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 like(http_get('/quality_var/webp?q=40'), qr/RIFF|415/, 'quality var');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 like(http_get('/resize/webp'), qr/RIFF/, 'resize as is');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 # generic error handling
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 like(http_get('/quality/webperr'), qr/415 Unsupported/, 'bad header');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 like(http_get('/quality/webptrunc'), qr/415 Unsupported/, 'truncated');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 like(http_get('/size/webperr'), qr/{}/, 'size - bad header');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 like(http_get('/size/webptrunc'), qr/{}/, 'size - truncated');
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128
37c18a92115b Tests: basic WebP tests in image filter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 ###############################################################################