From b94d3826380c9143390871cfbc1f6ebc7a23d2a3 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Wed, 5 Jun 2024 14:40:14 +0200 Subject: [PATCH] zip: Fix testcase on 32-bit and bsd --- lib/stdlib/test/zip_SUITE.erl | 40 +++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/lib/stdlib/test/zip_SUITE.erl b/lib/stdlib/test/zip_SUITE.erl index 8db0d2f554d5..80919febd711 100644 --- a/lib/stdlib/test/zip_SUITE.erl +++ b/lib/stdlib/test/zip_SUITE.erl @@ -114,12 +114,14 @@ 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)), @@ -127,8 +129,9 @@ init_per_group(zip64_group, Config) -> 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) -> @@ -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),