Changeset 30 for trunk


Ignore:
Timestamp:
06/17/08 13:58:49 (4 years ago)
Author:
dom
Message:

Tester re-runs tests when receiving a second module

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/shells.erl

    r28 r30  
    33 
    44install ([Test_node]) -> 
    5     process_flag(trap_exit, false), % called with erl -s shells install 
     5%xs    process_flag(trap_exit, false), % called with erl -s shells install 
    66    try 
    7         tests (Test_node) 
     7        Self = self (), 
     8        spawn_link (fun () -> tests (Test_node, Self) end), 
     9        receive {Self, done} -> ok; 
     10                M -> io:fwrite ("tests_crash: ~p~n", [M]) 
     11        end 
    812 
    913    catch C:E-> 
     
    1418      rpc: call (Test_node, init, stop, []) 
    1519    end, 
    16     receive_all(), 
     20    receive_all (), 
    1721    io: fwrite ("done~n", []). 
    1822 
    19 tests (Test_node) -> 
     23tests (Test_node, Caller) -> 
    2024    io: fwrite ("Running local developer tests~n", []), 
    2125    ok = tests_test: filter_by_attribute (), 
    2226    io: fwrite ("Running developer tests on test node: ~p~n", [Test_node]), 
    23     ok = tester_test: runs_given_tests (Test_node). 
     27    ok = tester_test: runs_a_test (Test_node), 
     28    ok = tester_test: runs_given_tests (Test_node), 
     29    Caller ! {Caller, done}. 
    2430     
    25 receive_all() -> 
    26     receive M -> 
     31receive_all () -> 
     32    receive 
     33        {'EXIT', _, normal} -> 
     34            receive_all (); 
     35        M -> 
    2736            io:fwrite("Received ~p~n", [M]), 
    28             receive_all() 
     37            receive_all () 
    2938    after 500 -> 
    3039           done 
  • trunk/src/tester.erl

    r28 r30  
    88init (Notify, Node) -> 
    99    process_flag (trap_exit, true), 
    10     loop (Notify, Node). 
     10    With_notify = dict: store (notify, Notify, dict: new ()), 
     11    With_tests = dict: store (tests, dict: new (), With_notify), 
     12    State = dict: store (node, Node, With_tests), 
     13    loop (State). 
    1114 
    12 loop (Notify, Node) -> 
     15loop (State) -> 
    1316    receive 
    14         {File_name, Binary} -> 
    15             test (File_name, Binary, Notify, Node); 
     17        {_, _} = Module -> 
     18            loop (test (load (Module, State))); 
    1619        _ -> 
    17             loop (Notify, Node) 
     20            loop (State) 
    1821    end. 
    1922 
    20 test (File_name, Binary, Notify, Node) -> 
    21     {Module, Tests} = tests: filter_by_attribute (Binary), 
    22     {module, Module} = rpc: call (Node, code, load_binary, [Module, File_name, Binary]), 
    23     Total = length (Tests), 
     23load ({File_name, Binary}, State) -> 
     24    {Module, Functions} = tests: filter_by_attribute (Binary), 
     25    Node = dict: fetch (node, State), 
     26    Load_args = [Module, File_name, Binary], 
     27    {module, Module} = rpc: call (Node, code, load_binary, Load_args), 
     28    New_tests = dict: store (Module, Functions, dict: fetch (tests, State)), 
     29    dict: store (tests, New_tests, State). 
     30 
     31test (State) -> 
     32    {Total, Tests} = flatten (dict: fetch (tests, State)), 
     33    Notify = dict: fetch (notify, State), 
    2434    Notify ({Total, 0, 0}), 
    25     test (Total, 0, 0, Tests, Notify, Node). 
     35    lists: foldl (test_fun (State, Total), {0, 0}, Tests), 
     36    State. 
    2637 
    27 test (Total, Run, Passed, [{M, F, A} | Tests], Notify, Node) -> 
    28     Pid = spawn_link (Node, M, F, A), 
    29     New_passed = 
    30         receive 
    31             {'EXIT', Pid, normal} -> 
    32                 Passed + 1; 
    33             {'EXIT', Pid, Reason} -> 
    34                 Notify (Reason), 
    35                 Passed 
     38flatten (Tests) -> 
     39    F = fun (_, Ts, {Count, List}) -> 
     40                {Count + length (Ts), [Ts | List]} 
    3641        end, 
    37     New_run = Run + 1, 
    38     Notify ({Total, New_run, New_passed}), 
    39     test (Total, New_run, New_passed, Tests, Notify, Node); 
    40 test (_, _, _, [], _, _) -> 
    41     bye. 
     42    {Total, All} = dict: fold (F, {0, []}, Tests), 
     43    {Total, lists: flatten (All)}. 
     44 
     45test_fun (State, Total) -> 
     46    Node = dict: fetch (node, State), 
     47    Notify = dict: fetch (notify, State), 
     48    fun ({M, F, A}, {Run, Passed}) -> 
     49            Pid = spawn_link (Node, M, F, A), 
     50            New_passed = 
     51                receive 
     52                    {'EXIT', Pid, normal} -> 
     53                        Passed + 1; 
     54                    {'EXIT', Pid, Reason} -> 
     55                        Notify (Reason), 
     56                        Passed 
     57                end, 
     58            New_run = Run + 1, 
     59            Notify ({Total, New_run, New_passed}), 
     60            {New_run, New_passed} 
     61    end. 
     62 
  • trunk/src/tester_test.erl

    r28 r30  
    44 
    55-module (tester_test). 
    6 -export ([runs_given_tests/1]). 
    7 -test ([{nodes_fix, test_node, [runs_given_tests]}]). 
     6-export ([runs_a_test/1, runs_given_tests/1]). 
     7-test ([{nodes_fix, test_node, [runs_a_test, runs_given_tests]}]). 
    88 
    9 runs_given_tests (Node) -> 
     9runs_a_test (Node) -> 
    1010    Self = self (), 
    1111    Notify = fun (Event) -> Self ! Event end, 
     
    1414    false = code: is_loaded (eg_test), 
    1515    Tester ! {"../fix/eg_test.erl", Binary}, 
    16     [{2, 0, 0}, {2, 1, 1}, Error, {2, 2, 1}] = tests: receive_all (), 
     16    [{2, 0, 0}, {2, 1, 1}, Error, {2, 2, 1}] = receive_all ([]), 
    1717    {{badmatch, nok}, [{eg_test, nok, 0} | _]} = Error,  
    1818    false = code: is_loaded (eg_test), 
    1919    ok. 
     20 
     21runs_given_tests (Node) -> 
     22    Self = self (), 
     23    Notify = fun (Event) -> Self ! Event end, 
     24    Tester = spawn_link (tester, init, [Notify, Node]), 
     25    Test_binary = modules: to_binary ("../fix/eg_test_of_code.erl"), 
     26    Code_binary = modules: to_binary ("../fix/eg_code.erl"), 
     27    false = code: is_loaded (eg_test_of_code), 
     28    false = code: is_loaded (eg_code), 
     29    Tester ! {"../fix/eg_test_of_code.erl", Test_binary}, 
     30    [{1, 0, 0}, Error, {1, 1, 0}] = receive_all ([]), 
     31    {undef, [{eg_code, ok, []}, {eg_test_of_code, ok, 0} | _]} = Error, 
     32    false = code: is_loaded (eg_test), 
     33    Tester ! {"../fix/eg_code.erl", Code_binary}, 
     34    [{1, 0, 0}, {1, 1, 1}] = receive_all ([]), 
     35    ok. 
    2036     
    21      
     37receive_all (Ms) -> 
     38    receive 
     39        {Run, Run, Passed} -> 
     40            lists: reverse ([{Run, Run, Passed} | Ms]); 
     41        M -> 
     42            receive_all ([M | Ms]) 
     43    end. 
     44 
    2245%%% Test to be added: 
    2346%%% with several modules, including non-test ones 
Note: See TracChangeset for help on using the changeset viewer.