buildframework/helium/tools/testing/ats/ats.ant.xml
author jascui
Wed, 17 Nov 2010 13:27:16 +0800
changeset 686 3e502c8c584c
parent 645 b8d81fa19e7d
permissions -rw-r--r--
Update release information and product version.

<?xml version="1.0" encoding="UTF-8"?>
<!-- 
============================================================================ 
Name        : ats.ant.xml 
Part of     : Helium 

Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
All rights reserved.
This component and the accompanying materials are made available
under the terms of the License "Eclipse Public License v1.0"
which accompanies this distribution, and is available
at the URL "http://www.eclipse.org/legal/epl-v10.html".

Initial Contributors:
Nokia Corporation - initial contribution.

Contributors:

Description:

============================================================================
-->
<!--* @package testing -->
<project name="_testing.ats" xmlns:hlm="http://www.nokia.com/helium">
    <description>
    ATS testing targets.
    </description>
          
    <!--* @property ats.enabled
    Value must be set to execute ats-test target.
    @type boolean
    @editable required
    @scope public
    @since 11.0
    -->
    
    <!--* @property ats.bootuptest.enabled
    Value must be set to execute ats-bootup-test target.
    @type boolean
    @scope public
    @since 12.0
    -->

    <!--* @property internal.ats.enabled
    Set to run ats targests if ats.enabled set to true.
    @type boolean
    @scope private
    -->

    <!--* @property ats.aste.testasset.location
    Location of SW Test Assets, if the TestAsset is not packaged then it is first compressed to a .zip  file. It should be a UNC path.
    @type string
    @editable required
    @scope public
    -->

    <!--* @property eunit.test.package
    The EUnit package name to be unzipped on the environment, for executing EUnit tests.
    @type string
    @scope public
    -->

    <!--* @property ats.script.type
    There are two types of ats script files to send drop to ATS server, runx and import; only difference is that with import  ATS doesn't have to have access rights to testdrop.zip file, as it is sent to the system over http and import doesn't need network shares. If that is not needed import should not be used. Default value is runx as import involves heavy processing on ATS server.
    @type string
    @scope public
    -->

    <!--* @property tsrc.path.list
    Contains list of the tsrc directories. Gets the list from system definition layer files. Assuming that the test components are defined already in te layers.sysdef.xml  files to get compiled. Not recommended, but the property value can be set if there are no System Definition file(s), and tsrc directories paths to set manually.
    @type string
    @scope public
    -->

    <!--* @property ats.diamonds.signal
    Should be true  so at end of the build diamonds is checked for test results and Helium fails if tests failed.
    @type string
    @scope public
    -->

    <!-- Contains a test filterset name. A filterset is used to select/unselect test components. The filter(s) is/are effective when the same filters are defined in the package definition file for component(s).
    @type string
    @editable required
    @scope public
    @since 10.79
    -->
    <property name="ats.test.filterset" value="sysdef.filters.test" />
    <hlm:sysdefFilterSet id="sysdef.filters.test" >
        <filter filter="test" />
    </hlm:sysdefFilterSet>
    
    <!--* @property tdriver.asset.location
    The location of the test asset where ruby test files, sip profiles, hardware data etc are located.
    @type string
    @editable required
    @scope public
    -->
    
    <!--* @property tdriver.test.profiles
    Test profiles to be executed should be mentioned in this comma separated list e.g., 'bat, fute'.
    @type string
    @editable required
    @scope public
    -->
    
    <!--* @property tdriver.tdrunner.enabled
    Mustbe set to 'true' if TDrunner is engine is to be used. If true .sip files are used otherwise .rb (ruby) files are used to execute tests.
    @type boolean
    @editable required
    @scope public
    -->

    <!--* @property tdriver.template.file
    Location of the TDriver template file if user wants to use own template file instead of the default one.
    @type string
    @scope public
    -->

    <!--* @property enabled.ats
    Value must be set to execute ats-test target. - deprecated: Start using ats.enabled property.
    @type boolean
    @editable required
    @scope public
    @deprecated since 11.0
    -->
    
    <!--* @property aste.enabled
    Value must be set to execute ats-aste target.
    @type boolean
    @editable required
    @scope public
    @since 11.0
    -->
    
    <!--* @property internal.aste.enabled
    Set to run aste targets if aste.enabled set to true.
    @type boolean
    @scope private
    -->
    
    <!--* @property enabled.aste
    Value must be set to execute ats-aste target. - deprecated: Start using aste.enabled property.
    @type boolean
    @editable required
    @scope public
    @deprecated since 11.0
    -->
    
    <!--* @property ats4.enabled
    Value must be set to execute ats4 features.
    @type boolean
    @editable required
    @scope public
    @since 11.0
    -->

    <!--* @property internal.ats4.enabled
    Set if ats4.enabled is set to true. To run ats4 dependent targets.
    @type boolean
    @scope private
    -->

    <!-- Execute test cases using stf on ats4. Defaults to True, Set it to False if you do not want to enable stf.
    @type boolean
    @scope public
    @since 12.0
    -->
    <property name="ats.stf.enabled" value="true"/>
    
    <!--* @property ats.product.name
    Name of the product to be tested. For example: "PRODUCT"
    @type string
    @editable required
    @scope public
    -->
    
    <!--* @property ats.drop.location
    Server location (UNC path) to save the drop file, before sending to the ATS. For example: \\trwsem00\some_folder\. In case, ``ats.script.type`` is set to "import", ATS doesn't need to have access to ats.drop.location, its value can be any local folder on build machine, for example c:\temp (no network share needed).
    @type string
    @editable required
    @scope public
    -->
    
    <!--* @property ats.server
    For example: "4fio00105" or "catstresrv001.cats.noklab.net:80". Default server port is "8080", but it is not allowed between intra and Noklab. Because of this we need to define server port as 80. The host can be different depending on site and/or product.
    @type string
    @editable required
    @scope public
    -->
    
    <!--* @property ats.password
    Password for ATS3. This password might be different from NOE or HTTP/UNIX password.
    @type string
    @editable required
    @scope public
    -->
    
    <!--* @property ats.username
    Username for ATS3 server. This is NOT the NOE or HTTP/UNIX username.
    @type string
    @editable required
    @scope public
    -->
    
    <!--* @property ats.create.singledrop.file
    defined as true if single drop file is required. Define as false or not present for multiple drop files. - deprecated:  Start using ats.singledrop.enabled
    @type boolean
    @editable required
    @scope public
    @deprecated since 11.0
    -->
    
    <!--* @property ats.singledrop.enabled
    defined as true if single drop file is required. Define as false or not present for multiple drop files.
    @type boolean
    @editable required
    @scope public
    @since 11.0
    -->
    
    <!--* @property internal.ats.singledrop.enabled
    set to true if ats.singledrop.enabled set to true.
    @type boolean
    @scope private
    -->
    
    <!--* @property ats.emulator.enabled
    Value must be set to true to run ats with emulator.
    @type boolean
    @editable required
    @scope public
    @since 11.0
    -->
    
    <!--* @property internal.ats.emulator.enabled
    Set to run emulator targets if ats.emulator.enabled is set to true.
    @type boolean
    @scope private
    -->
    
    <!--* @property ats.emulator.enable
    Value must be set to true to run ats with emulator. - deprecated: Start using ats.emulator.enabled property.
    @type boolean
    @editable required
    @scope public
    @deprecated since 11.0
    -->
    
    <!--* @property ats.tdriver.enabled
    Value must be set to true to enable testing with TDriver.
    @type boolean
    @editable required
    @scope public
    @since 11.0
    -->
    
    <!--* @property internal.ats.tdriver.enabled
    Set to run TDriver targets if ats.tdriver.enabled is set to true.
    @type boolean
    @scope private
    -->
    
    <!--* @property ats.delta.enabled
    Should be true so only ADOs changed during do-prep-work-area are tested by ATS.
    @type boolean
    @editable required
    @scope public
    @since 11.0
    -->
    
    <!--* @property ats.disable.java.importer
    To disable java importer for ats. - deprecated: Start using ats.java.importer.enabled property.
    @type boolean
    @editable required
    @scope public
    @deprecated since 11.0
    -->
        
    <!-- To disable java importer for ats3
    @type boolean
    @editable required
    @scope public
    @since 11.0
    -->
    <property name="ats.java.importer.enabled" value="true"/>
    
    <!--* @property ats.disable.iconfig
    To enable/disable iconfig with ats. - deprecated: Start using ats.iconfig.enabled property.
    @type boolean
    @editable required
    @scope public
    @deprecated since 11.0
    -->
        
    <!-- To enable/disable iconfig with ats
    @type boolean
    @editable required
    @scope public
    @since 11.0
    -->
    <property name="ats.iconfig.enabled" value="true"/>
    
    <!--* @property internal.ats.iconfig.enabled
    To run python if ats.iconfig.enabled is enable/disable.
    @type boolean
    @scope private
    -->
    
    <!--* For sending drop package file to ATS/ASTE after its creation.
    @type boolean
    @scope public
    @since 11.0
    -->
    <property name="ats.upload.enabled" value="true"/>
    
    <!--* @property internal.ats.upload.enabled
    Set to run sending the test drop targets if ats.upload.enabled is set to true.
    @type boolean
    @scope private
    -->
    
    <!--* @property skip.ats.sending
    For sending drop package file to ATS/ASTE after its creation. - deprecated: Start using ats.upload.enabled property.
    @type boolean
    @editable required
    @scope public
    @deprecated since 11.0
    -->
    
    <!-- Is it required to send ats test drop to server-->
    <condition property="internal.ats.upload.enabled">
        <and>
            <not>
                <isfalse value="${ats.upload.enabled}" />
            </not>
            <not>
                <isset property="skip.ats.sending"/>
            </not>
        </and>
    </condition>
    
    <!-- Check is the ATS enabled -->
    <condition property="internal.ats.enabled">
        <or>
            <istrue value="${ats.enabled}" />
            <istrue value="${enabled.ats}"/>
        </or>
    </condition>
    
    <!-- Check is the aste enabled -->
    <condition property="internal.aste.enabled">
        <or>
            <istrue value="${aste.enabled}" />
            <isset property="enabled.aste"/>
        </or>
    </condition>

    <!-- Check if bootup testing is enabled -->
    <condition property="internal.ats.bootuptest.enabled">
        <istrue value="${ats.bootuptest.enabled}" />
    </condition>

    <!-- Check is the ast4 enabled -->
    <condition property="internal.ats4.enabled" value="true" else="false">
        <istrue value="${ats4.enabled}" />
    </condition>

    <!-- Check is the ats emulator enabled -->
    <condition property="internal.ats.emulator.enabled">
        <or>
            <istrue value="${ats.emulator.enabled}" />
            <istrue value="${ats.emulator.enable}" />
        </or>
    </condition>
    
    <!-- Check is the ats TDriver enabled -->
    <condition property="internal.ats.tdriver.enabled">
        <or>
            <istrue value="${ats.tdriver.enabled}" />
            <istrue value="${tdriver.enabled}" />
            <istrue value="${matti.enabled}" />
        </or>
    </condition>
    
    <!-- Check is the ats ats delta enabled -->
    <condition property="internal.ats.delta.enabled">
        <istrue value="${ats.delta.enabled}" />
    </condition>
    
    <!-- Check is the ats ats delta enabled -->
    <condition property="internal.ats.iconfig.enabled" value="true" else="false">
        <and>
            <not>
                <isfalse value="${ats.iconfig.enabled}" />
            </not>
            <not>
                <isset property="ats.disable.iconfig" />
            </not>
        </and>
    </condition>
    
    <!-- Check is the ats ats single drop file enabled -->
    <condition property="internal.ats.singledrop.enabled">
        <or>
            <istrue value="${ats.singledrop.enabled}" />
            <istrue value="${ats.create.singledrop.file}" />
        </or>
    </condition>
    
    <!-- Should be "true" if coverage measurement and dynamic analysis (CTC) tool support is to be used by ATS. Default value is "false", the values are case-sensitive.
    @type boolean
    @editable required
    @scope public
    -->
    <property name="ats.ctc.enabled" value="false"/>
    
    <!--* @property internal.ats.ctc.enabled
    Set to run the ats ctc targets.
    @type boolean
    @scope private
    -->
    <condition property="internal.ats.ctc.enabled">
        <istrue value="${ats.ctc.enabled}" />
    </condition>
    
    <!--  -->
    <fileset id="reference.ats.flash.images" dir="${release.images.dir}">
        <include name="**/*.fpsx" />
        <include name="**/*rnd.C00" />
        <include name="**/*rnd.V01" />
    </fileset>
    
    <!--* @property ats.flashfiles.minlimit
    Limit of minimum number of flash files to execute ats-test target, otherwise ATSDrop.zip will not be generated. Default value is "2" files.
    @type string
    @scope public
    -->
    <condition property="ats.flashfiles.minlimit" value="0" else="2">
        <or>
            <istrue value="${ats.emulator.enabled}" />
            <istrue value="${ats.emulator.enable}" />
        </or>
    </condition>

    <fileset id="reference.ats.sis.images" dir="${ats.sis.images.dir}">
        <include name="**/*.sis" />
    </fileset>
    <!-- Limit of minimum number of sis files to execute tdriver-test target, otherwise TDriver-drop.zip will not be generated. Default value is "1" files.
    @type string
    @scope public
    -->
    <property name="ats.sisfiles.minlimit" value="1" />
    
    <property name="drop.file.counter" value="0" />

    <!-- The target creates ATSDrop.zip file which also includes test.xml file; and sends the drop to ATS.
        
    The layer definition, in system definition file, for tsrc directory should look like:

        <layer name="name_test_layer">
            <module name="module_name">
                <unit id="unit_id" name="unti_name" bldFile="path_of_tsrc_folder_to_be_built" filter=""/>
            </module>
        </layer>
    -->
    <target name="ats-test" if="internal.ats.enabled">
        <mkdir dir="${test.log.dir}"/>
        <runtarget target="load-property-from-cache-file" />
        <hlm:filterRecordStartMacro pattern="${ats.password}" category="ats"/>
        <trycatch reference="exception">
            <try>
                <runtarget target="ats-delta"/>
                <antcall target="create-canonical-sysdef-file" inheritRefs="true">
                    <reference refid="ats.system.definition.files" torefid="system.definition.files" />
                </antcall>
                <runtarget target="copy-mon-sym" />
                <runtarget target="ats-create-drop" />
            </try>
            <catch>
                <echo>Error: ${toString:exception}</echo>
            </catch>
        </trycatch>
        <hlm:filterRecordStopMacro log="${test.log.dir}/${build.id}_ats.log" append="false"/>
        <hlm:metadatarecord database="${metadata.dbfile}">
            <hlm:textmetadatainput>
                <fileset casesensitive="false" file="${test.log.dir}/${build.id}_ats.log" />
                <metadatafilterset refid="filterset.ats" />
            </hlm:textmetadatainput>
        </hlm:metadatarecord>
        <hlm:generateBuildStatus file="${test.log.dir}/${build.id}_ats.log" />
    </target>

    <!-- The target creates the ATSdrop.zip file including test.xml for ATS ASTE tests. This target is executable.-->
    <target name="ats-aste" if="internal.aste.enabled">
        <mkdir dir="${test.log.dir}"/>
        <runtarget target="load-property-from-cache-file" />
        <hlm:filterRecordStartMacro pattern="${ats.password}" category="ats"/>
        <runtarget target="do-ats-aste" />
        <hlm:filterRecordStopMacro log="${test.log.dir}/${build.id}_aste.log" append="false"/>
        <hlm:metadatarecord database="${metadata.dbfile}">
            <hlm:textmetadatainput>
                <fileset casesensitive="false" file="${test.log.dir}/${build.id}_aste.log" />
                <metadatafilterset refid="filterset.aste" />
            </hlm:textmetadatainput>
        </hlm:metadatarecord>
        <hlm:generateBuildStatus file="${test.log.dir}/${build.id}_aste.log" />
    </target>

    <!-- Old target for tdriver-test. Deprecated in Helium 12 -->
    <target name="matti-test">
        <runtarget target="tdriver-test" />
    </target>
    
    <!-- The target creates the TDriver_drop.zip file including test.xml for TDriver tests. This target is executable.-->
    <target name="tdriver-test" if="internal.ats.tdriver.enabled">
        <mkdir dir="${test.log.dir}"/>
        <runtarget target="load-property-from-cache-file" />
        <hlm:filterRecordStartMacro pattern="${ats.password}" category="ats"/>
        <runtarget target="copy-mon-sym" />
        <runtarget target="do-ats-tdriver" />
        <hlm:filterRecordStopMacro log="${test.log.dir}/${build.id}_tdriver.log" append="false"/>
        <hlm:metadatarecord database="${metadata.dbfile}">
            <hlm:textmetadatainput>
                <fileset casesensitive="false" file="${test.log.dir}/${build.id}_tdriver.log" />
                <metadatafilterset refid="filterset.tdriver" />
            </hlm:textmetadatainput>
        </hlm:metadatarecord>
        <hlm:generateBuildStatus file="${test.log.dir}/${build.id}_tdriver.log" />
    </target>

    <!-- Sends drop file to ATS/ASTE. Please see `ats-test` for description. -->
    <target name="do-ats-test" depends="ats-username, ats-password" if="internal.ats.upload.enabled">
        <property name="ats.sending" value="true" />
        <!-- Make the drop file visible to ATS. -->
        
        <var name="ats.drop.location.file" unset="true"/>
        <if>
            <isset property="ats.drop.location" />
            <then>
                <mkdir dir="${ats.drop.location}" />
                <property name="ats.drop.location.file" location="${ats.drop.location}/${ats.drop.file}" />
                <copy file="${build.output.dir}/ats/${ats.drop.file}" tofile="${ats.drop.location.file}" />
            </then>
            <else>
                <property name="ats.drop.location.file" location="${build.output.dir}/ats/${ats.drop.file}" />
            </else>
        </if>
        
        <!-- Notify ATS about the drop. -->
        <if>
            <istrue value="${internal.ats4.enabled}" />
            <then>
                <hlm:python failonerror="true">
