<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "../stax/stax.dtd">

<!--
    run_test.xml - Run the Tutorial examples test using STAX

    Job Description:
    This job runs the Tutorial examples using STAX.
    The examples are run within an installed distribution.
-->

<stax>
    <!-- Define default function to execute -->
    <defaultcall function="tutorial_main"/>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
    <!-- Function runs the Tutorial example test case -->
    <function name="tutorial_main" scope="local">
        <!-- Function description -->
        <function-prolog>
            Test runs OSPL on two nodes.
            Tutorial example is then run between them.
            If both Tutorial parts ("chatter" and "message board")
            return 0 the test succeeds.
            Fails otherwise.
        </function-prolog>

        <function-list-args> 
            <function-required-arg name="run_type">
                 The type of run - sp (Single Process) or shm (Shared memory), use the following format: "runtype"
            </function-required-arg>   
            <function-required-arg name="host_name1">
                HOST 1 - the name for the local host where the test will be performed
                (i.e. 'my_computer2').
            </function-required-arg>
            <function-required-arg name="ospl_home1">
                OSPL_HOME 1 - OSPL location on the 1st host
                (i.e. './Prismtech').
            </function-required-arg>
            <function-required-arg name="test_root1">
                TEST_ROOT 1 - the location of test root on the 1st host
                (i.e. './ospli').
            </function-required-arg>
            <function-required-arg name="operation_key1">
                OPERATION KEY 1 - operation key for the example to be tested on the 1st host
                (i.e. 'c', 'cpp', 'java', 'ALL')
            </function-required-arg>
            <function-required-arg name="host_name2">
                HOST 2 - the name for the remote host where the test will be performed
                (i.e. 'my_computer2').
            </function-required-arg>
            <function-required-arg name="ospl_home2">
                OSPL_HOME 2 - OSPL location on the 2nd host
                (i.e. './Prismtech').
            </function-required-arg>
            <function-required-arg name="test_root2">
                TEST_ROOT 2 - the location of test root on the 2nd host
                (i.e. './ospli').
            </function-required-arg>
            <function-optional-arg name="operation_key2" default="'ALL'">
                OPERATION KEY 2 - operation key for the example to be tested on the 2nd host
                (i.e. 'c', 'cpp', 'java')
            </function-optional-arg>
            <function-optional-arg name="api_key" default="'ALL'">
                API KEY - launch tutorial test on selected api
                (i.e. 'dcps').
            </function-optional-arg>
            <function-optional-arg name="staf_port1" default="'6500'">
                The STAF port number on the first machine you wish test on in double quotes, use the following format: "port"
            </function-optional-arg>
            <function-optional-arg name="staf_port2" default="'6500'">
                The STAF port number on the the second machine you wish to test on in double quotes, use the following format: "port"
            </function-optional-arg>
        </function-list-args>

        <!-- Function body begin -->
        <sequence>
            <import file="'../stax/test_ospl.xml'"/>
            <import file="'tutorial_test_functions.xml'"/>
            <try>
                <sequence>
                    <call function="'Initialise'"/>              
                    <script>
                        import time
                        from process import Process
                        # Add the "./common/python" directory into the Python module path:
                        the_script_current_dir = STAXCurrentXMLFile[:STAXCurrentXMLFile.rfind(local_file_sep)]
                        sys.path.append(the_script_current_dir + local_file_sep + "common" +local_file_sep + "python")
                        # Import the test classes definitions:
                        from ext_process import *
                        from log_result  import *
                        
                        test_scenario = BaseTestScenario("Tutorial", "Test OpenSplice Tutorial examples")

                        local_host = test_scenario.define_host(test_root = test_root1,
                                                                ospl_home = ospl_home1,
                                                                host_name = host_name1,
                                                                staf_port = staf_port1)
                        remote_host = test_scenario.define_host(test_root = test_root2,
                                                                ospl_home = ospl_home2,
                                                                host_name = host_name2,
                                                                staf_port = staf_port2)
                        # Set test case result log file:
                        this_xml_dir = STAXCurrentXMLFile[:STAXCurrentXMLFile.rfind(os.sep)]
                        local_host.set_log_dir(this_xml_dir)
                        test_scenario.set_result_file(local_host.get_log_dir() + local_host.get_file_sep() + test_scenario.get_name() + "_result.log")
                    </script>

                    <iterate var="host" in="test_scenario.get_all_hosts()">
                        <call function="'InitHost'">host</call>
                    </iterate>
                    
                    <script>
                        test_scenario.set_test_scenario_initialized(1)
                    </script>
       
                    <call function="'GetEnv'">[local_host, 'JACORB_HOME']</call>
                    <script> jacorb_home1 = STAXResult </script>
                    <call function="'GetEnv'">[remote_host, 'JACORB_HOME']</call>
                    <script> jacorb_home2 = STAXResult </script>

                </sequence>
                <!-- Catch all possible exceptions -->
                <catch exception="'...'" typevar="type" var="info">
                    <sequence>
                        <script>
                            test_scenario.fail()
                            test_scenario.errors.append("Initializing process error: %s (%s)!"% (type, info))
                        </script>
                    </sequence>
                </catch>
            </try> 
            <if expr="test_scenario.is_test_scenario_initialized() == 1">
                <sequence>
                    <script>
                        local_host.set_ospl_log_dir(ospl_home1)
                        remote_host.set_ospl_log_dir(ospl_home2)
                        
                        file_path_separator1 = local_host.get_file_sep()
                        file_path_separator2 = remote_host.get_file_sep()
                        
                        path_separator1 = local_host.get_path_sep()
                        path_separator2 = remote_host.get_path_sep()
                        
                        main_class_path1 = local_host.get_env_value("CLASSPATH")
                        main_class_path2 = remote_host.get_env_value("CLASSPATH")
                                        
                        
                        #for normalize of length of operation key
                        def normalize_length_of_key(in_key, mboard_keys, chatter_keys):
                            """
                            for normalize of length of operation key
                            """
                            max_length = 0
                            #search key with max length in mboard keys  
                            for key1 in mboard_keys:
                                if len(key1) > max_length:
                                    max_length = len(key1)
                            #search key with max length in chatter keys  
                            for key2 in chatter_keys:
                                if len(key2) > max_length:
                                    max_length = len(key2)
                            #getting current length
                            current_length = len(in_key)
                            #normalize length
                            if max_length > current_length:
                                for i in range(max_length - current_length + 1):
                                    in_key = in_key + "_"
                            return in_key
                    </script>
                    <script>
                        java_key = "java"
                        c_key = "c"
                        cpp_key = "cpp"
                        corba_cpp_key = "corba_cpp"
                        corba_java_key = "corba_java"
                        #rto_java_key = "RTO_Java"
                        sa_key = "standalone"
                        crb_key = "corba"
                        dcps_key = "dcps"
                        all_key = "ALL"
                        shm_type="shm"
                        
                        #init of test directories names
                        standalone_dir_name = "standalone"
                        corba_dir_name = "corba"
                        examples_dir_name = "examples"
                        dcps_dir_name = "dcps"
                        java_dir_name = "java"
                        c_dir_name = "c"
                        cpp_dir_name = "cpp"
                        tutorial_dir_name = test_scenario.get_name()
                        exec_dir_name = "exec"
                        bld_dir_name = "bld"
                        testsuite_dir_name = "testsuite"
                        tests_dir_name = "tests"
                        log_dir_name = "Log"
                        chatroom_dir_name = "chatroom"
                        mboard_dir_name = "MessageBoard"
                        chatter_dir_name = "Chatter"
                        wleditor_dir_name = "WhiteListEditor"
                        wlmboard_dir_name = "WhiteListedMessageBoard"
                        
                        # The test scenario name should be the test directory name. So you should edit this.
                        test_name = tutorial_dir_name
                        
                        #init of params array for chatter test (for detail read README file for tutorial test)
                        array_of_chatter_params = ["1","2","-1"]
                        #array_of_chatter_params = ["1","-1"]
                        chater_user_name = "Bill"
                        
                        #init of  array of results of tests
                        array_of_test_results = STAXGlobal([])
                        
                        #init of path to tests
                        path_to_examples1 = examples_dir_name + file_path_separator1
                        path_to_examples2 = examples_dir_name + file_path_separator2 
                        
                        path_to_dcps_tutorial1 = dcps_dir_name + file_path_separator1 + test_name + file_path_separator1
                        path_to_dcps_tutorial2 = dcps_dir_name + file_path_separator2 + test_name + file_path_separator2                   
                        
                        path_to_standalone1 = standalone_dir_name + file_path_separator1
                        path_to_standalone2 = standalone_dir_name + file_path_separator2
                        
                        path_to_corba1 = corba_dir_name + file_path_separator1
                        path_to_corba2 = corba_dir_name + file_path_separator2
                    
                        path_to_c_standalone_test1 = c_dir_name + file_path_separator1 + path_to_standalone1
                        path_to_c_standalone_test2 = c_dir_name + file_path_separator2 + path_to_standalone2

                        path_to_cpp_standalone_test1 = cpp_dir_name + file_path_separator1 + path_to_standalone1
                        path_to_cpp_standalone_test2 = cpp_dir_name + file_path_separator2 + path_to_standalone2

                        path_to_cpp_corba_test1 = cpp_dir_name + file_path_separator1 + path_to_corba1
                        path_to_cpp_corba_test2 = cpp_dir_name + file_path_separator2 + path_to_corba2

                        path_to_java_standalone_test1 = java_dir_name + file_path_separator1 + path_to_standalone1
                        path_to_java_standalone_test2 = java_dir_name + file_path_separator2 + path_to_standalone2

                        path_to_java_corba_test1 = java_dir_name + file_path_separator1 + path_to_corba1
                        path_to_java_corba_test2 = java_dir_name + file_path_separator2 + path_to_corba2

                        #setting path for commands for tests
                        dcps_full_path1 = ospl_home1 + file_path_separator1 + path_to_examples1 + path_to_dcps_tutorial1
                        dcps_full_path2 = ospl_home2 + file_path_separator2 + path_to_examples2 + path_to_dcps_tutorial2
                        
                        path_to_sa_classes1 = path_to_java_standalone_test1 + "classes" 
                        path_to_sa_classes2 = path_to_java_standalone_test2 + "classes"
                        
                        path_to_corba_classes1 = path_to_java_corba_test1 + "classes"
                        path_to_corba_classes2 = path_to_java_corba_test2 + "classes"
                        
                        dcps_path_to_java_lib1 = "jar" + file_path_separator1 + "dcpssaj.jar"
                        dcps_path_to_java_lib2 = "jar" + file_path_separator2 + "dcpssaj.jar"

                        dcps_path_to_corbajava_lib1 = "jar" + file_path_separator1 + "dcpscj.jar"
                        dcps_path_to_corbajava_lib2 = "jar" + file_path_separator2 + "dcpscj.jar"

                        path_to_crb_java1 = path_to_corba1 + java_dir_name + file_path_separator1
                        path_to_crb_java2 = path_to_corba2 + java_dir_name + file_path_separator2
                                                
                        jacorb_endorsed_dirs1 = jacorb_home1 + file_path_separator1 + "lib" + file_path_separator1 + "endorsed"
                        jacorb_endorsed_dirs2 = jacorb_home2 + file_path_separator2 + "lib" + file_path_separator2 + "endorsed"  

                        jacorb_jars1 = jacorb_endorsed_dirs1 + file_path_separator1 + "jacorb.jar"
                        jacorb_jars2 = jacorb_endorsed_dirs2 + file_path_separator2 + "jacorb.jar"

                        start_c_sa1 = ospl_home1 + file_path_separator1 + path_to_examples1 + path_to_standalone1
                        start_c_sa2 = ospl_home2 + file_path_separator2 + path_to_examples2 + path_to_standalone2
                        
                        dcps_start_java_sa1 = dcps_full_path1 + path_to_sa_classes1 + path_separator1 + ospl_home1 + file_path_separator1 + dcps_path_to_java_lib1 + ' '
                        dcps_start_java_sa2 = dcps_full_path2 + path_to_sa_classes2 + path_separator2 + ospl_home2 + file_path_separator2 + dcps_path_to_java_lib2 + ' '
                        
                        dcps_start_java_corba_1 = dcps_full_path1 + path_to_corba_classes1 + path_separator1 + ospl_home1 + file_path_separator1 + dcps_path_to_corbajava_lib1 + path_separator1 + jacorb_jars1 + ' '
                        
                        dcps_start_java_corba_2 = dcps_full_path2 + path_to_corba_classes2 + path_separator2 + ospl_home2 + file_path_separator2 + dcps_path_to_corbajava_lib2 + path_separator2 + jacorb_jars2 + ' '
                        
                        # set up keys list 
                        dcps_message_board_keys = []
                        dcps_chatter_keys = []
                        
                        api_keys = []
                        
                        dcps_message_board_process = []
                        dcps_chatter_process = []
                        
                        #setting arrays of operation keys by key
                        if (api_key == all_key):
                            api_keys.append(dcps_key)
                        else:
                            api_keys.append(api_key)
                        for api in api_keys:
                            if api == dcps_key:
                                if ((operation_key1 == sa_key) or (operation_key1 == crb_key) or (operation_key1 == all_key)):
                                    if operation_key1 == sa_key:
                                        dcps_message_board_keys.append(java_key)
                                        dcps_message_board_keys.append(c_key)
                                        dcps_message_board_keys.append(cpp_key)

                                        dcps_chatter_keys.append(java_key)
                                        dcps_chatter_keys.append(c_key)
                                        dcps_chatter_keys.append(cpp_key)
                                        
                                    if operation_key1 == crb_key:
                                        dcps_message_board_keys.append(corba_java_key)
                                        #dcps_message_board_keys.append(rto_java_key)
                                        dcps_message_board_keys.append(corba_cpp_key)
                                        
                                        dcps_chatter_keys.append(corba_java_key)
                                        #dcps_chatter_keys.append(rto_java_key)
                                        dcps_chatter_keys.append(corba_cpp_key)
                                        
                                    if operation_key1 == all_key:
                                        dcps_message_board_keys.append(java_key)
                                        dcps_message_board_keys.append(c_key)
                                        dcps_message_board_keys.append(cpp_key)
                                        dcps_message_board_keys.append(corba_java_key)
                                        #dcps_message_board_keys.append(rto_java_key)
                                        dcps_message_board_keys.append(corba_cpp_key)

                                        dcps_chatter_keys.append(java_key)
                                        dcps_chatter_keys.append(c_key)
                                        dcps_chatter_keys.append(cpp_key)
                                        dcps_chatter_keys.append(corba_java_key)
                                        #dcps_chatter_keys.append(rto_java_key)
                                        dcps_chatter_keys.append(corba_cpp_key)
                                        
                                    operation_key2 = "no_key"
                                else:
                                    dcps_message_board_keys.append(operation_key1)
                                    dcps_chatter_keys.append(operation_key2)                                                        

                    </script>
                    <call function="'CreateTestLogDirectory'">[local_host, test_name]</call>
                    <script>
                        current_log_dir_name1 = STAXResult
                        time.sleep(1)
                    </script>
                        <call function="'CreateTestLogDirectory'">[remote_host, test_name]</call>
                    <script>
                        current_log_dir_name2 = STAXResult
                        for dcps_key in dcps_message_board_keys: 
                       
                            next_message_board = local_host.define_process("no_command")
                            
                            if dcps_key == java_key:
                                #setting command
                                cp1 = main_class_path1 + path_separator1 + dcps_start_java_sa1
                                local_host.set_env_value("CLASSPATH", cp1)
                                next_message_board.set_command("java")
                                #setting message_board args
                                next_message_board.set_args("-classpath %s chatroom.MessageBoard" % dcps_start_java_sa1)
                                
                            if dcps_key == c_key:
                                #setting command
                                next_message_board.set_command(dcps_full_path1 + path_to_c_standalone_test1 + "MessageBoard")
                                #setting working dir
                                next_message_board.set_working_dir(dcps_full_path1 + path_to_c_standalone_test1)
                                
                            if dcps_key == cpp_key:
                                #setting command
                                next_message_board.set_command(dcps_full_path1 +  path_to_cpp_standalone_test1 + "MessageBoard")
                                #setting working dir
                                next_message_board.set_working_dir(dcps_full_path1 +  path_to_cpp_standalone_test1)    
                                                                    
                            if dcps_key == corba_cpp_key:
                                #setting command
                                next_message_board.set_command(dcps_full_path1 + path_to_cpp_corba_test1 + "MessageBoard")
                                #setting working dir
                                next_message_board.set_working_dir(dcps_full_path1 + path_to_cpp_corba_test1)
                                
                            if dcps_key == corba_java_key:
                                #setting command
                                cp1 = main_class_path1 + path_separator1 + dcps_start_java_corba_1
                                local_host.set_env_value("CLASSPATH", cp1)
                                next_message_board.set_command("java")
                                #setting message_board args
                                next_message_board.set_args(" -Djava.endorsed.dirs=" + jacorb_endorsed_dirs1 + " -classpath %s chatroom.MessageBoard" % dcps_start_java_corba_1)

                                
                            #if dcps_key == rto_java_key:
                                #setting command
                             #   cp1 = main_class_path1 + path_separator1 + dcps_start_java_rto_1
                             #  local_host.set_env_value("CLASSPATH", cp1)
                             #  next_message_board.set_command("java")
                                #setting message_board args
                             #  next_message_board.set_args("-classpath %s chatroom.MessageBoard" % dcps_start_java_rto_1)
          
                            next_message_board_ext = ExtProcess(next_message_board, dcps_key)
                            dcps_message_board_process.append(next_message_board_ext)
                            
                        #setting commands for tests by keys
                        for dcps_key in dcps_chatter_keys:
                
                            next_chatter = remote_host.define_process("no_command")
                            
                            if dcps_key == java_key:
                                #setting command
                                cp2 = main_class_path2 + path_separator2 + dcps_start_java_sa2
                                remote_host.set_env_value("CLASSPATH", cp2)
                                next_chatter.set_command("java")
                                next_chatter.set_args("-classpath %s chatroom.Chatter " % dcps_start_java_sa2)
                    
                            if dcps_key == c_key:
                                #setting command
                                next_chatter.set_command(dcps_full_path2  + path_to_c_standalone_test2 + "Chatter")
                                #setting working dir
                                next_chatter.set_working_dir(dcps_full_path2  + path_to_c_standalone_test2)
                                
                            if dcps_key == cpp_key:
                                #setting command
                                next_chatter.set_command(dcps_full_path2 + path_to_cpp_standalone_test2 + "Chatter")
                                #setting working dir
                                next_chatter.set_working_dir(dcps_full_path2 + path_to_cpp_standalone_test2)    
                            
                                
                            if dcps_key == corba_cpp_key:
                                #setting command
                                next_chatter.set_command(dcps_full_path2 + path_to_cpp_corba_test2 + "Chatter")
                                #setting working dir
                                next_chatter.set_working_dir(dcps_full_path2 + path_to_cpp_corba_test2)
                                
                            if dcps_key == corba_java_key:
                                #setting command
                                cp2 = main_class_path2 + path_separator2 + dcps_start_java_corba_2
                                remote_host.set_env_value("CLASSPATH", cp2)
                                next_chatter.set_command("java")
                                next_chatter.set_args(" -Djava.endorsed.dirs=" + jacorb_endorsed_dirs2 + " -classpath %s chatroom.Chatter " % dcps_start_java_corba_2)
                                
                            #if dcps_key == rto_java_key:
                                #setting command
                             #   cp2 = main_class_path2 + path_separator2 + dcps_start_java_rto_2
                             #   remote_host.set_env_value("CLASSPATH", cp2)
                             #   next_chatter.set_command("java")
                             #   next_chatter.set_args("-classpath %s chatroom.Chatter " % dcps_start_java_rto_2)
                            
                            next_chatter_ext = ExtProcess(next_chatter, dcps_key)
                            dcps_chatter_process.append(next_chatter_ext)

                        starttime = time.time() # record starting time
                    </script>

                    <!-- Start testing -->
                    <testcase name = "test_scenario.get_name()">
                        <sequence>
                            <script>
                                full_log_dir_path1 = test_root1 + file_path_separator1 + tutorial_dir_name + file_path_separator1 + current_log_dir_name1
                                full_log_dir_path2 = test_root2 + file_path_separator2 + tutorial_dir_name + file_path_separator2 + current_log_dir_name2
                            </script>
                                                        
                            <if expr="(len(dcps_message_board_process) > 0) and (len(dcps_chatter_process) > 0)">
                                <try>
                                    <sequence>
                                        <if expr="run_type == shm_type">
                                           <sequence>
                                              <call function="'StartOSPL'">local_host</call>
                                              <call function="'StartOSPL'">remote_host</call>
                                           </sequence>
                                        </if>
                                        <iterate var="dcps_message_board" in="dcps_message_board_process">
                                            <iterate var="dcps_chatter" in="dcps_chatter_process">
                                                <sequence>
                                                    <script>
                                                        #normalize keys length
                                                        message_board_name_key = normalize_length_of_key(dcps_message_board.get_op_key(), dcps_message_board_keys, dcps_chatter_keys)
                                                        chatter_name_key = normalize_length_of_key(dcps_chatter.get_op_key(), dcps_message_board_keys, dcps_chatter_keys)
                                                        #setting common part of log file name
                                                        start_log_name = "%s_%s_to_%s_%s" % (local_host.get_host_name(), message_board_name_key, remote_host.get_host_name(), chatter_name_key)
                                                        message_board_log_name = start_log_name + "___message_board_dcps.log"
                                                        #setting message_board log filename  
                                                        dcps_message_board.set_log_file(full_log_dir_path1+ file_path_separator1 + message_board_log_name)
                                                            
                                                        #addition in array of names
                                                        log_result = LogResult("dcps_message_board", full_log_dir_path1 + file_path_separator1 + message_board_log_name, full_log_dir_path1, dcps_message_board.get_op_key(),"")
                                                        if array_of_test_results.count(log_result) == 0:
                                                            array_of_test_results.append(log_result)
                                                        start_chater_param = dcps_chatter.get_args()
                                                    </script>
                                                    <parallel>
                                                        <sequence>
                                                            <call function="'RunProcess'">[local_host, dcps_message_board]</call>
                                                            <call function="'PASS-if-0'">STAXResult</call>
                                                        </sequence>
                                                        <sequence>
                                                            <loop var="index" from="0" to="len(array_of_chatter_params) - 1 ">
                                                                <sequence>
                                                                    <script>
                                                                        first_key = dcps_message_board.get_op_key()
                                                                        if (index == 0):
                                                                            #wait  (in some case message_board process not start at once)
                                                                            time.sleep(5)

                                                                        #addition of args for chatter tests
                                                                        dcps_chatter.set_args(start_chater_param + str(array_of_chatter_params[index]) + " " +chater_user_name)
                                                                        chatter_log_name = start_log_name + "_" + array_of_chatter_params[index] +  "_chatter_dcps.log"
                                                                        #setting chatter log filename
                                                                        dcps_chatter.set_log_file(full_log_dir_path2 + file_path_separator2 + chatter_log_name)
                                                                        #in case '-1' params we dont add log file in array cause this last process  - terminated chatter process
                                                                        if (array_of_chatter_params[index] != '-1'):
                                                                            log_result = LogResult("dcps_chatter", full_log_dir_path1 + file_path_separator1 + chatter_log_name, full_log_dir_path2, dcps_chatter.get_op_key(),str(array_of_chatter_params[index]))
                                                                            array_of_test_results.append(log_result)
                                                                        else:
                                                                            dcps_chatter.set_log_file("")
                                                                    </script>
                                                                    <sequence>
                                                                        <call function="'RunProcess'">[remote_host, dcps_chatter]</call>
                                                                        <call function="'PASS-if-0'">STAXResult</call>
                                                                    </sequence>
                                                                    <if expr="array_of_chatter_params[index] != '-1'">
                                                                        <call function="'CopyProcessLogToHost'">[remote_host, local_host, dcps_chatter, full_log_dir_path1]</call>
                                                                    </if>
                                                                </sequence>
                                                            </loop>                                    
                                                        </sequence>
                                                    </parallel>
                                                </sequence>
                                            </iterate>
                                        </iterate>
                                    </sequence>
                                <finally>
                                    <sequence>
                                        <if expr="run_type == shm_type">
                                           <sequence>
                                               <call function="'StopOSPL'">local_host</call>
                                               <call function="'StopOSPL'">remote_host</call>
                                           </sequence>
                                        </if>
                                        <call function="'MoveSysLogToHost'">[local_host, local_host, full_log_dir_path1]</call>
                                        <call function="'MoveSysLogToHost'">[remote_host, local_host, full_log_dir_path1]</call>
                                    </sequence>
                                </finally>
                                </try>    
                            </if>
                            <script>
                                stoptime = time.time()
                                elapsedSecs = stoptime - starttime
                            </script>

                            <message>'Test complete ran for %d seconds' % elapsedSecs</message>
                            
                            <call function="'AnalyzeTestLog'">[full_log_dir_path1, array_of_test_results, array_of_chatter_params, chater_user_name]</call>
                            
                        </sequence>
                    </testcase>
                </sequence>    
            <else>
                <script>
                    test_scenario.analyze()
                </script>
            </else>
            </if>
        </sequence>
        <!-- Function body end -->
    </function>
    <!-- function: tutorial_main -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
</stax>
