From a89ed3d94f3966d07a061fe540a87db15357e4d2 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Tue, 12 Feb 2013 20:00:09 +0100 Subject: [sasl] Update example/target_system.erl to handle unicode This example module can now create and install a release in a directory which contains unicode characters. The erlang node must be started with the +fnu* switch for this work. --- lib/sasl/test/release_handler_SUITE.erl | 95 +++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 9 deletions(-) (limited to 'lib/sasl/test') diff --git a/lib/sasl/test/release_handler_SUITE.erl b/lib/sasl/test/release_handler_SUITE.erl index a56924d5ca..f103537142 100644 --- a/lib/sasl/test/release_handler_SUITE.erl +++ b/lib/sasl/test/release_handler_SUITE.erl @@ -50,7 +50,7 @@ unix_cases() -> true -> [{group, release}]; false -> [no_run_erl] end, - [target_system] ++ RunErlCases ++ cases(). + [target_system, target_system_unicode] ++ RunErlCases ++ cases(). win32_cases() -> [{group,release} | cases()]. @@ -1559,6 +1559,9 @@ eval_appup_with_restart(Conf) when is_list(Conf) -> %% Test the example/target_system.erl module target_system(Conf) when is_list(Conf) -> PrivDir = priv_dir(Conf), + target_system1(Conf,PrivDir). + +target_system1(Conf,PrivDir) -> DataDir = ?config(data_dir,Conf), TargetCreateDir = filename:join([PrivDir,"target_system","create"]), @@ -1567,7 +1570,6 @@ target_system(Conf) when is_list(Conf) -> ok = filelib:ensure_dir(filename:join(TargetCreateDir,"xx")), ok = filelib:ensure_dir(filename:join(TargetInstallDir,"xx")), - %% Create the .rel file RelName = filename:join(TargetCreateDir,"ts-1.0"), RelFile = RelName++".rel", @@ -1607,7 +1609,8 @@ target_system(Conf) when is_list(Conf) -> StdlibVsn = vsn(stdlib,current), SaslVsn = vsn(sasl,current), RelFileBasename = filename:basename(RelFile), - true = filelib:is_dir(filename:join(LibDir,"kernel-"++KernelVsn)), + KernelLibDir = filename:join(LibDir,"kernel-"++KernelVsn), + true = filelib:is_dir(KernelLibDir), true = filelib:is_dir(filename:join(LibDir,"stdlib-"++StdlibVsn)), true = filelib:is_dir(filename:join(LibDir,"sasl-"++SaslVsn)), true = filelib:is_dir(filename:join(LibDir,"a-1.0")), @@ -1616,11 +1619,13 @@ target_system(Conf) when is_list(Conf) -> true = filelib:is_regular(filename:join(RelDir,"start_erl.data")), true = filelib:is_regular(filename:join(RelDir,RelFileBasename)), true = filelib:is_dir(filename:join(RelDir,RelVsn)), - true = filelib:is_regular(filename:join([RelDir,RelVsn,"start.boot"])), + StartBoot = filename:join([RelDir,RelVsn,"start.boot"]), + true = filelib:is_regular(StartBoot), true = filelib:is_regular(filename:join([RelDir,RelVsn,RelFileBasename])), BinDir = filename:join(TargetInstallDir,bin), + Erl = filename:join(BinDir,erl), + true = filelib:is_regular(Erl), true = filelib:is_regular(filename:join(BinDir,"start.boot")), - true = filelib:is_regular(filename:join(BinDir,erl)), true = filelib:is_regular(filename:join(BinDir,start_erl)), true = filelib:is_regular(filename:join(BinDir,start)), true = filelib:is_regular(filename:join(BinDir,epmd)), @@ -1631,9 +1636,81 @@ target_system(Conf) when is_list(Conf) -> ErtsVsn = vsn(erts,current), {ok,SED} = file:read_file(filename:join(RelDir,"start_erl.data")), [ErtsVsn,RelVsn] = string:tokens(binary_to_list(SED),"\s\n"), + + %% Check that installation can be started + Sname = list_to_atom(atom_to_list(?MODULE) ++ "-target_system"), + {ok,Node} = start_target_node_with_erl(Erl,Sname,StartBoot), + + TargetInstallDir = rpc:call(Node,code,root_dir,[]), + KernelLibDir = rpc:call(Node,code,lib_dir,[kernel]), + [{RelName,RelVsn,_Apps,permanent}] = + rpc:call(Node,release_handler,which_releases,[]), + + ?t:format("Target node ok:~nRootDir: ~ts~nKernelLibDir: ~ts~nRelease: ~ts", + [TargetInstallDir,KernelLibDir,RelName]), + ok. +target_system(cleanup,_Conf) -> + Sname = list_to_atom(atom_to_list(?MODULE) ++ "-target_system"), + stop_target_node(node_name(Sname)), + ok. +start_target_node_with_erl(Erl,Sname,Boot) -> + FullName = node_name(Sname), + FilenameMode = case file:native_name_encoding() of + latin1 -> "+fnl"; + utf8 -> "+fnui" + end, + Args = [FilenameMode,"-detached", "-noinput","-sname",atom_to_list(Sname), + "-boot",filename:rootname(Boot)], + ?t:format("Starting node ~p: ~ts~n", + [FullName, lists:flatten([[X," "] || X <- [Erl|Args]])]), + ?t:format("open_port({spawn_executable, ~tp}, [{args,~p}])~n",[Erl,Args]), + case open_port({spawn_executable, Erl}, [{args,Args}]) of + Port when is_port(Port) -> + unlink(Port), + erlang:port_close(Port), + %% timer:sleep(10000), + %% io:format("PING: ~p~n",[net_adm:ping(FullName)]), + ok = wait_nodes_up([FullName],"target_system test node"), + {ok,FullName}; + Error -> + ?t:fail({failed_to_start_node, FullName, Error}) + end. + +stop_target_node(Node) -> + monitor_node(Node, true), + _ = rpc:call(Node,erlang,halt,[]), + receive {nodedown, Node} -> ok end. + +%% Test that the example/target_system.erl module can create and +%% install under a path which includes unicode characters +target_system_unicode(Conf) when is_list(Conf) -> + PrivDir = priv_dir(Conf), + UnicodeStr = [945,946], % alhpa beta in greek letters + UnicodePrivDir = filename:join(PrivDir,UnicodeStr), + + PA = filename:dirname(code:which(?MODULE)), + + %% Make sure this runs on a node with unicode file name mode + Sname = list_to_atom(atom_to_list(?MODULE) ++ "-target_system_unicode"), + {ok,Node} = ?t:start_node(Sname,peer,[{args,"+fnui -pa " ++ PA}]), + ok = rpc:call(Node,file,make_dir,[UnicodePrivDir]), + case rpc:call(Node,application,start,[sasl]) of + ok -> ok; + {error,{already_started,sasl}} -> ok; + Error -> ?t:fail({failed_to_start_sasl_on_test_node,Node,Error}) + end, + ok = rpc:call(Node,?MODULE,target_system1,[Conf,UnicodePrivDir]), + ok. + +target_system_unicode(cleanup,Conf) -> + Sname = list_to_atom(atom_to_list(?MODULE) ++ "-target_system_unicode"), + Node = node_name(Sname), + _ = rpc:call(Node,?MODULE,target_system,[cleanup,Conf]), + _ = stop_node(Node), + ok. %%%================================================================= %%% Testing global groups. @@ -1852,7 +1929,7 @@ stop_node(Node) -> copy_client(Conf,Master,Sname,Client) -> - io:format("copy_client(Conf)"), + ?t:format("copy_client(Conf)"), DataDir = ?config(data_dir, Conf), MasterDir = filename:join(priv_dir(Conf),Master), @@ -2012,7 +2089,7 @@ chmod(Dest,Opts) -> copy_error(Src, Dest, Reason) -> - io:format("Copy ~s to ~s failed: ~s\n", + ?t:format("Copy ~s to ~s failed: ~s\n", [Src,Dest,file:format_error(Reason)]), ?t:fail(file_copy_failed). @@ -2513,9 +2590,9 @@ start_node_unix(Sname,NodeDir) -> Script = filename:join([NodeDir,"bin","start"]), Cmd = "env NODENAME="++atom_to_list(Sname) ++ " " ++ Script, %% {ok,StartFile} = file:read_file(Cmd), - %% io:format("~s:\n~s~n~n",[Start,binary_to_list(StartFile)]), + %% ?t:format("~s:\n~s~n~n",[Start,binary_to_list(StartFile)]), Res = os:cmd(Cmd), - io:format("Start ~p: ~p~n=>\t~p~n", [Sname,Cmd,Res]). + ?t:format("Start ~p: ~p~n=>\t~p~n", [Sname,Cmd,Res]). start_node_win32(Sname,NodeDir) -> Name = atom_to_list(Sname) ++ "_P1G", -- cgit v1.2.3 From 6a093c47d87707480d1710fc6790b57f1520cef7 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Wed, 13 Feb 2013 11:21:36 +0100 Subject: [sasl] Rewrite release_handler_SUITE:clean_priv_dir to work on unicode paths This function used os:cmd("rm -rf " ++ File), and it failed when the file path contained characters > 255. The function now uses file:delete/1 and file:del_dir/1 instead. --- lib/sasl/test/release_handler_SUITE.erl | 87 +++++++++++---------------------- 1 file changed, 28 insertions(+), 59 deletions(-) (limited to 'lib/sasl/test') diff --git a/lib/sasl/test/release_handler_SUITE.erl b/lib/sasl/test/release_handler_SUITE.erl index f103537142..4cf4122959 100644 --- a/lib/sasl/test/release_handler_SUITE.erl +++ b/lib/sasl/test/release_handler_SUITE.erl @@ -20,6 +20,7 @@ -include_lib("common_test/include/ct.hrl"). -include("test_lib.hrl"). +-include_lib("kernel/include/file.hrl"). -compile(export_all). @@ -1969,80 +1970,48 @@ copy_client(Conf,Master,Sname,Client) -> clean_priv_dir(Conf,Save) -> PrivDir = priv_dir(Conf), - {ok, OrigWd} = file:get_cwd(), - - ok = file:set_cwd(PrivDir), ?t:format("======== current dir ~p~n",[PrivDir]), - {ok, Dirs} = file:list_dir(PrivDir), + Dirs = filelib:wildcard(filename:join(PrivDir,"*")), ?t:format("======== deleting ~p~n",[Dirs]), - ok = clean_dirs_os(Dirs,Save), - {ok,Remaining} = file:list_dir(PrivDir), + ok = rm_rf(Dirs,Save), + Remaining = filelib:wildcard(filename:join(PrivDir,"*")), ?t:format("======== remaining ~p~n",[Remaining]), case Remaining of [] -> ok; _ -> - clean_dirs_os(Remaining,Save), - Remaining2 = file:list_dir(PrivDir), + rm_rf(Remaining,Save), + Remaining2 = filelib:wildcard(filename:join(PrivDir,"*")), ?t:format("======== remaining after second try ~p~n",[Remaining2]) end, - ok = file:set_cwd(OrigWd), ok. -clean_dirs_os(Dirs,Save) -> - case os:type() of - {unix, _} -> - clean_dirs_unix(Dirs,Save); - {win32, _} -> - clean_dirs_win32(Dirs,Save); - Os -> - test_server:fail({error, {not_yet_implemented_os, Os}}) - end. - - -clean_dirs_unix([],_) -> - ok; -clean_dirs_unix(["save"|Dirs],Save) when Save -> - clean_dirs_unix(Dirs,Save); -clean_dirs_unix([Dir|Dirs],Save) -> - Rm = string:concat("rm -rf ", Dir), - ?t:format("============== COMMAND ~p~n",[Rm]), - case file:list_dir(Dir) of - {error, enotdir} -> - ok; - X -> - ?t:format("------- Dir ~p~n ~p~n",[Dir, X]) - end, - case os:cmd(Rm) of - [] -> - ?t:format("------- Result of COMMAND ~p~n",[ok]); - Y -> - ?t:format("!!!!!!! delete ERROR Dir ~p Error ~p~n",[Dir, Y]), - ?t:format("------- ls -al ~p~n",[os:cmd("ls -al " ++ Dir)]) - end, - - clean_dirs_unix(Dirs,Save). - -clean_dirs_win32([],_) -> - ok; -clean_dirs_win32(["save"|Dirs],Save) when Save -> - clean_dirs_win32(Dirs,Save); -clean_dirs_win32([Dir|Dirs],Save) -> - Rm = - case filelib:is_dir(Dir) of - true -> - string:concat("rmdir /s /q ", Dir); - false -> - string:concat("del /q ", Dir) - end, - ?t:format("============== COMMAND ~p~n",[Rm]), - [] = os:cmd(Rm), - clean_dirs_win32(Dirs,Save). - +rm_rf([File|Files],Save) -> + case Save andalso filename:basename(File)=="save" of + true -> + rm_rf(Files,Save); + false -> + case file:read_link_info(File) of + {ok,#file_info{type=directory}} -> + MoreFiles = filelib:wildcard(filename:join(File,"*")), + rm_rf(MoreFiles,Save), + file:del_dir(File), + rm_rf(Files,Save); + {ok,#file_info{}} -> + file:delete(File), + rm_rf(Files,Save); + Other -> + ?t:format("======== could not delete file ~p~n" + "read_link_info -> ~p~n",[File,Other]), + rm_rf(Files,Save) + end + end; +rm_rf([],_) -> + ok. node_name(Sname) when is_atom(Sname) -> {ok,Host} = inet:gethostname(), -- cgit v1.2.3 From 44b76ccb2f2640e27214f3286acb5d798920babc Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Wed, 13 Feb 2013 20:53:45 +0100 Subject: [sasl] Update tests to run under unicode path In order to test that unicode paths can be used in release handling, the release_handler_SUITE will use a priv_dir with unicode characters if the file name translation mode is utf8 (not on windows). --- lib/sasl/test/installer.erl | 15 ++++---- lib/sasl/test/release_handler_SUITE.erl | 61 +++++++++++++++++++-------------- lib/sasl/test/rh_test_lib.erl | 11 ++++++ 3 files changed, 56 insertions(+), 31 deletions(-) (limited to 'lib/sasl/test') diff --git a/lib/sasl/test/installer.erl b/lib/sasl/test/installer.erl index 709269a73c..fa404c8b7b 100644 --- a/lib/sasl/test/installer.erl +++ b/lib/sasl/test/installer.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2011-2012. All Rights Reserved. +%% Copyright Ericsson AB 2011-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -54,8 +54,12 @@ -export([reg_proc/1]). -export([registered_loop/1]). --define(print(List), {rh_print, TestNode} ! {print, {?MODULE, ?LINE}, List}). --define(print_line(Line,List), {rh_print, TestNode} ! {print, {?MODULE, Line}, List}). +-define(print(List), + io:format(user,"(~w:~w) ~tp~n",[?MODULE,?LINE,List]), + {rh_print, TestNode} ! {print, {?MODULE, ?LINE}, List}). +-define(print_line(Line,List), + io:format(user,"(~w:~w) ~tp~n",[?MODULE,Line,List]), + {rh_print, TestNode} ! {print, {?MODULE, Line}, List}). -define(fail(Term), exit({?MODULE, ?LINE, Term})). -define(fail_line(Line,Term), exit({?MODULE, Line, Term})). @@ -905,10 +909,9 @@ start_client(TestNode,Client,Sname) -> start_client_unix(TestNode,Sname,Node) -> Start = filename:join(["clients", "type1", Node, "bin", "start"]), - Cmd = lists:concat(["env NODENAME=",Sname," ", - filename:join(code:root_dir(), Start)]), + Cmd = filename:join(code:root_dir(), Start), ?print([{start_client,Sname},Cmd]), - Res = os:cmd(Cmd), + Res = rh_test_lib:cmd(Cmd,[],[{"NODENAME",atom_to_list(Sname)}]), ?print([{start_client,result},Res]). start_client_win32(TestNode,Client,ClientSname) -> diff --git a/lib/sasl/test/release_handler_SUITE.erl b/lib/sasl/test/release_handler_SUITE.erl index 4cf4122959..2ca254ff87 100644 --- a/lib/sasl/test/release_handler_SUITE.erl +++ b/lib/sasl/test/release_handler_SUITE.erl @@ -24,6 +24,8 @@ -compile(export_all). +-define(unicode_string,[945,946]). % greek letters alpha and beta + % Default timetrap timeout (set in init_per_testcase). %-define(default_timeout, ?t:minutes(40)). -define(default_timeout, ?t:minutes(10)). @@ -1667,16 +1669,11 @@ start_target_node_with_erl(Erl,Sname,Boot) -> "-boot",filename:rootname(Boot)], ?t:format("Starting node ~p: ~ts~n", [FullName, lists:flatten([[X," "] || X <- [Erl|Args]])]), - ?t:format("open_port({spawn_executable, ~tp}, [{args,~p}])~n",[Erl,Args]), - case open_port({spawn_executable, Erl}, [{args,Args}]) of - Port when is_port(Port) -> - unlink(Port), - erlang:port_close(Port), - %% timer:sleep(10000), - %% io:format("PING: ~p~n",[net_adm:ping(FullName)]), + case rh_test_lib:cmd(Erl,Args,[]) of + ok -> ok = wait_nodes_up([FullName],"target_system test node"), {ok,FullName}; - Error -> + Error -> ?t:fail({failed_to_start_node, FullName, Error}) end. @@ -1689,7 +1686,7 @@ stop_target_node(Node) -> %% install under a path which includes unicode characters target_system_unicode(Conf) when is_list(Conf) -> PrivDir = priv_dir(Conf), - UnicodeStr = [945,946], % alhpa beta in greek letters + UnicodeStr = ?unicode_string, UnicodePrivDir = filename:join(PrivDir,UnicodeStr), PA = filename:dirname(code:which(?MODULE)), @@ -1970,13 +1967,13 @@ copy_client(Conf,Master,Sname,Client) -> clean_priv_dir(Conf,Save) -> PrivDir = priv_dir(Conf), - ?t:format("======== current dir ~p~n",[PrivDir]), + ?t:format("======== current dir ~tp~n",[PrivDir]), Dirs = filelib:wildcard(filename:join(PrivDir,"*")), - ?t:format("======== deleting ~p~n",[Dirs]), + ?t:format("======== deleting ~tp~n",[Dirs]), ok = rm_rf(Dirs,Save), Remaining = filelib:wildcard(filename:join(PrivDir,"*")), - ?t:format("======== remaining ~p~n",[Remaining]), + ?t:format("======== remaining ~tp~n",[Remaining]), case Remaining of [] -> @@ -1984,7 +1981,7 @@ clean_priv_dir(Conf,Save) -> _ -> rm_rf(Remaining,Save), Remaining2 = filelib:wildcard(filename:join(PrivDir,"*")), - ?t:format("======== remaining after second try ~p~n",[Remaining2]) + ?t:format("======== remaining after second try ~tp~n",[Remaining2]) end, ok. @@ -2058,7 +2055,7 @@ chmod(Dest,Opts) -> copy_error(Src, Dest, Reason) -> - ?t:format("Copy ~s to ~s failed: ~s\n", + ?t:format("Copy ~ts to ~ts failed: ~ts\n", [Src,Dest,file:format_error(Reason)]), ?t:fail(file_copy_failed). @@ -2098,9 +2095,11 @@ subst_file(Src, Dest, Vars) -> subst_file(Src, Dest, Vars, []). subst_file(Src, Dest, Vars, Opts) -> {ok, Bin} = file:read_file(Src), - Conts = binary_to_list(Bin), + Conts = binary_to_list(Bin), % The source will always be latin1 NConts = subst(Conts, Vars), - ok = file:write_file(Dest, NConts), + %% The destination must be utf8 if file name encoding is unicode + Enc = file:native_name_encoding(), + ok = file:write_file(Dest, unicode:characters_to_binary(NConts,Enc,Enc)), preserve(Src,Dest,Opts), chmod(Dest,Opts). @@ -2133,13 +2132,22 @@ subst_var([], Vars, Result, VarAcc) -> priv_dir(Conf) -> -%% filename:absname(?config(priv_dir, Conf)). % Get rid of trailing slash %% Due to problem with long paths on windows => creating a new %% priv_dir under data_dir - filename:absname(filename:join(?config(data_dir, Conf),priv_dir)). + %% And get rid of trailing slash (absname does that) + %% And if file name translation mode is utf8 when not on windows, + %% use a path with unicode characters... + PrivDir = + case {file:native_name_encoding(),os:type()} of + {utf8,{Os,_}} when Os=/=win32 -> + "priv_dir_" ++ ?unicode_string; + _ -> + "priv_dir" + end, + filename:absname(filename:join([?config(data_dir, Conf),PrivDir])). init_priv_dir(Conf) -> - Dir = filename:absname(filename:join(?config(data_dir, Conf),priv_dir)), + Dir = priv_dir(Conf), case filelib:is_dir(Dir) of true -> clean_priv_dir(Conf,false); @@ -2164,7 +2172,7 @@ rh_print() -> receive {print, {Module,Line}, [H|T]} -> ?t:format("=== ~p:~p - ~p",[Module,Line,H]), - lists:foreach(fun(Term) -> ?t:format(" ~p",[Term]) end, T), + lists:foreach(fun(Term) -> ?t:format(" ~tp",[Term]) end, T), ?t:format("",[]), rh_print(); kill -> @@ -2557,11 +2565,14 @@ start_nodes(Conf,Snames,Tag) -> start_node_unix(Sname,NodeDir) -> Script = filename:join([NodeDir,"bin","start"]), - Cmd = "env NODENAME="++atom_to_list(Sname) ++ " " ++ Script, - %% {ok,StartFile} = file:read_file(Cmd), - %% ?t:format("~s:\n~s~n~n",[Start,binary_to_list(StartFile)]), - Res = os:cmd(Cmd), - ?t:format("Start ~p: ~p~n=>\t~p~n", [Sname,Cmd,Res]). + ?t:format("Starting ~p: ~tp~n", [Sname,Script]), + case rh_test_lib:cmd(Script,[],[{"NODENAME",atom_to_list(Sname)}]) of + ok -> + {ok,node_name(Sname)}; + Error -> + ?t:fail({failed_to_start_node, Sname, Error}) + end. + start_node_win32(Sname,NodeDir) -> Name = atom_to_list(Sname) ++ "_P1G", diff --git a/lib/sasl/test/rh_test_lib.erl b/lib/sasl/test/rh_test_lib.erl index 99a7f919a7..06efa4acea 100644 --- a/lib/sasl/test/rh_test_lib.erl +++ b/lib/sasl/test/rh_test_lib.erl @@ -1,5 +1,6 @@ -module(rh_test_lib). +-export([cmd/3]). -export([erlsrv/3, erlsrv/4]). -export([get_service_args/3, @@ -10,6 +11,16 @@ get_client_args/4]). +cmd(Cmd,Args,Env) -> + case open_port({spawn_executable, Cmd}, [{args,Args},{env,Env}]) of + Port when is_port(Port) -> + unlink(Port), + erlang:port_close(Port), + ok; + Error -> + Error + end. + erlsrv(Erlsrv,Action,Name) -> erlsrv(Erlsrv,Action,Name,""). erlsrv(Erlsrv,Action,Name,Rest) -> -- cgit v1.2.3 From 91fc4f1f66332e9cc295c737a2f668153a025cc4 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Tue, 14 May 2013 12:05:53 +0200 Subject: [sasl] Use unicode characters in priv dir name also on windows --- lib/sasl/test/release_handler_SUITE.erl | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'lib/sasl/test') diff --git a/lib/sasl/test/release_handler_SUITE.erl b/lib/sasl/test/release_handler_SUITE.erl index 2ca254ff87..b343bd0be6 100644 --- a/lib/sasl/test/release_handler_SUITE.erl +++ b/lib/sasl/test/release_handler_SUITE.erl @@ -24,8 +24,6 @@ -compile(export_all). --define(unicode_string,[945,946]). % greek letters alpha and beta - % Default timetrap timeout (set in init_per_testcase). %-define(default_timeout, ?t:minutes(40)). -define(default_timeout, ?t:minutes(10)). @@ -1686,8 +1684,7 @@ stop_target_node(Node) -> %% install under a path which includes unicode characters target_system_unicode(Conf) when is_list(Conf) -> PrivDir = priv_dir(Conf), - UnicodeStr = ?unicode_string, - UnicodePrivDir = filename:join(PrivDir,UnicodeStr), + UnicodePrivDir = filename:join(PrivDir,"αβ"), PA = filename:dirname(code:which(?MODULE)), @@ -2135,12 +2132,12 @@ priv_dir(Conf) -> %% Due to problem with long paths on windows => creating a new %% priv_dir under data_dir %% And get rid of trailing slash (absname does that) - %% And if file name translation mode is utf8 when not on windows, - %% use a path with unicode characters... + %% And if file name translation mode is utf8, use a path with + %% unicode characters PrivDir = - case {file:native_name_encoding(),os:type()} of - {utf8,{Os,_}} when Os=/=win32 -> - "priv_dir_" ++ ?unicode_string; + case file:native_name_encoding() of + utf8 -> + "priv_dir_αβ"; _ -> "priv_dir" end, -- cgit v1.2.3 From 5ad4e9787c072ae8cea1ed1c9f2212551b307267 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Tue, 21 May 2013 18:21:06 +0200 Subject: [sasl] Clean priv_dir after systools_SUITE Some files with icky names (unicode) can not be deleted with the cleanup scripts after daily tests. Therefore it is better to clean up directly from the erlang node after test is run. --- lib/sasl/test/release_handler_SUITE.erl | 45 +---------------------------- lib/sasl/test/rh_test_lib.erl | 50 +++++++++++++++++++++++++++++++++ lib/sasl/test/systools_SUITE.erl | 6 ++-- 3 files changed, 54 insertions(+), 47 deletions(-) (limited to 'lib/sasl/test') diff --git a/lib/sasl/test/release_handler_SUITE.erl b/lib/sasl/test/release_handler_SUITE.erl index b343bd0be6..816dc7b36c 100644 --- a/lib/sasl/test/release_handler_SUITE.erl +++ b/lib/sasl/test/release_handler_SUITE.erl @@ -20,7 +20,6 @@ -include_lib("common_test/include/ct.hrl"). -include("test_lib.hrl"). --include_lib("kernel/include/file.hrl"). -compile(export_all). @@ -1963,49 +1962,7 @@ copy_client(Conf,Master,Sname,Client) -> clean_priv_dir(Conf,Save) -> PrivDir = priv_dir(Conf), - - ?t:format("======== current dir ~tp~n",[PrivDir]), - Dirs = filelib:wildcard(filename:join(PrivDir,"*")), - ?t:format("======== deleting ~tp~n",[Dirs]), - - ok = rm_rf(Dirs,Save), - Remaining = filelib:wildcard(filename:join(PrivDir,"*")), - ?t:format("======== remaining ~tp~n",[Remaining]), - - case Remaining of - [] -> - ok; - _ -> - rm_rf(Remaining,Save), - Remaining2 = filelib:wildcard(filename:join(PrivDir,"*")), - ?t:format("======== remaining after second try ~tp~n",[Remaining2]) - end, - - ok. - - -rm_rf([File|Files],Save) -> - case Save andalso filename:basename(File)=="save" of - true -> - rm_rf(Files,Save); - false -> - case file:read_link_info(File) of - {ok,#file_info{type=directory}} -> - MoreFiles = filelib:wildcard(filename:join(File,"*")), - rm_rf(MoreFiles,Save), - file:del_dir(File), - rm_rf(Files,Save); - {ok,#file_info{}} -> - file:delete(File), - rm_rf(Files,Save); - Other -> - ?t:format("======== could not delete file ~p~n" - "read_link_info -> ~p~n",[File,Other]), - rm_rf(Files,Save) - end - end; -rm_rf([],_) -> - ok. + rh_test_lib:clean_dir(PrivDir,Save). node_name(Sname) when is_atom(Sname) -> {ok,Host} = inet:gethostname(), diff --git a/lib/sasl/test/rh_test_lib.erl b/lib/sasl/test/rh_test_lib.erl index 06efa4acea..36996f7ab2 100644 --- a/lib/sasl/test/rh_test_lib.erl +++ b/lib/sasl/test/rh_test_lib.erl @@ -9,7 +9,10 @@ get_start_erl_args/3, get_client_args/3, get_client_args/4]). +-export([clean_dir/1, + clean_dir/2]). +-include_lib("kernel/include/file.hrl"). cmd(Cmd,Args,Env) -> case open_port({spawn_executable, Cmd}, [{args,Args},{env,Env}]) of @@ -109,3 +112,50 @@ single_quote() -> _ -> "\\'" end. + +clean_dir(Dir) -> + clean_dir(Dir,false). +clean_dir(Dir,Save) -> + test_server:format("======== current dir ~tp~n",[Dir]), + Dirs = filelib:wildcard(filename:join(Dir,"*")), + test_server:format("======== deleting ~tp~n",[Dirs]), + + ok = rm_rf(Dirs,Save), + Remaining = filelib:wildcard(filename:join(Dir,"*")), + test_server:format("======== remaining ~tp~n",[Remaining]), + + case Remaining of + [] -> + ok; + _ -> + rm_rf(Remaining,Save), + Remaining2 = filelib:wildcard(filename:join(Dir,"*")), + test_server:format("======== remaining after second try ~tp~n", + [Remaining2]) + end, + + ok. + + +rm_rf([File|Files],Save) -> + case Save andalso filename:basename(File)=="save" of + true -> + rm_rf(Files,Save); + false -> + case file:read_link_info(File) of + {ok,#file_info{type=directory}} -> + MoreFiles = filelib:wildcard(filename:join(File,"*")), + rm_rf(MoreFiles,Save), + file:del_dir(File), + rm_rf(Files,Save); + {ok,#file_info{}} -> + file:delete(File), + rm_rf(Files,Save); + Other -> + test_server:format("======== could not delete file ~p~n" + "read_link_info -> ~p~n",[File,Other]), + rm_rf(Files,Save) + end + end; +rm_rf([],_) -> + ok. diff --git a/lib/sasl/test/systools_SUITE.erl b/lib/sasl/test/systools_SUITE.erl index 5e95b13077..1cc9eb6986 100644 --- a/lib/sasl/test/systools_SUITE.erl +++ b/lib/sasl/test/systools_SUITE.erl @@ -137,9 +137,9 @@ compile_source(File) -> ok = file:write_file(OutFileTemp, Code), file:rename(OutFileTemp, OutFile). -end_per_suite(Conf) when is_list(Conf) -> - %% Nothing. - Conf. +end_per_suite(Config) when is_list(Config) -> + rh_test_lib:clean_dir(?privdir), + Config. init_per_testcase(link_tar, Config) -> case os:type() of -- cgit v1.2.3 From b81d9bf18cd99b60f4bd964f190f63673e0a9b6b Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Mon, 3 Jun 2013 17:47:34 +0200 Subject: [sasl] Remove priv dir after release_handler_SUITE Since introducing unicode paths, the name of the priv_dir will include "unicode characters" and on some platforms (e.g. Windows) these are not so easily removed by the daily cleanup scripts. To avoid lingering directories, the priv_dir is now completly removed by the suite itself (unless there are failed testcases and logs must be saved). --- lib/sasl/test/release_handler_SUITE.erl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/sasl/test') diff --git a/lib/sasl/test/release_handler_SUITE.erl b/lib/sasl/test/release_handler_SUITE.erl index 816dc7b36c..b73691310f 100644 --- a/lib/sasl/test/release_handler_SUITE.erl +++ b/lib/sasl/test/release_handler_SUITE.erl @@ -35,7 +35,8 @@ init_per_suite(Config) -> application:start(sasl), Config. -end_per_suite(_Config) -> +end_per_suite(Config) -> + clean_priv_dir(Config,true), ok. all() -> @@ -163,7 +164,6 @@ end_per_group(release, Config) -> {win32,_} -> delete_all_services(); _ -> ok end, - clean_priv_dir(Config,true), ?t:timetrap_cancel(Dog), Config; end_per_group(_GroupName, Config) -> @@ -1962,7 +1962,11 @@ copy_client(Conf,Master,Sname,Client) -> clean_priv_dir(Conf,Save) -> PrivDir = priv_dir(Conf), - rh_test_lib:clean_dir(PrivDir,Save). + rh_test_lib:clean_dir(PrivDir,Save), + case file:list_dir(PrivDir) of + {ok,[]} -> _ = file:del_dir(PrivDir); + _ -> ok + end. node_name(Sname) when is_atom(Sname) -> {ok,Host} = inet:gethostname(), -- cgit v1.2.3