diff options
author | Siri Hansen <[email protected]> | 2013-02-12 20:00:09 +0100 |
---|---|---|
committer | Siri Hansen <[email protected]> | 2013-05-14 17:01:54 +0200 |
commit | a89ed3d94f3966d07a061fe540a87db15357e4d2 (patch) | |
tree | 2f2f40afbb6a7f4030b0eca9dcc08b71c5bfc2b2 | |
parent | 45b6ff14ff5a644517ca029fafdae8a63700cd93 (diff) | |
download | otp-a89ed3d94f3966d07a061fe540a87db15357e4d2.tar.gz otp-a89ed3d94f3966d07a061fe540a87db15357e4d2.tar.bz2 otp-a89ed3d94f3966d07a061fe540a87db15357e4d2.zip |
[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.
-rw-r--r-- | lib/sasl/examples/src/target_system.erl | 35 | ||||
-rw-r--r-- | lib/sasl/test/release_handler_SUITE.erl | 95 |
2 files changed, 104 insertions, 26 deletions
diff --git a/lib/sasl/examples/src/target_system.erl b/lib/sasl/examples/src/target_system.erl index ffc0fcf443..fb9e9aaaaf 100644 --- a/lib/sasl/examples/src/target_system.erl +++ b/lib/sasl/examples/src/target_system.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2011. 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 @@ -34,9 +34,9 @@ create(RelFileName,SystoolsOpts) -> Dir = filename:dirname(RelFileName), PlainRelFileName = filename:join(Dir,"plain"), PlainRelFile = PlainRelFileName ++ ".rel", - io:fwrite("Reading file: ~p ...~n", [RelFile]), + io:fwrite("Reading file: ~tp ...~n", [RelFile]), {ok, [RelSpec]} = file:consult(RelFile), - io:fwrite("Creating file: ~p from ~p ...~n", + io:fwrite("Creating file: ~tp from ~tp ...~n", [PlainRelFile, RelFile]), {release, {RelName, RelVsn}, @@ -57,41 +57,41 @@ create(RelFileName,SystoolsOpts) -> io:fwrite(Fd, "~p.~n", [PlainRelSpec]), file:close(Fd), - io:fwrite("Making \"~s.script\" and \"~s.boot\" files ...~n", + io:fwrite("Making \"~ts.script\" and \"~ts.boot\" files ...~n", [PlainRelFileName,PlainRelFileName]), make_script(PlainRelFileName,SystoolsOpts), - io:fwrite("Making \"~s.script\" and \"~s.boot\" files ...~n", + io:fwrite("Making \"~ts.script\" and \"~ts.boot\" files ...~n", [RelFileName, RelFileName]), make_script(RelFileName,SystoolsOpts), TarFileName = filename:join(Dir,RelFileName ++ ".tar.gz"), - io:fwrite("Creating tar file ~p ...~n", [TarFileName]), + io:fwrite("Creating tar file ~tp ...~n", [TarFileName]), make_tar(RelFileName,SystoolsOpts), TmpDir = filename:join(Dir,"tmp"), - io:fwrite("Creating directory ~p ...~n",[TmpDir]), + io:fwrite("Creating directory ~tp ...~n",[TmpDir]), file:make_dir(TmpDir), - io:fwrite("Extracting ~p into directory ~p ...~n", [TarFileName,TmpDir]), + io:fwrite("Extracting ~tp into directory ~tp ...~n", [TarFileName,TmpDir]), extract_tar(TarFileName, TmpDir), TmpBinDir = filename:join([TmpDir, "bin"]), ErtsBinDir = filename:join([TmpDir, "erts-" ++ ErtsVsn, "bin"]), - io:fwrite("Deleting \"erl\" and \"start\" in directory ~p ...~n", + io:fwrite("Deleting \"erl\" and \"start\" in directory ~tp ...~n", [ErtsBinDir]), file:delete(filename:join([ErtsBinDir, "erl"])), file:delete(filename:join([ErtsBinDir, "start"])), - io:fwrite("Creating temporary directory ~p ...~n", [TmpBinDir]), + io:fwrite("Creating temporary directory ~tp ...~n", [TmpBinDir]), file:make_dir(TmpBinDir), - io:fwrite("Copying file \"~s.boot\" to ~p ...~n", + io:fwrite("Copying file \"~ts.boot\" to ~tp ...~n", [PlainRelFileName, filename:join([TmpBinDir, "start.boot"])]), copy_file(PlainRelFileName++".boot",filename:join([TmpBinDir, "start.boot"])), io:fwrite("Copying files \"epmd\", \"run_erl\" and \"to_erl\" from \n" - "~p to ~p ...~n", + "~tp to ~tp ...~n", [ErtsBinDir, TmpBinDir]), copy_file(filename:join([ErtsBinDir, "epmd"]), filename:join([TmpBinDir, "epmd"]), [preserve]), @@ -101,11 +101,11 @@ create(RelFileName,SystoolsOpts) -> filename:join([TmpBinDir, "to_erl"]), [preserve]), StartErlDataFile = filename:join([TmpDir, "releases", "start_erl.data"]), - io:fwrite("Creating ~p ...~n", [StartErlDataFile]), + io:fwrite("Creating ~tp ...~n", [StartErlDataFile]), StartErlData = io_lib:fwrite("~s ~s~n", [ErtsVsn, RelVsn]), write_file(StartErlDataFile, StartErlData), - io:fwrite("Recreating tar file ~p from contents in directory ~p ...~n", + io:fwrite("Recreating tar file ~tp from contents in directory ~tp ...~n", [TarFileName,TmpDir]), {ok, Tar} = erl_tar:open(TarFileName, [write, compressed]), %% {ok, Cwd} = file:get_cwd(), @@ -117,14 +117,14 @@ create(RelFileName,SystoolsOpts) -> erl_tar:add(Tar, filename:join(TmpDir,"lib"), "lib", []), erl_tar:close(Tar), %% file:set_cwd(Cwd), - io:fwrite("Removing directory ~p ...~n",[TmpDir]), + io:fwrite("Removing directory ~tp ...~n",[TmpDir]), remove_dir_tree(TmpDir), ok. install(RelFileName, RootDir) -> TarFile = RelFileName ++ ".tar.gz", - io:fwrite("Extracting ~p ...~n", [TarFile]), + io:fwrite("Extracting ~tp ...~n", [TarFile]), extract_tar(TarFile, RootDir), StartErlDataFile = filename:join([RootDir, "releases", "start_erl.data"]), {ok, StartErlData} = read_txt_file(StartErlDataFile), @@ -235,8 +235,9 @@ copy_file(Src, Dest, Opts) -> end. write_file(FName, Conts) -> + Enc = file:native_name_encoding(), {ok, Fd} = file:open(FName, [write]), - file:write(Fd, Conts), + file:write(Fd, unicode:characters_to_binary(Conts,Enc,Enc)), file:close(Fd). read_txt_file(File) -> 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", |