version = r'${java.version}'
if '1.6.0' in version:
    assert int(version.split('_')[1]) > 6, 'Java 6 u7 required'
                </hlm:python>
                <condition property="ats.import.arg" value="-import" else="">
                    <equals arg1="${ats.script.type}" arg2="import" />
                </condition>
                <condition property="ats4.libs" value="${helium.dir}/extensions/nokia/external/ats4" else="${helium.dir}/external/antlibs">
                    <available type="dir" file="${helium.dir}/extensions/nokia/external/ats4"/>
                </condition>
                <echo message="Uploading using: -url http://${ats.server}/ServerService -path ${ats.drop.location.file} ${ats.import.arg}"/>
                <java classname="com.nokia.ats.util.server.CommandLineClient" fork="true" maxmemory="1024m" failonerror="true">
                    <classpath>
                        <pathelement path="${java.class.path}"/>
                        <fileset dir="${ats4.libs}" includes="*.jar"/>
                    </classpath>
                    <arg line="-url http://${ats.server}/ServerService -path ${ats.drop.location.file} ${ats.import.arg}"/>
                </java>
            </then>
            <else>
                <if>
                    <and>
                        <equals arg1="${ats.script.type}" arg2="import" />
                        <available classname="com.nokia.taitei.util.TestDropImporter"/>
                        <not>
                            <or>
                                <istrue value="${ats.disable.java.importer}" />
                                <isfalse value="${ats.java.importer.enabled}" />
                            </or>    
                        </not>
                    </and>
                    <then>
                        <java classname="com.nokia.taitei.util.TestDropImporter" fork="true" maxmemory="1024m" failonerror="true">
                            <classpath>
                                <pathelement path="${java.class.path}"/>
                            </classpath>
                            <arg line="${ats.server} ${ats.drop.location.file} ${ats.username} ${ats.password}"/>
                        </java>
                    </then>
                    <else>
                        <condition property="ats.wsh.testrun.file" value="wshTestRunImport.vbs" else="wshTestRunX.vbs">
                            <equals arg1="${ats.script.type}" arg2="import" />
                        </condition>
                        <exec executable="cscript" dir="${build.drive}/" failonerror="true">
                            <env key="ats3.username" value="${ats.username}" />
                            <env key="ats3.password" value="${ats.password}" />
                            <env key="ats3.host" value="${ats.server}" />
                            <env key="ats3.pathToDrop" value="${ats.drop.location.file}"/>
                            <arg value="${helium.dir}/tools/testing/ats/${ats.wsh.testrun.file}" />
                        </exec>
                    </else>
                </if>             
            </else>
        </if>
    </target>

    <!-- The target is dependent on "ats-test", should not be called independently. The target fetches flash files location -->
    <target name="ats-set-flash-image-path" unless="internal.ats.emulator.enabled">
        <pathconvert pathsep="," property="ats.flash.images">
            <fileset refid="reference.ats.flash.images"/>
        </pathconvert>
        <script language="jython" setbeans="false">
