Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 225 lines (197 sloc) 8.449 kb
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
1 use v6;
2 use Test;
3
ef215fd lizmat Added tests for possible timeout related problems
lizmat authored
4 plan 41;
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
5
ef215fd lizmat Added tests for possible timeout related problems
lizmat authored
6 diag "{elapsed} starting tests";
7 my $elapsed;
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
8 sub elapsed {
ef215fd lizmat Added tests for possible timeout related problems
lizmat authored
9 state $last = time;
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
10 LEAVE $last = time;
ef215fd lizmat Added tests for possible timeout related problems
lizmat authored
11 return "[{ $elapsed = time - $last }s]";
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
12 }
7cf469f donaldh Enable INET tests on Mac OS X. Extend timeouts for JVM.
donaldh authored
13 my $toolong = 60;
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
14
820912f [t/spec] more smartlinks; less than 100 remain without smartlinks
moritz authored
15 # L<S32::IO/IO::Socket::INET>
16
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
17 # Testing socket must solve 2 problems: find an unused port to bind to,
18 # and fork a client process before the server is blocked in accept().
19
20 my $host = '127.0.0.1'; # or 'localhost' may be friendlier
21
22 # To find an free port, list the ports currently in use.
db10870 [t/spec] patching difficulties spotted by STD
lwall authored
23 my ( @ports, $netstat_cmd, $netstat_pat, $received, $expected );
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
24 given $*OS {
25 when 'linux' {
26 $netstat_cmd = "netstat --tcp --all --numeric";
1c9a698 Moritz Lenz avoid warnings
moritz authored
27 $netstat_pat = rx{ State .+? [ ^^ .+? ':' (\d+) .+? ]+ $ };
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
28 }
7cf469f donaldh Enable INET tests on Mac OS X. Extend timeouts for JVM.
donaldh authored
29 when any 'darwin', 'Mac OS X' {
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
30 $netstat_cmd = "netstat -f inet -p tcp -a -n";
1c9a698 Moritz Lenz avoid warnings
moritz authored
31 $netstat_pat = rx{ [ ^^ .+? '.' (\d+) ' ' .+? ]+ $ };
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
32 }
1f02366 [t/spec/S32-io] Make these tests run on solaris, confirmed passing
carlin authored
33 when 'solaris' {
34 $netstat_cmd = "netstat -an -P tcp -f inet";
1c9a698 Moritz Lenz avoid warnings
moritz authored
35 $netstat_pat = rx{ [ ^^ .+? '.' (\d+) ' ' .+? ]+ $ }; # same as darwin
1f02366 [t/spec/S32-io] Make these tests run on solaris, confirmed passing
carlin authored
36 }
7554daf [t/spec/S32-io] Fix the indenting and whitespace from my previous commit
carlin authored
37 when 'MSWin32' {
38 $netstat_cmd = "netstat -n";
1c9a698 Moritz Lenz avoid warnings
moritz authored
39 $netstat_pat = rx{ State .+? [ ^^ .+? ':' (\d+) .+? ]+ $ }; # same as linux
7554daf [t/spec/S32-io] Fix the indenting and whitespace from my previous commit
carlin authored
40 }
2e0ab17 [t/spec] made Socket test a bit more robust
moritz authored
41 default {
42 skip_rest('Operating system not yet supported');
43 exit 0;
44 }
e7439a1 [t/spec/S32-io] Remove/update some comments
carlin authored
45 # TODO: other operating systems; *BSD etc.
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
46 }
4753f03 fixed a bug in t/S32-io/IO-Socket-INET.t etc where an impatient timeout
mberends authored
47 $received = qqx{$netstat_cmd}; # refactor into 1 line after
a15591d [S32-io/IO-Socket-INET.t,.pl] Rakudo fudge 15 tests that alpha passes bu...
mberends authored
48 if $received ~~ $netstat_pat { @ports = $/.list; } # development complete
49 # was @ports = $/[] in Rakudo/alpha
50 # @ports = $/[0] also now in master
04afe09 [IO-Socket-INET.t] remove developer scaffolding
mberends authored
51 #warn @ports.elems ~ " PORTS=" ~ @ports;
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
52
53 # sequentially search for the first unused port
54 my $port = 1024;
55 while $port < 65535 && $port==any(@ports) { $port++; }
15c1b74 Moritz Lenz [socket] adapt to more p5 like IO::Socket::INET implementation
moritz authored
56 if $port >= 65535 {
57 diag "no free port; aborting";
2e0ab17 [t/spec] made Socket test a bit more robust
moritz authored
58 skip_rest 'No port free - cannot test';
59 exit 0;
60 }
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
61 diag "{elapsed} Testing on port $port";
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
62
63
7cf469f donaldh Enable INET tests on Mac OS X. Extend timeouts for JVM.
donaldh authored
64 if $*OS eq any <linux darwin solaris MSWin32>, 'Mac OS X' { # please add more valid OS names
d48a181 [t/spec/S32-io] Add batch file and allow these tests to run on Windows. ...
carlin authored
65
7554daf [t/spec/S32-io] Fix the indenting and whitespace from my previous commit
carlin authored
66 my $is-win;
67 $is-win = True if $*OS eq 'MSWin32';
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
68
69 # test 2 does echo protocol - Internet RFC 862
7554daf [t/spec/S32-io] Fix the indenting and whitespace from my previous commit
carlin authored
70 if $is-win {
71 $received = qqx{t\\spec\\S32-io\\IO-Socket-INET.bat 2 $port};
72 } else {
73 $received = qqx{sh t/spec/S32-io/IO-Socket-INET.sh 2 $port};
74 }
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
75 #warn "TEST 2 $received";
76 $expected = "echo '0123456789abcdefghijklmnopqrstuvwxyz' received\n";
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
77 is $received, $expected, "{elapsed} echo server and client";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
78 nok $elapsed > $toolong, "finished in time #1";
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
79
80 # test 3 does discard protocol - Internet RFC 863
7554daf [t/spec/S32-io] Fix the indenting and whitespace from my previous commit
carlin authored
81 if $is-win {
82 $received = qqx{t\\spec\\S32-io\\IO-Socket-INET.bat 3 $port};
83 } else {
84 $received = qqx{sh t/spec/S32-io/IO-Socket-INET.sh 3 $port};
85 }
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
86 #warn "TEST 3 $received";
87 $expected = "discard '' received\n";
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
88 is $received, $expected, "{elapsed} discard server and client";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
89 nok $elapsed > $toolong, "finished in time #2";
12cdb6d [t/spec/S32-io] Add (fudged) tests for recv with a parameter
carlin authored
90
91 # test 4 tests recv with a parameter
7554daf [t/spec/S32-io] Fix the indenting and whitespace from my previous commit
carlin authored
92 if $is-win {
93 $received = qqx{t\\spec\\S32-io\\IO-Socket-INET.bat 4 $port};
94 } else {
95 $received = qqx{sh t/spec/S32-io/IO-Socket-INET.sh 4 $port};
d48a181 [t/spec/S32-io] Add batch file and allow these tests to run on Windows. ...
carlin authored
96 }
7554daf [t/spec/S32-io] Fix the indenting and whitespace from my previous commit
carlin authored
97 $expected = $received.split("\n");
12cdb6d [t/spec/S32-io] Add (fudged) tests for recv with a parameter
carlin authored
98 my $i = 0;
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
99 is $expected[$i++], '0123456', "{elapsed} received first 7 characters";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
100 nok $elapsed > $toolong, "finished in time #3";
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
101 is $expected[$i++], '789', "{elapsed} received next 3 characters";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
102 nok $elapsed > $toolong, "finished in time #4";
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
103 is $expected[$i++], 'abcdefghijklmnopqrstuvwxyz', "{elapsed} remaining 26 were buffered";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
104 nok $elapsed > $toolong, "finished in time #5";
12cdb6d [t/spec/S32-io] Add (fudged) tests for recv with a parameter
carlin authored
105 # Multibyte characters
c07dfde Tobias Leich tests for multibyte chars successful
FROGGS authored
106 # RT #115862
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
107 is $expected[$i], chr(0xbeef), "{elapsed} received {chr 0xbeef}";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
108 nok $elapsed > $toolong, "finished in time #6";
3c2dc0e Tobias Leich RT #115862, skipping multibyte tests for release
FROGGS authored
109 $i++;
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
110 is $expected[$i++], 1, "{elapsed} ... which is 1 character";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
111 nok $elapsed > $toolong, "finished in time #7";
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
112 is $expected[$i++], 1, "{elapsed} received another character";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
113 nok $elapsed > $toolong, "finished in time #8";
c07dfde Tobias Leich tests for multibyte chars successful
FROGGS authored
114 # RT #115862
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
115 is $expected[$i], chr(0xbabe), "{elapsed} combined the bytes form {chr 0xbabe}";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
116 nok $elapsed > $toolong, "finished in time #9";
3c2dc0e Tobias Leich RT #115862, skipping multibyte tests for release
FROGGS authored
117 $i++;
096645d [t/spec/S32-io] Add (fudged) tests for IO::Socket.get()
carlin authored
118
119 # test 5 tests get()
7554daf [t/spec/S32-io] Fix the indenting and whitespace from my previous commit
carlin authored
120 if $is-win {
121 $received = qqx{t\\spec\\S32-io\\IO-Socket-INET.bat 5 $port};
122 } else {
123 $received = qqx{sh t/spec/S32-io/IO-Socket-INET.sh 5 $port};
d48a181 [t/spec/S32-io] Add batch file and allow these tests to run on Windows. ...
carlin authored
124 }
7554daf [t/spec/S32-io] Fix the indenting and whitespace from my previous commit
carlin authored
125 $expected = $received.split("\n");
096645d [t/spec/S32-io] Add (fudged) tests for IO::Socket.get()
carlin authored
126 $i = 0;
127 is $expected[$i++], "'Twas brillig, and the slithy toves",
ef215fd lizmat Added tests for possible timeout related problems
lizmat authored
128 "{elapsed} get() with default separator";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
129 nok $elapsed > $toolong, "finished in time #10";
ef215fd lizmat Added tests for possible timeout related problems
lizmat authored
130 is $expected[$i++], 'Did gyre and gimble in the wabe;',
131 "{elapsed} default separator";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
132 nok $elapsed > $toolong, "finished in time #11";
ef215fd lizmat Added tests for possible timeout related problems
lizmat authored
133 is $expected[$i++], 'All mimsy were the borogoves,',
134 "{elapsed} \\r\\n separator";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
135 nok $elapsed > $toolong, "finished in time #12";
ef215fd lizmat Added tests for possible timeout related problems
lizmat authored
136 is $expected[$i++], 'And the mome raths outgrabe',
137 "{elapsed} . as a separator";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
138 nok $elapsed > $toolong, "finished in time #13";
ef215fd lizmat Added tests for possible timeout related problems
lizmat authored
139 is $expected[$i++], 'O frabjous day',
140 "{elapsed} ! separator not at end of string";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
141 nok $elapsed > $toolong, "finished in time #14";
ef215fd lizmat Added tests for possible timeout related problems
lizmat authored
142 is $expected[$i++], ' Callooh',
143 "{elapsed} Multiple separators not at end of string";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
144 nok $elapsed > $toolong, "finished in time #15";
ef215fd lizmat Added tests for possible timeout related problems
lizmat authored
145 is $expected[$i++], ' Callay',
146 "{elapsed} ! separator at end of string";
bbc7541 Tobias Leich RT #116288, test that $socket.read will give us the whole cake
FROGGS authored
147
033cbc9 Tobias Leich RT #116288, linked ticket to test case
FROGGS authored
148 # RT #116288, test 6 tests read with a parameter
bbc7541 Tobias Leich RT #116288, test that $socket.read will give us the whole cake
FROGGS authored
149 if $is-win {
150 $received = qqx{t\\spec\\S32-io\\IO-Socket-INET.bat 6 $port};
151 } else {
152 $received = qqx{sh t/spec/S32-io/IO-Socket-INET.sh 6 $port};
153 }
154 $expected = $received.split("\n");
155 $i = 0;
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
156 is $expected[$i++], '0', "{elapsed} received first character";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
157 nok $elapsed > $toolong, "finished in time #16";
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
158 is $expected[$i++], '3', "{elapsed} received last character";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
159 nok $elapsed > $toolong, "finished in time #17";
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
160 is $expected[$i++], 4096 * 4, "{elapsed} total amount ";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
161 nok $elapsed > $toolong, "finished in time #18";
7bcb012 Tobias Leich tests for binary data
FROGGS authored
162
a793f13 Tobias Leich expect .recv( bin => True ) to return Buf
FROGGS authored
163 # test 7 tests recv with binary data
7bcb012 Tobias Leich tests for binary data
FROGGS authored
164 if $is-win {
165 $received = qqx{t\\spec\\S32-io\\IO-Socket-INET.bat 7 $port};
166 } else {
167 $received = qqx{sh t/spec/S32-io/IO-Socket-INET.sh 7 $port};
168 }
169 $expected = $received.split("\n");
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
170 is $expected[0], 'OK-7', "{elapsed} successful read binary data";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
171 nok $elapsed > $toolong, "finished in time #19";
7bcb012 Tobias Leich tests for binary data
FROGGS authored
172
a793f13 Tobias Leich expect .recv( bin => True ) to return Buf
FROGGS authored
173 # test 8 tests recv with binary data.
7bcb012 Tobias Leich tests for binary data
FROGGS authored
174 if $is-win {
175 $received = qqx{t\\spec\\S32-io\\IO-Socket-INET.bat 8 $port};
176 } else {
177 $received = qqx{sh t/spec/S32-io/IO-Socket-INET.sh 8 $port};
178 }
179 $expected = $received.split("\n");
5c99b82 lizmat Add elapsed time information for debugging
lizmat authored
180 is $expected[0], 'OK-8', "{elapsed} successful received binary data";
d05f498 lizmat Made 'took too long" test comments a bit more understandable
lizmat authored
181 nok $elapsed > $toolong, "finished in time #20";
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
182 }
183 else {
8b5a87e Moritz Lenz reverse order of skip() arguments all over the test suite
moritz authored
184 skip "OS '$*OS' shell support not confirmed", 1;
ba86db9 [t/spec/S32-io/IO-Socket-INET.t] shell script forks client and server
mberends authored
185 }
186
187
188 =begin pod
189
190 =head1 Perl 6 Internet Sockets Testing
191 The initial use of the BSD Sockets library by Parrot and Rakudo happened
192 without a formal test suite, slowing development and causing occasional
193 random errors. This set of tests aims to ensure the future stability of
194 of the Sockets library integration, and to help enhance Rakudo's
195 IO::Socket::INET class in the 'setting'.
196
197 The BSD Sockets functions provide server and client functions that run
198 synchronously, blocking and waiting indefinitely for communication from
199 a remote process. Sockets testing therefore requires separate server and
200 client processes or threads. Rakudo does not currently fork or thread,
201 so these tests employ a unix shell script that uses the & symbol to fork
202 background processes. When Rakudo starts forking or threading, this
203 testing solution should be refactored down to just the main script.
204
205 =head1 Scope of tests
206 To date, only single TCP sessions have been tested, and only on Linux.
207 The Internet standard protocols are used, except that a dynamic port
208 number above the first 1024 is used so that superuser (root) privileges
209 are not required. Execution time is 5 to 10 seconds.
210
211 =head1 TODO
212 UDP. Unix sockets. Concurrent connections (needs threads).
213
214 =head1 SEE ALSO
215
216 echo L<http://www.ietf.org/rfc/rfc862.txt> port 7
217 discard L<http://www.ietf.org/rfc/rfc863.txt> port 9
218 chargen L<http://www.ietf.org/rfc/rfc864.txt> port 19
219 daytime L<http://www.ietf.org/rfc/rfc867.txt> port 13
220 time L<http://www.ietf.org/rfc/rfc868.txt> port 37
221
222 =end pod
2e0ab17 [t/spec] made Socket test a bit more robust
moritz authored
223
224 # vim: ft=perl6
Something went wrong with that request. Please try again.