4
%% Copyright Ericsson AB 2008-2010. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
20
%%%-------------------------------------------------------------------
21
%%% File : ignore_cores.erl
22
%%% Author : Rickard Green <rickard.s.green@ericsson.com>
25
%%% Created : 11 Feb 2008 by Rickard Green <rickard.s.green@ericsson.com>
26
%%%-------------------------------------------------------------------
28
-module(ignore_cores).
30
-include_lib("test_server/include/test_server.hrl").
32
-export([init/1, fini/1, setup/3, setup/4, restore/1, dir/1]).
34
-record(ignore_cores, {org_cwd,
41
%% Takes a testcase config
45
{ok, OrgCWD} = file:get_cwd(),
47
#ignore_cores{org_cwd = OrgCWD,
48
org_path = code:get_path(),
49
org_pwd_env = os:getenv("PWD")}}
50
| lists:keydelete(ignore_cores, 1, Config)].
53
#ignore_cores{org_cwd = OrgCWD,
55
org_pwd_env = OrgPWD} = ?config(ignore_cores, Config),
56
ok = file:set_cwd(OrgCWD),
57
true = code:set_path(OrgPath),
60
_ -> true = os:putenv("PWD", OrgPWD)
62
lists:keydelete(ignore_cores, 1, Config).
64
setup(Suite, Testcase, Config) ->
65
setup(Suite, Testcase, Config, false).
67
setup(Suite, Testcase, Config, SetCwd) when is_atom(Suite),
70
#ignore_cores{org_cwd = OrgCWD,
72
org_pwd_env = OrgPWD} = ?config(ignore_cores, Config),
73
Path = lists:map(fun (".") -> OrgCWD; (Dir) -> Dir end, OrgPath),
74
true = code:set_path(Path),
75
PrivDir = ?config(priv_dir, Config),
76
IgnDir = filename:join([PrivDir,
79
++ atom_to_list(Testcase)
81
ok = file:make_dir(IgnDir),
86
ok = file:set_cwd(IgnDir),
87
OrgPWD = case os:getenv("PWD") of
90
os:putenv("PWD", IgnDir),
94
ok = file:write_file(filename:join([IgnDir, "ignore_core_files"]), <<>>),
95
%% cores are dumped in /cores on MacOS X
96
CoresDir = case {?t:os_type(), filelib:is_dir("/cores")} of
97
{{unix,darwin}, true} ->
98
filelib:fold_files("/cores",
101
fun (C,Cs) -> [C|Cs] end,
106
lists:keyreplace(ignore_cores,
110
#ignore_cores{org_cwd = OrgCWD,
112
org_pwd_env = OrgPWD,
114
cores_dir = CoresDir}}).
117
#ignore_cores{org_cwd = OrgCWD,
119
org_pwd_env = OrgPWD,
121
cores_dir = CoresDir} = ?config(ignore_cores, Config),
127
%% Move cores dumped by these testcases in /cores
129
lists:foreach(fun (C) ->
130
case lists:member(C, CoresDir) of
135
filename:basename(C)]),
136
{ok, _} = file:copy(C, Dst),
140
filelib:fold_files("/cores",
143
fun (C,Cs) -> [C|Cs] end,
147
catch file:set_cwd(OrgCWD),
148
catch code:set_path(OrgPath),
151
_ -> catch os:putenv("PWD", OrgPWD)
157
#ignore_cores{ign_dir = Dir} = ?config(ignore_cores, Config),