<commit_before>%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1996-2011. 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
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
%%
-module(erl_prim_loader_SUITE).

-include_lib("kernel/include/file.hrl").
-include_lib("test_server/include/test_server.hrl").

-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, 
	 init_per_group/2,end_per_group/2]).

-export([get_path/1, set_path/1, get_file/1,
	 inet_existing/1, inet_coming_up/1, inet_disconnects/1,
	 multiple_slaves/1, file_requests/1,
	 local_archive/1, remote_archive/1,
	 primary_archive/1, virtual_dir_in_archive/1]).

-export([init_per_testcase/2, end_per_testcase/2]).

%%-----------------------------------------------------------------
%% Test suite for erl_prim_loader. (Most code is run during system start/stop.)
%%-----------------------------------------------------------------

suite() -> [{ct_hooks,[ts_install_cth]}].

all() -> 
    [get_path, set_path, get_file, inet_existing,
     inet_coming_up, inet_disconnects, multiple_slaves,
     file_requests, local_archive, remote_archive,
     primary_archive, virtual_dir_in_archive].

groups() -> 
    [].

init_per_suite(Config) ->
    Config.

end_per_suite(_Config) ->
    ok.

init_per_group(_GroupName, Config) ->
    Config.

end_per_group(_GroupName, Config) ->
    Config.


init_per_testcase(Func, Config) when is_atom(Func), is_list(Config) ->
    Dog=?t:timetrap(?t:minutes(3)),
    [{watchdog, Dog}|Config].

end_per_testcase(_Func, Config) ->
    Dog=?config(watchdog, Config),
    ?t:timetrap_cancel(Dog).

get_path(doc) -> [];
get_path(Config) when is_list(Config) ->
    ?line case erl_prim_loader:get_path() of
	      {ok, Path} when is_list(Path) ->
		  ok;
	      _ ->
		  test_server:fail(get_path)
	  end,
    ok.

set_path(doc) -> [];
set_path(Config) when is_list(Config) ->
    ?line {ok, Path} = erl_prim_loader:get_path(),
    ?line ok = erl_prim_loader:set_path(Path),
    ?line {ok, Path} = erl_prim_loader:get_path(),
    NewPath = Path ++ ["dummy_dir","/dummy_dir/dummy_dir"],
    ?line ok = erl_prim_loader:set_path(NewPath),
    ?line {ok, NewPath} = erl_prim_loader:get_path(),

    ?line ok = erl_prim_loader:set_path(Path), % Reset path.
    ?line {ok, Path} = erl_prim_loader:get_path(),

    ?line {'EXIT',_} = (catch erl_prim_loader:set_path(not_a_list)),
    ?line {ok, Path} = erl_prim_loader:get_path(),
    ok.

get_file(doc) -> [];
get_file(Config) when is_list(Config) ->
    ?line case erl_prim_loader:get_file("lists" ++ code:objfile_extension()) of
	      {ok,Bin,File} when is_binary(Bin), is_list(File) ->
		  ok;
	      _ ->
		  test_server:fail(get_valid_file)
	  end,
    ?line error = erl_prim_loader:get_file("duuuuuuummmy_file"),
    ?line error = erl_prim_loader:get_file(duuuuuuummmy_file),
    ?line error = erl_prim_loader:get_file({dummy}),
    ok.

inet_existing(doc) -> ["Start a node using the 'inet' loading method, ",
		       "from an already started boot server."];
inet_existing(Config) when is_list(Config) ->
    case os:type() of
	vxworks ->
	    {comment, "VxWorks: tested separately"};
	_ ->
	    ?line Name = erl_prim_test_inet_existing,
	    ?line Host = host(),
	    ?line Cookie = atom_to_list(erlang:get_cookie()),
	    ?line IpStr = ip_str(Host),
	    ?line LFlag = get_loader_flag(os:type()),
	    ?line Args = LFlag ++ " -hosts " ++ IpStr ++
		" -setcookie " ++ Cookie,
	    ?line {ok, BootPid} = erl_boot_server:start_link([Host]),
	    ?line {ok, Node} = start_node(Name, Args),
	    ?line {ok,[["inet"]]} = rpc:call(Node, init, get_argument, [loader]),
	    ?line stop_node(Node),
	    ?line unlink(BootPid),
	    ?line exit(BootPid, kill),
	    ok
    end.

inet_coming_up(doc) -> ["Start a node using the 'inet' loading method, ",
			"but start the boot server afterwards."];
