diff options
Diffstat (limited to 'lib/common_test')
-rw-r--r-- | lib/common_test/doc/src/ct.xml | 3 | ||||
-rw-r--r-- | lib/common_test/doc/src/ct_run.xml | 8 | ||||
-rw-r--r-- | lib/common_test/doc/src/run_test_chapter.xml | 56 | ||||
-rw-r--r-- | lib/common_test/doc/src/write_test_chapter.xml | 2 | ||||
-rw-r--r-- | lib/common_test/src/ct_logs.erl | 37 | ||||
-rw-r--r-- | lib/common_test/src/ct_run.erl | 18 | ||||
-rw-r--r-- | lib/common_test/src/ct_slave.erl | 7 | ||||
-rw-r--r-- | lib/common_test/src/test_server.erl | 17 | ||||
-rw-r--r-- | lib/common_test/src/test_server_node.erl | 4 | ||||
-rw-r--r-- | lib/common_test/test/Makefile | 3 | ||||
-rw-r--r-- | lib/common_test/test/ct_keep_logs_SUITE.erl | 186 | ||||
-rw-r--r-- | lib/common_test/test/ct_keep_logs_SUITE_data/keep_logs_SUITE.erl | 32 | ||||
-rw-r--r-- | lib/common_test/test/ct_test_support.erl | 3 |
13 files changed, 349 insertions, 27 deletions
diff --git a/lib/common_test/doc/src/ct.xml b/lib/common_test/doc/src/ct.xml index ea9f956271..cd1e51a9a9 100644 --- a/lib/common_test/doc/src/ct.xml +++ b/lib/common_test/doc/src/ct.xml @@ -1190,7 +1190,7 @@ Opts.</fsummary> <type> <v>Opts = [OptTuples]</v> - <v>OptTuples = {dir, TestDirs} | {suite, Suites} | {group, Groups} | {testcase, Cases} | {spec, TestSpecs} | {join_specs, Bool} | {label, Label} | {config, CfgFiles} | {userconfig, UserConfig} | {allow_user_terms, Bool} | {logdir, LogDir} | {silent_connections, Conns} | {stylesheet, CSSFile} | {cover, CoverSpecFile} | {cover_stop, Bool} | {step, StepOpts} | {event_handler, EventHandlers} | {include, InclDirs} | {auto_compile, Bool} | {abort_if_missing_suites, Bool} | {create_priv_dir, CreatePrivDir} | {multiply_timetraps, M} | {scale_timetraps, Bool} | {repeat, N} | {duration, DurTime} | {until, StopTime} | {force_stop, ForceStop} | {decrypt, DecryptKeyOrFile} | {refresh_logs, LogDir} | {logopts, LogOpts} | {verbosity, VLevels} | {basic_html, Bool} | {esc_chars, Bool} | {ct_hooks, CTHs} | {enable_builtin_hooks, Bool} | {release_shell, Bool}</v> + <v>OptTuples = {dir, TestDirs} | {suite, Suites} | {group, Groups} | {testcase, Cases} | {spec, TestSpecs} | {join_specs, Bool} | {label, Label} | {config, CfgFiles} | {userconfig, UserConfig} | {allow_user_terms, Bool} | {logdir, LogDir} | {silent_connections, Conns} | {stylesheet, CSSFile} | {cover, CoverSpecFile} | {cover_stop, Bool} | {step, StepOpts} | {event_handler, EventHandlers} | {include, InclDirs} | {auto_compile, Bool} | {abort_if_missing_suites, Bool} | {create_priv_dir, CreatePrivDir} | {multiply_timetraps, M} | {scale_timetraps, Bool} | {repeat, N} | {duration, DurTime} | {until, StopTime} | {force_stop, ForceStop} | {decrypt, DecryptKeyOrFile} | {refresh_logs, LogDir} | {logopts, LogOpts} | {verbosity, VLevels} | {basic_html, Bool} | {esc_chars, Bool} | {keep_logs,KeepSpec} | {ct_hooks, CTHs} | {enable_builtin_hooks, Bool} | {release_shell, Bool}</v> <v>TestDirs = [string()] | string()</v> <v>Suites = [string()] | [atom()] | string() | atom()</v> <v>Cases = [atom()] | atom()</v> @@ -1226,6 +1226,7 @@ <v>VLevels = VLevel | [{Category, VLevel}]</v> <v>VLevel = integer()</v> <v>Category = atom()</v> + <v>KeepSpec = all | pos_integer()</v> <v>CTHs = [CTHModule | {CTHModule, CTHInitArgs}]</v> <v>CTHModule = atom()</v> <v>CTHInitArgs = term()</v> diff --git a/lib/common_test/doc/src/ct_run.xml b/lib/common_test/doc/src/ct_run.xml index 9e6229f1dd..af30550719 100644 --- a/lib/common_test/doc/src/ct_run.xml +++ b/lib/common_test/doc/src/ct_run.xml @@ -125,6 +125,7 @@ [-until [YYMoMoDD]HHMMSS [-force_stop [skip_rest]]] [-basic_html] [-no_esc_chars] + [-keep_logs all | NLogs] [-ct_hooks CTHModule1 CTHOpts1 and CTHModule2 CTHOpts2 and .. CTHModuleN CTHOptsN] [-exit_status ignore_config] @@ -164,6 +165,7 @@ [-until [YYMoMoDD]HHMMSS [-force_stop [skip_rest]]] [-basic_html] [-no_esc_chars] + [-keep_logs all | NLogs] [-ct_hooks CTHModule1 CTHOpts1 and CTHModule2 CTHOpts2 and .. CTHModuleN CTHOptsN] [-exit_status ignore_config]</pre> @@ -189,13 +191,15 @@ [-scale_timetraps] [-create_priv_dir auto_per_run | auto_per_tc | manual_per_tc] [-basic_html] - [-no_esc_chars]</pre> + [-no_esc_chars] + [-keep_logs all | NLogs]</pre> </section> <section> <title>Refresh HTML Index Files</title> <pre> - ct_run -refresh_logs [-logdir LogDir] [-basic_html]</pre> + ct_run -refresh_logs [-logdir LogDir] [-basic_html] + [-keep_logs all | NLogs]</pre> </section> <section> diff --git a/lib/common_test/doc/src/run_test_chapter.xml b/lib/common_test/doc/src/run_test_chapter.xml index 76e306c4ed..fa336b7e16 100644 --- a/lib/common_test/doc/src/run_test_chapter.xml +++ b/lib/common_test/doc/src/run_test_chapter.xml @@ -1322,8 +1322,8 @@ <title>The Unexpected I/O Log</title> <p>The test suites overview page includes a link to the Unexpected I/O Log. In this log, <c>Common Test</c> saves printouts made with - <seealso marker="ct#log-2"><c>ct:log/2</c></seealso> and - <seealso marker="ct#pal-2"><c>ct:pal/2</c></seealso>, as well as captured system + <seealso marker="ct#log-2"><c>ct:log/1,2,3,4,5</c></seealso> and + <seealso marker="ct#pal-2"><c>ct:pal/1,2,3,4,5</c></seealso>, as well as captured system error- and progress reports, which cannot be associated with particular test cases and therefore cannot be written to individual test case log files. This occurs, for example, if a log printout is made from an external process (not a test @@ -1338,7 +1338,7 @@ <title>The Pre- and Post Test I/O Log</title> <p>The <c>Common Test</c> Framework Log page includes links to the Pre- and Post Test I/O Log. In this log, <c>Common Test</c> saves printouts made - with <c>ct:log/2</c> and <c>ct:pal/2</c>, as well as captured system error- + with <c>ct:log/1,2,3,4,5</c> and <c>ct:pal/1,2,3,4,5</c>, as well as captured system error- and progress reports, which take place before, and after, the test run. Examples of this are printouts from a CT hook init- or terminate function, or progress reports generated when an OTP application is started from a CT hook @@ -1349,10 +1349,22 @@ applications, see section <seealso marker="ct_hooks_chapter#synchronizing">Synchronizing</seealso> in section Common Test Hooks.</p> - <note><p>Logging to file with <c>ct:log/2</c> or <c>ct:pal/2</c> - only works when <c>Common Test</c> is running. Printouts with <c>ct:pal/2</c> + <note><p>Logging to file with <c>ct:log/1,2,3,4,5</c> or <c>ct:pal/1,2,3,4,5</c> + only works when <c>Common Test</c> is running. Printouts with <c>ct:pal/1,2,3,4,5</c> are however always displayed on screen.</p></note> </section> + + <section> + <marker id="delete_old_logs"></marker> + <title>Delete Old Logs</title> + <p><c>Common Test</c> can automatically delete old log. This + is specified with the <c>keep_logs</c> option. The default + value for this option is <c>all</c>, which means that no + logs are deleted. If the value is set to an + integer, <c>N</c>, <c>Common Test</c> deletes + all <c>ct_run.<timestamp></c> directories, except + the <c>N</c> newest.</p> + </section> </section> <section> @@ -1371,24 +1383,38 @@ <p><c>Common Test</c> includes an <em>optional</em> feature to allow user HTML style sheets for customizing printouts. The functions in <c>ct</c> that print to a test case HTML log - file (<c>log/3</c> and <c>pal/3</c>) accept <c>Category</c> + file (<c>log/3,4,5</c> and <c>pal/3,4,5</c>) accept <c>Category</c> as first argument. With this argument a category can be specified - that can be mapped to a selector in a CSS - definition. This is useful, especially for coloring text + that can be mapped to a named <c>div</c> selector in a CSS rule-set. + This is useful, especially for coloring text differently depending on the type of (or reason for) the - printout. Say you want one color for test system + printout. Say you want one particular background color for test system configuration information, a different one for test system state information, and finally one for errors detected by the test case functions. The corresponding style sheet can look as follows:</p> <pre> - div.sys_config { background:blue; color:white } - div.sys_state { background:yellow; color:black } - div.error { background:red; color:white }</pre> + div.sys_config { background:blue } + div.sys_state { background:yellow } + div.error { background:red }</pre> + + <p>Common Test prints the text from <c>ct:log/3,4,5</c> or + <c>ct:pal/3,4,5</c> inside a <c>pre</c> element + nested under the named <c>div</c> element. Since the <c>pre</c> selector + has a predefined CSS rule (in file <c>ct_default.css</c>) for the attributes + <c>color</c>, <c>font-family</c> and <c>font-size</c>, if a user wants to + change any of the predefined attribute settings, a new rule for <c>pre</c> + must be added to the user stylesheet. Example:</p> + + <pre> +div.error pre { color:white }</pre> + + <p>Here, white text is used instead of the default black for <c>div.error</c> + printouts (and no other attribute settings for <c>pre</c> are affected).</p> <p>To install the CSS file (<c>Common Test</c> inlines the definition in the - HTML code), the name can be provided when executing <c>ct_run</c>.</p> + HTML code), the file name can be provided when executing <c>ct_run</c>.</p> <p><em>Example:</em></p> <pre> @@ -1436,8 +1462,8 @@ suite.</p> <p>Argument <c>Category</c> in the previous example can have the - value (atom) <c>sys_config</c> (white on blue), <c>sys_state</c> - (black on yellow), or <c>error</c> (white on red).</p> + value (atom) <c>sys_config</c> (blue background), <c>sys_state</c> + (yellow background), or <c>error</c> (white text on red background).</p> </section> <section> diff --git a/lib/common_test/doc/src/write_test_chapter.xml b/lib/common_test/doc/src/write_test_chapter.xml index 6a0d87bcaf..c230148b29 100644 --- a/lib/common_test/doc/src/write_test_chapter.xml +++ b/lib/common_test/doc/src/write_test_chapter.xml @@ -1036,7 +1036,7 @@ Importance >= (100-VerbosityLevel)</pre> <p>Note that the category argument is not required in order to only specify the importance of a printout. Example:</p> <pre> -<c>ct:pal(?LOW_IMPORTANCE, "Info report: ~p", [Info])</c></pre> +ct:pal(?LOW_IMPORTANCE, "Info report: ~p", [Info])</pre> <p>Or perhaps in combination with constants:</p> <pre> -define(INFO, ?LOW_IMPORTANCE). diff --git a/lib/common_test/src/ct_logs.erl b/lib/common_test/src/ct_logs.erl index 09ad709da5..544b019b64 100644 --- a/lib/common_test/src/ct_logs.erl +++ b/lib/common_test/src/ct_logs.erl @@ -41,6 +41,7 @@ -export([xhtml/2, locate_priv_file/1, make_relative/1]). -export([insert_javascript/1]). -export([uri/1]). +-export([parse_keep_logs/1]). %% Logging stuff directly from testcase -export([tc_log/3, tc_log/4, tc_log/5, tc_log/6, @@ -1946,7 +1947,11 @@ make_all_runs_index(When) -> end, Dirs = filelib:wildcard(logdir_prefix()++"*.*"), - DirsSorted = (catch sort_all_runs(Dirs)), + DirsSorted0 = (catch sort_all_runs(Dirs)), + DirsSorted = + if When == start -> DirsSorted0; + true -> maybe_delete_old_dirs(DirsSorted0) + end, LogCacheInfo = get_cache_data(UseCache), @@ -2064,6 +2069,36 @@ sort_ct_runs(Dirs) -> {DateHH1,MM1,SS1} =< {DateHH2,MM2,SS2} end, Dirs). +parse_keep_logs([Str="all"]) -> + parse_keep_logs(list_to_atom(Str)); +parse_keep_logs([NStr]) -> + parse_keep_logs(list_to_integer(NStr)); +parse_keep_logs(all) -> + all; +parse_keep_logs(N) when is_integer(N), N>0 -> + N. + +maybe_delete_old_dirs(Sorted) -> + {Keep,Delete} = + case application:get_env(common_test, keep_logs) of + {ok,MaxN} when is_integer(MaxN), length(Sorted)>MaxN -> + lists:split(MaxN,Sorted); + _ -> + {Sorted,[]} + end, + delete_old_dirs(Delete), + Keep. + +delete_old_dirs([]) -> + ok; +delete_old_dirs(Dirs) -> + io:put_chars("\n Removing old test directories:\n"), + [begin + io:put_chars(" " ++ Dir ++ "\n"), + rm_dir(Dir) + end|| Dir <- Dirs], + ok. + dir_diff_all_runs(Dirs, LogCache) -> case LogCache#log_cache.all_runs of [] -> diff --git a/lib/common_test/src/ct_run.erl b/lib/common_test/src/ct_run.erl index cac176de3a..ba27303c81 100644 --- a/lib/common_test/src/ct_run.erl +++ b/lib/common_test/src/ct_run.erl @@ -363,6 +363,12 @@ script_start1(Parent, Args) -> _ -> application:set_env(common_test, disable_log_cache, true) end, + %% log_cleanup - used by ct_logs + KeepLogs = get_start_opt(keep_logs, + fun ct_logs:parse_keep_logs/1, + all, + Args), + application:set_env(common_test, keep_logs, KeepLogs), Opts = #opts{label = Label, profile = Profile, vts = Vts, shell = Shell, @@ -970,6 +976,12 @@ run_test1(StartOpts) when is_list(StartOpts) -> stop_trace(Tracing), exit(Res); RefreshDir -> + %% log_cleanup - used by ct_logs + KeepLogs = get_start_opt(keep_logs, + fun ct_logs:parse_keep_logs/1, + all, + StartOpts), + application:set_env(common_test, keep_logs, KeepLogs), ok = refresh_logs(?abs(RefreshDir)), exit(done) end. @@ -1131,6 +1143,12 @@ run_test2(StartOpts) -> DisableCacheBool -> application:set_env(common_test, disable_log_cache, DisableCacheBool) end, + %% log_cleanup - used by ct_logs + KeepLogs = get_start_opt(keep_logs, + fun ct_logs:parse_keep_logs/1, + all, + StartOpts), + application:set_env(common_test, keep_logs, KeepLogs), %% stepped execution Step = get_start_opt(step, value, StartOpts), diff --git a/lib/common_test/src/ct_slave.erl b/lib/common_test/src/ct_slave.erl index 571958ca03..4188bd7c3b 100644 --- a/lib/common_test/src/ct_slave.erl +++ b/lib/common_test/src/ct_slave.erl @@ -309,7 +309,12 @@ is_started(ENode) -> % make a Erlang node name from name and hostname enodename(Host, Node) -> - list_to_atom(atom_to_list(Node)++"@"++atom_to_list(Host)). + case lists:member($@, atom_to_list(Node)) of + true -> + Node; + false -> + list_to_atom(atom_to_list(Node)++"@"++atom_to_list(Host)) + end. % performs actual start of the "slave" node do_start(Host, Node, Options) -> diff --git a/lib/common_test/src/test_server.erl b/lib/common_test/src/test_server.erl index be49191f2e..0256206e59 100644 --- a/lib/common_test/src/test_server.erl +++ b/lib/common_test/src/test_server.erl @@ -359,10 +359,10 @@ stick_all_sticky(Node,Sticky) -> %% cover. run_test_case_apply({Mod,Func,Args,Name,RunInit,TimetrapData}) -> - case os:getenv("TS_RUN_VALGRIND") of + case is_valgrind() of false -> ok; - _ -> + true -> os:putenv("VALGRIND_LOGFILE_INFIX",atom_to_list(Mod)++"."++ atom_to_list(Func)++"-") end, @@ -1827,7 +1827,8 @@ timetrap_scale_factor() -> { 2, fun() -> has_lock_checking() end}, { 3, fun() -> has_superfluous_schedulers() end}, { 6, fun() -> is_debug() end}, - {10, fun() -> is_cover() end} + {10, fun() -> is_cover() end}, + {10, fun() -> is_valgrind() end} ]). timetrap_scale_factor(Scales) -> @@ -2729,6 +2730,16 @@ is_commercial() -> _ -> true end. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% is_valgrind() -> boolean() +%% +%% Returns true if valgrind is running, else false +is_valgrind() -> + case os:getenv("TS_RUN_VALGRIND") of + false -> false; + _ -> true + end. + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% %% Apply given function and reply to caller or proxy. diff --git a/lib/common_test/src/test_server_node.erl b/lib/common_test/src/test_server_node.erl index 0b406c54cc..92c610730e 100644 --- a/lib/common_test/src/test_server_node.erl +++ b/lib/common_test/src/test_server_node.erl @@ -18,11 +18,11 @@ %% %CopyrightEnd% %% -module(test_server_node). --compile(r12). +-compile(r16). %%% %%% The same compiled code for this module must be possible to load -%%% in R12B and later. +%%% in R16B and later. %%% %% Test Controller interface diff --git a/lib/common_test/test/Makefile b/lib/common_test/test/Makefile index 2f0fc2e05a..b8fb678dbd 100644 --- a/lib/common_test/test/Makefile +++ b/lib/common_test/test/Makefile @@ -71,7 +71,8 @@ MODULES= \ test_server_test_lib \ ct_release_test_SUITE \ ct_log_SUITE \ - ct_SUITE + ct_SUITE \ + ct_keep_logs_SUITE ERL_FILES= $(MODULES:%=%.erl) HRL_FILES= test_server_test_lib.hrl diff --git a/lib/common_test/test/ct_keep_logs_SUITE.erl b/lib/common_test/test/ct_keep_logs_SUITE.erl new file mode 100644 index 0000000000..34bfaaa97a --- /dev/null +++ b/lib/common_test/test/ct_keep_logs_SUITE.erl @@ -0,0 +1,186 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2009-2016. 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. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% +%% + +%%%------------------------------------------------------------------- +%%% File: ct_keep_logs_SUITE +%%% +%%% Description: +%%% Test the 'keep_logs' option +%%% +%%%------------------------------------------------------------------- +-module(ct_keep_logs_SUITE). + +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). +-include_lib("common_test/include/ct_event.hrl"). + +-define(eh, ct_test_support_eh). + +%%-------------------------------------------------------------------- +%% TEST SERVER CALLBACK FUNCTIONS +%%-------------------------------------------------------------------- + +init_per_suite(Config0) -> + ct_test_support:init_per_suite(Config0). + +end_per_suite(Config) -> + ct_test_support:end_per_suite(Config). + +init_per_testcase(TestCase, Config) -> + ct_test_support:init_per_testcase(TestCase, Config). + +end_per_testcase(TestCase, Config) -> + ct_test_support:end_per_testcase(TestCase, Config). + +suite() -> [{ct_hooks,[ts_install_cth]}]. + +all() -> + [ + keep_logs, + refresh_logs + ]. + +%%-------------------------------------------------------------------- +%% TEST CASES +%%-------------------------------------------------------------------- + +%% Test the keep_logs option with normal common_test runs +keep_logs(Config) -> + DataDir = ?config(data_dir, Config), + Suite = filename:join(DataDir, "keep_logs_SUITE"), + Opts0 = ct_test_support:get_opts(Config), + Opts = [{suite,Suite},{label,keep_logs} | Opts0], + + LogDir=?config(logdir,Opts), + KeepLogsDir = filename:join(LogDir,unique_name("keep_logs-")), + ok = file:make_dir(KeepLogsDir), + Opts1 = lists:keyreplace(logdir,1,Opts,{logdir,KeepLogsDir}), + ct:log("New LogDir = ~s", [KeepLogsDir]), + + %% Create 6 ct_run.* log directories + [ok = ct_test_support:run(Opts1, Config) || _ <- lists:seq(1,3)], + + %% Verify the number of directories + WC = filename:join(KeepLogsDir,"ct_run.ct@*"), + L1 = filelib:wildcard(WC), + 6 = length(L1), + + %% Keep all logs + {1,0,{0,0}}=ct_test_support:run_ct_run_test([{keep_logs,all}|Opts1], Config), + L2 = filelib:wildcard(WC), + 7 = length(L2), + 0 = ct_test_support:run_ct_script_start([{keep_logs,all}|Opts1], Config), + L3 = filelib:wildcard(WC), + 8 = length(L3), + + %% N<length of list + {1,0,{0,0}}=ct_test_support:run_ct_run_test([{keep_logs,7}|Opts1], Config), + L4 = filelib:wildcard(WC), + 7 = length(L4), + 0 = ct_test_support:run_ct_script_start([{keep_logs,6}|Opts1], Config), + L5 = filelib:wildcard(WC), + 6 = length(L5), + + %% N>length of list + {1,0,{0,0}}=ct_test_support:run_ct_run_test([{keep_logs,10}|Opts1], Config), + L6 = filelib:wildcard(WC), + 7 = length(L6), + 0 = ct_test_support:run_ct_script_start([{keep_logs,10}|Opts1], Config), + L7 = filelib:wildcard(WC), + 8 = length(L7), + + %% N==length of list + {1,0,{0,0}}=ct_test_support:run_ct_run_test([{keep_logs,8}|Opts1], Config), + L8 = filelib:wildcard(WC), + 8 = length(L8), + 0 = ct_test_support:run_ct_script_start([{keep_logs,8}|Opts1], Config), + L9 = filelib:wildcard(WC), + 8 = length(L9), + + %% N==length of list + current run + {1,0,{0,0}}=ct_test_support:run_ct_run_test([{keep_logs,9}|Opts1], Config), + L10 = filelib:wildcard(WC), + 9 = length(L10), + 0 = ct_test_support:run_ct_script_start([{keep_logs,10}|Opts1], Config), + L11 = filelib:wildcard(WC), + 10 = length(L11). + +%% Test the keep_logs option togwther with the refresh_logs option +refresh_logs(Config) -> + DataDir = ?config(data_dir, Config), + Suite = filename:join(DataDir, "keep_logs_SUITE"), + Opts0 = ct_test_support:get_opts(Config), + LogDir=?config(logdir,Opts0), + KeepLogsDir = filename:join(LogDir,unique_name("refresh_logs-")), + ok = file:make_dir(KeepLogsDir), + Opts1 = lists:keyreplace(logdir,1,Opts0,{logdir,KeepLogsDir}), + ct:log("New LogDir = ~s", [KeepLogsDir]), + + %% Create 6 ct_run.* log directories + SuiteOpts = [{suite,Suite},{label,refresh_logs} | Opts1], + [ok = ct_test_support:run(SuiteOpts, Config) || _ <- lists:seq(1,3)], + + %% Verify the number of directories + WC = filename:join(KeepLogsDir,"ct_run.ct@*"), + L1 = filelib:wildcard(WC), + 6 = length(L1), + + RefreshOpts = [{refresh_logs,KeepLogsDir},{label,refresh_logs} | Opts1], + + %% Keep all logs (note that refresh_logs option prevents the + %% creation of a new log directory for the current run) + done = ct_test_support:run_ct_run_test([{keep_logs,all}|RefreshOpts], Config), + L2 = filelib:wildcard(WC), + 6 = length(L2), + 0 = ct_test_support:run_ct_script_start([{keep_logs,all}|RefreshOpts],Config), + L3 = filelib:wildcard(WC), + 6 = length(L3), + + %% N<length of list + done = ct_test_support:run_ct_run_test([{keep_logs,5}|RefreshOpts], Config), + L5 = filelib:wildcard(WC), + 5 = length(L5), + 0 = ct_test_support:run_ct_script_start([{keep_logs,4}|RefreshOpts], Config), + L6 = filelib:wildcard(WC), + 4 = length(L6), + + %% N>length of list + done = ct_test_support:run_ct_run_test([{keep_logs,5}|RefreshOpts], Config), + L7 = filelib:wildcard(WC), + 4 = length(L7), + 0 = ct_test_support:run_ct_script_start([{keep_logs,5}|RefreshOpts], Config), + L8 = filelib:wildcard(WC), + 4 = length(L8), + + %% N==length of list + done = ct_test_support:run_ct_run_test([{keep_logs,4}|RefreshOpts], Config), + L9 = filelib:wildcard(WC), + 4 = length(L9), + 0 = ct_test_support:run_ct_script_start([{keep_logs,4}|RefreshOpts], Config), + L10 = filelib:wildcard(WC), + 4 = length(L10), + + ok. +%%%----------------------------------------------------------------- +%%% Internal +unique_name(Prefix) -> + I = erlang:unique_integer([positive]), + Prefix ++ integer_to_list(I). diff --git a/lib/common_test/test/ct_keep_logs_SUITE_data/keep_logs_SUITE.erl b/lib/common_test/test/ct_keep_logs_SUITE_data/keep_logs_SUITE.erl new file mode 100644 index 0000000000..2bccae564b --- /dev/null +++ b/lib/common_test/test/ct_keep_logs_SUITE_data/keep_logs_SUITE.erl @@ -0,0 +1,32 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2009-2016. 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. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% +%% +-module(keep_logs_SUITE). + +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). + +suite() -> + []. +all() -> + [test_case]. + +test_case(_Config) -> + ok. diff --git a/lib/common_test/test/ct_test_support.erl b/lib/common_test/test/ct_test_support.erl index 05a452b99d..06d591871f 100644 --- a/lib/common_test/test/ct_test_support.erl +++ b/lib/common_test/test/ct_test_support.erl @@ -351,6 +351,9 @@ check_result(CtRunTestResult,ExitStatus,Opts) catch _:_ -> {error,{unexpected_return_value,{CtRunTestResult,ExitStatus}}} end; +check_result(done,0,_Opts) -> + %% refresh_logs return + ok; check_result(CtRunTestResult,ExitStatus,_Opts) -> {error,{unexpected_return_value,{CtRunTestResult,ExitStatus}}}. |