diff --git a/lib/stdlib/test/zip_SUITE.erl b/lib/stdlib/test/zip_SUITE.erl index d42964cd25f0..7f06a04212d6 100644 --- a/lib/stdlib/test/zip_SUITE.erl +++ b/lib/stdlib/test/zip_SUITE.erl @@ -99,36 +99,42 @@ zip64_testcases() -> zip64_central_directory]. init_per_suite(Config) -> - Config. + {ok, Started} = application:ensure_all_started(os_mon), + [{started, Started} | Config]. -end_per_suite(_Config) -> +end_per_suite(Config) -> + [application:stop(App) || App <- lists:reverse(get_value(started, Config))], ok. init_per_group(zip64_group, Config) -> PrivDir = get_value(priv_dir, Config), - 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]; + case disc_free(PrivDir) of + 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]), + 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]), + {skip,"Less than 16 GByte free"} + end; init_per_group(Group, Config) -> case lists:member(Group, ?ZIP_MODES ++ ?UNZIP_MODES ++ z64(?ZIP_MODES ++ ?UNZIP_MODES)) of true -> case get_value(zip, Config) of undefined -> - [throw({skip, "zip does not support zip64"}) || - Group =:= zip andalso - get_value(large,Config) =/= undefined andalso - os:cmd("zip -v | grep ZIP64_SUPPORT") == ""], - ct:print("Zip: ~p", [Group]), Pdir = filename:join(get_value(priv_dir, Config),Group), ok = filelib:ensure_path(Pdir), [{pdir, Pdir},{zip, noz64(Group)} | Config]; _Zip -> - ct:print("UnZip: ~p", [Group]), Pdir = filename:join(get_value(pdir, Config),Group), ok = filelib:ensure_path(Pdir), [{pdir, Pdir},{unzip, noz64(Group)} | Config] @@ -138,12 +144,24 @@ init_per_group(Group, Config) -> end. end_per_group(_GroupName, Config) -> + file:del_dir_r(get_value(pdir,Config)), Config. init_per_testcase(TC, Config) -> - PrivDir = filename:join(get_value(pdir, Config,get_value(priv_dir, Config)), TC), - ok = filelib:ensure_path(PrivDir), - [{pdir, PrivDir} | Config]. + UsesZip = get_value(zip, Config) =:= zip orelse get_value(unzip, Config) =:= unzip, + HasZip = has_zip(), + UsesEMZip = get_value(zip, Config) =:= emzip orelse get_value(unzip, Config) =:= unemzip, + Memsize = memsize(), + if UsesZip andalso not HasZip -> + {skip, "No zip command found"}; + UsesEMZip andalso Memsize < 8 bsl 30 -> + {skip, "Testing emzip needs more that 8 GB of memory"}; + true -> + PrivDir = filename:join(get_value(pdir, Config,get_value(priv_dir, Config)), TC), + ok = filelib:ensure_path(PrivDir), + [{pdir, PrivDir} | Config] + end. + end_per_testcase(_TC, Config) -> file:del_dir_r(get_value(pdir,Config)), @@ -1617,3 +1635,27 @@ cmd(Cmd) -> Res = os:cmd(Cmd), ct:log("Cmd: ~ts~nRes: ~ts~n",[Cmd, Res]), Res. + +disc_free(Path) -> + Data = disksup:get_disk_data(), + + %% What partitions could Data be mounted on? + Partitions = + [D || {P, _Tot, _Perc}=D <- Data, + lists:prefix(filename:nativename(P), filename:nativename(Path))], + + %% Sorting in descending order places the partition with the most specific + %% path first. + case lists:sort(fun erlang:'>='/2, Partitions) of + [{_,Tot, Perc} | _] -> round(Tot * (1-(Perc/100))); + [] -> error + end. + +memsize() -> + case proplists:get_value(available_memory, memsup:get_system_memory_data()) of + undefined -> + {Tot,_Used,_} = memsup:get_memory_data(), + Tot; + Available -> + Available + end.