Skip to content

Commit

Permalink
new folder with benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
german-vidal committed Apr 18, 2024
1 parent 6372f09 commit 1230f1e
Show file tree
Hide file tree
Showing 220 changed files with 111,075 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-module(ac_tab_insert).

-compile(export_all).

scenarios() ->
[ test
].

%% This test exercises code for restoring the state of public tables
%% not owned by any process under Concuerror. This code might become
%% useful again if e.g. support for application:start is added back.

test() ->
[] = ets:lookup(ac_tab, fake),
true = ets:insert(ac_tab, {fake, value}),
[{fake, value}] = ets:lookup(ac_tab, fake),
true = ets:delete(ac_tab, fake),
[] = ets:lookup(ac_tab, fake),
true = ets:insert(ac_tab, {fake, value}),
[{fake, value}] = ets:lookup(ac_tab, fake),
P = self(),
spawn(fun() -> P ! ok end),
receive
ok -> ok
after
0 -> ok
end.
23 changes: 23 additions & 0 deletions examples/benchmarks/concuerror_suites/basic_tests/after_test_2.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-module(after_test_2).

-export([after_test_2/0]).
-export([scenarios/0]).

scenarios() -> [{?MODULE, inf, dpor}].

after_test_2() ->
Parent = self(),
spawn(fun() -> Parent ! one end),
receive
two -> throw(two)
after
0 -> ok
end,
receive
one -> ok
after
0 -> ok
end,
receive
deadlock -> ok
end.
32 changes: 32 additions & 0 deletions examples/benchmarks/concuerror_suites/basic_tests/after_test_3.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-module(after_test_3).

-export([after_test_3/0]).
-export([scenarios/0]).

-concuerror_options_forced([{instant_delivery, false}]).

scenarios() -> [{?MODULE, inf, dpor}].

after_test_3() ->
Parent = self(),
Child =
spawn(fun() ->
receive
Get1 ->
receive
Get2 ->
throw({Get1, Get2})
end
end
end),
spawn(fun() ->
Child ! a,
Parent ! f
end),
Msg =
receive
f -> b
after
0 -> c
end,
Child ! Msg.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-module(after_vs_trap_exit).

-export([after_vs_trap_exit/0]).
-export([scenarios/0]).

scenarios() -> [{?MODULE, inf, dpor}].

after_vs_trap_exit() ->
P1 = self(),
_ = spawn_link(
fun() ->
process_flag(trap_exit, true),
P1 ! ok,
receive after infinity -> block end
end),
receive ok -> ok end,
P3 =
spawn(
fun() ->
process_flag(trap_exit, true),
receive
Msg -> throw(Msg)
after
0 -> ok
end
end),
catch link(P3).
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-module(allow_first_crash).

-export([scenarios/0]).
-export([test/0]).

-concuerror_options_forced([{keep_going, false}]).

scenarios() ->
[{test, inf, dpor}].

test() ->
P = self(),
spawn(fun() -> P ! ok end),
receive
ok -> ok
after
0 -> ok
end,
exit(error).
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-module(bad_dictionary).

-compile(export_all).

scenarios() ->
[ bad_put
, bad_get
, bad_erase
].

bad_put() ->
BadFun =
fun() ->
erlang:put(key, value),
erlang:put(key, value, extra_arg_bad)
end,
spawn_monitor(BadFun).

bad_get() ->
BadFun =
fun() ->
erlang:get(key),
erlang:get(key, extra_arg_bad)
end,
spawn_monitor(BadFun).

bad_erase() ->
BadFun =
fun() ->
erlang:erase(key),
erlang:erase(key, value)
end,
spawn_monitor(BadFun).
10 changes: 10 additions & 0 deletions examples/benchmarks/concuerror_suites/basic_tests/bad_whereis.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-module(bad_whereis).

-export([scenarios/0]).
-export([test/0]).

scenarios() ->
[{test, inf, dpor}].

test() ->
whereis(1).
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-module(code_when_undef).

-compile(export_all).

scenarios() ->
[ test
].

test() ->
catch ets:non_existing_function(),
code:module_info(),
P = self(),
spawn(fun() -> P ! ok end),
receive
ok -> ok
after
0 -> ok
end,
exit(error).
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-module(concuerror_crash).

