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.

96 lines
2.3 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(bad_return_string, _, _) ->
  18. {tuple, {tuple, "string"}};
  19. handle_call(case_clause, _, State) ->
  20. case State of
  21. goober ->
  22. {reply, ok, State}
  23. end;
  24. handle_call(case_clause_string, _, State) ->
  25. Foo = atom_to_list(?MODULE),
  26. case Foo of
  27. State ->
  28. {reply, ok, State}
  29. end;
  30. handle_call(if_clause, _, State) ->
  31. if State == 1 ->
  32. {reply, ok, State}
  33. end;
  34. handle_call(try_clause, _, State) ->
  35. Res = try tuple_to_list(State) of
  36. [_A, _B] -> ok
  37. catch
  38. _:_ -> ok
  39. end,
  40. {reply, Res, State};
  41. handle_call(badmatch, _, State) ->
  42. {A, B, C} = State,
  43. {reply, [A, B, C], State};
  44. handle_call(function_clause, _, State) ->
  45. {reply, function(State), State};
  46. handle_call(badarith, _, State) ->
  47. Res = 1 / length(tuple_to_list(State)),
  48. {reply, Res, State};
  49. handle_call(badarg1, _, State) ->
  50. Res = list_to_binary(["foo", bar]),
  51. {reply, Res, State};
  52. handle_call(badarg2, _, State) ->
  53. Res = erlang:iolist_to_binary(["foo", bar]),
  54. {reply, Res, State};
  55. handle_call(system_limit, _, State) ->
  56. Res = list_to_atom(lists:flatten(lists:duplicate(256, "a"))),
  57. {reply, Res, State};
  58. handle_call(process_limit, _, State) ->
  59. %% run with +P 300 to make this crash
  60. [erlang:spawn(fun() -> timer:sleep(5000) end) || _ <- lists:seq(0, 500)],
  61. {reply, ok, State};
  62. handle_call(port_limit, _, State) ->
  63. [erlang:open_port({spawn, "ls"}, []) || _ <- lists:seq(0, 1024)],
  64. {reply, ok, State};
  65. handle_call(noproc, _, State) ->
  66. Res = gen_event:call(foo, bar, baz),
  67. {reply, Res, State};
  68. handle_call(badarity, _, State) ->
  69. F = fun(A, B, C) -> A + B + C end,
  70. Res = F(State),
  71. {reply, Res, State};
  72. handle_call(_Call, _From, State) ->
  73. {reply, ok, State}.
  74. handle_cast(_Cast, State) ->
  75. {noreply, State}.
  76. handle_info(_Info, State) ->
  77. {noreply, State}.
  78. terminate(_, _) ->
  79. ok.
  80. code_change(_, State, _) ->
  81. {ok, State}.
  82. function(X) when is_list(X) ->
  83. ok.