1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2012-2016. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20-module(timetrap_8_SUITE). 21 22-compile(export_all). 23 24-include_lib("common_test/include/ct.hrl"). 25 26-define(TO, 4). 27 28%%-------------------------------------------------------------------- 29%% Function: suite() -> Info 30%% Info = [tuple()] 31%%-------------------------------------------------------------------- 32suite() -> 33 [{timetrap,{timetrap_utils,timetrap_val,[{seconds,?TO}]}}]. 34 35%%-------------------------------------------------------------------- 36%% Function: init_per_suite(Config0) -> 37%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} 38%% Config0 = Config1 = [tuple()] 39%% Reason = term() 40%%-------------------------------------------------------------------- 41init_per_suite(Config) -> 42 Config. 43 44%%-------------------------------------------------------------------- 45%% Function: end_per_suite(Config0) -> void() | {save_config,Config1} 46%% Config0 = Config1 = [tuple()] 47%%-------------------------------------------------------------------- 48end_per_suite(_Config) -> 49 ok. 50 51%%-------------------------------------------------------------------- 52%% Function: init_per_group(GroupName, Config0) -> 53%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} 54%% GroupName = atom() 55%% Config0 = Config1 = [tuple()] 56%% Reason = term() 57%%-------------------------------------------------------------------- 58init_per_group(G6, Config) when G6==g6; G6==pg6 -> 59 ct:sleep({seconds,1}), 60 Config; 61init_per_group(_GroupName, Config) -> 62 Config. 63 64%%-------------------------------------------------------------------- 65%% Function: end_per_group(GroupName, Config0) -> 66%% void() | {save_config,Config1} 67%% GroupName = atom() 68%% Config0 = Config1 = [tuple()] 69%%-------------------------------------------------------------------- 70end_per_group(G7or8, _Config) when G7or8==g7; G7or8==pg7; G7or8==g8; G7or8==pg8 -> 71 ct:sleep({seconds,5}), 72 ok; 73end_per_group(_GroupName, _Config) -> 74 ok. 75 76%%-------------------------------------------------------------------- 77%% Function: init_per_testcase(TestCase, Config0) -> 78%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} 79%% TestCase = atom() 80%% Config0 = Config1 = [tuple()] 81%% Reason = term() 82%%-------------------------------------------------------------------- 83init_per_testcase(_, Config) -> 84 Config. 85 86%%-------------------------------------------------------------------- 87%% Function: end_per_testcase(TestCase, Config0) -> 88%% void() | {save_config,Config1} 89%% TestCase = atom() 90%% Config0 = Config1 = [tuple()] 91%%-------------------------------------------------------------------- 92end_per_testcase(_, _Config) -> 93 ok. 94 95%%-------------------------------------------------------------------- 96%% Function: groups() -> [Group] 97%% Group = {GroupName,Properties,GroupsAndTestCases} 98%% GroupName = atom() 99%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}] 100%% GroupsAndTestCases = [Group | {group,GroupName} | TestCase] 101%% TestCase = atom() 102%% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}} 103%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | 104%% repeat_until_any_ok | repeat_until_any_fail 105%% N = integer() | forever 106%%-------------------------------------------------------------------- 107groups() -> 108 [ 109 {g0,[],[tc0,tc2]}, % group override suite and tc overrides group 110 {g1,[],[tc0,tc2]}, % group override suite and tc overrides group 111 {g2,[],[tc1,tc2]}, % tc override group 112 {g3,[],[tc4,{group,g1},{group,g2}]}, % subgroup override group 113 {g4,[],[tc0,tc2]}, % exit during init_per_group 114 {g5,[],[tc0,tc2]}, % exit during init_per_group 115 {g6,[],[tc0,tc2]}, % timeout during init_per_group 116 {g7,[],[tc5]}, % exit during end_per_group 117 {g8,[],[tc5]}, % timeout during end_per_group 118 {g9,[],[tc5,tc0]}, % exit during testcase 119 {g10,[],[tc0,tc5]}, % exit during testcase 120 {g11,[],[tc3,tc2]}, % suite is valid if nothing else is specified 121 {pg0,[parallel],[tc0,tc2]}, % group override suite and tc overrides group 122 {pg1,[parallel],[tc0,tc2]}, % group override suite and tc overrides group 123 {pg2,[parallel],[tc1,tc2]}, % tc override group 124 {pg3,[parallel],[tc4,{group,pg1},{group,pg2}]}, % subgroup override group 125 {pg4,[parallel],[tc0,tc2]}, % exit during init_per_group 126 {pg5,[parallel],[tc0,tc2]}, % exit during init_per_group 127 {pg6,[parallel],[tc0,tc2]}, % timeout during init_per_group 128 {pg7,[parallel],[tc5]}, % exit during end_per_group 129 {pg8,[parallel],[tc5]}, % timeout during end_per_group 130 {pg9,[parallel],[tc5,tc0]}, % exit during testcase 131 {pg10,[parallel],[tc0,tc5]},% exit during testcase 132 {pg11,[parallel],[tc3,tc2]},% suite is valid if nothing else is specified 133 {sg1,[sequence],[tc5,tc0,tc1,tc2]}, % exit during sequencial testcase 134 {sg2,[sequence],[tc5,tc0,tc1,tc2]}].% timeout during sequencial testcase 135 136group(g0) -> 137 [{timetrap,{timetrap_utils,timetrap_val,[{seconds,1}]}}]; 138group(g1) -> 139 [{timetrap,fun() -> timetrap_utils:timetrap_val(1000) end}]; 140group(g2) -> 141 [{timetrap,fun() -> timetrap_utils:timetrap_val(3000) end}]; 142group(g3) -> 143 [{timetrap,fun() -> timetrap_utils:timetrap_val(2000) end}]; 144group(g4) -> 145 [{timetrap,{timetrap_utils,timetrap_exit,[kaboom]}}]; 146group(g5) -> 147 [{timetrap,fun() -> exit(kaboom) end}]; 148group(g6) -> 149 [{timetrap,{timetrap_utils,timetrap_val,[500]}}]; 150group(g7) -> 151 [{timetrap,fun() -> ct:sleep(1000),exit(kaboom) end}]; 152group(g8) -> 153 [{timetrap,{timetrap_utils,timetrap_val,[500]}}]; 154group(g9) -> 155 [{timetrap,fun() -> ct:sleep(1000),exit(kaboom) end}]; 156group(g10) -> 157 [{timetrap,fun() -> ct:sleep(1000),exit(kaboom) end}]; 158group(g11) -> 159 []; 160group(pg0) -> 161 [{timetrap,{timetrap_utils,timetrap_val,[{seconds,1}]}}]; 162group(pg1) -> 163 [{timetrap,fun() -> timetrap_utils:timetrap_val(1000) end}]; 164group(pg2) -> 165 [{timetrap,fun() -> timetrap_utils:timetrap_val(3000) end}]; 166group(pg3) -> 167 [{timetrap,fun() -> timetrap_utils:timetrap_val(2000) end}]; 168group(pg4) -> 169 [{timetrap,{timetrap_utils,timetrap_exit,[kaboom]}}]; 170group(pg5) -> 171 [{timetrap,fun() -> exit(kaboom) end}]; 172group(pg6) -> 173 [{timetrap,{timetrap_utils,timetrap_val,[500]}}]; 174group(pg7) -> 175 [{timetrap,fun() -> ct:sleep(1000),exit(kaboom) end}]; 176group(pg8) -> 177 [{timetrap,{timetrap_utils,timetrap_val,[500]}}]; 178group(pg9) -> 179 [{timetrap,fun() -> ct:sleep(1000),exit(kaboom) end}]; 180group(pg10) -> 181 [{timetrap,fun() -> ct:sleep(1000),exit(kaboom) end}]; 182group(pg11) -> 183 []; 184group(sg1) -> 185 [{timetrap,fun() -> ct:sleep(1000),exit(kaboom) end}]; 186group(sg2) -> 187 [{timetrap,{timetrap_utils,timetrap_val,[{seconds,1}]}}]. 188 189 190%%-------------------------------------------------------------------- 191%% Function: all() -> GroupsAndTestCases | {skip,Reason} 192%% GroupsAndTestCases = [{group,GroupName} | TestCase] 193%% GroupName = atom() 194%% TestCase = atom() 195%% Reason = term() 196%%-------------------------------------------------------------------- 197all() -> 198 [ 199 {group,g0}, 200 {group,g1}, 201 {group,g2}, 202 {group,g3}, 203 {group,g4}, 204 {group,g5}, 205 {group,g6}, 206 {group,g7}, 207 {group,g8}, 208 {group,g9}, 209 {group,g10}, 210 {group,g11}, 211 {group,pg0}, 212 {group,pg1}, 213 {group,pg2}, 214 {group,pg3}, 215 {group,pg4}, 216 {group,pg5}, 217 {group,pg6}, 218 {group,pg7}, 219 {group,pg8}, 220 {group,pg9}, 221 {group,pg10}, 222 {group,pg11}, 223 {group,sg1}, 224 {group,sg2}]. 225 226 227 228tc0(_) -> 229 ct:comment("TO set by group"), 230 ct:sleep({seconds,5}), 231 ok. 232 233tc1() -> 234 [{timetrap,{timetrap_utils,timetrap_val,[1000]}}]. 235tc1(_) -> 236 ct:comment("TO after 1 sec"), 237 ct:sleep({seconds,2}), 238 ok. 239 240tc2() -> 241 [{timetrap,fun() -> timetrap_utils:timetrap_val(500) end}]. 242tc2(_) -> 243 ct:comment("TO after 0.5 sec"), 244 ct:sleep({seconds,2}), 245 ok. 246 247tc3(_) -> 248 ct:comment(io_lib:format("TO after ~w sec", [?TO])), 249 ct:sleep({seconds,5}), 250 ok. 251 252tc4(_) -> 253 ct:comment("TO set by group"), 254 ct:sleep({seconds,5}), 255 ok. 256 257tc5(_) -> 258 ct:comment("No TO in this testcase, maybe later"), 259 ok. 260