diff options
author | Siri Hansen <[email protected]> | 2013-06-05 14:58:58 +0200 |
---|---|---|
committer | Siri Hansen <[email protected]> | 2013-06-05 14:58:58 +0200 |
commit | 3a40a631313ea3a5b05de121ebd6a559d8543329 (patch) | |
tree | 846a70b93f4870e5dcaeae7026b67f4afe5f3db1 /lib/sasl/test | |
parent | 00e93e8948c84bc5150e3c8dbea0820e60491461 (diff) | |
parent | b81d9bf18cd99b60f4bd964f190f63673e0a9b6b (diff) | |
download | otp-3a40a631313ea3a5b05de121ebd6a559d8543329.tar.gz otp-3a40a631313ea3a5b05de121ebd6a559d8543329.tar.bz2 otp-3a40a631313ea3a5b05de121ebd6a559d8543329.zip |
Merge branch 'siri/install-otp-in-unicode-path'
* siri/install-otp-in-unicode-path:
[sasl] Remove priv dir after release_handler_SUITE
Update preloaded init.beam
Allow unicode characters for boot and config in init:make_permanent
[sasl] Clean priv_dir after systools_SUITE
[reltool] Use unicode characters in work dir for unicode test
[sasl] Use unicode characters in priv dir name also on windows
[reltool] Write erl.ini as UTF-8
[sasl] Update tests to run under unicode path
[sasl] Rewrite release_handler_SUITE:clean_priv_dir to work on unicode paths
[sasl] Update example/target_system.erl to handle unicode
[sasl] Write erl.ini as utf8, allowing unicode path for root dir and bin dir
Diffstat (limited to 'lib/sasl/test')
-rw-r--r-- | lib/sasl/test/installer.erl | 15 | ||||
-rw-r--r-- | lib/sasl/test/release_handler_SUITE.erl | 203 | ||||
-rw-r--r-- | lib/sasl/test/rh_test_lib.erl | 61 | ||||
-rw-r--r-- | lib/sasl/test/systools_SUITE.erl | 6 |
4 files changed, 182 insertions, 103 deletions
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 66de19ed19..cb82fdd060 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() -> @@ -50,7 +51,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()]. @@ -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) -> @@ -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,75 @@ 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]])]), + case rh_test_lib:cmd(Erl,Args,[]) of + ok -> + 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), + UnicodePrivDir = filename:join(PrivDir,"αβ"), + + 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 +1923,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), @@ -1891,82 +1962,12 @@ 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), - ?t:format("======== deleting ~p~n",[Dirs]), - - ok = clean_dirs_os(Dirs,Save), - {ok,Remaining} = file:list_dir(PrivDir), - ?t:format("======== remaining ~p~n",[Remaining]), - - case Remaining of - [] -> - ok; - _ -> - clean_dirs_os(Remaining,Save), - Remaining2 = file:list_dir(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}}) + rh_test_lib:clean_dir(PrivDir,Save), + case file:list_dir(PrivDir) of + {ok,[]} -> _ = file:del_dir(PrivDir); + _ -> ok 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). - - node_name(Sname) when is_atom(Sname) -> {ok,Host} = inet:gethostname(), list_to_atom(atom_to_list(Sname) ++ "@" ++ Host). @@ -2012,7 +2013,7 @@ chmod(Dest,Opts) -> copy_error(Src, Dest, Reason) -> - io: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). @@ -2052,9 +2053,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). @@ -2087,13 +2090,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, use a path with + %% unicode characters + PrivDir = + case file:native_name_encoding() of + utf8 -> + "priv_dir_αβ"; + _ -> + "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); @@ -2118,7 +2130,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 -> @@ -2511,11 +2523,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), - %% io: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("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 c9a425c729..11935496d8 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, @@ -8,7 +9,20 @@ 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 + Port when is_port(Port) -> + unlink(Port), + erlang:port_close(Port), + ok; + Error -> + Error + end. erlsrv(Erlsrv,Action,Name) -> erlsrv(Erlsrv,Action,Name,""). @@ -99,3 +113,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 |