if project.getProperty('internal.ats.iconfig.enabled') == 'true':
    import atsant
    ic = None
    try:
        ic = atsant.IConfigATS(project.getProperty('release.images.dir'), project.getProperty('ats.product.name'))
    except IOError, ex:
        print ex
    if ic:
        project.setProperty('ats.flash.images', ic.findimages())
        </script>
        <hlm:python failonerror="true">
<![CDATA[
flashfilescount = len(r'${ats.flash.images}'.split(','))
mincount = int(r'${ats.flashfiles.minlimit}')
if mincount > 0:
    assert r'${ats.flash.images}' != '', 'No images found in ' + r'${release.images.dir}'
if flashfilescount < mincount:
    raise Exception('Not enough flash files, check reference.ats.flash.images and build.id, found: ' + r'${ats.flash.images}' + ', looking in: ' + r'${release.images.dir}')
]]>
        </hlm:python>
    </target>

    <!-- The target is dependent on "ats-test", should not be called independently. The target fetches flash files location -->
    <target name="ats-set-sis-flash-image-path">
        <pathconvert pathsep="," property="ats.sis.images">
            <fileset refid="reference.ats.sis.images"/>
        </pathconvert>
    </target>

    <!-- Sets values common for ATS, this is a dependent target and shouldn't be used as an individual target -->
    <target name="ats-common">
        <property name="ats.config.file" value="" />

        <!-- Text in name of PKG files to use eg. 'sanity' would only use xxxsanity.pkg files from components.
        @type string
        @scope public
        -->
        <property name="ats.specific.pkg" value="" />
        
        <!-- Product HardWare ID (HWID) attached to ATS. By default the value of HWID is not set.
        @type string
        @scope public
        -->
        <property name="ats.product.hwid" value="" />
        <!-- To set test commands execution time limit on ATS server, in seconds. Default value is "60".
        @type string
        @scope public
        -->
        <property name="ats.test.timeout" value="60" />
        <!-- Sets ATS reports store location. Default location is "${publish.dir}/${publish.subdir}"
        @type string
        @scope public
        -->
        <property name="ats.report.location" value="${publish.dir}/${publish.subdir}" />
        <condition property="internal.ats.diamonds.arg" value="--diamonds-build-url=http://${diamonds.host}:${diamonds.port}${diamonds.build.id}" else="">
            <isset property="diamonds.build.url" />
        </condition>
    </target>

    <!-- Sets default values for the ATS (STIF and EUnit), this is a dependent target and shouldn't be used as an individual target -->
    <target name="ats-set-defaults-stifeunit" depends="ats-common,lookup-email">
        <!-- Default values for the properties -->
        <!-- The property is needed if you want to get an email from ATS server after the tests are executed. There can be one to many semicolon(s) ";" separated email addresses.
        @type string
        @scope public
        -->
        <property name="ats.email.list" value="${email.from}" />
        <!-- Value of the ats email report
        @type string
        @scope public
        -->
        <property name="ats.report.type" value="ATS3_REPORT" />
        <!-- The default value is "data" and refers to the 'data' directory under 'tsrc' directory.
        @type string
        @scope public
        -->
        <property name="tsrc.data.dir" value="data" />
        <!-- Modify the plan name if you have understanding of test.xml file or leave it as it is. Default value is "plan"
        @type string
        @scope public
        -->
        <property name="ats.plan.name" value="plan" />
        <!-- Modify the test-run name if you have understanding of test.xml file or leave it as it is. Default value is a string consist of build id, product name, major and minor versions
        @type string
        @scope public
        -->
        <property name="ats.testrun.name" value="${build.id}_${ats.product.name}" />
        <!-- CTC host, provided by CATS used to create coverage measurement reports. MON.sym files are copied to this location, for example "10.0.0.1". If not given, code coverage reports are not created
        @type string
        @scope public
        -->
        <property name="ats.ctc.host" value="" />
        <condition property="ats.version" value="4" else="3">
            <istrue value="${internal.ats4.enabled}" />
        </condition>
        <var name="ats.drop.file" value="${build.id}_ATS${ats.version}Drop${drop.file.counter}.zip" />
        
        <!--* @property ats.target.platform
        Sets target platform for compiling test components. Default value is "armv5 urel".
        @type string
        @scope public
        -->
        <condition property="ats.target.platform" value="winscw urel" else="armv5 urel">
            <or>
                <istrue value="${ats.emulator.enabled}" />
                <istrue value="${ats.emulator.enable}" />
            </or>
        </condition>
        <!-- Should be "true" if tracing is needed during the tests running on ATS. Default value is "false", the values are case-sensitive.
        @type boolean
        @scope public
        @editable required
        -->
        <property name="ats.trace.enabled" value="false"/>
        <!-- Should be ``true`` so a set is used for each pkg file in a component, this allows tests to run in parallel on several devices.
        @type boolean
        @scope public
        -->
        <property name="ats.multiset.enabled" value="false"/>
        
        <!-- Flags for EUnit exerunner can be set by setting the value of this variable. The default flags are set to "/E S60AppEnv /R Off".
        @type string
        @editable required
        @scope public
        -->         
        <property name="eunitexerunner.flags" value="/E S60AppEnv /R Off" />
            
        <!--* @property ats.obey.pkgfiles.rule.enabled
        If the property is set to "true", then the only test components which will have PKG files, will be included into the test.xml as a test-set. Which means, even if there's a test component (executable) but there's no PKG file, it should not be considered as a test component and hence not included into the test.xml as a separate test. By default the property value is false.
        @type boolean
        @scope public
        -->
        
        <!--* @property ats.obey.pkgfiles.rule
        If the property is set to "true", then the only test components which will have PKG files, will be included into the test.xml as a test-set. Which means, even if there's a test component (executable) but there's no PKG file, it should not be considered as a test component and hence not included into the test.xml as a separate test. By default the property value is false. - deprecated: Start using ats.obey.pkgfiles.rule.enabled property
        @type boolean
        @scope public
        @deprecated since 11.0
        -->
        
        <!-- * @property internal.ats.obey.pkgfiles.rule.enabled
        If the property is set to "true", if ats.obey.pkgfiles.rule.enabled set to true.
        @type boolean
        @scope private
        -->
        <condition property="internal.ats.obey.pkgfiles.rule.enabled" value="true" else="false">
            <or>
                <istrue value="${ats.obey.pkgfiles.rule.enabled}" />
                <istrue value="${ats.obey.pkgfiles.rule}" />
            </or>
        </condition>
        
        
        <fail unless="ats.product.name" message="Error: ats.product.name property not defined" />
        
        <!--* @property ats.hti.enabled
        Set to true if  ats.emulator.enabled set to true. To enable hti feature while creating ats test drop.
        @type boolean
        @scope private
        -->        
        <condition property="ats.hti.enabled" value="false" else="true">
            <or>
                <istrue value="${ats.emulator.enabled}" />
                <istrue value="${ats.emulator.enable}" />
            </or>
        </condition>
    </target>

    <!-- Sets default values for the ASTE, this is a dependent target and shouldn't be used as an individual target -->
    <target name="ats-set-defaults-aste" depends="ats-common">
        <var name="ats.drop.file" value="ATSAsteDrop.zip" />
        <!-- Type of test to run. Default is 'smoke'.
        @type string
        @scope public
        -->
        <property name="ats.aste.test.type" value="smoke" />
        <!-- These are the cases that which tests should be run from the TestAsset. For example, value can be set as 100,101,102,103,105,106,. A comma is needed to separate case IDs
        @type string
        @scope public
        -->
        <property name="ats.aste.testasset.caseids" value="100,101,102,103,105,106,107,108,109,110,111,112,113,114,115" />
        <!-- Version of the software to be tested. For example: 'W81'
        @type string
        @editable required
        @scope public
        -->
        <property name="ats.aste.software.version" value="${build.id}" />
        <!-- Variant Language to be tested. Default is 'English'
        @type string
        @scope public
        -->
        <property name="ats.aste.language" value="English" />
        <!-- Flash images releases, for example 'SPP 51.32'.
        @type string
        @editable required
        @scope public
        -->
        <property name="ats.aste.software.release" value="${build.name}" />
        <!-- Modify the plan name if you have understanding of test.xml file or leave it as it is. Default value is "plan"
        @type string
        @scope public
        -->
        <property name="ats.aste.plan.name" value="plan" />
        <!-- Modify the test-run name if you have understanding of test.xml file or leave it as it is. Default value is a string consist of build id, product name, major and minor versions
        @type string
        @scope public
        -->
        <property name="ats.aste.testrun.name" value="${build.id}_${ats.product.name}_${major.version}.${minor.version}" />
        <!-- The property is needed if you want to get an email from ATS server after the tests are executed. There can be one to many semicolon(s) ";" separated email addresses.
        @type string
        @scope public
        -->
        <property name="ats.aste.email.list" value="" />
    </target>

    
    <macrodef name="getModuleTsrcMacro" uri="http://www.nokia.com/helium">
        <attribute name="property" />
        <attribute name="prefix"/>        
        <sequential>
            <if>
                <istrue value="${sysdef3.enabled}" />
                <then>
                    <hlm:filterSysdef epocroot="${build.drive}/" srcfile="${canonical.sysdef.file}" 
                        destfile="${build.drive}/output/build/canonical_system_definition_filtered_ats_test.xml">
                        <filterSet>
                            <filter filter="test" />
                        </filterSet>

                        <filterSet refid="${ats.test.filterset}" />
                    </hlm:filterSysdef>
                    <hlm:getModuleTsrcInternalMacro property="@{property}" prefix="@{prefix}" sysdef="${build.drive}/output/build/canonical_system_definition_filtered_ats_test.xml" />
                </then>
                <else>
                    <hlm:getModuleTsrcInternalMacro property="@{property}" prefix="@{prefix}" sysdef="${canonical.sysdef.file}" />
                </else>
            </if>
        </sequential>
    </macrodef>
    
    <!-- This macro fetches the tsrc paths from system definition file (layers.sysdef.xml).
        
    The layer defintion should look like:

        <layer name="name_test_layer">
            <module name="module_name">
                <unit id="unit_id" name="unti_name" bldFile="path_of_tsrc_folder_to_be_built" filter="" />
            </module>
        </layer>
    -->
    <scriptdef name="getModuleTsrcInternalMacro" language="jython" uri="http://www.nokia.com/helium">
        <attribute name="property" />
        <attribute name="prefix"/>        
        <attribute name="sysdef"/>        
