Skip to content

Commit

Permalink
Port to rebar3
Browse files Browse the repository at this point in the history
  • Loading branch information
Vagabond committed Feb 10, 2018
1 parent be16bd1 commit 9768dfb
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ c_src/system
*~
.local_dialyzer_plt
.rebar
_build
28 changes: 15 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
REBAR ?= ./rebar
.PHONY: compile rel cover test dialyzer
REBAR=./rebar3

all: compile
compile:
$(REBAR) compile

get-deps:
./c_src/build_deps.sh get-deps
clean:
$(REBAR) clean

deps:
${REBAR} get-deps
cover: test
$(REBAR) cover

rm-deps:
./c_src/build_deps.sh rm-deps
test: compile
$(REBAR) as test do eunit

compile: deps
${REBAR} compile
dialyzer:
$(REBAR) dialyzer

clean:
${REBAR} clean
xref:
$(REBAR) xref

include tools.mk
check: test dialyzer xref
16 changes: 15 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@
{eunit_opts, [verbose]}.
{so_name, "eleveldb.so"}.

{xref_checks, [undefined_function_calls]}.
{plugins, [{rebar3_eqc, {git, "https://github.com/Vagabond/rebar3-eqc-plugin", {branch, "master"}}}, pc]}.

{provider_hooks,
[
{pre,
[
{compile, {pc, compile}},
{clean, {pc, clean}}
]
}
]
}.

{xref_checks,[undefined_function_calls,undefined_functions,locals_not_used,
deprecated_function_calls, deprecated_functions]}.

{port_sources, ["c_src/*.cc"]}.

Expand Down
1 change: 1 addition & 0 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[].
Binary file added rebar3
Binary file not shown.
44 changes: 6 additions & 38 deletions src/eleveldb.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
terminal_format/2
]).
-ifdef(EQC).
-export([prop_put_delete/0, prop_put_delete_always/0]).
-include_lib("eqc/include/eqc.hrl").
-define(QC_OUT(P), eqc:on_output(fun terminal_format/2, P)).
-endif. % EQC
Expand Down Expand Up @@ -692,9 +693,6 @@ run_load(TestDir, IntSeq) ->

-ifdef(EQC).

qc(P) ->
?assert(eqc:quickcheck(?QC_OUT(P))).

keys() ->
eqc_gen:non_empty(list(eqc_gen:non_empty(binary()))).

Expand Down Expand Up @@ -723,7 +721,8 @@ apply_kv_ops([{delete, K, _} | Rest], Ref, Acc0) ->
?assertEqual(ok, ?MODULE:delete(Ref, K, [])),
apply_kv_ops(Rest, Ref, orddict:store(K, deleted, Acc0)).

prop_put_delete(TestDir) ->
prop_put_delete() ->
TestDir = create_test_dir(),
?LET({Keys, Values}, {keys(), values()},
?FORALL(Ops, eqc_gen:non_empty(list(ops(Keys, Values))),
begin
Expand All @@ -747,40 +746,9 @@ prop_put_delete(TestDir) ->
true
end)).

prop_put_delete_test_() ->
Timeout1 = 10,
Timeout2 = 15,
{foreach,
fun create_test_dir/0,
fun delete_test_dir/1,
[
fun(TestRoot) ->
TestDir = filename:join(TestRoot, "putdelete.qc"),
InnerTO = Timeout1,
OuterTO = (InnerTO * 3),
Title = "Without ?ALWAYS()",
TestFun = fun() ->
qc(eqc:testing_time(InnerTO, prop_put_delete(TestDir)))
end,
{timeout, OuterTO, {Title, TestFun}}
end,
fun(TestRoot) ->
TestDir = filename:join(TestRoot, "putdelete.qc"),
InnerTO = Timeout2,
OuterTO = (InnerTO * 10),
AwCount = (InnerTO * 9),
%% We use the ?ALWAYS(AwCount, ...) wrapper as a regression test.
%% It's not clear how this is effectively different than the first
%% fixture, but I'm leaving it here in case I'm missing something.
Title = lists:flatten(io_lib:format("With ?ALWAYS(~b)", [AwCount])),
TestFun = fun() ->
qc(eqc:testing_time(InnerTO,
?ALWAYS(AwCount, prop_put_delete(TestDir))))
end,
{timeout, OuterTO, {Title, TestFun}}
end
]
}.
prop_put_delete_always() ->
AwCount= 15*9,
?ALWAYS(AwCount, prop_put_delete()).

-endif. % EQC

Expand Down
23 changes: 12 additions & 11 deletions test/rand_gen_1.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-module(rand_gen_1).
-compile(export_all).
-export([random_bin/2, almost_completely_sequential/3, mostly_sequential/2,
pareto_as_bin/2, pareto/2]).

%% !@#$! pareto key generators are not exported from basho_bench_keygen.erl
%%
Expand All @@ -15,9 +16,9 @@

random_bin(_Id, Size) ->
HunkSize = 16*1024*1024,
BigHunk = crypto:rand_bytes(HunkSize),
BigHunk = crypto:strong_rand_bytes(HunkSize),
fun() ->
Offset = random:uniform(HunkSize - Size),
Offset = rand:uniform(HunkSize - Size),
<<_:Offset/binary, Bin:Size/binary, _/binary>> = BigHunk,
Bin
end.
Expand All @@ -32,11 +33,11 @@ almost_completely_sequential(_Id, MaxSuffix, PercentAlmostSeq) ->
fun() ->
{A, B, C} = os:timestamp(),
TimeT = (A*1000000) + B,
End = case random:uniform(100) of
End = case rand:uniform(100) of
N when N < PercentAlmostSeq ->
C; % microseconds
_ ->
random:uniform(MaxSuffix)
rand:uniform(MaxSuffix)
end,
[integer_to_list(TimeT), $_,
integer_to_list(End)]
Expand All @@ -54,19 +55,19 @@ almost_completely_sequential(_Id, MaxSuffix, PercentAlmostSeq) ->
%% still have the same "integer1_integer2" form, but the first integer
%% will up to approximately 3 million seconds earlier than the current
%% time_t wall clock time, and the second integer will be generated by
%% random:uniform(1000*1000).
%% rand:uniform(1000*1000).
%%
%% As MillionNotSequential approaches zero, the keys generated will
%% become more and more perfectly sorted.

mostly_sequential(_Id, MillionNotSequential) ->
fun() ->
{A, B, C} = os:timestamp(),
{X, Y, Z} = case random:uniform(1000*1000) of
{X, Y, Z} = case rand:uniform(1000*1000) of
N when N < MillionNotSequential ->
{A - random:uniform(3),
abs(B - random:uniform(500*1000)),
random:uniform(1000*1000)};
{A - rand:uniform(3),
abs(B - rand:uniform(500*1000)),
rand:uniform(1000*1000)};
_ ->
{A, B, C}
end,
Expand All @@ -89,7 +90,7 @@ pareto(Mean, Shape) ->
S1 = (-1 / Shape),
S2 = Mean * (Shape - 1),
fun() ->
U = 1 - random:uniform(),
U = 1 - rand:uniform(),
trunc((math:pow(U, S1) - 1) * S2)
end.

0 comments on commit 9768dfb

Please sign in to comment.