-export([scenarios/0]).
-export([test/0]).

scenarios() ->
[{test, inf, dpor, crash}].

test() ->
P = self(),
spawn(fun() -> P ! ok end),
receive
ok ->
list_to_pid("<0.42.42>") ! ok
after
0 -> ok
end.
19 changes: 19 additions & 0 deletions examples/benchmarks/concuerror_suites/basic_tests/fun_fail.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-module(fun_fail).

-export([scenarios/0]).
-export([test1/0,test2/0,test3/0]).

scenarios() ->
[{T, inf, dpor} || T <- [test1,test2,test3]].

test1() ->
A = ban,
A(foo).

test2() ->
A = fun() -> ok end,
A(foo).

test3() ->
A = 1,
A:foo(blip).
19 changes: 19 additions & 0 deletions examples/benchmarks/concuerror_suites/basic_tests/group_leader.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-module(group_leader).

-export([scenarios/0]).
-export([test/0, test1/0]).

scenarios() ->
[{T, inf, dpor} || T <- [test,test1]].

test() ->
C = spawn(fun() -> receive _ -> ok end end),
group_leader(C, self()),
C ! ok.

test1() ->
{C, _} = spawn_monitor(fun() -> ok end),
receive
_MonitorDown -> ok
end,
group_leader(C, self()).
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-module(group_leader2).

-export([scenarios/0]).
-export([test/0]).

scenarios() ->
[{test, inf, dpor}].

test() ->
UserPid = whereis(user),
UserPid = group_leader(),
group_leader(self(), self()),
true = self() =:= group_leader(),
Fun =
fun() ->
case flip_coin() of
true -> io:format("Block");
false -> ok
end
end,
Fun(),
spawn(Fun),
group_leader(UserPid, self()),
UserPid = group_leader(),
io:format("All fine").

flip_coin() ->
P = self(),
spawn(fun() -> P ! ok end),
receive
ok -> true
after
0 -> receive ok -> false end
end.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-module(hopeless_after).

-export([hopeless_after/0]).
-export([scenarios/0]).

scenarios() -> [{?MODULE, inf, dpor}].

hopeless_after() ->
P = self(),
spawn(fun() -> P ! hopeless end),
receive
hope -> saved
after
100 ->
throw(no_hope)
end.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-module(i_hate_myself).

-export([i_hate_myself/0]).
-export([scenarios/0]).

scenarios() -> [{?MODULE, inf, dpor}].

i_hate_myself() ->
Name = list_to_atom(lists:flatten(io_lib:format("~p",[make_ref()]))),
spawn(fun() -> Name ! message end),
register(Name, self()),
receive
message -> ok
end.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-module(immediate_delivery).

-export([test1/0, test2/0, test3/0]).
-export([scenarios/0]).

-concuerror_options_forced([{instant_delivery, true}]).

scenarios() ->
[{T, inf, dpor} ||
{T,0} <- ?MODULE:module_info(exports),
T =/= scenarios,
T =/= concuerror_options,
T =/= module_info
].

test1() ->
P = self(),
C1 = spawn(fun() ->
receive
p ->
receive
c -> ok
end;
c -> error(fault)
end
end),
C1 ! p,
spawn(fun() -> C1 ! c end).

test2() ->
P = self(),
C1 = spawn(fun() ->
receive
p ->
receive
c -> ok
end;
c -> error(fault)
end
end),
spawn(fun() -> C1 ! c end),
C1 ! p.

test3() ->
Fun = fun() -> io:format("Foo") end,
Fun(),
spawn(Fun),
Fun(),
spawn(Fun).
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
%% A late reply from init could be registered as unblocking the respective child
%% but not be previously instrumented. This bug appears on bigger machines.

-module(init_race_condition).

-export([scenarios/0]).
-export([test/0]).

scenarios() -> [{test, inf, dpor}].

get_arguments() ->
init ! {self(), get_arguments},
receive
{init, Rep} -> Rep
end.

test() ->
[ spawn(fun() -> get_arguments() end) || _ <- lists:seq(1, 2) ].
Loading

0 comments on commit 1230f1e

Please sign in to comment.