You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 line
2.1 KiB

  1. %% a module that crashes in just about every way possible
  2. -module(crash).
  3. -behaviour(gen_server).
  4. -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
  5. -export([start/0]).
  6. start() ->
  7. gen_server:start({local, ?MODULE}, ?MODULE, [], []).
  8. init(_) ->
  9. {ok, {}}.
  10. handle_call(undef, _, State) ->
  11. {reply, ?MODULE:booger(), State};
  12. handle_call(badfun, _, State) ->
  13. M = booger,
  14. {reply, M(), State};
  15. handle_call(bad_return, _, _) ->
  16. bleh;
  17. handle_call(case_clause, _, State) ->
  18. case State of
  19. goober ->
  20. {reply, ok, State}
  21. end;
  22. handle_call(if_clause, _, State) ->
  23. if State == 1 ->
  24. {reply, ok, State}
  25. end;
  26. handle_call(try_clause, _, State) ->
  27. Res = try tuple_to_list(State) of
  28. [_A, _B] -> ok
  29. catch
  30. _:_ -> ok
  31. end,
  32. {reply, Res, State};
  33. handle_call(badmatch, _, State) ->
  34. {A, B, C} = State,
  35. {reply, [A, B, C], State};
  36. handle_call(function_clause, _, State) ->
  37. {reply, function(State), State};
  38. handle_call(badarith, _, State) ->
  39. Res = 1 / length(tuple_to_list(State)),
  40. {reply, Res, State};
  41. handle_call(badarg1, _, State) ->
  42. Res = list_to_binary(["foo", bar]),
  43. {reply, Res, State};
  44. handle_call(badarg2, _, State) ->
  45. Res = erlang:iolist_to_binary(["foo", bar]),
  46. {reply, Res, State};
  47. handle_call(system_limit, _, State) ->
  48. Res = list_to_atom(lists:flatten(lists:duplicate(256, "a"))),
  49. {reply, Res, State};
  50. handle_call(process_limit, _, State) ->
  51. %% run with +P 300 to make this crash
  52. [erlang:spawn(fun() -> timer:sleep(5000) end) || _ <- lists:seq(0, 500)],
  53. {reply, ok, State};
  54. handle_call(port_limit, _, State) ->
  55. [erlang:open_port({spawn, "ls"}, []) || _ <- lists:seq(0, 1024)],
  56. {reply, ok, State};
  57. handle_call(noproc, _, State) ->
  58. Res = gen_event:call(foo, bar, baz),
  59. {reply, Res, State};
  60. handle_call(badarity, _, State) ->
  61. F = fun(A, B, C) -> A + B + C end,
  62. Res = F(State),
  63. {reply, Res, State};
  64. handle_call(_Call, _From, State) ->
  65. {reply, ok, State}.
  66. handle_cast(_Cast, State) ->
  67. {noreply, State}.
  68. handle_info(_Info, State) ->
  69. {noreply, State}.
  70. terminate(_, _) ->
  71. ok.
  72. code_change(_, State, _) ->
  73. {ok, State}.
  74. function(X) when is_list(X) ->
  75. ok.