import traceback
import os
import atsant
from com.nokia.ant.util import Helper

canonicalsysdeffile = attributes.get('sysdef')
createsingledropfile = project.getProperty('internal.ats.singledrop.enabled')
sysdef3 = atsant.get_boolean(str(project.getProperty('sysdef3.enabled')))
modules = atsant.files_to_test(canonicalsysdeffile, project.getProperty('exclude.test.layers'), project.getProperty('ido.build.filter'), project.getProperty('build.drive'), createsingledropfile, sysdef3)

for name in modules.keys():    
    if modules[name] == []:
        del modules[name]
    else:
        project.setProperty("%s.%s" % (attributes.get('prefix'), name), " ".join(modules[name]))

if modules == {}:
    raise Exception('No test modules found in ' + canonicalsysdeffile)

project.setProperty(attributes.get('property'), ",".join(modules.keys()))
project.setProperty('ats.drops.count', str(len(modules)))
    </scriptdef>

    <!-- The target is dependent on "ats-test", should not be called individually. The target creates the ATSdrop.zip file including test:xml file -->
    <target name="ats-create-drop" depends="ats-set-flash-image-path,ats-emulator-zip">
        <mkdir dir="${build.output.dir}/ats" />
        <hlm:getModuleTsrcMacro property="module.list" prefix="module.tsrc" />
        <for list="${module.list}" delimiter="," param="module">
            <sequential>
                <runtarget target="ats-set-defaults-stifeunit" />
                <exec executable="python">
                    <arg line="-m ats3.__init__" />
                    <arg value="--device-type=${ats.product.name}" />
                    <arg value="--device-hwid=${ats.product.hwid}" />
                    <arg value="${internal.ats.diamonds.arg}" />
                    <arg value="--drop-file=${build.output.dir}/ats/${ats.drop.file}" />
                    <arg value="--report-email=${ats.email.list}" />
                    <arg value="--report-type=${ats.report.type}" />
                    <arg value="--plan-name=${ats.plan.name}" />
                    <arg value="--testrun-name=${ats.testrun.name}_@{module}" />
                    <arg value="--flash-images=${ats.flash.images}" />
                    <arg value="--minimum-flash-images=${ats.flashfiles.minlimit}" />
                    <arg value="--target-platform=${ats.target.platform}" />
                    <arg value="--data-dir=${tsrc.data.dir}" />
                    <arg value="--test-timeout=${ats.test.timeout}" />
                    <arg value="--build-drive=${build.drive}" />
                    <arg value="--trace-enabled=${ats.trace.enabled}" />
                    <arg value="--ctc-enabled=${ats.ctc.enabled}" />
                    <arg value="--multiset-enabled=${ats.multiset.enabled}" />
                    <arg value="--file-store=${ats.report.location}" />
                    <arg value="--eunitexerunner-flags=${eunitexerunner.flags}" />
                    <arg value="--ctc-run-process-params=${ats.ctc.host}#${ats.drop.file}#${ats.drops.count}" /> <!-- Three differnt value are combined with '#' character which is later parsed inside the script -->
                    <arg value="--monsym-files=${ats.ctc.monsyms}" />
                    <arg value="--config=${ats.config.file}" />
                    <arg value="--obey-pkgfiles=${internal.ats.obey.pkgfiles.rule.enabled}" />
                    <arg value="--ats4-enabled=${internal.ats4.enabled}" />
                    <arg value="--ats-stf-enabled=${ats.stf.enabled}" />
                    <arg value="--specific-pkg=${ats.specific.pkg}" />
                    <arg value="--hti=${ats.hti.enabled}" />
                    <arg value="--minimum-execution-blocks=${ats.minimum.execution.blocks.enabled}" />
                    <arg value="--verbose" />
                    <arg line="${module.tsrc.@{module}}" />
                </exec>
                <antcall target="do-ats-test" />
                <math result="drop.file.counter" operand1="1" operation="+" operand2="${drop.file.counter}" datatype="int" />
            </sequential>
        </for>
    </target>


    <!-- Please see ats-aste for description.-->
    <target name="do-ats-aste" depends="ats-set-flash-image-path, ats-set-defaults-aste" if="internal.aste.enabled">
        <mkdir dir="${build.output.dir}/ats" />
        <exec executable="python">
            <arg line="-m ats3.aste" />
            <arg value="--report-email=${ats.aste.email.list}" />
            <arg value="--device-type=${ats.product.name}" />
            <arg value="--flash-images=${ats.flash.images}" />
            <arg value="--minimum-flash-images=${ats.flashfiles.minlimit}" />
            <arg value="--plan-name=${ats.aste.plan.name}" />
            <arg value="--testrun-name=${ats.aste.testrun.name}" />
            <arg value="--device-hwid=${ats.product.hwid}" />
            <arg value="--test-timeout=${ats.test.timeout}" />
            <arg value="--build-drive=${build.drive}" />
            <arg value="${internal.ats.diamonds.arg}" />
            <arg value="--drop-file=${build.output.dir}/ats/${ats.drop.file}" />
            <arg value="--test-type=${ats.aste.test.type}" />
            <arg value="--testasset-location=${ats.aste.testasset.location}" />
            <arg value="--testasset-caseids=${ats.aste.testasset.caseids}" />
            <arg value="--software-version=${ats.aste.software.version}" />
            <arg value="--device-language=${ats.aste.language}" />
            <arg value="--software-release=${ats.aste.software.release}" />
            <arg value="--ats4-enabled=${internal.ats4.enabled}" />
            <arg value="--verbose" />
        </exec>
        <runtarget target="do-ats-test" />
    </target>

    <!--
        This target search the mon.sym files using unit information from the canonical sysdef file.
        Then it copies the discovered files under the ftp server defined by ats.ctc.host.
        The target url is: ftp ://[server]/ctc_helium/[diamonds_id]/mon_syms/[id]/mon.sym 
    -->
    <target name="copy-mon-sym" if="internal.ats.ctc.enabled">
        <if>
            <istrue value="${internal.ats4.enabled}"/>
            <then>
                <var name="ats.ctc.host" value="${diamonds.host}"/>
            </then>
        </if>
        <fmpp sourceFile="${helium.dir}/tools/testing/ats/templates/monsym-file-list.txt.ftl"
            outputFile="${temp.build.dir}/monsym-file-list.txt">
            <data expandProperties="yes">
                data: xml(${canonical.sysdef.file})
                ant: antProperties()
            </data>
        </fmpp>
        <hlm:path2file reference="mon.sym.list" file="${temp.build.dir}/monsym-file-list.txt" />
        <script language="jython">
