From 9e9230c129816dc2ee7092734e72bffb2ac17748 Mon Sep 17 00:00:00 2001 From: Paul Joseph Davis Date: Sat, 30 May 2009 21:12:06 +0000 Subject: Added code coverage report generation target. To generate reports: # Assuming etap is installed $ cd /path/to/couchdb $ ./bootstrap && ERLC_FLAGS=+debug_info ./configure && make cover You can browse the report by opening ./cover/index.html in your html consuming software of choice. Shoutout to Nick Gerakines in THANKS for helping with etap and testing in general. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@780326 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/Makefile.am | 2 +- src/couchdb/couch_btree.erl | 215 -------------------------------------------- 2 files changed, 1 insertion(+), 216 deletions(-) (limited to 'src/couchdb') diff --git a/src/couchdb/Makefile.am b/src/couchdb/Makefile.am index e19a7539..b34155c7 100644 --- a/src/couchdb/Makefile.am +++ b/src/couchdb/Makefile.am @@ -169,7 +169,7 @@ couch.app: couch.app.tpl # $(ERL) -noshell -run edoc_run files [\"$<\"] %.beam: %.erl couch_db.hrl - $(ERLC) ${TEST} $<; + $(ERLC) $(ERLC_FLAGS) ${TEST} $<; install-data-hook: if test -f "$(DESTDIR)/$(couchprivlibdir)/couch_erl_driver"; then \ diff --git a/src/couchdb/couch_btree.erl b/src/couchdb/couch_btree.erl index 4c94a68c..0231d83c 100644 --- a/src/couchdb/couch_btree.erl +++ b/src/couchdb/couch_btree.erl @@ -15,7 +15,6 @@ -export([open/2, open/3, query_modify/4, add/2, add_remove/3, foldl/3, foldl/4]). -export([foldr/3, foldr/4, fold/4, fold/5, full_reduce/1, final_reduce/2]). -export([fold_reduce/6, fold_reduce/7, lookup/2, get_state/1, set_options/2]). --export([test/1, test/0, test_remove/2, test_add/2]). -define(CHUNK_THRESHOLD, 16#4ff). @@ -652,217 +651,3 @@ stream_kv_node2(Bt, Reds, PrevKVs, [{K,V} | RestKVs], Dir, Fun, Acc) -> {stop, Acc2} -> {stop, Acc2} end. - -shuffle(List) -> -%% Determine the log n portion then randomize the list. - randomize(round(math:log(length(List)) + 0.5), List). - -randomize(1, List) -> - randomize(List); -randomize(T, List) -> - lists:foldl(fun(_E, Acc) -> - randomize(Acc) - end, randomize(List), lists:seq(1, (T - 1))). - -randomize(List) -> - D = lists:map(fun(A) -> - {random:uniform(), A} - end, List), - {_, D1} = lists:unzip(lists:keysort(1, D)), - D1. - - - -test()-> - test(1000). - -test(N) -> - Sorted = [{Seq, random:uniform()} || Seq <- lists:seq(1, N)], - test_btree(Sorted), % sorted regular - test_btree(lists:reverse(Sorted)), % sorted reverse - test_btree(shuffle(Sorted)). % randomly distributed - - -test_btree(KeyValues) -> - {ok, Fd} = couch_file:open("foo", [create,overwrite]), - {ok, Btree} = open(nil, Fd), - ReduceFun = - fun(reduce, KVs) -> - length(KVs); - (rereduce, Reds) -> - lists:sum(Reds) - end, - Btree1 = set_options(Btree, [{reduce, ReduceFun}]), - - % first dump in all the values in one go - {ok, Btree10} = add_remove(Btree1, KeyValues, []), - - - Len = length(KeyValues), - - % get the leading reduction as we foldl/r - % and count of all from start to Val1 - Val1 = Len div 3, - {ok, _} = foldl(Btree10, Val1, - fun(_X, LeadingReds, Acc) -> - CountToStart = Val1 + Acc - 1, - CountToStart = final_reduce(Btree10, LeadingReds), - {ok, Acc + 1} - end, - 0), - - {ok, true} = foldr(Btree10, Val1, fun(_X, LeadingReds, _Acc) -> - CountToEnd = Len - Val1, - CountToEnd = final_reduce(Btree10, LeadingReds), - {stop, true} % change Acc to 'true' - end, - false), - - ok = test_keys(Btree10, KeyValues), - - % remove everything - {ok, Btree20} = test_remove(Btree10, KeyValues), - - % make sure its empty - {ok, false} = foldl(Btree20, fun(_X, _Acc) -> - {ok, true} % change Acc to 'true' - end, - false), - - % add everything back one at a time. - {ok, Btree30} = test_add(Btree20, KeyValues), - - ok = test_keys(Btree30, KeyValues), - - KeyValuesRev = lists:reverse(KeyValues), - - % remove everything, in reverse order - {ok, Btree40} = test_remove(Btree30, KeyValuesRev), - - % make sure its empty - {ok, false} = foldl(Btree40, fun(_X, _Acc) -> - {ok, true} % change Acc to 'true' - end, - false), - - - {A, B} = every_other(KeyValues), - - % add everything back - {ok, Btree50} = test_add(Btree40,KeyValues), - - ok = test_keys(Btree50, KeyValues), - - % remove half the values - {ok, Btree60} = test_remove(Btree50, A), - - % verify the remaining - ok = test_keys(Btree60, B), - - % add A back - {ok, Btree70} = test_add(Btree60, A), - - % verify - ok = test_keys(Btree70, KeyValues), - - % remove B - {ok, Btree80} = test_remove(Btree70, B), - - % verify the remaining - ok = test_keys(Btree80, A), - - {ok, Btree90} = test_remove(Btree80, A), - - EvenOdd = fun(V) when V rem 2 == 1 -> "odd"; (_) -> "even" end, - - EvenOddKVs = [{{EvenOdd(Key),Key}, 1} || {Key, _} <- KeyValues], - - {ok, Btree100} = test_add(Btree90, EvenOddKVs), - GroupingFun = fun({K1, _},{K2,_}) -> K1 == K2 end, - FoldFun = fun(GroupedKey, Unreduced, Acc) -> - {ok, [{GroupedKey, final_reduce(Btree100, Unreduced)} | Acc]} - end, - - Half = Len div 2, - - {ok, [{{"odd", _}, Half}, {{"even",_}, Half}]} = - fold_reduce(Btree100, nil, nil, GroupingFun, FoldFun, []), - - {ok, [{{"even",_}, Half}, {{"odd", _}, Half}]} = - fold_reduce(Btree100, rev, nil, nil, GroupingFun, FoldFun, []), - - {ok, [{{"even",_}, Half}]} = - fold_reduce(Btree100, fwd, {"even", -1}, {"even", foo}, GroupingFun, FoldFun, []), - - {ok, [{{"even",_}, Half}]} = - fold_reduce(Btree100, rev, {"even", foo}, {"even", -1}, GroupingFun, FoldFun, []), - - {ok, [{{"odd",_}, Half}]} = - fold_reduce(Btree100, fwd, {"odd", -1}, {"odd", foo}, GroupingFun, FoldFun, []), - - {ok, [{{"odd",_}, Half}]} = - fold_reduce(Btree100, rev, {"odd", foo}, {"odd", -1}, GroupingFun, FoldFun, []), - - {ok, [{{"odd", _}, Half}, {{"even",_}, Half}]} = - fold_reduce(Btree100, {"even", -1}, {"odd", foo}, GroupingFun, FoldFun, []), - - ok = couch_file:close(Fd). - - - - - -every_other(List) -> - every_other(List, [], [], 1). - -every_other([], AccA, AccB, _Flag) -> - {lists:reverse(AccA), lists:reverse(AccB)}; -every_other([H|T], AccA, AccB, 1) -> - every_other(T, [H|AccA], AccB, 0); -every_other([H|T], AccA, AccB, 0) -> - every_other(T, AccA, [H|AccB], 1). - -test_keys(Btree, List) -> - FoldFun = - fun(Element, [HAcc|TAcc]) -> - Element = HAcc, % must match - {ok, TAcc} - end, - Sorted = lists:sort(List), - {ok, []} = foldl(Btree, FoldFun, Sorted), - {ok, []} = foldr(Btree, FoldFun, lists:reverse(Sorted)), - - test_lookup(Btree, List). - -% Makes sure each key value pair is found in the btree -test_lookup(_Btree, []) -> - ok; -test_lookup(Btree, [{Key, Value} | Rest]) -> - [{ok,{Key, Value}}] = lookup(Btree, [Key]), - {ok, []} = foldl(Btree, Key, fun({KeyIn, ValueIn}, []) -> - KeyIn = Key, - ValueIn = Value, - {stop, []} - end, - []), - {ok, []} = foldr(Btree, Key, fun({KeyIn, ValueIn}, []) -> - KeyIn = Key, - ValueIn = Value, - {stop, []} - end, - []), - test_lookup(Btree, Rest). - -% removes each key one at a time from the btree -test_remove(Btree, []) -> - {ok, Btree}; -test_remove(Btree, [{Key, _Value} | Rest]) -> - {ok, Btree2} = add_remove(Btree,[], [Key]), - test_remove(Btree2, Rest). - -% adds each key one at a time from the btree -test_add(Btree, []) -> - {ok, Btree}; -test_add(Btree, [KeyValue | Rest]) -> - {ok, Btree2} = add_remove(Btree, [KeyValue], []), - test_add(Btree2, Rest). -- cgit v1.2.3