Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Torben Hoffmann
committed
Feb 16, 2012
1 parent
4e94bec
commit 1576efa
Showing
5 changed files
with
357 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- | ||
%% ex: ts=4 sw=4 ft=erlang et | ||
|
||
{lib_dirs, ["deps"]}. | ||
|
||
{deps, [ | ||
{lager, ".*", {git, "git://github.com/basho/lager.git", {branch, "master"}}}, | ||
{gproc, ".*", %%"0.2.10", | ||
{git,"https://github.com/uwiger/gproc.git", | ||
{branch, "master"} | ||
%% {tag,"v0.2.10"} | ||
}}, | ||
{parse_trans, ".*", {git, "git://github.com/uwiger/parse_trans.git", "master"}}, | ||
{meck, ".*", | ||
{git, "git://github.com/eproxus/meck.git", {branch, "master"}}}, | ||
{hamcrest, ".*", | ||
{git, "git://github.com/hyperthunk/hamcrest-erlang.git", | ||
{branch, "master"}}} | ||
]}. | ||
|
||
{require_otp_vsn, "R14|R15|R16"}. | ||
|
||
{clean_files, ["release/chronos"]}. | ||
|
||
{erl_opts, [ | ||
fail_on_warning, | ||
debug_info, | ||
%%warn_missing_spec, | ||
{src_dirs, ["test_"]}, | ||
{parse_transform, lager_transform} | ||
]}. | ||
|
||
{cover_enabled, true}. | ||
|
||
{clean_files, ["*.eunit", "ebin/*.beam"]}. | ||
|
||
{validate_app_modules, false}. | ||
|
||
{sub_dirs, ["src", | ||
"test", | ||
"release"]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
%% This is the application resource file (.app file) for the, | ||
%% application. | ||
{application, chronos, | ||
[{description, "chronos - a timer utility for Erlang"}, | ||
{vsn, "0.0.1"}, | ||
{modules, [chronos]}, | ||
{registered,[]}, | ||
{applications, [kernel, stdlib, gproc]}, | ||
%% {mod, {chronos_app,[]}}, | ||
{start_phases, []}]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
%%% @author Torben Hoffmann <th@issuu.com> | ||
%%% @copyright (C) 2012, Torben Hoffmann | ||
%%% @doc | ||
%%% | ||
%%% @end | ||
%%% Created : 13 Feb 2012 by Torben Hoffmann <th@issuu.com> | ||
|
||
-module(chronos_eqc). | ||
|
||
|
||
-include_lib("eqc/include/eqc.hrl"). | ||
-include_lib("eqc/include/eqc_statem.hrl"). | ||
|
||
-compile(export_all). | ||
|
||
-record(state, | ||
{servers = [], | ||
timers = [] :: [{chronos:server_name(), chronos:timer_name()}] | ||
}). | ||
|
||
%% Initialize the state | ||
initial_state() -> | ||
#state{ | ||
servers = [], | ||
timers = [] | ||
}. | ||
|
||
%% Command generator, S is the state | ||
command(S) -> | ||
frequency( [ {100, {call, timer_expiry, start_server, [server_name()]}} ] | ||
). | ||
|
||
%% Next state transformation, S is the current state | ||
next_state(S,_V,{call,timer_expiry, start_server, [ServerName]}) -> | ||
S#state{ servers = [ServerName | S#state.servers] }. | ||
|
||
%% Precondition, checked before command is added to the command sequence | ||
precondition(S,{call,timer_expiry, start_server, [ServerName]}) -> | ||
not lists:member(ServerName, S#state.servers). | ||
|
||
%% Postcondition, checked after command has been evaluated | ||
%% OBS: S is the state before next_state(S,_,<command>) | ||
postcondition(_S,{call,timer_expiry, start_server, [_ServerName]}, ok) -> | ||
true; | ||
postcondition(_S,{call,timer_expiry, start_server, [_ServerName]}, _Other) -> | ||
false. | ||
|
||
prop_chronos() -> | ||
?FORALL(Cmds,commands(?MODULE), | ||
?TRAPEXIT( | ||
begin | ||
start_context(), | ||
{H,S,Res} = run_commands(?MODULE,Cmds), | ||
stop_context(), | ||
?WHENFAIL( | ||
io:format("History: ~p\nState: ~p\nRes: ~p\n",[H,S,Res]), | ||
Res == ok) | ||
end)). | ||
|
||
start_context() -> | ||
application:start(gproc), | ||
timer_expiry:start_link(). | ||
|
||
stop_context() -> | ||
timer_expiry:stop(), | ||
application:stop(gproc). | ||
|
||
|
||
|
||
%%-------------------- GENERATORS ------------------------------ | ||
|
||
|
||
server_name() -> {server, nat()}. | ||
|
||
timer_name() -> {timer, nat()}. | ||
|
||
timer_timeout() -> choose(10, 100). | ||
|
||
%%---------------------- OPERATIONS ---------------------- | ||
|
||
start_server(ServerName) -> | ||
chronos:start_link(ServerName). | ||
|
||
start_timer(Server, Timer, Timeout) -> | ||
ok. |
Oops, something went wrong.