4
%% Copyright Ericsson AB 2000-2009. All Rights Reserved.
4
%% Copyright Ericsson AB 2000-2011. All Rights Reserved.
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
19
19
-module(prim_file_SUITE).
22
read_write_file/1, dirs/1, files/1]).
20
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
21
init_per_group/2,end_per_group/2,
23
23
-export([cur_dir_0a/1, cur_dir_0b/1,
24
24
cur_dir_1a/1, cur_dir_1b/1,
25
25
make_del_dir_a/1, make_del_dir_b/1,
26
pos/1, pos1/1, pos2/1]).
28
28
delete_a/1, delete_b/1]).
29
-export([open/1, open1/1, modes/1]).
31
file_info_basic_file_a/1, file_info_basic_file_b/1,
32
file_info_basic_directory_a/1, file_info_basic_directory_b/1,
33
file_info_bad_a/1, file_info_bad_b/1,
34
file_info_times_a/1, file_info_times_b/1,
35
file_write_file_info_a/1, file_write_file_info_b/1]).
29
-export([ open1/1, modes/1]).
31
file_info_basic_file_a/1, file_info_basic_file_b/1,
32
file_info_basic_directory_a/1, file_info_basic_directory_b/1,
33
file_info_bad_a/1, file_info_bad_b/1,
34
file_info_times_a/1, file_info_times_b/1,
35
file_write_file_info_a/1, file_write_file_info_b/1]).
36
36
-export([rename_a/1, rename_b/1,
37
access/1, truncate/1, sync/1,
38
read_write/1, pread_write/1, append/1]).
39
-export([errors/1, e_delete/1, e_rename/1, e_make_dir/1, e_del_dir/1]).
41
-export([compression/1, read_not_really_compressed/1,
42
read_compressed/1, write_compressed/1,
46
make_link_a/1, make_link_b/1,
47
read_link_info_for_non_link/1,
48
symlinks_a/1, symlinks_b/1,
51
-include("test_server.hrl").
37
access/1, truncate/1, datasync/1, sync/1,
38
read_write/1, pread_write/1, append/1, exclusive/1]).
39
-export([ e_delete/1, e_rename/1, e_make_dir/1, e_del_dir/1]).
41
-export([ read_not_really_compressed/1,
42
read_compressed/1, write_compressed/1,
46
make_link_a/1, make_link_b/1,
47
read_link_info_for_non_link/1,
48
symlinks_a/1, symlinks_b/1,
53
-include_lib("test_server/include/test_server.hrl").
52
54
-include_lib("kernel/include/file.hrl").
54
56
-define(PRIM_FILE, prim_file).
65
67
_ -> apply(?PRIM_FILE, F, [H | A])
68
all(suite) -> {req, [kernel],
70
[read_write_file, dirs, files,
71
delete_a, delete_b, rename_a, rename_b, errors,
72
compression, links, list_dir_limit],
75
init(Config) when is_list(Config) ->
70
suite() -> [{ct_hooks,[ts_install_cth]}].
73
[read_write_file, {group, dirs}, {group, files},
74
delete_a, delete_b, rename_a, rename_b, {group, errors},
75
{group, compression}, {group, links}, list_dir_limit].
79
[make_del_dir_a, make_del_dir_b, cur_dir_0a, cur_dir_0b,
80
cur_dir_1a, cur_dir_1b]},
82
[{group, open}, {group, pos}, {group, file_info},
83
truncate, sync, datasync, advise]},
85
[open1, modes, close, access, read_write, pread_write,
87
{pos, [], [pos1, pos2]},
89
[file_info_basic_file_a, file_info_basic_file_b,
90
file_info_basic_directory_a,
91
file_info_basic_directory_b, file_info_bad_a,
92
file_info_bad_b, file_info_times_a, file_info_times_b,
93
file_write_file_info_a, file_write_file_info_b]},
95
[e_delete, e_rename, e_make_dir, e_del_dir]},
97
[read_compressed, read_not_really_compressed,
98
write_compressed, compress_errors]},
100
[make_link_a, make_link_b, read_link_info_for_non_link,
101
symlinks_a, symlinks_b]}].
103
init_per_group(_GroupName, Config) ->
106
end_per_group(_GroupName, Config) ->
110
init_per_suite(Config) when is_list(Config) ->
78
113
Priv = ?config(priv_dir, Config),
243
275
%% Try deleting some bad directories
244
276
%% Deleting the parent directory to the current, sounds dangerous, huh?
245
277
%% Don't worry ;-) the parent directory should never be empty, right?
246
?line {error, eexist} = ?PRIM_FILE_call(del_dir, Handle, [".."]),
278
case ?PRIM_FILE_call(del_dir, Handle, [".."]) of
279
{error, eexist} -> ok;
280
{error, einval} -> ok %FreeBSD
247
282
?line {error, enoent} = ?PRIM_FILE_call(del_dir, Handle, [""]),
248
283
?line {error, badarg} = ?PRIM_FILE_call(del_dir, Handle, [[3,2,1,{}]]),
605
637
?line test_server:timetrap_cancel(Dog),
640
exclusive(suite) -> [];
641
exclusive(doc) -> "Test exclusive access to a file.";
642
exclusive(Config) when is_list(Config) ->
643
?line Dog = test_server:timetrap(test_server:seconds(5)),
644
?line RootDir = ?config(priv_dir,Config),
645
?line NewDir = filename:join(RootDir,
646
atom_to_list(?MODULE)
648
?line ok = ?PRIM_FILE:make_dir(NewDir),
649
?line Name = filename:join(NewDir, "ex_file.txt"),
650
?line {ok,Fd} = ?PRIM_FILE:open(Name, [write, exclusive]),
651
?line {error, eexist} = ?PRIM_FILE:open(Name, [write, exclusive]),
652
?line ok = ?PRIM_FILE:close(Fd),
653
?line test_server:timetrap_cancel(Dog),
608
656
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
610
pos(suite) -> [pos1,pos2].
612
659
pos1(suite) -> [];
1141
advise(suite) -> [];
1142
advise(doc) -> "Tests that ?PRIM_FILE:advise/4 at least doesn't crash.";
1143
advise(Config) when is_list(Config) ->
1144
?line Dog = test_server:timetrap(test_server:seconds(5)),
1145
?line PrivDir = ?config(priv_dir, Config),
1146
?line Advise = filename:join(PrivDir,
1147
atom_to_list(?MODULE)
1153
?line {ok, Fd} = ?PRIM_FILE:open(Advise, [write]),
1154
?line ok = ?PRIM_FILE:advise(Fd, 0, 0, normal),
1155
?line ok = ?PRIM_FILE:write(Fd, Line1),
1156
?line ok = ?PRIM_FILE:write(Fd, Line2),
1157
?line ok = ?PRIM_FILE:close(Fd),
1159
?line {ok, Fd2} = ?PRIM_FILE:open(Advise, [write]),
1160
?line ok = ?PRIM_FILE:advise(Fd2, 0, 0, random),
1161
?line ok = ?PRIM_FILE:write(Fd2, Line1),
1162
?line ok = ?PRIM_FILE:write(Fd2, Line2),
1163
?line ok = ?PRIM_FILE:close(Fd2),
1165
?line {ok, Fd3} = ?PRIM_FILE:open(Advise, [write]),
1166
?line ok = ?PRIM_FILE:advise(Fd3, 0, 0, sequential),
1167
?line ok = ?PRIM_FILE:write(Fd3, Line1),
1168
?line ok = ?PRIM_FILE:write(Fd3, Line2),
1169
?line ok = ?PRIM_FILE:close(Fd3),
1171
?line {ok, Fd4} = ?PRIM_FILE:open(Advise, [write]),
1172
?line ok = ?PRIM_FILE:advise(Fd4, 0, 0, will_need),
1173
?line ok = ?PRIM_FILE:write(Fd4, Line1),
1174
?line ok = ?PRIM_FILE:write(Fd4, Line2),
1175
?line ok = ?PRIM_FILE:close(Fd4),
1177
?line {ok, Fd5} = ?PRIM_FILE:open(Advise, [write]),
1178
?line ok = ?PRIM_FILE:advise(Fd5, 0, 0, dont_need),
1179
?line ok = ?PRIM_FILE:write(Fd5, Line1),
1180
?line ok = ?PRIM_FILE:write(Fd5, Line2),
1181
?line ok = ?PRIM_FILE:close(Fd5),
1183
?line {ok, Fd6} = ?PRIM_FILE:open(Advise, [write]),
1184
?line ok = ?PRIM_FILE:advise(Fd6, 0, 0, no_reuse),
1185
?line ok = ?PRIM_FILE:write(Fd6, Line1),
1186
?line ok = ?PRIM_FILE:write(Fd6, Line2),
1187
?line ok = ?PRIM_FILE:close(Fd6),
1189
?line {ok, Fd7} = ?PRIM_FILE:open(Advise, [write]),
1190
?line {error, einval} = ?PRIM_FILE:advise(Fd7, 0, 0, bad_advise),
1191
?line ok = ?PRIM_FILE:close(Fd7),
1193
%% test write without advise, then a read after an advise
1194
?line {ok, Fd8} = ?PRIM_FILE:open(Advise, [write]),
1195
?line ok = ?PRIM_FILE:write(Fd8, Line1),
1196
?line ok = ?PRIM_FILE:write(Fd8, Line2),
1197
?line ok = ?PRIM_FILE:close(Fd8),
1198
?line {ok, Fd9} = ?PRIM_FILE:open(Advise, [read]),
1200
%% same as a 0 length in some implementations
1201
Length = length(Line1) + length(Line2),
1202
?line ok = ?PRIM_FILE:advise(Fd9, Offset, Length, sequential),
1203
?line {ok, Line1} = ?PRIM_FILE:read_line(Fd9),
1204
?line {ok, Line2} = ?PRIM_FILE:read_line(Fd9),
1205
?line eof = ?PRIM_FILE:read_line(Fd9),
1206
?line ok = ?PRIM_FILE:close(Fd9),
1208
?line test_server:timetrap_cancel(Dog),
1082
1212
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1084
1214
delete_a(suite) -> [];