From e34cd721545915266a00b1ec55a9a5867c8459a4 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Wed, 9 Feb 2011 13:59:50 +0100 Subject: Update SCBs to use a specific id/1 function for SCb overriding instead of returning it from init/1. --- .../scb/tests/crash_id_scb.erl | 34 ++++++++++++++++++++++ .../scb/tests/crash_init_scb.erl | 6 ++-- .../scb/tests/empty_scb.erl | 26 +++++++++++------ .../scb/tests/fail_post_suite_scb.erl | 4 +-- .../scb/tests/fail_pre_suite_scb.erl | 4 +-- .../scb/tests/id_no_init_scb.erl | 32 ++++++++++++++++++++ .../scb/tests/minimal_scb.erl | 6 ++-- .../scb/tests/recover_post_suite_scb.erl | 4 +-- .../scb/tests/same_id_scb.erl | 9 ++++-- .../scb/tests/skip_post_suite_scb.erl | 4 +-- .../scb/tests/skip_pre_suite_scb.erl | 4 +-- .../scb/tests/state_update_scb.erl | 6 ++-- .../scb/tests/undef_scb.erl | 4 +-- .../scb/tests/update_config_scb.erl | 4 +-- 14 files changed, 112 insertions(+), 35 deletions(-) create mode 100644 lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/crash_id_scb.erl create mode 100644 lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/id_no_init_scb.erl (limited to 'lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests') diff --git a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/crash_id_scb.erl b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/crash_id_scb.erl new file mode 100644 index 0000000000..2c256c46df --- /dev/null +++ b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/crash_id_scb.erl @@ -0,0 +1,34 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2010. 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(crash_id_scb). + + +-include_lib("common_test/src/ct_util.hrl"). +-include_lib("common_test/include/ct_event.hrl"). + + +%% Suite Callbacks +-export([id/1]). + +id(Opts) -> + empty_scb:id(Opts), + exit(diediedie). + diff --git a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/crash_init_scb.erl b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/crash_init_scb.erl index 683459853f..c4138bbcef 100644 --- a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/crash_init_scb.erl +++ b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/crash_init_scb.erl @@ -26,9 +26,9 @@ %% Suite Callbacks --export([init/1]). +-export([init/2]). -init(Opts) -> - empty_scb:init(Opts), +init(Id, Opts) -> + empty_scb:init(Id, Opts), exit(diediedie). diff --git a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/empty_scb.erl b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/empty_scb.erl index d9aa1e77e4..a82ca02d04 100644 --- a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/empty_scb.erl +++ b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/empty_scb.erl @@ -35,7 +35,8 @@ -module(empty_scb). %% Suite Callbacks --export([init/1]). +-export([id/1]). +-export([init/2]). -export([pre_init_per_suite/3]). -export([post_init_per_suite/4]). @@ -68,16 +69,23 @@ -record(state, { id = ?MODULE :: term()}). %% @doc Always called before any other callback function. Use this to initiate -%% any common state. It should return an ID for this SCB and a state. The ID -%% is used to uniquly identify an SCB instance, if two SCB's return the same -%% ID the seconds SCB is ignored. This function should NOT have any side -%% effects as it might be called multiple times by common test. --spec init(Opts :: proplist()) -> +%% any common state. It should return an ID for this SCB and a state. +-spec init(Id :: term(), Opts :: proplist()) -> {Id :: term(), State :: #state{}}. -init(Opts) -> +init(Id, Opts) -> gen_event:notify(?CT_EVMGR_REF, #event{ name = scb, node = node(), - data = {?MODULE, init, [Opts]}}), - {now(), Opts}. + data = {?MODULE, init, [Id, Opts]}}), + Opts. + +%% @doc The ID is used to uniquly identify an SCB instance, if two SCB's +%% return the same ID the seconds SCB is ignored. This function should NOT +%% have any side effects as it might be called multiple times by common test. +-spec id(Opts :: proplist()) -> + Id :: term(). +id(Opts) -> + gen_event:notify(?CT_EVMGR_REF, #event{ name = scb, node = node(), + data = {?MODULE, id, [Opts]}}), + now(). %% @doc Called before init_per_suite is called. Note that this callback is %% only called if the SCB is added before init_per_suite is run (eg. in a test diff --git a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/fail_post_suite_scb.erl b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/fail_post_suite_scb.erl index b3a3a5f94c..44c72f6795 100644 --- a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/fail_post_suite_scb.erl +++ b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/fail_post_suite_scb.erl @@ -28,8 +28,8 @@ %% Suite Callbacks -compile(export_all). -init(Opts) -> - empty_scb:init(Opts). +init(Id, Opts) -> + empty_scb:init(Id, Opts). pre_init_per_suite(Suite, Config, State) -> empty_scb:pre_init_per_suite(Suite,Config,State). diff --git a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/fail_pre_suite_scb.erl b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/fail_pre_suite_scb.erl index d49387ff8c..90f10d7531 100644 --- a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/fail_pre_suite_scb.erl +++ b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/fail_pre_suite_scb.erl @@ -28,8 +28,8 @@ %% Suite Callbacks -compile(export_all). -init(Opts) -> - empty_scb:init(Opts). +init(Id, Opts) -> + empty_scb:init(Id, Opts). pre_init_per_suite(Suite, Config, State) -> empty_scb:pre_init_per_suite(Suite,Config,State), diff --git a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/id_no_init_scb.erl b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/id_no_init_scb.erl new file mode 100644 index 0000000000..11fb8d739f --- /dev/null +++ b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/id_no_init_scb.erl @@ -0,0 +1,32 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2010. 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(id_no_init_scb). + + +-include_lib("common_test/src/ct_util.hrl"). +-include_lib("common_test/include/ct_event.hrl"). + + +%% Suite Callbacks +-export([id/1]). + +id(Opts) -> + empty_scb:id(Opts). diff --git a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/minimal_scb.erl b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/minimal_scb.erl index e5fdbfb8a0..b3feb1383c 100644 --- a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/minimal_scb.erl +++ b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/minimal_scb.erl @@ -26,8 +26,8 @@ %% Suite Callbacks --export([init/1]). +-export([init/2]). -init(Opts) -> - empty_scb:init(Opts). +init(Id, Opts) -> + empty_scb:init(Id, Opts). diff --git a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/recover_post_suite_scb.erl b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/recover_post_suite_scb.erl index 864a09e3d0..26468f0789 100644 --- a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/recover_post_suite_scb.erl +++ b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/recover_post_suite_scb.erl @@ -28,8 +28,8 @@ %% Suite Callbacks -compile(export_all). -init(Opts) -> - empty_scb:init(Opts). +init(Id, Opts) -> + empty_scb:init(Id, Opts). pre_init_per_suite(Suite, Config, State) -> empty_scb:pre_init_per_suite(Suite,Config,State). diff --git a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/same_id_scb.erl b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/same_id_scb.erl index 6853aa52e8..0fa708d5b6 100644 --- a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/same_id_scb.erl +++ b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/same_id_scb.erl @@ -28,9 +28,12 @@ %% Suite Callbacks -compile(export_all). -init(Opts) -> - {_,State} = empty_scb:init(Opts), - {?MODULE,State}. +id(Opts) -> + empty_scb:id(Opts), + ?MODULE. + +init(Id, Opts) -> + empty_scb:init(Id, Opts). pre_init_per_suite(Suite, Config, State) -> empty_scb:pre_init_per_suite(Suite,Config,State). diff --git a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/skip_post_suite_scb.erl b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/skip_post_suite_scb.erl index a2e0578814..bb93ebee0f 100644 --- a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/skip_post_suite_scb.erl +++ b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/skip_post_suite_scb.erl @@ -28,8 +28,8 @@ %% Suite Callbacks -compile(export_all). -init(Opts) -> - empty_scb:init(Opts). +init(Id, Opts) -> + empty_scb:init(Id, Opts). pre_init_per_suite(Suite, Config, State) -> empty_scb:pre_init_per_suite(Suite,Config,State). diff --git a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/skip_pre_suite_scb.erl b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/skip_pre_suite_scb.erl index 4a0725ce2f..9818964e7f 100644 --- a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/skip_pre_suite_scb.erl +++ b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/skip_pre_suite_scb.erl @@ -28,8 +28,8 @@ %% Suite Callbacks -compile(export_all). -init(Opts) -> - empty_scb:init(Opts). +init(Id, Opts) -> + empty_scb:init(Id, Opts). pre_init_per_suite(Suite, Config, State) -> diff --git a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/state_update_scb.erl b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/state_update_scb.erl index 1da0f7a6e4..13c50cf1a1 100644 --- a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/state_update_scb.erl +++ b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/state_update_scb.erl @@ -27,9 +27,9 @@ %% Suite Callbacks -compile(export_all). -init(Opts) -> - {Id,State} = empty_scb:init(Opts), - {Id,[init|State]}. +init(Id, Opts) -> + State = empty_scb:init(Id, Opts), + [init|State]. pre_init_per_suite(Suite, Config, State) -> empty_scb:pre_init_per_suite(Suite,Config,State), diff --git a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/undef_scb.erl b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/undef_scb.erl index 9479f9d937..1cb64574c3 100644 --- a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/undef_scb.erl +++ b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/undef_scb.erl @@ -28,8 +28,8 @@ %% Suite Callbacks -compile(export_all). -init(Opts) -> - empty_scb:init(Opts). +init(Id, Opts) -> + empty_scb:init(Id, Opts). pre_init_per_suite(_Suite, _Config, _State) -> lists:flaten([1,2,[3,4]]). diff --git a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/update_config_scb.erl b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/update_config_scb.erl index 6f21e49656..46a027403d 100644 --- a/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/update_config_scb.erl +++ b/lib/common_test/test/ct_suite_callback_SUITE_data/scb/tests/update_config_scb.erl @@ -28,8 +28,8 @@ %% Suite Callbacks -compile(export_all). -init(Opts) -> - empty_scb:init(Opts). +init(Id, Opts) -> + empty_scb:init(Id, Opts). pre_init_per_suite(Suite, Config, State) -> empty_scb:pre_init_per_suite(Suite,Config,State), -- cgit v1.2.3