inet_coming_up(Config) when is_list(Config) ->
    case os:type() of
	vxworks ->
	    {comment, "VxWorks: tested separately"};
	_ ->
	    ?line Name = erl_prim_test_inet_coming_up,
	    ?line Cookie = atom_to_list(erlang:get_cookie()),
	    ?line Host = host(),
	    ?line IpStr = ip_str(Host),
	    ?line LFlag = get_loader_flag(os:type()),
	    ?line Args = LFlag ++ 
		" -hosts " ++ IpStr ++
		" -setcookie " ++ Cookie,
	    ?line {ok, Node} = start_node(Name, Args, [{wait, false}]),

	    %% Wait a while, then start boot server, and wait for node to start.
	    ?line test_server:sleep(test_server:seconds(6)),
	    io:format("erl_boot_server:start_link([~p]).", [Host]),
	    ?line {ok, BootPid} = erl_boot_server:start_link([Host]),
	    ?line wait_really_started(Node, 25),

	    %% Check loader argument, then cleanup.
	    ?line {ok,[["inet"]]} = rpc:call(Node, init, get_argument, [loader]),
	    ?line stop_node(Node),
	    ?line unlink(BootPid),
	    ?line exit(BootPid, kill),
	    ok
    end.

wait_really_started(Node, 0) ->
    test_server:fail({not_booted,Node});
wait_really_started(Node, N) ->
    case rpc:call(Node, init, get_status, []) of
 	{started, _} ->
 	    ok;
	_ ->
	    test_server:sleep(1000),
 	    wait_really_started(Node, N - 1)
    end.

inet_disconnects(doc) -> ["Start a node using the 'inet' loading method, ",
			  "then lose the connection."];
inet_disconnects(Config) when is_list(Config) ->
    case os:type() of
	vxworks ->
	    {comment, "VxWorks: tested separately"};
	_ ->
	    ?line Name = erl_prim_test_inet_disconnects,
	    ?line Host = host(),
	    ?line Cookie = atom_to_list(erlang:get_cookie()),
	    ?line IpStr = ip_str(Host),
	    ?line LFlag = get_loader_flag(os:type()),
	    ?line Args = LFlag ++ " -hosts " ++ IpStr ++
		" -setcookie " ++ Cookie,
	    
	    ?line {ok, BootPid} = erl_boot_server:start([Host]),<commit_msg>erl_prim_loader_SUITE: Handle native-compiled erl_boot_server<commit_after>%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1996-2011. 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
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
%%
-module(erl_prim_loader_SUITE).

-include_lib("kernel/include/file.hrl").
-include_lib("test_server/include/test_server.hrl").

-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, 
	 init_per_group/2,end_per_group/2]).

-export([get_path/1, set_path/1, get_file/1,
	 inet_existing/1, inet_coming_up/1, inet_disconnects/1,
	 multiple_slaves/1, file_requests/1,
	 local_archive/1, remote_archive/1,
	 primary_archive/1, virtual_dir_in_archive/1]).

-export([init_per_testcase/2, end_per_testcase/2]).

%%-----------------------------------------------------------------
%% Test suite for erl_prim_loader. (Most code is run during system start/stop.)
%%-----------------------------------------------------------------

suite() -> [{ct_hooks,[ts_install_cth]}].

all() -> 
    [get_path, set_path, get_file, inet_existing,
     inet_coming_up, inet_disconnects, multiple_slaves,
     file_requests, local_archive, remote_archive,
     primary_archive, virtual_dir_in_archive].

groups() -> 
    [].

init_per_suite(Config) ->
    Config.

end_per_suite(_Config) ->
    ok.

init_per_group(_GroupName, Config) ->
    Config.

end_per_group(_GroupName, Config) ->
    Config.


init_per_testcase(Func, Config) when is_atom(Func), is_list(Config) ->
    Dog=?t:timetrap(?t:minutes(3)),
    [{watchdog, Dog}|Config].

end_per_testcase(_Func, Config) ->
    Dog=?config(watchdog, Config),
    ?t:timetrap_cancel(Dog).

get_path(doc) -> [];
get_path(Config) when is_list(Config) ->
    ?line case erl_prim_loader:get_path() of
	      {ok, Path} when is_list(Path) ->
		  ok;
	      _ ->
		  test_server:fail(get_path)
	  end,
    ok.

set_path(doc) -> [];
set_path(Config) when is_list(Config) ->
    ?line {ok, Path} = erl_prim_loader:get_path(),
    ?line ok = erl_prim_loader:set_path(Path),
    ?line {ok, Path} = erl_prim_loader:get_path(),
    NewPath = Path ++ ["dummy_dir","/dummy_dir/dummy_dir"],
    ?line ok = erl_prim_loader:set_path(NewPath),
    ?line {ok, NewPath} = erl_prim_loader:get_path(),

    ?line ok = erl_prim_loader:set_path(Path), % Reset path.
    ?line {ok, Path} = erl_prim_loader:get_path(),

    ?line {'EXIT',_} = (catch erl_prim_loader:set_path(not_a_list)),
    ?line {ok, Path} = erl_prim_loader:get_path(),
    ok.