import os
import ctc

if not project.getProperty('ats.ctc.host'):
    raise Exception('ats.ctc.host property is not defined.')
if not project.getProperty('diamonds.build.id'):
    raise Exception('diamonds.build.id property is not defined.')

server = project.getProperty('ats.ctc.host')
diamondsid = os.path.basename(os.path.dirname(project.getProperty('diamonds.build.id')))
if project.getProperty('internal.ats4.enabled') != 'true':
    diamondsid = r'ctc_helium/' + diamondsid

path = project.getReference('mon.sym.list')
if not path:
    raise Exception('mon.sym.list reference has not been set')

uploader = ctc.MonSymFTPUploader(server, path.list(), diamondsid)
monsyms = uploader.upload()
            
# Using ; to separate the path because the target script is running on windows
project.setNewProperty('ats.ctc.monsyms', ';'.join([ "//%s/%s" % (server, x) for x in monsyms]))
        </script>
        <echo>ats.ctc.monsyms: ${ats.ctc.monsyms}</echo>
    </target>
    
    <!-- Temp dir
    @type string
    @scope private
    -->
    <property name="ats.evalid.pre" value="${temp.build.dir}/${build.id}_atsevalidpre" />
    <!-- Temp dir
    @type string
    @scope private
    -->
    <property name="ats.evalid.post" value="${temp.build.dir}/${build.id}_atsevalidpost" />
    
    <!-- Call before preperation -->
    <target name="find-files-pre" if="internal.ats.delta.enabled">
        <hlm:evalidMacro dir="${ats.evalid.pre}"/>
    </target>
    
    <!-- Call after preperation -->
    <target name="find-files-post" if="internal.ats.delta.enabled">
        <hlm:evalidMacro dir="${ats.evalid.post}"/>
    </target>
    
    <!-- Run evalid on ido directories -->
    <macrodef name="evalidMacro" uri="http://www.nokia.com/helium">
        <attribute name="dir"/>
        <sequential>
            <property name="evalid.mapping.file" location="${build.output.dir}/build/ado_mapping_evalid.ini" />
            <hlm:createAdoMappingMacro adoMapFile="${evalid.mapping.file}" />
            <hlm:python>
