diff options
author | Björn Gustavsson <[email protected]> | 2010-01-19 11:34:56 +0000 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2010-01-19 13:01:29 +0100 |
commit | 74d7b1b942c6f1d984e263f6675a9423197a3215 (patch) | |
tree | 4644ffbb46b3f166507ffa8739e5ecbfccd4aba7 /lib/tools/test/cover_SUITE_data | |
parent | 81f4b1f7f453e1242d7f81ef2347230a9ff3fb0f (diff) | |
download | otp-74d7b1b942c6f1d984e263f6675a9423197a3215.tar.gz otp-74d7b1b942c6f1d984e263f6675a9423197a3215.tar.bz2 otp-74d7b1b942c6f1d984e263f6675a9423197a3215.zip |
Add test suite for the tools application
Diffstat (limited to 'lib/tools/test/cover_SUITE_data')
-rw-r--r-- | lib/tools/test/cover_SUITE_data/a.erl | 55 | ||||
-rw-r--r-- | lib/tools/test/cover_SUITE_data/b.erl | 14 | ||||
-rw-r--r-- | lib/tools/test/cover_SUITE_data/cc.erl | 88 | ||||
-rw-r--r-- | lib/tools/test/cover_SUITE_data/compile_beam/crypt.erl | 6 | ||||
-rw-r--r-- | lib/tools/test/cover_SUITE_data/compile_beam/d/y.erl | 6 | ||||
-rw-r--r-- | lib/tools/test/cover_SUITE_data/compile_beam/v.erl | 6 | ||||
-rw-r--r-- | lib/tools/test/cover_SUITE_data/compile_beam/w.erl | 6 | ||||
-rw-r--r-- | lib/tools/test/cover_SUITE_data/compile_beam/x.erl | 6 | ||||
-rw-r--r-- | lib/tools/test/cover_SUITE_data/d.erl | 156 | ||||
-rw-r--r-- | lib/tools/test/cover_SUITE_data/d1/e.erl | 127 | ||||
-rw-r--r-- | lib/tools/test/cover_SUITE_data/f.erl | 10 | ||||
-rw-r--r-- | lib/tools/test/cover_SUITE_data/included_functions/cover_inc.erl | 8 | ||||
-rw-r--r-- | lib/tools/test/cover_SUITE_data/included_functions/cover_inc.hrl | 7 | ||||
-rw-r--r-- | lib/tools/test/cover_SUITE_data/otp_6115/f1.erl | 12 | ||||
-rw-r--r-- | lib/tools/test/cover_SUITE_data/otp_6115/f2.erl | 13 |
15 files changed, 520 insertions, 0 deletions
diff --git a/lib/tools/test/cover_SUITE_data/a.erl b/lib/tools/test/cover_SUITE_data/a.erl new file mode 100644 index 0000000000..31119821cd --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/a.erl @@ -0,0 +1,55 @@ +-module(a). +-export([start/1, stop/1]). +-export([pong/1]). +-export([loop/3,exit_kalle/0]). + +%% start(N) -> pid() +%% N = integer() +start(N) -> + Pong = b:start(), + spawn(?MODULE, loop, [self(), N, Pong]), + receive + done -> + {exit,kalle} = trycatch(fun ?MODULE:exit_kalle/0), + {throw,kalle} = trycatch(fun() -> throw(kalle) end), + done + end. + +%% stop(Ping) -> stop +%% Ping = pid() +stop(Ping) -> + Ping ! stop. + +%% pong(Ping) -> pong +%% Ping = pid() +pong(Ping) -> + Ping ! pong. + +%%--Internal functions------------------------------------------------ + +loop(Starter, N, Pong) when N>0 -> + Pong ! {ping, self()}, + receive + pong -> + loop(Starter, N-1, Pong); + stop -> + done + end; +loop(Starter, 0, Pong) -> + Pong ! stop, + Starter ! done. + + +trycatch(Fun) -> + try Fun() + catch + Throw -> + {throw,Throw}; + exit:Reason -> + {exit,Reason} + after + cleanup + end. + +exit_kalle() -> + exit(kalle). diff --git a/lib/tools/test/cover_SUITE_data/b.erl b/lib/tools/test/cover_SUITE_data/b.erl new file mode 100644 index 0000000000..13f39b8cb9 --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/b.erl @@ -0,0 +1,14 @@ +-module(b). +-export([start/0, loop/0]). + +start() -> + spawn(?MODULE, loop, []). + +loop() -> + receive + {ping, Ping} -> + a:pong(Ping), + loop(); + stop -> + done + end. diff --git a/lib/tools/test/cover_SUITE_data/cc.erl b/lib/tools/test/cover_SUITE_data/cc.erl new file mode 100644 index 0000000000..587bdbe493 --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/cc.erl @@ -0,0 +1,88 @@ +-module(cc). +-export([epp/1, epp/2, dbg/1, dbg/2, cvr/1, cvr/2]). +-export([p/2, pp/2]). + +%% epp(Module) - Creates Module.epp which contains all forms of Module +%% as obtained by using epp. +%% +%% dbg(Module) - Creates Module.dbg which contains all forms of Module +%% as obtained by using beam_lib:chunks/2. +%% +%% cvr(Module) - Creates Module.cvr which contains all forms of Module +%% as obtained by using cover:transform/3. +%% + +epp(Module) -> + epp(Module, p). +epp(Module, P) -> + File = atom_to_list(Module)++".erl", + {ok,Cwd} = file:get_cwd(), + {ok, Fd1} = epp:open(File, [Cwd], []), + {ok, Fd2} = file:open(atom_to_list(Module)++".epp", write), + + epp(Fd1, Fd2, P), + + epp:close(Fd1), + file:close(Fd2), + ok. + +epp(Fd1, Fd2, P) -> + case epp:parse_erl_form(Fd1) of + {ok, {attribute,Line,Attr,Data}} -> + epp(Fd1, Fd2, P); + {ok, Form} when P==p -> + io:format(Fd2, "~p.~n", [Form]), + epp(Fd1, Fd2, P); + {ok, Form} when P==pp -> + io:format(Fd2, "~p.~n", [erl_pp:form(Form)]), + epp(Fd1, Fd2, P); + {eof, Line} -> + ok + end. + +cvr(Module) -> + cvr(Module, p). +cvr(Module, P) -> + case beam_lib:chunks(Module, [abstract_code]) of + {ok, {Module, [{abstract_code, no_abstract_code}]}} -> + {error, {no_debug_info,Module}}; + {ok, {Module, [{abstract_code, {Vsn, Forms}}]}} -> + Vars = {vars,Module,Vsn, [], + undefined, undefined, undefined, undefined, undefined, + undefined, + false}, + {ok, TForms, _Vars2} = cover:transform(Forms, [], Vars), + File = atom_to_list(Module)++".cvr", + apply(?MODULE, P, [File, TForms]); + Error -> + Error + end. + +dbg(Module) -> + dbg(Module, p). +dbg(Module, P) -> + case beam_lib:chunks(Module, [abstract_code]) of + {ok, {Module, [{abstract_code, no_abstract_code}]}} -> + {error, {no_debug_info,Module}}; + {ok, {Module, [{abstract_code, {Vsn, Forms}}]}} -> + File = atom_to_list(Module)++".dbg", + apply(?MODULE, P, [File, Forms]); + Error -> + Error + end. + +p(File, Forms) -> + {ok, Fd} = file:open(File, write), + lists:foreach(fun(Form) -> + io:format(Fd, "~p.~n", [Form]) + end, + Forms), + file:close(Fd). + +pp(File, Forms) -> + {ok, Fd} = file:open(File, write), + lists:foreach(fun(Form) -> + io:format(Fd, "~s", [erl_pp:form(Form)]) + end, + Forms), + file:close(Fd). diff --git a/lib/tools/test/cover_SUITE_data/compile_beam/crypt.erl b/lib/tools/test/cover_SUITE_data/compile_beam/crypt.erl new file mode 100644 index 0000000000..1596777edf --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/compile_beam/crypt.erl @@ -0,0 +1,6 @@ +-module(crypt). + +-export([f/0]). + +f() -> + ok. diff --git a/lib/tools/test/cover_SUITE_data/compile_beam/d/y.erl b/lib/tools/test/cover_SUITE_data/compile_beam/d/y.erl new file mode 100644 index 0000000000..14b9461410 --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/compile_beam/d/y.erl @@ -0,0 +1,6 @@ +-module(y). + +-export([f/0]). + +f() -> + ok. diff --git a/lib/tools/test/cover_SUITE_data/compile_beam/v.erl b/lib/tools/test/cover_SUITE_data/compile_beam/v.erl new file mode 100644 index 0000000000..007957297a --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/compile_beam/v.erl @@ -0,0 +1,6 @@ +-module(v). + +-export([f/0]). + +f() -> + ok. diff --git a/lib/tools/test/cover_SUITE_data/compile_beam/w.erl b/lib/tools/test/cover_SUITE_data/compile_beam/w.erl new file mode 100644 index 0000000000..88ad606db8 --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/compile_beam/w.erl @@ -0,0 +1,6 @@ +-module(w). + +-export([f/0]). + +f() -> + ok. diff --git a/lib/tools/test/cover_SUITE_data/compile_beam/x.erl b/lib/tools/test/cover_SUITE_data/compile_beam/x.erl new file mode 100644 index 0000000000..8953f6d05d --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/compile_beam/x.erl @@ -0,0 +1,6 @@ +-module(x). + +-export([f/0]). + +f() -> + ok. diff --git a/lib/tools/test/cover_SUITE_data/d.erl b/lib/tools/test/cover_SUITE_data/d.erl new file mode 100644 index 0000000000..696e27e49b --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/d.erl @@ -0,0 +1,156 @@ +-module(d). + +-export([start/0, stop/0]). +-export([store/2, store/3, move/2, + location/1, who_are_at/1, who_are_older/1, + size/0]). +-export([init/0]). % spawn + +-record(person, {name, age, location, moved=false}). + +%%%---------------------------------------------------------------------- +%%% User interface functions +%%%---------------------------------------------------------------------- + +%%% start() -> pid() +start() -> + spawn(?MODULE, init, []). + +%%% stop() +stop() -> + arne ! stop. + +%%% store(Name, Location) -> +%%% store(Name, Age, Location) -> ok | {error,Reason} +%%% Name = Location = atom() +%%% Age = integer() +%%% Reason = not_started | no_response | {internal_error,term()} +store(Name, Location) -> + store(Name, ?AGE, Location). +store(Name, Age, Location) when atom(Name), integer(Age), atom(Location) -> + send({store, Name, Age, Location}). + +%%% move(OldLocation, NewLocation) -> Names | {error,Reason} +%%% OldLocation = NewLocation = atom() +%%% Names = [Name] +%%% Name = atom() +%%% Reason = not_started | no_response | {internal_error,term()} +move(OldLocation, NewLocation) -> + send({move, OldLocation, NewLocation}). + +%%% location(Name) -> Location | no_such_person | {error,Reason} +%%% Name = atom() +%%% Reason = not_started | no_response | {internal_error,term()} +location(Name) when atom(Name) -> + send({location, Name}). + +%%% who_are_at(Location) -> Names | {error,Reason} +%%% Location = atom() +%%% Names = [Name] +%%% Name = atom() +%%% Reason = not_started | no_response | {internal_error,term()} +who_are_at(Location) when atom(Location) -> + send({who_are_at, Location}). + +%%% who_are_older(Age) -> Names | {error,Reason} +%%% Age = integer() +%%% Names = [Name] +%%% Name = atom() +%%% Reason = not_started | no_response | {internal_error,term()} +who_are_older(Age) when integer(Age) -> + send({who_are_older, Age}). + +%%% size() -> N | {error,Reason} +%%% N = integer() +%%% Reason = not_started | no_response | {internal_error,term()} +size() -> + send(size). + +%%%---------------------------------------------------------------------- +%%% Main loop +%%%---------------------------------------------------------------------- +send(Request) -> + Pid = whereis(arne), + if + Pid==undefined -> + {error, not_started}; + true -> + send(Pid, Request) + end. +send(Pid, Request) -> + Pid ! {request, self(), Request}, + receive + {reply, Reply} -> + Reply + after + 1000 -> + {error, no_response} + end. + +init() -> + register(arne, self()), + loop([]). + +loop(Db) -> + receive + stop -> + true; + {request, From, Request} -> + case catch handle(Request, Db) of + {reply, Reply, NewDb} -> + From ! {reply, Reply}, + loop(NewDb); + {'EXIT', Reason} -> + From ! {reply, {error, {internal_error, Reason}}}, + loop(Db) + end + end. + +%%%---------------------------------------------------------------------- +%%% DB functionality +%%%---------------------------------------------------------------------- +handle({store, Name, Age, Location}, Db) -> + {reply, ok, [#person{name=Name, age=Age, location=Location} | Db]}; +handle({move, OldLocation, NewLocation}, Db) -> + {Names, NewDb} = move(OldLocation, NewLocation, Db, [], []), + {reply, Names, NewDb}; +handle({location, Name}, Db) -> + case lists:keysearch(Name, #person.name, Db) of + {value, #person{location=Location}} when atom(Location) -> + {reply, Location, Db}; + false -> + {reply, no_such_name, Db} + end; +handle({who_are_at, Location}, Db) -> + Result = lists:foldl(fun(Person, Names) -> + case Person#person.location of + Location -> + [Person#person.name | Names]; + _OtherLocation -> + Names + end + end, + [], + Db), + {reply, Result, Db}; +handle({who_are_older, Old}, Db) -> + Result = [Name || {person,Name,Age,Location} <- Db, + Age>Old], + {reply, Result, Db}; +handle(size, Db) -> + Result = count(Db, 0), {reply, Result, Db}. + +count([H|T], N) -> + count(T, N+1); +count([], N) -> + N. + +move(OldLoc, NewLoc, [#person{location=OldLoc} = Person|T], Db, Names) -> + NewPerson = Person#person{location=NewLoc, + moved=true}, + NewNames = [Person#person.name|Names], + move(OldLoc, NewLoc, T, [NewPerson|Db], NewNames); +move(OldLoc, NewLoc, [Person|T], Db, Names) -> + move(OldLoc, NewLoc, T, [Person|Db], Names); +move(OldLoc, NewLoc, [], Db, Names) -> + {lists:reverse(Names), lists:reverse(Db)}. diff --git a/lib/tools/test/cover_SUITE_data/d1/e.erl b/lib/tools/test/cover_SUITE_data/d1/e.erl new file mode 100644 index 0000000000..b4041d48e6 --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/d1/e.erl @@ -0,0 +1,127 @@ +-module(e). +-behaviour(gen_server). + +%% External exports +-export([start_link/0]). +-export([hello/0]). + +%% gen_server callbacks +-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, + code_change/3]). + +-record(state, {}). + +%%%---------------------------------------------------------------------- +%%% API +%%%---------------------------------------------------------------------- +start_link() -> + gen_server:start_link({local, myserver}, myserver, [], []). + +hello() -> + gen_server:call(myserver, hello). + +%%%---------------------------------------------------------------------- +%%% Callback functions from gen_server +%%%---------------------------------------------------------------------- + +%%---------------------------------------------------------------------- +%% Func: init/1 +%% Returns: {ok, State} | +%% {ok, State, Timeout} | +%% ignore | +%% {stop, Reason} +%%---------------------------------------------------------------------- +init([]) -> + {ok, #state{}}. + +%%---------------------------------------------------------------------- +%% Func: handle_call/3 +%% Returns: {reply, Reply, State} | +%% {reply, Reply, State, Timeout} | +%% {noreply, State} | +%% {noreply, State, Timeout} | +%% {stop, Reason, Reply, State} | (terminate/2 is called) +%% {stop, Reason, State} (terminate/2 is called) +%%---------------------------------------------------------------------- +handle_call(Request, From, State) -> + Reply = case Request of + char -> + $B; + integer -> + 17; + float -> + 32.76; + string -> + "hi there"; + atom -> + hello; + block -> + begin + a, + b + end; + binary -> + <<1, 2, 3>> + end, + {reply, Reply, State}. + +%%---------------------------------------------------------------------- +%% Func: handle_cast/2 +%% Returns: {noreply, State} | +%% {noreply, State, Timeout} | +%% {stop, Reason, State} (terminate/2 is called) +%%---------------------------------------------------------------------- +handle_cast(Msg, State) when atom(Msg) -> + {noreply, State}; +handle_cast(Msg, State) when binary(Msg) -> + {noreply, State}; +handle_cast(Msg, State) when not is_tuple(Msg), not is_list(Msg) -> + {noreply, State}; +handle_cast(Msg, State) when float(Msg) -> + {noreply, State}; +handle_cast(Msg, State) when function(Msg) -> + {noreply, State}; +handle_cast(Msg, State) when integer(Msg) -> + {noreply, State}; +handle_cast(Msg, State) when list(Msg) -> + {noreply, State}; +handle_cast(Msg, State) when number(Msg) -> + {noreply, State}; +handle_cast(Msg, State) when pid(Msg) -> + {noreply, State}; +handle_cast(Msg, State) when port(Msg) -> + {noreply, State}; +handle_cast(Msg, State) when reference(Msg) -> + {noreply, State}; +handle_cast(Msg, State) when tuple(Msg) -> + {noreply, State}. + +%%---------------------------------------------------------------------- +%% Func: handle_info/2 +%% Returns: {noreply, State} | +%% {noreply, State, Timeout} | +%% {stop, Reason, State} (terminate/2 is called) +%%---------------------------------------------------------------------- +handle_info(Info, State) -> + {noreply, State}. + +%%---------------------------------------------------------------------- +%% Func: terminate/2 +%% Purpose: Shutdown the server +%% Returns: any (ignored by gen_server) +%%---------------------------------------------------------------------- +terminate(Reason, State) -> + ok. + +%%---------------------------------------------------------------------- +%% Func: code_change/3 +%% Purpose: Convert process state when code is changed +%% Returns: {ok, NewState} +%%---------------------------------------------------------------------- +code_change(OldVsn, State, Extra) -> + {ok, State}. + +%%%---------------------------------------------------------------------- +%%% Internal functions +%%%---------------------------------------------------------------------- + diff --git a/lib/tools/test/cover_SUITE_data/f.erl b/lib/tools/test/cover_SUITE_data/f.erl new file mode 100644 index 0000000000..1ef8bbdb49 --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/f.erl @@ -0,0 +1,10 @@ +-module(f). +-export([f1/0,f2/0]). + +f1() -> + f1_line1, + f1_line2. + +f2() -> + f2_line1, + f2_line2. diff --git a/lib/tools/test/cover_SUITE_data/included_functions/cover_inc.erl b/lib/tools/test/cover_SUITE_data/included_functions/cover_inc.erl new file mode 100644 index 0000000000..fa8eebfd00 --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/included_functions/cover_inc.erl @@ -0,0 +1,8 @@ +-module(cover_inc). +-compile(export_all). +-include("cover_inc.hrl"). + +func() -> + func1(), + ok. + diff --git a/lib/tools/test/cover_SUITE_data/included_functions/cover_inc.hrl b/lib/tools/test/cover_SUITE_data/included_functions/cover_inc.hrl new file mode 100644 index 0000000000..cbdfe601d1 --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/included_functions/cover_inc.hrl @@ -0,0 +1,7 @@ +func1() -> + A = line_2_in_include_file, + erlang:display(A), + line_4_in_include_file. + + + diff --git a/lib/tools/test/cover_SUITE_data/otp_6115/f1.erl b/lib/tools/test/cover_SUITE_data/otp_6115/f1.erl new file mode 100644 index 0000000000..b659e5d818 --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/otp_6115/f1.erl @@ -0,0 +1,12 @@ +-module(f1). +-export([start_fail/0, start_ok/0]). + +start_fail() -> + f2:start(fun() -> + io:format("this does not work\n",[]) + end). + +start_ok() -> + f2:start(fun fun1/0). +fun1() -> + io:format("this works\n",[]). diff --git a/lib/tools/test/cover_SUITE_data/otp_6115/f2.erl b/lib/tools/test/cover_SUITE_data/otp_6115/f2.erl new file mode 100644 index 0000000000..72a6a64c4d --- /dev/null +++ b/lib/tools/test/cover_SUITE_data/otp_6115/f2.erl @@ -0,0 +1,13 @@ +-module(f2). +-export([start/1]). + +start(Fun) -> + spawn(fun() -> + wait(Fun) + end). + +wait(Fun) -> + receive + go -> + Fun() + end. |