get_file(doc) -> [];
get_file(Config) when is_list(Config) ->
    ?line case erl_prim_loader:get_file("lists" ++ code:objfile_extension()) of
	      {ok,Bin,File} when is_binary(Bin), is_list(File) ->
		  ok;
	      _ ->
		  test_server:fail(get_valid_file)
	  end,
    ?line error = erl_prim_loader:get_file("duuuuuuummmy_file"),
    ?line error = erl_prim_loader:get_file(duuuuuuummmy_file),
    ?line error = erl_prim_loader:get_file({dummy}),
    ok.

inet_existing(doc) -> ["Start a node using the 'inet' loading method, ",
		       "from an already started boot server."];
inet_existing(Config) when is_list(Config) ->
    case os:type() of
	vxworks ->
	    {comment, "VxWorks: tested separately"};
	_ ->
	    ?line Name = erl_prim_test_inet_existing,
	    ?line Host = host(),
	    ?line Cookie = atom_to_list(erlang:get_cookie()),
	    ?line IpStr = ip_str(Host),
	    ?line LFlag = get_loader_flag(os:type()),
	    ?line Args = LFlag ++ " -hosts " ++ IpStr ++
		" -setcookie " ++ Cookie,
	    ?line {ok, BootPid} = erl_boot_server:start_link([Host]),
	    ?line {ok, Node} = start_node(Name, Args),
	    ?line {ok,[["inet"]]} = rpc:call(Node, init, get_argument, [loader]),
	    ?line stop_node(Node),
	    ?line unlink(BootPid),
	    ?line exit(BootPid, kill),
	    ok
    end.

inet_coming_up(doc) -> ["Start a node using the 'inet' loading method, ",
			"but start the boot server afterwards."];
inet_coming_up(Config) when is_list(Config) ->
    case os:type() of
	vxworks ->
	    {comment, "VxWorks: tested separately"};
	_ ->
	    ?line Name = erl_prim_test_inet_coming_up,
	    ?line Cookie = atom_to_list(erlang:get_cookie()),
	    ?line Host = host(),
	    ?line IpStr = ip_str(Host),
	    ?line LFlag = get_loader_flag(os:type()),
	    ?line Args = LFlag ++ 
		" -hosts " ++ IpStr ++
		" -setcookie " ++ Cookie,
	    ?line {ok, Node} = start_node(Name, Args, [{wait, false}]),

	    %% Wait a while, then start boot server, and wait for node to start.
	    ?line test_server:sleep(test_server:seconds(6)),
	    io:format("erl_boot_server:start_link([~p]).", [Host]),
	    ?line {ok, BootPid} = erl_boot_server:start_link([Host]),
	    ?line wait_really_started(Node, 25),

	    %% Check loader argument, then cleanup.
	    ?line {ok,[["inet"]]} = rpc:call(Node, init, get_argument, [loader]),
	    ?line stop_node(Node),
	    ?line unlink(BootPid),
	    ?line exit(BootPid, kill),
	    ok
    end.

wait_really_started(Node, 0) ->
    test_server:fail({not_booted,Node});
wait_really_started(Node, N) ->
    case rpc:call(Node, init, get_status, []) of
 	{started, _} ->
 	    ok;
	_ ->
	    test_server:sleep(1000),
 	    wait_really_started(Node, N - 1)
    end.

inet_disconnects(doc) -> ["Start a node using the 'inet' loading method, ",
			  "then lose the connection."];
inet_disconnects(Config) when is_list(Config) ->
    case test_server:is_native(erl_boot_server) of
	true ->
	    {skip,"erl_boot_server is native"};
	false ->
	    ?line Name = erl_prim_test_inet_disconnects,
	    ?line Host = host(),
	    ?line Cookie = atom_to_list(erlang:get_cookie()),
	    ?line IpStr = ip_str(Host),
	    ?line LFlag = get_loader_flag(os:type()),
	    ?line Args = LFlag ++ " -hosts " ++ IpStr ++
		" -setcookie " ++ Cookie,
	    
	    ?line {ok, BootPid} = erl_boot_server:start([Host]),
{'fraction_non_alphanumeric': 0.16636168350704114, 'fraction_numerical': 0.006523987588511417, 'mean_word_length': 3.5118449389806172, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4879979', 'n_tokens_mistral': 4672, 'n_tokens_neox': 4409, 'n_words': 984}