import delta_zip
delta_zip.evalidAdomapping(r'${build.drive}', r'@{dir}', r'${evalid.mapping.file}')
            </hlm:python>
        </sequential>
    </macrodef>
    
    <!-- Generate sysdef fileset based on evalid data -->
    <target name="ats-delta" if="internal.ats.delta.enabled">
        <script language="jython">
import ido
from com.nokia.ant.util import Helper
import delta_zip
import os

atspath = project.createDataType("path")
i = project.getReference('system.definition.files').iterator()
changedfiles = delta_zip.changedFiles(Helper.getProperty(project, 'ats.evalid.pre'), Helper.getProperty(project, 'ats.evalid.post'))
while i.hasNext():
    path = i.next().toString()
    sysdefpath = os.path.abspath(os.path.join(project.getProperty('build.drive') + os.sep, ido.get_sysdef_location(path)))
    for f in changedfiles:
        if sysdefpath.lower() in os.path.abspath(f).lower():
            pe = atspath.createPathElement()
            pe.setPath(path)
            break
project.addReference('ats.system.definition.files', atspath)
        </script>
    </target>
    
    <!-- Common target to run ats, aste and TDriver -->
    <target name="run-test" depends="ats-test,ats-aste,tdriver-test"/>
    
    <!-- Zip build area for emulator -->
    <target name="ats-emulator-zip" if="internal.ats.emulator.enabled">
        <property name="zips.emulator_zip.spec.name" value="emulator_zip"/>
        <hlm:zipContentMacro type="emulator_zip" file="${helium.dir}/tools/testing/ats/emulator_zip.cfg.xml" />

        <if>
            <isset property="ats.drop.location" />
            <then>
                <property name="ats.flash.images" value="${ats.drop.location}\${build.id}_emulator_urel.zip"/>
                <copy file="${build.output.dir}/ats/${build.id}_emulator_urel.zip" tofile="${ats.flash.images}" />
            </then>
            <else>
                <property name="ats.flash.images" value="${build.output.dir}/ats/${build.id}_emulator_urel.zip"/>
            </else>
        </if>        
    </target>
    
    <!-- Generate and upload drop using custom template -->
    <target name="ats-custom-drop">
        <mkdir dir="${build.output.dir}/ats" />
        <runtarget target="ats-set-flash-image-path" />
        <runtarget target="ats-set-defaults-stifeunit" />
        <property name="ats.custom.template" value="${helium.dir}/tools/testing/ats/templates/ats4_naviengine_template.xml"/>
        <exec executable="python">
            <arg line="-Wignore -m ats3.custom" />
            <arg value="--custom-template=${ats.custom.template}" />
            <arg value="--device-type=${ats.product.name}" />
            <arg value="${internal.ats.diamonds.arg}" />
            <arg value="--drop-file=${build.output.dir}/ats/${ats.drop.file}" />
            <arg value="--report-email=${ats.email.list}" />
            <arg value="--testrun-name=${ats.testrun.name}" />
            <arg value="--flash-images=${ats.flash.images}" />
            <arg value="--test-timeout=${ats.test.timeout}" />
            <arg value="--test-type=${ats.custom.test.type}" />
        </exec>
        <runtarget target="do-ats-test" />
    </target>

    <!-- a dependant target please do not call directly use tdriver-test,
     target calls the TDriver script that creates the TDriver_drop.zip file and runs the tests
     listed in test.rb.  ats-set-flash-image-path and ats-set-sis-flash-image-path look for lists of files-->
    <target name="do-ats-tdriver" depends="ats-set-flash-image-path" >
        <runtarget target="ats-set-defaults-stifeunit" />

        <!-- Separate but similar property to ats.test.timeout for TDriver tests.
        @type string
        @editable required
        @scope public
        -->
        <property name="tdriver.test.timeout" value="60" />
        <!-- There are special sis files required to execute with test execution. This is a comma separated list in which several sis files can be deifned in a certain format like '<src file on build area>#<destination to save the file on memory card>#<destination to install the file>' e.g. <x:dir1abc.sis#f:memory1abc.sis#c:phonememoryprivateabc.sis>
        @type string
        @editable required
        @scope public
        -->
        <property name="tdriver.sis.files" value=""/>
        <!-- TDrunner parameters are set using this property. e.g. 'teardown ordered'.
        @type string
        @editable required
        @scope public
        -->
        <property name="tdriver.tdrunner.parameters" value=""/>
        <!-- TDriver test parameters can be given through TDriver parameters xml file.
        @type string
        @editable required
        @scope public
        -->
        <property name="tdriver.parameters" value=""/>
        <!-- Alias name for the test cases to be used in test.xml files for ATS4 drops only. 
        @type string
        @scope public
        @since 11.0
        -->
        <property name="ats.alias.name" value="sut_s60"/>
        <!-- The Subject for the ATS report email. This email is received in the end of the test execution.
        @type string
        @scope public
        -->
        <property name="ats.email.subject" value="${build.id} TDriver test results"/>
        <!-- This specifies email format. E.g. to receive email without attachment 'simplelogger'.
        @type string
        @scope public
        -->
        <property name="ats.email.format" value="simplelogger"/>
        <fail unless="tdriver.asset.location" message="Error: tdriver.asset.location property not defined" />
        
        <!--need to set theseup for use by do-ats-test target-->
        <mkdir dir="${build.output.dir}/ats" />
        <var name="ats.drop.file" value="ATSTDriverDrop.zip" />
        <!-- execute the tdriver.py script with parameters-->
        <exec executable="python" resultproperty="script.response">
            <arg line="-m ats3.tdriver" />
            <arg value="--build-drive=${build.drive}" />
            <arg value="--test-profiles=${tdriver.test.profiles}" />      <!--"all, !bat1" -->
            <arg value="--tdrunner-enabled=${tdriver.tdrunner.enabled}" />    <!--"true/false" -->
            <arg value="--tdriver-timeout=${tdriver.test.timeout}" />       <!--"600" -->
            <arg value="${internal.ats.diamonds.arg}" />
            <arg value="--testasset-location=${tdriver.asset.location}" />    <!--"local and/or network drive" -->
            <arg value="--file-store=${ats.report.location}" />                <!--"network drive" -->
            <arg value="--testrun-name=${ats.testrun.name}" />          <!--"TDriver_Profile_Name" -->
            <arg value="--alias-name=${ats.alias.name}" />                        <!--"agents_alias_Name" -->
            <arg value="--device-type=${ats.product.name}" />
            <arg value="--flash-images=${ats.flash.images}" /> 
            <arg value="--drop-file=${build.output.dir}/ats/${ats.drop.file}" />
            <arg value="--minimum-flash-images=${ats.flashfiles.minlimit}" />
            <arg value="--template-loc=${tdriver.template.file}" />             <!--"local and/or network drive. No comma separated list" -->
            <arg value="--email-format=${ats.email.format}" />          <!--"Email Formatting. e.g. simplelogger" -->
            <arg value="--email-subject=${ats.email.subject}" />        <!--"Email Subject. e.g. TDriver testing" -->
            <arg value="--report-email=${ats.email.list}" /> 
            <arg value="--ats4-enabled=${internal.ats4.enabled}" />
            <arg value="--tdriver-sis-files=${tdriver.sis.files}" />        <!--"src#store#dst, src#store#dst" -->
            <arg value="--tdriver-parameters=${tdriver.parameters}" />
            <arg value="--tdrunner-parameters=${tdriver.tdrunner.parameters}" />    <!--Additional TDrunner parameters for tdriver task e.g. ordered teardown -->
            <arg value="--ctc-enabled=${ats.ctc.enabled}" />
        </exec>
        <runtarget target="do-ats-test" />
    </target>

    <!-- The target is used to test ROM image files that whether device boots up -->
    <target name="ats-bootup-test" depends="ats-common,ats-set-flash-image-path" if="internal.ats.bootuptest.enabled">
        <!--need to set the setup for use by do-ats-test target-->
        <mkdir dir="${build.output.dir}/ats" />
        <var name="ats.drop.file" value="ATSBootupDrop.zip" />
        <!-- execute the bootup_testing.py script with parameters-->
        <exec executable="python" resultproperty="script.response">
            <arg line="-m ats3.bootup_testing" />
            <arg value="--build-drive=${build.drive}" />
            <arg value="${internal.ats.diamonds.arg}" />
            <arg value="--file-store=${ats.report.location}" />         <!--"network drive" -->
            <arg value="--testrun-name=${ats.testrun.name}" />          <!--"bootup_test" -->
            <arg value="--alias-name=${ats.alias.name}" />              <!--"agents_alias_Name" -->
            <arg value="--device-type=${ats.product.name}" />
            <arg value="--flash-images=${ats.flash.images}" /> 
            <arg value="--drop-file=${build.output.dir}/ats/${ats.drop.file}" />
            <arg value="--minimum-flash-images=${ats.flashfiles.minlimit}" />
            <arg value="--email-format=${ats.email.format}" />          <!--"Email Formatting. e.g. simplelogger" -->
            <arg value="--email-subject=${ats.email.subject}" />        <!--"Email Subject. e.g. TDriver testing" -->
            <arg value="--report-email=${ats.email.list}" /> 
            <arg value="--ats4-enabled=${internal.ats4.enabled}" />
        </exec>
        <runtarget target="do-ats-test" />
    </target>

</project>