Skip to content

Commit

Permalink
zip: Fix testcase on 32-bit and bsd
Browse files Browse the repository at this point in the history
  • Loading branch information
garazdawi committed Jun 8, 2024
1 parent 5f3df01 commit b94d382
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions lib/stdlib/test/zip_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,24 @@ end_per_suite(Config) ->
init_per_group(zip64_group, Config) ->
PrivDir = get_value(priv_dir, Config),

case disc_free(PrivDir) of
error ->
case {erlang:system_info(wordsize), disc_free(PrivDir), memsize()} of
{4, _, _} ->
{skip, "Zip64 tests only work on 64-bit systems"};
{8, error, _} ->
{skip, "Failed to query disk space for priv_dir. "
"Is it on a remote file system?~n"};
N when N >= 16 * (1 bsl 20) ->
ct:pal("Free disk: ~w KByte~n", [N]),
{8, N,M} when N >= 16 * (1 bsl 20), M >= 6 * (1 bsl 30) ->
ct:log("Free disk: ~w KByte~n", [N]),
OneMB = <<0:(8 bsl 20)>>,
Large4GB = filename:join(PrivDir, "large.txt"),
ok = file:write_file(Large4GB, lists:duplicate(4 bsl 10, OneMB)),
Medium4MB = filename:join(PrivDir, "medium.txt"),
ok = file:write_file(Medium4MB, lists:duplicate(4, OneMB)),

[{large, Large4GB},{medium,Medium4MB}|Config];
N when N < 16 * (1 bsl 20) ->
ct:pal("Free disk: ~w KByte~n", [N]),
{8,N,M} when N < 16 * (1 bsl 20) ->
ct:log("Free disk: ~w KByte~n", [N]),
ct:log("Free memory: ~w Byte~n", [M]),
{skip,"Less than 16 GByte free"}
end;
init_per_group(Group, Config) ->
Expand Down Expand Up @@ -1634,7 +1637,30 @@ unzip(unemzip, Archive, Opts) ->
end || {F, B} <- Files])}.

cmp(Source, Target) ->
"" = cmd("cmp --silent "++Source++" "++Target++~s' || echo "files are different"').
{ok, SrcInfo} = file:read_file_info(Source),
{ok, TgtInfo} = file:read_file_info(Target),
?assertEqual(SrcInfo#file_info.size, TgtInfo#file_info.size),
?assertEqual(SrcInfo#file_info.mode, TgtInfo#file_info.mode),

{ok, Src} = file:open(Source, [read, binary]),
{ok, Tgt} = file:open(Target, [read, binary]),

cmp(Src, Tgt, 0),

file:close(Src),
file:close(Tgt).

%% Check if first 100 MB are the same
cmp(Src, Tgt, Pos) when Pos < 100 bsl 20 ->

case {file:read(Src, 20 bsl 20), file:read(Tgt, 20 bsl 20)} of
{{ok, Data}, {ok, Data}} ->
cmp(Src, Tgt, Pos + 20 bsl 20);
{E, E} ->
ok
end;
cmp(_Src, _Tgt, _) ->
ok.

cmd(Cmd) ->
Res = os:cmd(Cmd),
Expand Down

0 comments on commit b94d382

Please sign in to comment.