Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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