summaryrefslogtreecommitdiff
path: root/erts/emulator/test/time_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'erts/emulator/test/time_SUITE.erl')
-rw-r--r--erts/emulator/test/time_SUITE.erl125
1 files changed, 82 insertions, 43 deletions
diff --git a/erts/emulator/test/time_SUITE.erl b/erts/emulator/test/time_SUITE.erl
index e01efac86b..ce3e796da5 100644
--- a/erts/emulator/test/time_SUITE.erl
+++ b/erts/emulator/test/time_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1997-2017. All Rights Reserved.
+%% Copyright Ericsson AB 1997-2022. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -42,7 +42,8 @@
monotonic_time_monotonicity_parallel/1,
time_unit_conversion/1,
signed_time_unit_conversion/1,
- erlang_timestamp/1]).
+ erlang_timestamp/1,
+ native_time_unit_gh6165/1]).
-export([init_per_testcase/2, end_per_testcase/2]).
@@ -69,8 +70,8 @@
init_per_testcase(Func, Config) when is_atom(Func), is_list(Config) ->
[{testcase, Func}|Config].
-end_per_testcase(_Func, _Config) ->
- ok.
+end_per_testcase(_Func, Config) ->
+ erts_test_utils:ept_check_leaked_nodes(Config).
suite() -> [{ct_hooks,[ts_install_cth]}].
@@ -85,7 +86,8 @@ all() ->
monotonic_time_monotonicity_parallel,
time_unit_conversion,
signed_time_unit_conversion,
- erlang_timestamp].
+ erlang_timestamp,
+ native_time_unit_gh6165].
groups() ->
[{now, [], [now_unique, now_update]}].
@@ -108,9 +110,7 @@ local_to_univ_utc(Config) when is_list(Config) ->
case os:type() of
{unix,_} ->
%% TZ variable has a meaning
- {ok, Node} =
- test_server:start_node(local_univ_utc,peer,
- [{args, "-env TZ UTC"}]),
+ {ok, Peer, Node} = ?CT_PEER(["-env", "TZ", "UTC"]),
{{2008,8,1},{0,0,0}} =
rpc:call(Node,
erlang,localtime_to_universaltime,
@@ -125,17 +125,33 @@ local_to_univ_utc(Config) when is_list(Config) ->
rpc:call(Node,
calendar,local_time_to_universal_time_dst,
[{{2008, 8, 1}, {0, 0, 0}}]),
- test_server:stop_node(Node),
- ok;
+ peer:stop(Peer);
_ ->
{skip,"Only valid on Unix"}
end.
%% Tests conversion from universal to local time.
+%% These cases are currently implemented only for MET and fail in
+%% all other timezones
+is_stockholm_time() ->
+ case os:type() of
+ {win32, _} -> case os:cmd("tzutil /g") of
+ "W. Europe Standard Time"++_ -> true;
+ _ -> false
+ end;
+ {unix, _} -> case os:cmd("date '+%Z'") of
+ "ME"++_ -> true; %% covers MET/MEST
+ "CE"++_ -> true; %% covers CET/CEST
+ _ -> false
+ end
+ end.
univ_to_local(Config) when is_list(Config) ->
- test_univ_to_local(test_data()).
+ case is_stockholm_time() of
+ true -> test_univ_to_local(test_data());
+ false -> {skip, "This test is only valid for Stockholm timezone"}
+ end.
test_univ_to_local([{Utc, Local}|Rest]) ->
io:format("Testing ~p => ~p~n", [Local, Utc]),
@@ -147,7 +163,10 @@ test_univ_to_local([]) ->
%% Tests conversion from local to universal time.
local_to_univ(Config) when is_list(Config) ->
- test_local_to_univ(test_data()).
+ case is_stockholm_time() of
+ true -> test_local_to_univ(test_data());
+ false -> {skip, "This test is only valid for Stockholm timezone"}
+ end.
test_local_to_univ([{Utc, Local}|Rest]) ->
io:format("Testing ~p => ~p~n", [Utc, Local]),
@@ -241,7 +260,7 @@ compare_local_and_universal(Times) when Times > 0 ->
Diff when abs(Diff) < AcceptableDiff ->
ok;
Diff ->
- io:format("More than ~p seconds difference betwen "
+ io:format("More than ~p seconds difference between "
"local and universal time", [Diff]),
ct:fail(huge_diff)
end.
@@ -431,41 +450,39 @@ now_update1(0) ->
time_warp_modes(Config) when is_list(Config) ->
%% All time warp modes always supported in
%% combination with no time correction...
- check_time_warp_mode(Config, false, no_time_warp),
- check_time_warp_mode(Config, false, single_time_warp),
- check_time_warp_mode(Config, false, multi_time_warp),
+ check_time_warp_mode(false, no_time_warp),
+ check_time_warp_mode(false, single_time_warp),
+ check_time_warp_mode(false, multi_time_warp),
erts_debug:set_internal_state(available_internal_state, true),
try
case erts_debug:get_internal_state({check_time_config,
true, no_time_warp}) of
false -> ok;
- true -> check_time_warp_mode(Config, true, no_time_warp)
+ true -> check_time_warp_mode(true, no_time_warp)
end,
case erts_debug:get_internal_state({check_time_config,
true, single_time_warp}) of
false -> ok;
- true -> check_time_warp_mode(Config, true, single_time_warp)
+ true -> check_time_warp_mode(true, single_time_warp)
end,
case erts_debug:get_internal_state({check_time_config,
true, multi_time_warp}) of
false -> ok;
- true -> check_time_warp_mode(Config, true, multi_time_warp)
+ true -> check_time_warp_mode(true, multi_time_warp)
end
after
erts_debug:set_internal_state(available_internal_state, false)
end.
-check_time_warp_mode(Config, TimeCorrection, TimeWarpMode) ->
+check_time_warp_mode(TimeCorrection, TimeWarpMode) ->
io:format("~n~n~n***** Testing TimeCorrection=~p TimeWarpMode=~p *****~n",
[TimeCorrection, TimeWarpMode]),
Mon = erlang:monitor(time_offset, clock_service),
_ = erlang:time_offset(),
Start = erlang:monotonic_time(1000),
MonotonicityTimeout = 2000,
- {ok, Node} = start_node(Config,
- "+c " ++ atom_to_list(TimeCorrection)
- ++ " +C " ++ atom_to_list(TimeWarpMode)),
+ {ok, Peer, Node} = ?CT_PEER(["+c", atom_to_list(TimeCorrection), "+C", atom_to_list(TimeWarpMode)]),
StartTime = rpc:call(Node, erlang, system_info, [start_time]),
Me = self(),
MonotincityTestStarted = make_ref(),
@@ -494,7 +511,7 @@ check_time_warp_mode(Config, TimeCorrection, TimeWarpMode) ->
millisecond),
io:format("UpMilliSeconds=~p~n", [UpMilliSeconds]),
End = erlang:monotonic_time(millisecond),
- stop_node(Node),
+ peer:stop(Peer),
try
true = (UpMilliSeconds > (98*MonotonicityTimeout) div 100),
true = (UpMilliSeconds < (102*(End-Start)) div 100)
@@ -857,6 +874,41 @@ process_changed_time_offset(Mon, TO, Changed, Wait) ->
end.
+native_time_unit_gh6165(Config) when is_list(Config) ->
+ %% This test could potentially fail even when no bug exists if
+ %% run during heavy load, or if OS system time or Erlang system time
+ %% is changed at an unfortunate time, but it is hard to make the test
+ %% more stable than this without losing actual testing...
+
+ ChkDiff = fun (Val) ->
+ case erlang:convert_time_unit(Val, native, nanosecond) of
+ Ns when -1000000 < Ns andalso Ns < 1000000 ->
+ erlang:display({diff, Ns}),
+ ok;
+ Ns ->
+ erlang:display({large_diff, Ns}),
+ ct:fail({large_diff, Ns})
+ end
+ end,
+
+ process_flag(priority, max),
+
+ erlang:yield(),
+ V1 = erlang:monotonic_time(native) - erlang:monotonic_time(),
+ ChkDiff(V1),
+
+ erlang:yield(),
+ V2 = erlang:system_time(native) - erlang:system_time(),
+ ChkDiff(V2),
+
+ erlang:yield(),
+ V3 = os:system_time(native) - os:system_time(),
+ ChkDiff(V3),
+
+ erlang:yield(),
+ 0 = erlang:time_offset() - erlang:time_offset(native),
+
+ ok.
%% Returns the test data: a list of {Utc, Local} tuples.
@@ -867,6 +919,12 @@ test_data() ->
case os:cmd("date '+%Z'") of
"SAST"++_ ->
{2,2};
+ "PDT"++_ ->
+ {-8,-7};
+ "PST"++_ ->
+ {-8,-7};
+ "UTC"++_ ->
+ {0,0};
_ ->
{?timezone,?dst_timezone}
end;
@@ -992,22 +1050,3 @@ bad_dates() ->
{{1996, 4, 30}, {12, 0, -1}}, % Sec
{{1996, 4, 30}, {12, 0, 60}}].
-
-start_node(Config, Args) ->
- TestCase = proplists:get_value(testcase, Config),
- PA = filename:dirname(code:which(?MODULE)),
- ESTime = erlang:monotonic_time(1) + erlang:time_offset(1),
- Unique = erlang:unique_integer([positive]),
- Name = list_to_atom(atom_to_list(?MODULE)
- ++ "-"
- ++ atom_to_list(TestCase)
- ++ "-"
- ++ integer_to_list(ESTime)
- ++ "-"
- ++ integer_to_list(Unique)),
- test_server:start_node(Name,
- slave,
- [{args, "-pa " ++ PA ++ " " ++ Args}]).
-
-stop_node(Node) ->
- test_server:stop_node(Node).