658
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,NewComment);
674
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,NewComment,CurrConf);
659
675
{io_request,From,ReplyAs,{put_chars,io_lib,Func,[Format,Args]}}
660
676
when is_list(Format) ->
661
677
Msg = (catch io_lib:Func(Format,Args)),
662
678
run_test_case_msgloop_io(ReplyAs,CaptureStdout,Msg,From,Func),
663
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
679
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
664
680
{io_request,From,ReplyAs,{put_chars,io_lib,Func,[Format,Args]}}
665
681
when is_atom(Format) ->
666
682
Msg = (catch io_lib:Func(Format,Args)),
667
683
run_test_case_msgloop_io(ReplyAs,CaptureStdout,Msg,From,Func),
668
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
684
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
669
685
{io_request,From,ReplyAs,{put_chars,Bytes}} ->
670
686
run_test_case_msgloop_io(
671
687
ReplyAs,CaptureStdout,Bytes,From,put_chars),
672
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
673
{io_request,From,ReplyAs,{put_chars,unicode,io_lib,Func,[Format,Args]}}
674
when is_list(Format) ->
675
Msg = unicode_to_latin1(catch io_lib:Func(Format,Args)),
676
run_test_case_msgloop_io(ReplyAs,CaptureStdout,Msg,From,Func),
677
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
678
{io_request,From,ReplyAs,{put_chars,latin1,io_lib,Func,[Format,Args]}}
679
when is_list(Format) ->
680
Msg = (catch io_lib:Func(Format,Args)),
681
run_test_case_msgloop_io(ReplyAs,CaptureStdout,Msg,From,Func),
682
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
683
{io_request,From,ReplyAs,{put_chars,unicode,io_lib,Func,[Format,Args]}}
684
when is_atom(Format) ->
685
Msg = unicode_to_latin1(catch io_lib:Func(Format,Args)),
686
run_test_case_msgloop_io(ReplyAs,CaptureStdout,Msg,From,Func),
687
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
688
{io_request,From,ReplyAs,{put_chars,latin1,io_lib,Func,[Format,Args]}}
689
when is_atom(Format) ->
690
Msg = (catch io_lib:Func(Format,Args)),
691
run_test_case_msgloop_io(ReplyAs,CaptureStdout,Msg,From,Func),
692
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
688
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
689
{io_request,From,ReplyAs,{put_chars,unicode,io_lib,Func,[Format,Args]}}
690
when is_list(Format) ->
691
Msg = unicode_to_latin1(catch io_lib:Func(Format,Args)),
692
run_test_case_msgloop_io(ReplyAs,CaptureStdout,Msg,From,Func),
693
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
694
{io_request,From,ReplyAs,{put_chars,latin1,io_lib,Func,[Format,Args]}}
695
when is_list(Format) ->
696
Msg = (catch io_lib:Func(Format,Args)),
697
run_test_case_msgloop_io(ReplyAs,CaptureStdout,Msg,From,Func),
698
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
699
{io_request,From,ReplyAs,{put_chars,unicode,io_lib,Func,[Format,Args]}}
700
when is_atom(Format) ->
701
Msg = unicode_to_latin1(catch io_lib:Func(Format,Args)),
702
run_test_case_msgloop_io(ReplyAs,CaptureStdout,Msg,From,Func),
703
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
704
{io_request,From,ReplyAs,{put_chars,latin1,io_lib,Func,[Format,Args]}}
705
when is_atom(Format) ->
706
Msg = (catch io_lib:Func(Format,Args)),
707
run_test_case_msgloop_io(ReplyAs,CaptureStdout,Msg,From,Func),
708
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
693
709
{io_request,From,ReplyAs,{put_chars,unicode,Bytes}} ->
694
710
run_test_case_msgloop_io(
695
711
ReplyAs,CaptureStdout,unicode_to_latin1(Bytes),From,put_chars),
696
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
712
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
697
713
{io_request,From,ReplyAs,{put_chars,latin1,Bytes}} ->
698
714
run_test_case_msgloop_io(
699
715
ReplyAs,CaptureStdout,Bytes,From,put_chars),
700
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
716
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
701
717
IoReq when element(1, IoReq) == io_request ->
702
718
%% something else, just pass it on
703
719
group_leader() ! IoReq,
704
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
720
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
705
721
{structured_io,ClientPid,Msg} ->
706
722
output(Msg, ClientPid),
707
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
723
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
708
724
{capture,NewCapture} ->
709
run_test_case_msgloop(Ref,Pid,NewCapture,Terminate,Comment);
725
run_test_case_msgloop(Ref,Pid,NewCapture,Terminate,Comment,CurrConf);
710
726
{sync_apply,From,MFA} ->
711
727
sync_local_or_remote_apply(false,From,MFA),
712
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
728
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
713
729
{sync_apply_proxy,Proxy,From,MFA} ->
714
730
sync_local_or_remote_apply(Proxy,From,MFA),
715
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
731
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
716
732
{printout,Detail,Format,Args} ->
717
733
print(Detail,Format,Args),
718
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
734
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
719
735
{comment,NewComment} ->
721
737
case Terminate of
722
{true,{Time,Value,Loc,Opts,_OldComment}} ->
738
{true,{Time,Value,Loc,Opts,_OldComment}} ->
723
739
{true,{Time,Value,mod_loc(Loc),Opts,NewComment}};
727
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate1,NewComment);
743
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate1,NewComment,CurrConf);
744
{set_curr_conf,NewCurrConf} ->
745
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,NewCurrConf);
728
746
{'EXIT',Pid,{Ref,Time,Value,Loc,Opts}} ->
729
747
RetVal = {Time/1000000,Value,mod_loc(Loc),Opts,Comment},
730
run_test_case_msgloop(Ref,Pid,CaptureStdout,{true,RetVal},Comment);
748
run_test_case_msgloop(Ref,Pid,CaptureStdout,{true,RetVal},Comment,undefined);
731
749
{'EXIT',Pid,Reason} ->
733
751
{timetrap_timeout,TVal,Loc} ->
734
752
%% convert Loc to form that can be formatted
736
{Mod,Func} = get_mf(Loc1),
737
%% The framework functions mustn't execute on this
738
%% group leader process or io will cause deadlock,
739
%% so we spawn a dedicated process for the operation
740
%% and let the group leader go back to handle io.
741
spawn_fw_call(Mod,Func,Pid,{timetrap_timeout,TVal},
742
Loc1,self(),Comment),
743
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
754
{FwMod,FwFunc,framework} ->
755
%% timout during framework call
756
spawn_fw_call(FwMod,FwFunc,Pid,
757
{framework_error,{timetrap,TVal}},
758
unknown,self(),Comment),
759
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,
762
{Mod,Func} = get_mf(Loc1),
763
%% call end_per_testcase on a separate process,
764
%% only so that the user has a chance to clean up
765
%% after init_per_testcase, even after a timetrap timeout
770
call_end_conf(Mod,Func,Pid,
771
{timetrap_timeout,TVal},
774
timetrap_timeout}}|Conf],
776
{EndConfPid,{Mod,Func},Conf};
778
%% The framework functions mustn't execute on this
779
%% group leader process or io will cause deadlock,
780
%% so we spawn a dedicated process for the operation
781
%% and let the group leader go back to handle io.
782
spawn_fw_call(Mod,Func,Pid,{timetrap_timeout,TVal},
783
Loc1,self(),Comment),
786
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,
744
789
{timetrap_timeout,TVal,Loc,InitOrEnd} ->
746
{Mod,_Func} = get_mf(Loc1),
747
spawn_fw_call(Mod,InitOrEnd,Pid,{timetrap_timeout,TVal},
748
Loc1,self(),Comment),
749
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
750
{testcase_aborted,Reason,Loc} ->
752
{Mod,Func} = get_mf(Loc1),
753
spawn_fw_call(Mod,Func,Pid,{testcase_aborted,Reason},
754
Loc1,self(),Comment),
755
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
791
{FwMod,FwFunc,framework} ->
792
%% timout during framework call
793
spawn_fw_call(FwMod,FwFunc,Pid,
794
{framework_error,{timetrap,TVal}},
795
unknown,self(),Comment);
797
{Mod,_Func} = get_mf(Loc1),
798
spawn_fw_call(Mod,InitOrEnd,Pid,{timetrap_timeout,TVal},
801
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
802
{testcase_aborted,AbortReason,AbortLoc} ->
803
ErrorMsg = {testcase_aborted,AbortReason},
804
case mod_loc(AbortLoc) of
805
{FwMod,FwFunc,framework} ->
806
%% abort during framework call
807
spawn_fw_call(FwMod,FwFunc,Pid,
808
{framework_error,ErrorMsg},
809
unknown,self(),Comment),
810
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,
813
{Mod,Func} = get_mf(Loc1),
814
%% call end_per_testcase on a separate process, only so
815
%% that the user has a chance to clean up after init_per_testcase,
816
%% even after abortion
820
TVal = case lists:keysearch(default_timeout,1,Conf) of
821
{value,{default_timeout,Tmo}} -> Tmo;
822
_ -> ?DEFAULT_TIMETRAP_SECS*1000
825
call_end_conf(Mod,Func,Pid,ErrorMsg,
827
[{tc_status,{failed,ErrorMsg}}|Conf],
829
{EndConfPid,{Mod,Func},Conf};
831
spawn_fw_call(Mod,Func,Pid,ErrorMsg,
832
Loc1,self(),Comment),
835
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,
757
839
%% result of an exit(TestCase,kill) call, which is the
758
%% only way to abort a testcase process that traps exits
840
%% only way to abort a testcase process that traps exits
759
841
%% (see abort_current_testcase)
760
842
spawn_fw_call(undefined,undefined,Pid,testcase_aborted_or_killed,
761
843
unknown,self(),Comment),
762
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
844
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
845
{fw_error,{FwMod,FwFunc,FwError}} ->
846
spawn_fw_call(FwMod,FwFunc,Pid,{framework_error,FwError},
847
unknown,self(),Comment),
848
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
764
850
%% the testcase has terminated because of Reason (e.g. an exit
765
851
%% because a linked process failed)
766
852
spawn_fw_call(undefined,undefined,Pid,Reason,
767
853
unknown,self(),Comment),
768
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment)
854
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf)
856
{EndConfPid,{call_end_conf,Data,_Result}} ->
858
{EndConfPid,{Mod,Func},_Conf} ->
859
{_Mod,_Func,TCPid,TCExitReason,Loc} = Data,
860
spawn_fw_call(Mod,Func,TCPid,TCExitReason,Loc,self(),Comment),
861
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,undefined);
863
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf)
770
865
{_FwCallPid,fw_notify_done,RetVal} ->
771
866
%% the framework has been notified, we're finished
772
run_test_case_msgloop(Ref,Pid,CaptureStdout,{true,RetVal},Comment);
867
run_test_case_msgloop(Ref,Pid,CaptureStdout,{true,RetVal},Comment,undefined);
773
868
{'EXIT',_FwCallPid,{fw_notify_done,Func,Error}} ->
774
869
%% a framework function failed
775
870
CB = os:getenv("TEST_SERVER_FRAMEWORK"),
872
FW when FW =:= false; FW =:= "undefined" ->
778
873
{test_server,Func};
780
875
{list_to_atom(CB),Func}
782
877
RetVal = {died,{framework_error,Loc,Error},Loc,"Framework error"},
783
run_test_case_msgloop(Ref,Pid,CaptureStdout,{true,RetVal},Comment);
878
run_test_case_msgloop(Ref,Pid,CaptureStdout,{true,RetVal},Comment,undefined);
784
879
{failed,File,Line} ->
785
put(test_server_detected_fail,
880
put(test_server_detected_fail,
786
881
[{File, Line}| get(test_server_detected_fail)]),
787
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
882
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
788
883
_Other when not is_tuple(_Other) ->
789
884
%% ignore anything not generated by test server
790
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment);
885
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf);
791
886
_Other when element(1, _Other) /= 'EXIT',
792
887
element(1, _Other) /= started,
793
888
element(1, _Other) /= finished,
794
889
element(1, _Other) /= print ->
795
890
%% ignore anything not generated by test server
796
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment)
891
run_test_case_msgloop(Ref,Pid,CaptureStdout,Terminate,Comment,CurrConf)