aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/test/sendfile_SUITE.erl
diff options
context:
space:
mode:
authorJohn Högberg <[email protected]>2017-11-02 21:27:56 +0100
committerJohn Högberg <[email protected]>2017-11-30 15:44:39 +0100
commit8e634f0063acb8009c2afb303111a2fd35aad78b (patch)
tree9f2221d07b699d695e831ed2581753e363ebe80a /lib/kernel/test/sendfile_SUITE.erl
parentc9fc20af633bbdc68206ca7d7438cd803793875f (diff)
downloadotp-8e634f0063acb8009c2afb303111a2fd35aad78b.tar.gz
otp-8e634f0063acb8009c2afb303111a2fd35aad78b.tar.bz2
otp-8e634f0063acb8009c2afb303111a2fd35aad78b.zip
Make file:sendfile/5 follow its documented error behavior
Diffstat (limited to 'lib/kernel/test/sendfile_SUITE.erl')
-rw-r--r--lib/kernel/test/sendfile_SUITE.erl36
1 files changed, 34 insertions, 2 deletions
diff --git a/lib/kernel/test/sendfile_SUITE.erl b/lib/kernel/test/sendfile_SUITE.erl
index 4872ce53b7..0c0b1cbcb6 100644
--- a/lib/kernel/test/sendfile_SUITE.erl
+++ b/lib/kernel/test/sendfile_SUITE.erl
@@ -40,7 +40,8 @@
t_sendfile_sendduring/1,
t_sendfile_recvduring/1,
t_sendfile_closeduring/1,
- t_sendfile_crashduring/1]).
+ t_sendfile_crashduring/1,
+ t_sendfile_arguments/1]).
all() ->
[t_sendfile_small,
@@ -55,7 +56,8 @@ all() ->
t_sendfile_sendduring,
t_sendfile_recvduring,
t_sendfile_closeduring,
- t_sendfile_crashduring].
+ t_sendfile_crashduring,
+ t_sendfile_arguments].
init_per_suite(Config) ->
case {os:type(),os:version()} of
@@ -371,6 +373,36 @@ t_sendfile_crashduring(Config) ->
end
end.
+t_sendfile_arguments(Config) ->
+ Filename = proplists:get_value(small_file, Config),
+
+ {ok, Listener} = gen_tcp:listen(0,
+ [{packet, 0}, {active, false}, {reuseaddr, true}]),
+ {ok, Port} = inet:port(Listener),
+
+ ErrorCheck =
+ fun(Reason, Offset, Length, Opts) ->
+ {ok, Sender} = gen_tcp:connect({127, 0, 0, 1}, Port,
+ [{packet, 0}, {active, false}]),
+ {ok, Receiver} = gen_tcp:accept(Listener),
+ {ok, Fd} = file:open(Filename, [read, raw]),
+ {error, Reason} = file:sendfile(Fd, Sender, Offset, Length, Opts),
+ gen_tcp:close(Receiver),
+ gen_tcp:close(Sender),
+ file:close(Fd)
+ end,
+
+ ErrorCheck(einval, -1, 0, []),
+ ErrorCheck(einval, 0, -1, []),
+ ErrorCheck(badarg, gurka, 0, []),
+ ErrorCheck(badarg, 0, gurka, []),
+ ErrorCheck(badarg, 0, 0, gurka),
+ ErrorCheck(badarg, 0, 0, [{chunk_size, gurka}]),
+
+ gen_tcp:close(Listener),
+
+ ok.
+
%% Generic sendfile server code
sendfile_send(Send) ->
sendfile_send({127,0,0,1},Send).