buildframework/helium/tools/common/python/lib/cpythontest/test_ats3.py
changeset 179 d8ac696cc51f
child 593 4367a1b2db65
equal deleted inserted replaced
1:be27ed110b50 179:d8ac696cc51f
       
     1 # -*- encoding: latin-1 -*-
       
     2 
       
     3 #============================================================================ 
       
     4 #Name        : test_ats3.py 
       
     5 #Part of     : Helium 
       
     6 
       
     7 #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     8 #All rights reserved.
       
     9 #This component and the accompanying materials are made available
       
    10 #under the terms of the License "Eclipse Public License v1.0"
       
    11 #which accompanies this distribution, and is available
       
    12 #at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    13 #
       
    14 #Initial Contributors:
       
    15 #Nokia Corporation - initial contribution.
       
    16 #
       
    17 #Contributors:
       
    18 #
       
    19 #Description:
       
    20 #===============================================================================
       
    21 
       
    22 """ Testing ATS3 framework. """
       
    23 # pylint: disable-msg=E1101,C0302,w0142,w0603,R0912,F0401,R0902,R0903,R0201,W0404
       
    24 #w0142 => * and ** were used
       
    25 #w0603 => global variables used TSRC_PATH etc
       
    26 #R*    => will be fixed while refactoring
       
    27 #F0401 => pylint didn't find "path" module
       
    28 #E1101 => Mocker shows mockery
       
    29 
       
    30 
       
    31 from cStringIO import StringIO
       
    32 from pprint import pprint
       
    33 from xml.etree.ElementTree import fromstring, tostring
       
    34 from xml.etree import ElementTree as et
       
    35 import difflib
       
    36 import logging
       
    37 logging.getLogger().setLevel(logging.ERROR)
       
    38 import tempfile
       
    39 import zipfile
       
    40 import os
       
    41 import re
       
    42 import subprocess
       
    43 
       
    44 from path import path
       
    45 import amara
       
    46 import mocker
       
    47 
       
    48 from ntpath import sep as atssep
       
    49 from ntpath import sep as sossep
       
    50 
       
    51 
       
    52 import ats3
       
    53 import ats3.testconfigurator as atc
       
    54 import ats3.dropgenerator as adg
       
    55 import ats3.parsers as parser
       
    56 
       
    57 
       
    58 TEST_PATH = None
       
    59 TEST_FILES = {}
       
    60 TSRC = None
       
    61 OUTPUT = None
       
    62 
       
    63 # Shortcuts
       
    64 E = et.Element
       
    65 SE = et.SubElement
       
    66 
       
    67 class Bunch(object):
       
    68     """ Configuration object. Argument from constructor are converted into class attributes. """
       
    69     def __init__(self, **kwargs):
       
    70         self.__dict__.update(kwargs)
       
    71         
       
    72 def equal_xml(xml1, xml2):
       
    73     """Check the equality of the given XML snippets.
       
    74     
       
    75     Tag name equality:
       
    76     
       
    77     >>> equal_xml('<a/>', '<a/>')
       
    78     True
       
    79     >>> equal_xml('<a/>', '<b/>')
       
    80     False
       
    81     
       
    82     Attribute equality:
       
    83     
       
    84     >>> equal_xml('<a k="v"/>', '<a k="v"/>')
       
    85     True
       
    86     >>> equal_xml('<a k="v"/>', '<a k="w"/>')
       
    87     False
       
    88     
       
    89     Text content equality:
       
    90     
       
    91     >>> equal_xml('<a>v</a>', '<a>v</a>')
       
    92     True
       
    93     >>> equal_xml('<a>v</a>', '<a>w</a>')
       
    94     False
       
    95     >>> equal_xml('<a>v</a>', '<a></a>')
       
    96     False
       
    97     
       
    98     Text content equality when whitespace differs:
       
    99     >>> equal_xml('<a>v</a>', '<a>v </a>')
       
   100     True
       
   101 
       
   102     Equality of child elements:
       
   103     
       
   104     >>> equal_xml('<a><b><c k="v"/></b></a>', '<a><b><c k="v"/></b></a>')
       
   105     True
       
   106     >>> equal_xml('<a><b><c k="v"/></b></a>', '<a><b><c k="w"/></b></a>')
       
   107     False
       
   108     >>> equal_xml('<a><b><c k="v"/>v</b></a>', '<a><b><c k="v"/>w</b></a>')
       
   109     False
       
   110     >>> equal_xml('<a><b><c k="v"/>v</b></a>', '<a><b><c k="v"/>v </b></a>')
       
   111     True
       
   112     
       
   113     """
       
   114     def __init__():
       
   115         check_instance(xml1, xml2)
       
   116     
       
   117     def check_instance(xml1, xml2):
       
   118         """if xml1 and xml2 are instances, converts to strings"""
       
   119         if isinstance(xml1, basestring):
       
   120             xml1 = fromstring(xml1)
       
   121         if isinstance(xml2, basestring):
       
   122             xml2 = fromstring(xml2)
       
   123         check_tags(xml1, xml2)
       
   124 
       
   125     def check_tags(xml1, xml2):
       
   126         """check xml tags and text equality"""
       
   127         if xml1.tag != xml2.tag:
       
   128             return False
       
   129         if xml1.attrib != xml2.attrib:
       
   130             return False
       
   131         if xml1.text:
       
   132             if not xml2.text:
       
   133                 return False
       
   134         if xml2.text:
       
   135             if not xml1.text:
       
   136                 return False
       
   137 
       
   138         produce_xml_children(xml1, xml2)
       
   139 
       
   140     def produce_xml_children(xml1, xml2):
       
   141         """checks if xml children are of same length and are equal?"""
       
   142         if xml1.text and xml2.text and xml1.text.strip() != xml2.text.strip():
       
   143             return False
       
   144         if xml1.tail is not None and xml2.tail is not None:
       
   145             if xml1.tail.strip() != xml2.tail.strip():
       
   146                 return False
       
   147         elif xml1.tail != xml2.tail:
       
   148             return False
       
   149         
       
   150         children1 = list(xml1.getchildren())
       
   151         children2 = list(xml2.getchildren())
       
   152         if len(children1) != len(children2):
       
   153             return False
       
   154         for child1, child2 in zip(children1, children2):
       
   155             return equal_xml(child1, child2)
       
   156     return True        
       
   157 
       
   158 
       
   159 def setup_module():
       
   160     """ Setup test environment. """
       
   161     global TEST_PATH, TSRC, OUTPUT
       
   162     TEST_PATH = path(tempfile.mkdtemp())
       
   163     OUTPUT = TEST_PATH.joinpath(r"output")
       
   164     component = TEST_PATH
       
   165     component.joinpath("group").makedirs()
       
   166     for path_parts in (("tsrc", "group", "bld.inf"),
       
   167                        ("tsrc", "group", "test.pkg"),
       
   168                        ("tsrc", "testmodules", "file1.dll"),
       
   169                        ("tsrc", "testmodules", "file2.dll"),
       
   170                        ("tsrc", "data", "file1"),
       
   171                        ("tsrc", "data", "file2"),
       
   172                        ("tsrc", "data", "file3"),
       
   173                        ("tsrc", "data", "mmc", "file4"),
       
   174                        ("tsrc", "data", "c", "file5"),
       
   175                        ("tsrc", "conf", "file1.cfg"),
       
   176                        ("tsrc", "conf", "file2.cfg"),
       
   177                        ("tsrc", "init", "TestFramework.ini"),
       
   178                        ("tsrc", "custom", "prepostaction.xml"),
       
   179                        ("tsrc", "custom", "postpostaction.xml"),
       
   180                        # These do not have to be under 'tsrc':
       
   181                        ("tsrc", "output", "images", "file1.fpsx"),
       
   182                        ("tsrc", "output", "images", "file2.fpsx"),
       
   183                        ("tsrc", "sis", "file1.sisx"),
       
   184                        ("tsrc", "sis", "file2.sisx"),
       
   185                        ("tsrc", "sis", "file3.sisx"),
       
   186                        ("tsrc", "trace_init", "trace_activation_1.xml")):
       
   187         filepath = component.joinpath(*path_parts)
       
   188         if not filepath.parent.exists():
       
   189             filepath.parent.makedirs()
       
   190         filepath.touch()
       
   191         TEST_FILES.setdefault(path_parts[1], []).append(filepath)
       
   192     TSRC = component.joinpath("tsrc")
       
   193     filepath = OUTPUT.joinpath("pmd", "pmd_file.pmd")
       
   194     if not filepath.parent.exists():
       
   195         filepath.parent.makedirs()
       
   196     filepath.touch()
       
   197     TEST_FILES.setdefault("pmd_file", []).append(filepath)
       
   198     tracing = component.joinpath("tsrc", "trace_init")
       
   199     root = E('ConfigurationFile')
       
   200     confs = E("Configurations")
       
   201     trace_act = SE(confs, "TraceActivation")
       
   202     conf = SE(trace_act, "Configuration")
       
   203     conf.set('Name', 'MCU')
       
   204     mcu = SE(conf, "MCU")
       
   205     sett = SE(mcu, "settings")
       
   206     SE(sett, "timestamp")
       
   207     root.append(confs)
       
   208     ettree = et.ElementTree(root)
       
   209     doc = amara.parse(et.tostring(ettree.getroot()))
       
   210     handle = open(tracing.joinpath("trace_activation_1.xml"), "w")
       
   211     handle.write(doc.xml(indent="yes"))
       
   212     handle.close()
       
   213 #    tracing.writestr("trace_activation_1.xml", doc.xml(indent=u"yes"))
       
   214     group = component.joinpath("tsrc", "group")
       
   215     group.joinpath("bld.inf").write_text(
       
   216         r"""
       
   217         PRJ_TESTMMPFILES
       
   218         stif.mmp /* xyz.mmp */ abcd.mmp
       
   219         /*xyz.mmp*/
       
   220         eunit.mmp /* xyz.mmp */
       
   221         both.mmp
       
   222         ..\sub-component\group\sub-component.mmp
       
   223         """.replace('\\', os.sep))
       
   224 
       
   225     group.joinpath("test.pkg").write_text(
       
   226         r"""
       
   227         ;Language - standard language definitions
       
   228         &EN
       
   229         
       
   230         ; standard SIS file header
       
   231         #{"BTEngTestApp"},(0x04DA27D5),1,0,0
       
   232         
       
   233         ;Supports Series 60 v 3.0
       
   234         (0x101F7961), 0, 0, 0, {"Series60ProductID"}
       
   235         
       
   236         ;Localized Vendor Name
       
   237         %{"BTEngTestApp"}
       
   238         
       
   239         ;Unique Vendor name
       
   240         :"Nokia"
       
   241         
       
   242         ; Files to copy
       
   243         "\tsrc\testmodules\file1.dll"-"c:\sys\bin\file1.dll"
       
   244         "\tsrc\testmodules\file2.dll"-"c:\sys\bin\file2.dll"
       
   245         "\tsrc\data\file1"-"e:\sys\bin\file1"
       
   246         "\tsrc\data\file2"-"e:\sys\bin\file2"
       
   247         "\tsrc\data\file3"-"e:\sys\bin\file3"
       
   248         "\tsrc\conf\file1.cfg"-"!:\sys\bin\file1.cfg"
       
   249         "\tsrc\conf\file2.cfg"-"!:\sys\bin\file2.cfg"
       
   250         "\tsrc\init\TestFramework.ini"-"!:\sys\bin\TestFramework.ini"
       
   251         "\tsrc\sis\file1.sisx"-"!:\sys\bin\file1.sisx"
       
   252         "\tsrc\sis\file2.sisx"-"!:\sys\bin\file2.sisx"
       
   253         """.replace('\\', os.sep))
       
   254     group.joinpath("stif.mmp").write_text("LIBRARY stiftestinterface.lib")
       
   255     group.joinpath("eunit.mmp").write_text("LIBRARY eunit.lib")
       
   256     group.joinpath("both.mmp").write_text("LIBRARY stiftestinterface.lib eunit.lib")
       
   257     init = component.joinpath("tsrc", "init")
       
   258     
       
   259     init.joinpath("TestFramework.ini").write_text(
       
   260         r"""
       
   261 #     - Sets a device reset module's dll name(Reboot).
       
   262 #        + If Nokia specific reset module is not available or it is not correct one
       
   263 #          StifHWResetStub module may use as a template for user specific reset
       
   264 #          module. 
       
   265 
       
   266 [Engine_Defaults]
       
   267 
       
   268 TestReportMode= FullReport        # Possible values are: 'Empty', 'Summary', 'Environment',
       
   269                                                                'TestCases' or 'FullReport'
       
   270 
       
   271 CreateTestReport= YES            # Possible values: YES or NO
       
   272 
       
   273 TestReportFilePath= C:\LOGS\TestFramework\
       
   274 TestReportFileName= TestReport
       
   275 
       
   276 TestReportFormat= TXT            # Possible values: TXT or HTML
       
   277         
       
   278         """)
       
   279 
       
   280 
       
   281 def teardown_module():
       
   282     """ Cleanup environment after testing. """    
       
   283     def __init__():
       
   284         path(TEST_PATH).rmtree()
       
   285 
       
   286 # CTC related functions    
       
   287 def check_ctc_write(steps):
       
   288     """Checks if CTC data is written on the CTC log"""
       
   289     step = steps.next()
       
   290     assert step.get("name") == "Save CTC data"
       
   291     assert step.findtext("./command") == "execute"
       
   292     params = step.findall("./params/param")
       
   293     assert params[0].get("parameters") == "writelocal"
       
   294     assert params[1].get("file") == path(r"z:\sys\bin\ctcman.exe")
       
   295     step = steps.next()
       
   296     assert step.get("name") == "Save CTC data"
       
   297     assert step.findtext("./command") == "execute"
       
   298     params = step.findall("./params/param")
       
   299     assert params[0].get("parameters") == "writefile"
       
   300     assert params[1].get("file") == path(r"z:\sys\bin\ctcman.exe")
       
   301 
       
   302 def check_ctc_log(steps, testtype=""):
       
   303     """Fetches CTC Log"""
       
   304     #For the ctcdata.txt to be published on the ATS network drive
       
   305     step = steps.next()
       
   306     assert step.get("name") == "Fetch CTC data for post commands execution" #"Fetch and clean CTC data"
       
   307     assert step.findtext("./command") == "fetch-log"
       
   308     params = step.findall("./params/param")
       
   309     assert params[0].get("delete") == "false"
       
   310     if testtype == "withpkgfiles":
       
   311         assert params[1].get("local-path") == r"\\10.0.0.1\ctc_helium\builds\drop0\set1\ctcdata"
       
   312     else:
       
   313         assert params[1].get("local-path") == r"\\10.0.0.1\ctc_helium\builds\drop0\set0\ctcdata"
       
   314     assert params[2].get("path") == path(r"c:" + os.sep + "data" + os.sep + "ctc" + os.sep + "ctcdata.txt")
       
   315     
       
   316     #For the ctcdata.txt to be published on the build network drive
       
   317     step = steps.next()
       
   318     assert step.get("name") == "Fetch and clean CTC data" #"Fetch and clean CTC data"
       
   319     assert step.findtext("./command") == "fetch-log"
       
   320     params = step.findall("./params/param")
       
   321     assert params[0].get("delete") == "true"
       
   322     assert params[1].get("path") == path(r"c:" + os.sep + "data" + os.sep + "ctc" + os.sep + "ctcdata.txt")
       
   323 
       
   324 def check_ctc_start(steps):
       
   325     """Checks if CTC starts in ATS"""
       
   326     step = steps.next()
       
   327     assert step.get("name") == "Create CTC log dir"
       
   328     assert step.findtext("./command") == "makedir"
       
   329     params = step.findall("./params/param")
       
   330     assert params[0].get("dir") == path(r"c:" + os.sep + "data" + os.sep + "ctc")
       
   331     step = steps.next()
       
   332     assert step.get("name") == "CTC start"
       
   333     assert step.findtext("./command") == "execute"
       
   334     params = step.findall("./params/param")
       
   335     assert params[0].get("file") == path(r"z:\sys\bin\ctcman.exe")   
       
   336 
       
   337 def check_fetch_logs(steps):
       
   338     """Checks fetching log directory is created"""
       
   339     step = steps.next()
       
   340     if "Fetch test" in step.get("name"):
       
   341         assert step.get("name") == "Fetch test module logs"
       
   342         assert step.findtext("./command") == "fetch-log"
       
   343         params = step.findall("./params/param")
       
   344         assert params[0].get("type") == "text"
       
   345         assert params[1].get("delete") == "true"
       
   346         if step.get("harness") == "STIF":
       
   347             assert params[2].get("path") == path(r"c:" + os.sep + "logs" + os.sep + "testframework" + os.sep + "*")
       
   348         elif step.get("harness") == "EUNIT":
       
   349             assert params[2].get("path") == path(r"c:" + os.sep + "Shared" + os.sep + "EUnit" + os.sep + "logs" + os.sep + "*")
       
   350     else:
       
   351         step = steps.next()
       
   352         assert step.get("name") == "Fetch test module logs"
       
   353         assert step.findtext("./command") == "fetch-log"
       
   354         params = step.findall("./params/param")
       
   355         assert params[0].get("type") == "text"
       
   356         assert params[1].get("delete") == "true"
       
   357         assert params[2].get("path") == path(r"c:" + os.sep + "logs" + os.sep + "testframework" + os.sep + "*")  
       
   358 
       
   359 def check_diamonds_action(action):
       
   360     """ Testing Diamonds action. """
       
   361     assert action.findtext("./type") == "DiamondsAction"
       
   362     assert not action.findall("./params/param") 
       
   363 
       
   364 def check_send_email_action(action, reportemail):
       
   365     """verifies if sening email option works"""
       
   366     assert action.findtext("./type") == "SendEmailAction"
       
   367     params = action.findall("./params/param")
       
   368     assert params[0].get("name") == "subject"
       
   369     assert params[0].get("value") == "email subject"
       
   370     assert params[1].get("name") == "type"
       
   371     assert params[1].get("value") == "ATS3_REPORT"
       
   372     assert params[2].get("name") == "send-files"
       
   373     assert params[2].get("value") == "true"
       
   374     assert params[3].get("name") == "to"
       
   375     assert params[3].get("value") == reportemail
       
   376     
       
   377 def check_ctc_run_process_action(action):
       
   378     """verifies if CTC run process action works"""
       
   379     #The parameters for this test are intended to execute on a windows machine
       
   380     assert action.findtext("./type") == "RunProcessAction"
       
   381     params = action.findall("./params/param")
       
   382     assert params[0].get("name") == "file"
       
   383     assert params[0].get("value") == "catsctc2html/catsctc2html.exe"
       
   384     assert params[1].get("name") == "parameters"
       
   385     assert params[1].get("value") == r"--ctcdata_files=\\10.0.0.1\ctc_helium\1234\drop0\set0\ctcdata --monsym_files=\\10.0.0.1\ctc_helium\1234\mon_syms\1\MON.sym --diamonds_build_id=1234 --drop_id=0 --total_amount_of_drops=1"
       
   386 
       
   387 def check_ats_report_action(action, filestore):
       
   388     """verifies if sening ATS report option works"""
       
   389     assert action.findtext("./type") == "FileStoreAction"
       
   390     params = action.findall("./params/param")
       
   391     assert params[0].get("name") == "to-folder"
       
   392     assert params[0].get("value") == filestore
       
   393     assert params[1].get("name") == "report-type"
       
   394     assert params[1].get("value") == "ATS_REPORT"
       
   395     assert params[2].get("name") == "date-format"
       
   396     assert params[2].get("value") == "yyyyMMdd"
       
   397     assert params[3].get("name") == "time-format"
       
   398     assert params[3].get("value") == "HHmmss"
       
   399 
       
   400 def check_stif_report_action(action, filestore):
       
   401     """verifies if sening STIF report option works"""
       
   402     assert action.findtext("./type") == "FileStoreAction"
       
   403     params = action.findall("./params/param")
       
   404     assert params[0].get("name") == "to-folder"
       
   405     assert params[0].get("value") == filestore
       
   406     assert params[1].get("name") == "report-type"
       
   407     assert params[1].get("value") == "STIF_COMPONENT_REPORT_ALL_CASES"
       
   408     assert params[2].get("name") == "run-log"
       
   409     assert params[2].get("value") == "true"
       
   410     assert params[3].get("name") == "date-format"
       
   411     assert params[3].get("value") == "yyyyMMdd"
       
   412     assert params[4].get("name") == "time-format"
       
   413     assert params[4].get("value") == "HHmmss"
       
   414 
       
   415 def check_log_dir(steps):
       
   416     """ Test the log dir. """
       
   417     step = steps.next()
       
   418     if step.get("harness") is "STIF":
       
   419         assert step.get("name") == "Create STIF log dir"
       
   420     elif step.get("harness") is "EUNIT":
       
   421         assert step.get("name") == "Create EUNIT log dir"
       
   422     assert step.findtext("./command") == "makedir"
       
   423 
       
   424 def check_trace_start(steps, filestore):
       
   425     """Checks if tracing is started on the ATS"""
       
   426     step = steps.next()
       
   427     assert step.get("name") == "Start tracing"
       
   428     assert step.findtext("./command") == "trace-start"
       
   429     params = step.findall("./params/param")
       
   430     assert params[0].get("ta") == path(r"ATS3Drop" + os.sep + "set0" + os.sep + "trace_activation" + os.sep + "trace_activation_1.xml")
       
   431     assert params[1].get("tgrp") == "MCU"
       
   432     assert params[2].get("pmd") == path(r"ATS3Drop" + os.sep + "pmds" + os.sep + "pmd_file.pmd")
       
   433     assert params[3].get("log") == filestore.joinpath("traces", "set0", "tracelog.blx")
       
   434     assert params[4].get("timeout") == "60"
       
   435     assert params[5].get("date-format") == "yyyyMMdd"
       
   436     assert params[6].get("time-format") == "HHmmss"
       
   437     
       
   438 def check_trace_end_steps(steps, filestore):
       
   439     """ Test trace end step. """
       
   440     step = steps.next()
       
   441     assert step.get("name") == "Stop tracing"
       
   442     assert step.findtext("./command") == "trace-stop"
       
   443     params = step.findall("./params/param")
       
   444     assert params[0].get("timeout") == "60"
       
   445     step = steps.next()
       
   446     assert step.get("name") == "Convert tracing"
       
   447     assert step.findtext("./command") == "trace-convert"
       
   448     params = step.findall("./params/param")
       
   449     assert params[0].get("pmd") == path(r"ATS3Drop" + os.sep + "pmds" + os.sep + "pmd_file.pmd")
       
   450     assert params[1].get("log") == filestore.joinpath("traces", "set0", "tracelog.blx")
       
   451     assert params[2].get("timeout") == "60"
       
   452     assert params[3].get("date-format") == "yyyyMMdd"
       
   453     assert params[4].get("time-format") == "HHmmss"
       
   454 
       
   455 class TestTestPlan(mocker.MockerTestCase):
       
   456     """Creates TestPlan mocker setup"""
       
   457     def __init__(self, methodName="runTest"):
       
   458         mocker.MockerTestCase.__init__(self, methodName)  
       
   459           
       
   460     def setUp(self):
       
   461         """ Setup TestTestPlan testsuite. """
       
   462         opts = Bunch(testrun_name="testrun", harness="STIF", 
       
   463                      device_type="product", plan_name="ats3_test_plan",
       
   464                      diamonds_build_url="", report_email="", file_store=path(), test_timeout="60",
       
   465                      device_hwid="5425", trace_enabled="True", ctc_enabled="True", eunitexerunner_flags="/E S60AppEnv /R Off", 
       
   466                      multiset_enabled=False, ctc_run_process_params=r"10.0.0.1#drop0.zip#1", monsym_files="")
       
   467         self.atp = ats3.Ats3TestPlan(opts)
       
   468         self.config_files = TEST_FILES["conf"]
       
   469         self.data_files = TEST_FILES["data"]
       
   470         self.engine_ini_file = TEST_FILES["init"][0]
       
   471         self.image_files = TEST_FILES["output"]
       
   472         self.sis_files = TEST_FILES["sis"]
       
   473         self.testmodule_files = TEST_FILES["testmodules"]
       
   474         self.ctc_enabled = self.atp["ctc_enabled"]
       
   475         self.custom_dir = "CustomD"
       
   476         self.eunitexerunner_flags = self.atp["eunitexerunner_flags"]
       
   477         if self.atp["trace_enabled"].lower() == "true":
       
   478             self.trace_activation_files = TEST_FILES["trace_init"]    
       
   479             self.pmd_files = TEST_FILES["pmd_file"]
       
   480         else:
       
   481             self.trace_activation_files = []    
       
   482             self.pmd_files = []
       
   483         self.test_timeout = self.atp["test_timeout"]
       
   484         self.eunitexerunner_flags = self.atp["eunitexerunner_flags"]
       
   485         self.device_hwid = self.atp["device_hwid"]
       
   486         self.test_harness = self.atp["harness"]
       
   487         self.src_dst = [("" + os.sep + "tsrc" + os.sep + "testmodules" + os.sep + "file1.dll", "c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.dll", "testmodule"),
       
   488             ("" + os.sep + "tsrc" + os.sep + "testmodules" + os.sep + "file2.dll", "c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.dll", "testmodule"),
       
   489             ("" + os.sep + "tsrc" + os.sep + "data" + os.sep + "file1", "e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1", "data"),
       
   490             ("" + os.sep + "tsrc" + os.sep + "data" + os.sep + "file2", "e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2", "data"),
       
   491             ("" + os.sep + "tsrc" + os.sep + "data" + os.sep + "file3", "e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file3", "data"),
       
   492             ("" + os.sep + "tsrc" + os.sep + "conf" + os.sep + "file1.cfg", "c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.cfg", "conf"),
       
   493             ("" + os.sep + "tsrc" + os.sep + "conf" + os.sep + "file2.cfg", "c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.cfg", "conf"),
       
   494             ("" + os.sep + "tsrc" + os.sep + "init" + os.sep + "TestFramework.ini", "c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "TestFramework.ini", "engine_ini"),
       
   495             ("" + os.sep + "tsrc" + os.sep + "sis" + os.sep + "file1.sisx", "c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.sisx", ""),
       
   496             ("" + os.sep + "tsrc" + os.sep + "sis" + os.sep + "file2.sisx", "c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.sisx", ""),]
       
   497         self.component_path = str(TEST_PATH.joinpath("tsrc", "group"))
       
   498 
       
   499     def test_creation(self):
       
   500         """ Testing creation. """        
       
   501         assert self.atp["testrun_name"] == "testrun"
       
   502         assert self.atp["harness"] == "STIF"
       
   503         assert self.atp["device_type"] == "product"
       
   504     
       
   505     def test_insert_set(self):
       
   506         """ Inserting a set of file. """        
       
   507         self.atp.insert_set(data_files=self.data_files,
       
   508                            config_files=self.config_files,
       
   509                            engine_ini_file=self.engine_ini_file,
       
   510                            image_files=self.image_files,
       
   511                            testmodule_files=self.testmodule_files,
       
   512                            test_timeout=self.test_timeout,
       
   513                            eunitexerunner_flags=self.eunitexerunner_flags,
       
   514                            pmd_files=self.pmd_files,                            
       
   515                            trace_activation_files=self.trace_activation_files,
       
   516                            component_path=self.component_path)
       
   517         self.atp.insert_set(image_files=self.image_files,                           
       
   518                            engine_ini_file=self.engine_ini_file,
       
   519                            sis_files=self.sis_files,
       
   520                            test_timeout=self.test_timeout,
       
   521                            eunitexerunner_flags=self.eunitexerunner_flags,
       
   522                            pmd_files=self.pmd_files,                            
       
   523                            trace_activation_files=self.trace_activation_files,
       
   524                            component_path=self.component_path)
       
   525         self.atp.insert_set(data_files=self.data_files,
       
   526                            config_files=self.config_files,
       
   527                            engine_ini_file=self.engine_ini_file,
       
   528                            image_files=self.image_files,
       
   529                            testmodule_files=self.testmodule_files,
       
   530                            test_timeout=self.test_timeout,
       
   531                            eunitexerunner_flags=self.eunitexerunner_flags,
       
   532                            src_dst=self.src_dst,
       
   533                            pmd_files=self.pmd_files,                            
       
   534                            trace_activation_files=self.trace_activation_files,
       
   535                            component_path=self.component_path)
       
   536         self.atp.insert_set(engine_ini_file=self.engine_ini_file,
       
   537                            test_timeout=self.test_timeout,
       
   538                            eunitexerunner_flags=self.eunitexerunner_flags,
       
   539                            image_files=self.image_files,
       
   540                            test_harness=self.test_harness,
       
   541                            src_dst=self.src_dst,
       
   542                            pmd_files=self.pmd_files,                            
       
   543                            trace_activation_files=self.trace_activation_files,
       
   544                            component_path=self.component_path)
       
   545         self.atp.insert_set(test_timeout=self.test_timeout,      
       
   546                            eunitexerunner_flags=self.eunitexerunner_flags,               
       
   547                            image_files=self.image_files,                        
       
   548                            test_harness=self.test_harness,                      
       
   549                            src_dst=self.src_dst,                                
       
   550                            pmd_files=self.pmd_files,                            
       
   551                            trace_activation_files=self.trace_activation_files,
       
   552                            component_path=self.component_path)  
       
   553 
       
   554         assert self.atp.sets[0] == dict(name="set0",
       
   555                                        data_files=self.data_files,
       
   556                                        config_files=self.config_files,
       
   557                                        engine_ini_file=self.engine_ini_file,
       
   558                                        image_files=self.image_files,
       
   559                                        testmodule_files=self.testmodule_files,
       
   560                                        test_timeout=self.test_timeout,
       
   561                                        eunitexerunner_flags=self.eunitexerunner_flags,
       
   562                                        test_harness=self.test_harness,
       
   563                                        src_dst=[],
       
   564                                        pmd_files=self.pmd_files,
       
   565                                        trace_path=self.atp.file_store.joinpath(u"§RUN_NAME§" + os.sep + u"§RUN_START_DATE§_§RUN_START_TIME§", "traces", "set0", "tracelog.blx"),
       
   566                                        trace_activation_files=self.trace_activation_files,
       
   567                                        ctc_enabled=self.atp["ctc_enabled"],
       
   568                                        custom_dir=None,
       
   569                                        component_path=self.component_path)
       
   570         assert self.atp.sets[1] == dict(name="set1",
       
   571                                        image_files=self.image_files,
       
   572                                        engine_ini_file=self.engine_ini_file,
       
   573                                        sis_files=self.sis_files,
       
   574                                        test_timeout=self.test_timeout,
       
   575                                        eunitexerunner_flags=self.eunitexerunner_flags,
       
   576                                        test_harness=self.test_harness,
       
   577                                        pmd_files=self.pmd_files,
       
   578                                        trace_path=self.atp.file_store.joinpath(u"§RUN_NAME§" + os.sep + u"§RUN_START_DATE§_§RUN_START_TIME§", "traces", "set1", "tracelog.blx"),
       
   579                                        trace_activation_files=self.trace_activation_files,
       
   580                                        ctc_enabled=self.atp["ctc_enabled"],
       
   581                                        custom_dir=None,
       
   582                                        component_path=self.component_path)
       
   583 
       
   584         assert self.atp.sets[2] == dict(name="set2",
       
   585                                        data_files=self.data_files,
       
   586                                        config_files=self.config_files,
       
   587                                        engine_ini_file=self.engine_ini_file,
       
   588                                        image_files=self.image_files,
       
   589                                        testmodule_files=self.testmodule_files,
       
   590                                        test_timeout=self.test_timeout,
       
   591                                        eunitexerunner_flags=self.eunitexerunner_flags,
       
   592                                        test_harness=self.test_harness,
       
   593                                        src_dst=self.src_dst,
       
   594                                        pmd_files=self.pmd_files,
       
   595                                        trace_path=self.atp.file_store.joinpath(u"§RUN_NAME§" + os.sep + u"§RUN_START_DATE§_§RUN_START_TIME§", "traces", "set2", "tracelog.blx"),
       
   596                                        trace_activation_files=self.trace_activation_files,
       
   597                                        ctc_enabled=self.atp["ctc_enabled"],
       
   598                                        custom_dir=None,
       
   599                                        component_path=self.component_path)
       
   600         assert self.atp.sets[3] == dict(name="set3",
       
   601                                        data_files=[],
       
   602                                        config_files=[],
       
   603                                        engine_ini_file=self.engine_ini_file,
       
   604                                        image_files=self.image_files,
       
   605                                        testmodule_files=[],
       
   606                                        test_timeout=self.test_timeout,
       
   607                                        eunitexerunner_flags=self.eunitexerunner_flags,
       
   608                                        test_harness=self.test_harness,
       
   609                                        src_dst=self.src_dst,
       
   610                                        pmd_files=self.pmd_files,
       
   611                                        trace_path=self.atp.file_store.joinpath(u"§RUN_NAME§" + os.sep + u"§RUN_START_DATE§_§RUN_START_TIME§", "traces", "set3", "tracelog.blx"),
       
   612                                        trace_activation_files=self.trace_activation_files,
       
   613                                        ctc_enabled=self.atp["ctc_enabled"],
       
   614                                        custom_dir=None,
       
   615                                        component_path=self.component_path)
       
   616 
       
   617         assert self.atp.sets[4] == dict(name="set4",
       
   618                                        data_files=[],
       
   619                                        config_files=[],
       
   620                                        engine_ini_file=None,
       
   621                                        image_files=self.image_files,
       
   622                                        testmodule_files=[],
       
   623                                        test_timeout=self.test_timeout,
       
   624                                        eunitexerunner_flags=self.eunitexerunner_flags,
       
   625                                        test_harness=self.test_harness,
       
   626                                        src_dst=self.src_dst,
       
   627                                        pmd_files=self.pmd_files,
       
   628                                        trace_path=self.atp.file_store.joinpath(u"§RUN_NAME§" + os.sep + u"§RUN_START_DATE§_§RUN_START_TIME§", "traces", "set4", "tracelog.blx"),
       
   629                                        trace_activation_files=self.trace_activation_files,
       
   630                                        ctc_enabled=self.atp["ctc_enabled"],
       
   631                                        custom_dir=None,
       
   632                                        component_path=self.component_path)
       
   633         
       
   634     def test_post_actions_email(self):
       
   635         """ Testing the send email post-action. """        
       
   636         assert not self.atp.post_actions
       
   637         receiver = "joe.average@example.com"
       
   638         self.atp.report_email = receiver
       
   639         assert len(self.atp.post_actions) == 1
       
   640         action, items = self.atp.post_actions[0]
       
   641         items = dict(items)
       
   642         assert action == "SendEmailAction"
       
   643         assert items["to"] == receiver
       
   644     
       
   645     def test_post_actions_ats3_report_only(self):
       
   646         """ Testing the ats3 report only post-action. """        
       
   647         file_store = path("path/to/files")
       
   648         self.atp.file_store = file_store
       
   649         self.atp.harness = "EUNIT"
       
   650         assert len(self.atp.post_actions) == 2
       
   651         action, items = self.atp.post_actions[0]
       
   652         items = dict(items)
       
   653         assert action == "FileStoreAction"
       
   654         assert items["report-type"] == "ATS3_REPORT"
       
   655         assert items["to-folder"].startswith(file_store)
       
   656         assert items["to-folder"].endswith("ATS3_REPORT")
       
   657     
       
   658     def test_post_actions_stif(self):
       
   659         """ Testing STIF post-actions. """        
       
   660         file_store = path("path/to/files")
       
   661         self.atp.file_store = file_store
       
   662         assert len(self.atp.post_actions) == 2
       
   663         action, items = self.atp.post_actions[1]
       
   664         items = dict(items)
       
   665         assert action == "FileStoreAction"
       
   666         assert items["report-type"] == "STIF_COMPONENT_REPORT_ALL_CASES"
       
   667         assert items["to-folder"].startswith(file_store)
       
   668         assert items["to-folder"].endswith("STIF_REPORT")
       
   669         
       
   670     def test_post_actions_diamonds(self):
       
   671         """ Testing Diamonds post-actions. """        
       
   672         self.atp.diamonds_build_url = "http://diamonds.nmp.company.com/diamonds/builds/1234"
       
   673         assert len(self.atp.post_actions) == 1
       
   674         action, items = self.atp.post_actions[0]
       
   675         assert action == "DiamondsAction"
       
   676         assert not items
       
   677 
       
   678 
       
   679 class TestComponentParser(mocker.MockerTestCase):
       
   680     """ Testing the Ats3ComponentParser component parser. """
       
   681     
       
   682     def __init__(self, methodName="runTest"):
       
   683         mocker.MockerTestCase.__init__(self, methodName)
       
   684     
       
   685     def assert_paths(self, path1, path2):
       
   686         """ Checking the path. Validates that path1 and path2 are instance of path and they are equals. """
       
   687         if not isinstance(path1, path):
       
   688             path1 = path(path1)
       
   689         if not isinstance(path2, path):
       
   690             path2 = path(path2)            
       
   691         return self.assertEqual(path1.normpath(), path2.normpath())
       
   692     
       
   693     def setUp(self):
       
   694         """ Setting up TestComponentParser testsuite."""
       
   695         opts = Bunch(build_drive=path(TEST_PATH+os.sep), target_platform="target platform", eunitexerunner_flags="/E S60AppEnv /R Off",
       
   696                      data_dir=["data"], flash_images=[], sis_files=[], test_timeout="60", harness="STIF", trace_enabled="True")
       
   697         self.acp = atc.Ats3ComponentParser(opts)
       
   698         self.acp.tsrc_dir = TSRC
       
   699       
       
   700     def test_detect_dlls(self):
       
   701         """ Testing dlls detection. """
       
   702         # Setup mock objects.
       
   703         logging.getLogger().setLevel(logging.DEBUG)
       
   704         process = self.mocker.mock()
       
   705         process.communicate()
       
   706         self.mocker.result(["lib1.dll\npath/to/another/library.dll\nsome/other/file.txt\nlib2.dll\nlib3.dll\n"])
       
   707         obj = self.mocker.replace("subprocess.Popen")
       
   708         obj("abld -w test build target platform", shell=True, stdout=subprocess.PIPE)
       
   709         self.mocker.result(process)
       
   710         
       
   711         exists = self.mocker.replace("os.path.exists")
       
   712         exists()
       
   713         self.mocker.result(True)
       
   714         exists()
       
   715         self.mocker.result(True)
       
   716         exists()
       
   717         self.mocker.result(True)
       
   718         exists()
       
   719         self.mocker.result(False)
       
   720         
       
   721         self.mocker.replay()
       
   722         
       
   723         self.assertEqual([u"lib1.dll", u"library.dll", u"lib2.dll"],
       
   724                          [dll.name for dll in self.acp.tsrc_dll_files()])
       
   725         logging.getLogger().setLevel(logging.ERROR)
       
   726 
       
   727     def test_harness(self):
       
   728         """ Detect test harness."""
       
   729         mmp_parser = parser.MmpFileParser()
       
   730         group = TSRC.joinpath("group")
       
   731         for harness, mmp in [
       
   732             ("STIF", group / "stif.mmp"),
       
   733             ("EUNIT", group / "eunit.mmp"),
       
   734             ("STIF", group / "both.mmp"),
       
   735             ]:
       
   736             self.assertEqual(harness, mmp_parser.get_harness(mmp))
       
   737 
       
   738 class TestXMLGeneration(mocker.MockerTestCase):
       
   739     """
       
   740     Unit tests for the test.xml generation.
       
   741     """
       
   742     def __init__(self, methodName="runTest"):
       
   743         mocker.MockerTestCase.__init__(self, methodName)
       
   744         self.data_files = None
       
   745         self.config_files = None
       
   746         self.testmodule_files = None
       
   747         self.image_files = None
       
   748         self.engine_ini_file = None
       
   749         self.report_email = None
       
   750         self.file_store = None
       
   751         self.diamonds_build_url = None
       
   752         self.test_harness = None     
       
   753         self.src_dst = []
       
   754         self.trace_enabled = None
       
   755         self.pmd_files = None
       
   756         self.trace_activation_files = None
       
   757         self.ctc_enabled = None
       
   758         self.eunitexerunner_flags = None
       
   759         self.test_plan = None
       
   760         self.gen = None
       
   761         self.custom_dir = None
       
   762             
       
   763     def generate_xml(self, trace_enabled="False"):
       
   764         """ Generating the XML. """
       
   765         def files(*paths):
       
   766             """creating tsrc path list"""
       
   767             return [TEST_PATH.joinpath("tsrc", tpath) for tpath in paths]
       
   768         self.testmodule_files = files("testmodules/file1.dll", "testmodules/file2.dll")
       
   769         self.data_files = files("data/file1", "data/file2", "data/file3")
       
   770         self.config_files = files("conf/file1.cfg", "conf/file2.cfg")
       
   771         self.image_files = files("output/images/file1.fpsx", "output/images/file2.fpsx")
       
   772         self.engine_ini_file = files("init/TestFramework.ini")[0]
       
   773         self.report_email = "test.receiver@company.com"
       
   774         self.file_store = path(r"path/to/reports")
       
   775         self.diamonds_build_url = "http://diamonds.nmp.company.com/diamonds/builds/1234"
       
   776         self.test_harness = "STIF"        
       
   777         self.src_dst = []
       
   778         self.trace_enabled = trace_enabled
       
   779         self.pmd_files = TEST_FILES["pmd_file"]
       
   780         self.trace_activation_files = files("trace_init/trace_activation_1.xml")
       
   781         self.ctc_enabled = "True"
       
   782         self.eunitexerunner_flags = "/E S60AppEnv /R Off"
       
   783         self.custom_dir = "CustomB"
       
   784         self.component_path = str(TEST_PATH.joinpath("tsrc", "group"))
       
   785         self.ctc_run_process_params = r"10.0.0.1#x:\ats\drop0.zip#1"
       
   786         
       
   787         self.ctc_network = self.ctc_run_process_params.rsplit("#", 2)[0]
       
   788         self.drop_id = re.findall(".*drop(\d*).zip.*", self.ctc_run_process_params.lower())[0] #extracting int part of drop name
       
   789         self.drop_count = self.ctc_run_process_params.rsplit("#", 1)[1]
       
   790         self.diamonds_id = self.diamonds_build_url.rsplit(r"/", 1)[1]
       
   791 
       
   792         self.mocker.restore()
       
   793         test_plan = self.mocker.mock(count=False)
       
   794         mocker.expect(test_plan["testrun_name"]).result("test")
       
   795         mocker.expect(test_plan["harness"]).result("STIF")
       
   796         mocker.expect(test_plan["device_type"]).result("product")
       
   797         mocker.expect(test_plan["plan_name"]).result("test plan")
       
   798         mocker.expect(test_plan["diamonds_build_url"]).result(self.diamonds_build_url)
       
   799         mocker.expect(test_plan["test_timeout"]).result("60")
       
   800         mocker.expect(test_plan["eunitexerunner_flags"]).result("/E S60AppEnv /R Off")
       
   801         mocker.expect(test_plan["device_hwid"]).result("5425")
       
   802         mocker.expect(test_plan["custom_dir"]).result("custom")
       
   803         mocker.expect(test_plan.custom_dir).result(path(r"self.custom_dir"))
       
   804         
       
   805         mocker.expect(test_plan["ctc_run_process_params"]).result(self.ctc_run_process_params)
       
   806                 
       
   807         if self.trace_enabled.lower() == "true":
       
   808             mocker.expect(test_plan["trace_enabled"]).result("True")
       
   809         else:
       
   810             mocker.expect(test_plan["trace_enabled"]).result("False")
       
   811         if self.trace_enabled == "False":
       
   812             mocker.expect(test_plan.sets).result([
       
   813                 dict(name="set0", image_files=self.image_files, data_files=self.data_files,
       
   814                      config_files=self.config_files, testmodule_files=self.testmodule_files,
       
   815                      engine_ini_file=self.engine_ini_file, test_harness="STIF", src_dst=self.src_dst,
       
   816                      ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags,
       
   817                      custom_dir=self.custom_dir, component_path=self.component_path),
       
   818                 dict(name="set1", image_files=self.image_files, data_files=self.data_files,
       
   819                      config_files=self.config_files, testmodule_files=self.testmodule_files,
       
   820                      engine_ini_file=self.engine_ini_file,test_harness="STIF", src_dst=self.src_dst,
       
   821                      ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags,
       
   822                      custom_dir=self.custom_dir, component_path=self.component_path),
       
   823             ])
       
   824         elif self.trace_enabled == "True":
       
   825             mocker.expect(test_plan.sets).result([
       
   826                 dict(name="set0", image_files=self.image_files, data_files=self.data_files,
       
   827                      config_files=self.config_files, testmodule_files=self.testmodule_files,
       
   828                      engine_ini_file=self.engine_ini_file, test_harness="STIF", src_dst=self.src_dst,
       
   829                      pmd_files=self.pmd_files, trace_activation_files=self.trace_activation_files,
       
   830                      trace_path=self.file_store.joinpath("traces", "set0", "tracelog.blx"),
       
   831                      ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags, component_path=self.component_path),
       
   832                 dict(name="set1", image_files=self.image_files, data_files=self.data_files,
       
   833                      config_files=self.config_files, testmodule_files=self.testmodule_files,
       
   834                      engine_ini_file=self.engine_ini_file,test_harness="STIF", src_dst=self.src_dst,
       
   835                      pmd_files=self.pmd_files, trace_activation_files=self.trace_activation_files,
       
   836                      trace_path=self.file_store.joinpath("traces", "set1", "tracelog.blx"),
       
   837                      ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags, component_path=self.component_path),
       
   838             ])
       
   839 
       
   840         ctc_file_name = "catsctc2html/catsctc2html.exe"
       
   841         ctc_data_path = str(os.path.normpath(r"\\%s\ctc_helium\%s\drop0\set0\ctcdata" % (self.ctc_network, self.diamonds_id)))
       
   842         mon_files = str(os.path.normpath(r"\\%s\ctc_helium\%s\mon_syms\1\MON.sym" % (self.ctc_network, self.diamonds_id)))
       
   843         self.ctc_test_data = [ctc_file_name, self.ctc_network, self.drop_id, self.drop_count, self.diamonds_id, ctc_data_path, mon_files] 
       
   844         
       
   845         mocker.expect(test_plan.post_actions).result([
       
   846             ("RunProcessAction", (("file", ctc_file_name ),
       
   847                                   ("parameters", r"--ctcdata_files=" + ctc_data_path + " --monsym_files=" + mon_files + " --diamonds_build_id=" + self.diamonds_id + " --drop_id=" + self.drop_id + " --total_amount_of_drops=" + self.drop_count ))),
       
   848             ("SendEmailAction", (("subject", "email subject"),
       
   849                                  ("type", "ATS3_REPORT"),
       
   850                                  ("send-files", "true"),
       
   851                                  ("to", self.report_email))),
       
   852             ("FileStoreAction", (("to-folder", self.file_store),
       
   853                                  ("report-type", "ATS_REPORT"),
       
   854                                  ("date-format", "yyyyMMdd"),
       
   855                                  ("time-format", "HHmmss"))),
       
   856             ("FileStoreAction", (("to-folder", self.file_store),
       
   857                                  ("report-type", "STIF_COMPONENT_REPORT_ALL_CASES"),
       
   858                                  ("run-log", "true"),
       
   859                                  ("date-format", "yyyyMMdd"),
       
   860                                  ("time-format", "HHmmss"))),
       
   861             ("DiamondsAction", ())
       
   862         ])
       
   863         
       
   864         self.mocker.replay()
       
   865         self.test_plan = test_plan
       
   866         
       
   867         self.gen = adg.Ats3TestDropGenerator()
       
   868         return self.gen.generate_xml(test_plan)
       
   869 
       
   870     def test_basic_structure(self):
       
   871         """ Check that the overall test.xml structure is valid. """
       
   872         xml = self.generate_xml()
       
   873         # Check basics.
       
   874         assert xml.find(".").tag == "test"
       
   875         assert xml.find("./name").text == "test"
       
   876         assert xml.find("./buildid").text == self.diamonds_build_url
       
   877         assert xml.find("./target").tag
       
   878         assert xml.find("./target/device").tag
       
   879         harness, type_, device_hwid = xml.findall("./target/device/property")
       
   880         assert harness.get("value") == "STIF"
       
   881         assert type_.get("value") == "product"
       
   882         assert device_hwid.get("value") == "5425"
       
   883         
       
   884         # Check generation of the test plan.
       
   885         assert xml.find("./plan").get("name") == "test Plan"
       
   886         assert xml.find("./plan/session").tag 
       
   887         sets = xml.findall("./plan/session/set")
       
   888         assert len(sets) == 2
       
   889         assert sets[0].get("name") == "set0-"+str(TEST_PATH.joinpath("tsrc", "group"))
       
   890         assert sets[0].find("./target/device").tag
       
   891     
       
   892     def test_set_structure(self):
       
   893         """ Check that a <set> element's structure is valid. """
       
   894         xml = self.generate_xml()
       
   895         tstset = xml.find("./plan/session/set")
       
   896         assert tstset.tag
       
   897         case = tstset.find("./case")
       
   898         assert case.tag
       
   899         assert case.get("name") == "set0 case"
       
   900         
       
   901     def test_case_flash_elems(self):
       
   902         """ Test case flash elems. """
       
   903         xml = self.generate_xml()
       
   904         case = xml.find("./plan/session/set/case")
       
   905         flashes = case.findall("./flash")
       
   906         assert len(flashes) == len(self.image_files)
       
   907         for i, flash_file in enumerate(self.image_files):
       
   908             assert flashes[i].get("target-alias") == "DEFAULT_STIF"
       
   909             assert flashes[i].get("images") == path(r"ATS3Drop" + os.sep + "images") / flash_file.name
       
   910         
       
   911     def test_case_steps(self):
       
   912         """ Test case steps. """
       
   913         xml = self.generate_xml()
       
   914         steps = iter(xml.findall("./plan/session/set/case/step"))
       
   915         check_ctc_start(steps)
       
   916         check_log_dir(steps)
       
   917         self.check_install_data(steps)
       
   918         self.check_install_configuration(steps)
       
   919         self.check_install_tmodules(steps)
       
   920         self.check_install_engine_ini(steps)
       
   921         self.check_run_cases(steps)
       
   922         check_ctc_write(steps)
       
   923         check_ctc_log(steps)
       
   924         check_fetch_logs(steps)
       
   925 
       
   926     def check_install_data(self, steps):
       
   927         """ Test install data. """
       
   928         for filename in self.data_files:
       
   929             step = steps.next()
       
   930             assert step.get("name") == "Install data: %s" % filename.name
       
   931             assert step.findtext("./command") == "install"
       
   932             params = step.findall("./params/param")            
       
   933             src = params[0].get("src")
       
   934             assert src.name == filename.name
       
   935             assert src.parent == path(r"ATS3Drop" + os.sep + "set0" + os.sep + "data")            
       
   936             dst = params[1].get("dst")
       
   937             assert dst.name == filename.name
       
   938             assert dst.parent == path(r"e:\testing\data")
       
   939     
       
   940     def check_install_configuration(self, steps):
       
   941         """ Test install configuration. """
       
   942         for filepath in self.config_files:
       
   943             step = steps.next()
       
   944             assert step.get("name") == "Install conf: %s" % filepath.name
       
   945             assert step.findtext("./command") == "install"
       
   946             params = step.findall("./params/param")
       
   947             assert params[0].get("src") == path(r"ATS3Drop" + os.sep + "set0" + os.sep + "conf") / filepath.name
       
   948             assert params[1].get("dst") == path(r"e:\testing\conf") / filepath.name
       
   949 
       
   950     def check_install_tmodules(self, steps):
       
   951         """ Test install tmodules. """
       
   952         for filepath in self.testmodule_files:
       
   953             step = steps.next()
       
   954             assert step.get("name") == "Install testmodule: %s" % filepath.name
       
   955             assert step.findtext("./command") == "install"
       
   956             params = step.findall("./params/param")
       
   957             assert params[0].get("src") == path(r"ATS3Drop" + os.sep + "set0" + os.sep + "testmodules") / filepath.name
       
   958             assert params[1].get("dst") == path(r"c:\sys\bin") / filepath.name            
       
   959     
       
   960     def check_install_engine_ini(self, steps):
       
   961         """ Test install engine ini. """
       
   962         filepath = self.engine_ini_file
       
   963         step = steps.next()
       
   964         assert step.get("name") == "Install engine_ini: %s" % filepath.name
       
   965         assert step.findtext("./command") == "install"
       
   966         params = step.findall("./params/param")
       
   967         assert params[0].get("src") == path(r"ATS3Drop" + os.sep + "set0" + os.sep + "init") / filepath.name
       
   968         assert params[1].get("dst") == path(r"c:" + os.sep + "testframework") / filepath.name
       
   969     
       
   970     def check_run_cases(self, steps):
       
   971         """ Test run cases. """
       
   972         step = steps.next()
       
   973         filepath = self.engine_ini_file
       
   974         assert step.get("name") == "Execute test: %s" % filepath.name
       
   975         assert step.findtext("./command") == "run-cases"
       
   976         params = step.findall("./params/param")
       
   977         assert params[0].get("filter") == "*"
       
   978         assert params[1].get("timeout") == "60"
       
   979         assert params[2].get("engineini") == path(r"c:" + os.sep + "testframework") / self.engine_ini_file.name
       
   980 
       
   981     def test_steps_trace_enabled(self):
       
   982         """ Test steps trace enabled. """
       
   983         xml = self.generate_xml(trace_enabled="True")
       
   984         steps = iter(xml.findall("./plan/session/set/case/step"))
       
   985         check_ctc_start(steps)
       
   986         check_log_dir(steps)
       
   987         self.check_install_data(steps)
       
   988         self.check_install_configuration(steps)
       
   989         self.check_install_tmodules(steps)
       
   990         self.check_install_engine_ini(steps)
       
   991         check_trace_start(steps, self.file_store)
       
   992         self.check_run_cases(steps)
       
   993         check_trace_end_steps(steps, self.file_store)
       
   994         check_ctc_write(steps)
       
   995         check_ctc_log(steps)
       
   996         check_fetch_logs(steps) 
       
   997     
       
   998     def test_post_actions(self):
       
   999         """ Post actions are inserted into XML. """
       
  1000         xml = self.generate_xml()        
       
  1001         post_actions = xml.findall("./postAction")
       
  1002         check_ctc_run_process_action(post_actions[0])
       
  1003         check_send_email_action(post_actions[1], self.report_email)
       
  1004         check_ats_report_action(post_actions[2], self.file_store)
       
  1005         check_stif_report_action(post_actions[3], self.file_store)
       
  1006         check_diamonds_action(post_actions[4])
       
  1007     
       
  1008     def test_files(self):
       
  1009         """ Testing files. """
       
  1010         xml = self.generate_xml()
       
  1011         files = iter(xml.findall("./files/file"))
       
  1012         assert files.next().text == r"ATS3Drop" + os.sep + "images" + os.sep + "file1.fpsx"
       
  1013         assert files.next().text == r"ATS3Drop" + os.sep + "images" + os.sep + "file2.fpsx"
       
  1014         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file1"
       
  1015         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file2"
       
  1016         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file3"
       
  1017         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "conf" + os.sep + "file1.cfg"
       
  1018         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "conf" + os.sep + "file2.cfg"
       
  1019         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "testmodules" + os.sep + "file1.dll"
       
  1020         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "testmodules" + os.sep + "file2.dll"
       
  1021         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "init" + os.sep + "TestFramework.ini"        
       
  1022         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file1"
       
  1023         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file2"
       
  1024         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file3"
       
  1025         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "conf" + os.sep + "file1.cfg"
       
  1026         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "conf" + os.sep + "file2.cfg"
       
  1027         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "testmodules" + os.sep + "file1.dll"
       
  1028         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "testmodules" + os.sep + "file2.dll"
       
  1029         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "init" + os.sep + "TestFramework.ini"        
       
  1030         self.assertRaises(StopIteration, files.next)
       
  1031         xml = self.generate_xml(trace_enabled="True")
       
  1032         files = iter(xml.findall("./files/file"))
       
  1033         assert files.next().text == r"ATS3Drop" + os.sep + "images" + os.sep + "file1.fpsx"
       
  1034         assert files.next().text == r"ATS3Drop" + os.sep + "images" + os.sep + "file2.fpsx"
       
  1035         assert files.next().text == r"ATS3Drop" + os.sep + "pmds" + os.sep + "pmd_file.pmd"
       
  1036         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file1"
       
  1037         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file2"
       
  1038         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file3"
       
  1039         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "conf" + os.sep + "file1.cfg"
       
  1040         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "conf" + os.sep + "file2.cfg"
       
  1041         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "testmodules" + os.sep + "file1.dll"
       
  1042         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "testmodules" + os.sep + "file2.dll"
       
  1043         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "init" + os.sep + "TestFramework.ini"
       
  1044         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "trace_init" + os.sep + "trace_activation_1.xml"
       
  1045         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file1"
       
  1046         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file2"
       
  1047         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file3"
       
  1048         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "conf" + os.sep + "file1.cfg"
       
  1049         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "conf" + os.sep + "file2.cfg"
       
  1050         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "testmodules" + os.sep + "file1.dll"
       
  1051         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "testmodules" + os.sep + "file2.dll"
       
  1052         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "init" + os.sep + "TestFramework.ini"
       
  1053         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "trace_init" + os.sep + "trace_activation_1.xml"        
       
  1054         self.assertRaises(StopIteration, files.next)
       
  1055         
       
  1056     def test_generate_drop(self):
       
  1057         """ Manifest for ATS3Drop directory structure is generated. """
       
  1058         xml = self.generate_xml()
       
  1059         strbuffer = StringIO()
       
  1060         
       
  1061         self.gen.generate_drop(self.test_plan, xml, strbuffer)
       
  1062         zfile = zipfile.ZipFile(strbuffer, "r")
       
  1063         try:
       
  1064             contents = sorted(path(tpath).normpath() for tpath in zfile.namelist())
       
  1065             expected = sorted(path(tpath).normpath()
       
  1066                            for tpath in [r"ATS3Drop" + os.sep + "set0" + os.sep + "conf" + os.sep + "file1.cfg",
       
  1067                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "conf" + os.sep + "file2.cfg",
       
  1068                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file1",
       
  1069                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file2",
       
  1070                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file3",
       
  1071                                      r"ATS3Drop" + os.sep + "images" + os.sep + "file1.fpsx",
       
  1072                                      r"ATS3Drop" + os.sep + "images" + os.sep + "file2.fpsx",
       
  1073                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "init" + os.sep + "TestFramework.ini",
       
  1074                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "testmodules" + os.sep + "file1.dll",
       
  1075                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "testmodules" + os.sep + "file2.dll",
       
  1076                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "conf" + os.sep + "file1.cfg",
       
  1077                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "conf" + os.sep + "file2.cfg",
       
  1078                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file1",
       
  1079                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file2",
       
  1080                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file3",
       
  1081                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "init" + os.sep + "TestFramework.ini",
       
  1082                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "testmodules" + os.sep + "file1.dll",
       
  1083                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "testmodules" + os.sep + "file2.dll",
       
  1084                                      r"test.xml"])
       
  1085             diff = difflib.context_diff(expected, contents)
       
  1086             assert contents == expected, "\n".join(diff)
       
  1087         finally:
       
  1088             zfile.close()
       
  1089 
       
  1090     def test_generate_drop_trace (self):
       
  1091         "Manifest for ATS3Drop directory structure is generated when trace enabled."
       
  1092         xml = self.generate_xml(trace_enabled="True")
       
  1093         strbuffer = StringIO()
       
  1094         
       
  1095         self.gen.generate_drop(self.test_plan, xml, strbuffer)
       
  1096         zfile = zipfile.ZipFile(strbuffer, "r")
       
  1097         try:
       
  1098             contents = sorted(path(tpath).normpath() for tpath in zfile.namelist())
       
  1099             expected = sorted(path(tpath).normpath()
       
  1100                            for tpath in [r"ATS3Drop" + os.sep + "set0" + os.sep + "conf" + os.sep + "file1.cfg",
       
  1101                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "conf" + os.sep + "file2.cfg",
       
  1102                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file1",
       
  1103                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file2",
       
  1104                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file3",
       
  1105                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "trace_init" + os.sep + "trace_activation_1.xml",
       
  1106                                      r"ATS3Drop" + os.sep + "images" + os.sep + "file1.fpsx",
       
  1107                                      r"ATS3Drop" + os.sep + "images" + os.sep + "file2.fpsx",
       
  1108                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "init" + os.sep + "TestFramework.ini",
       
  1109                                      r"ATS3Drop" + os.sep + "pmds" + os.sep + "pmd_file.pmd",
       
  1110                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "testmodules" + os.sep + "file1.dll",
       
  1111                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "testmodules" + os.sep + "file2.dll",
       
  1112                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "conf" + os.sep + "file1.cfg",
       
  1113                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "conf" + os.sep + "file2.cfg",
       
  1114                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file1",
       
  1115                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file2",
       
  1116                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file3",
       
  1117                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "trace_init" + os.sep + "trace_activation_1.xml",
       
  1118                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "init" + os.sep + "TestFramework.ini",
       
  1119                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "testmodules" + os.sep + "file1.dll",
       
  1120                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "testmodules" + os.sep + "file2.dll",
       
  1121                                      r"test.xml"])
       
  1122             diff = difflib.context_diff(expected, contents)
       
  1123             assert contents == expected, "\n".join(diff)
       
  1124         finally:
       
  1125             zfile.close()
       
  1126 
       
  1127 
       
  1128 class TestXMLGenerationWithPKG(mocker.MockerTestCase):
       
  1129     """
       
  1130     Unit tests for the test.xml generation.
       
  1131     """
       
  1132     def __init__(self, methodName="runTest"):
       
  1133         mocker.MockerTestCase.__init__(self, methodName)
       
  1134         self.src_dst1 = []
       
  1135         self.data_files = None
       
  1136         self.config_files = None
       
  1137         self.testmodule_files = None
       
  1138         self.image_files = None
       
  1139         self.engine_ini_file = None
       
  1140         self.report_email = None
       
  1141         self.file_store = None
       
  1142         self.diamonds_build_url = None
       
  1143         self.trace_enabled = None
       
  1144         self.pmd_files = None
       
  1145         self.trace_activation_files = None
       
  1146         self.ctc_enabled = None
       
  1147         self.eunitexerunner_flags = None
       
  1148         self.test_plan = None
       
  1149         self.gen = None
       
  1150         self.src_dst0 = []
       
  1151         self.custom_dir = None
       
  1152         
       
  1153     def generate_xml(self, harness, trace_enabled="False"):
       
  1154         """Generates XML"""
       
  1155         def files(*paths):
       
  1156             """generates paths for the files"""
       
  1157             return [TEST_PATH.joinpath("tsrc", tpath) for tpath in paths]
       
  1158         self.src_dst1 = []
       
  1159         self.data_files = files("data/file1", "data/file2", "data/file3")
       
  1160         self.config_files = files("conf/file1.cfg", "conf/file2.cfg")
       
  1161         self.testmodule_files = files("testmodules/file1.dll", "testmodules/file2.dll")
       
  1162         self.image_files = files("output/images/file1.fpsx", "output/images/file2.fpsx")
       
  1163         self.engine_ini_file = files("init/TestFramework.ini")[0]
       
  1164         self.report_email = "test.receiver@company.com"
       
  1165         self.file_store = path("path/to/reports")
       
  1166         self.diamonds_build_url = "http://diamonds.nmp.company.com/diamonds/builds/1234"
       
  1167         self.trace_enabled = trace_enabled
       
  1168         self.pmd_files = TEST_FILES["pmd_file"]
       
  1169         self.trace_activation_files = files("trace_init/trace_activation_1.xml")
       
  1170         self.ctc_enabled = "True"
       
  1171         self.eunitexerunner_flags = "/E S60AppEnv /R Off"
       
  1172         self.custom_dir = "custom"
       
  1173         self.custom_files = files("custom/postpostaction.xml", "custom/prepostaction.xml")
       
  1174         self.component_path = str(TEST_PATH.joinpath("tsrc", "group"))
       
  1175         self.ctc_run_process_params = r"10.0.0.1#drop0.zip#1"
       
  1176         
       
  1177         
       
  1178         self.src_dst0 = [
       
  1179             (TEST_PATH.joinpath(r"tsrc" + os.sep + "testmodules" + os.sep + "file1.dll"), path(r"c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.dll"), "testmodule"),
       
  1180             (TEST_PATH.joinpath(r"tsrc" + os.sep + "testmodules" + os.sep + "file2.dll"), path(r"c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.dll"), "testmodule"),
       
  1181             (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file1"), path(r"e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1"), "data"),
       
  1182             (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file2"), path(r"e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2"), "data"),
       
  1183             (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file3"), path(r"e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file3"), "data"),
       
  1184             ]
       
  1185         if harness == "STIF" or harness == "MULTI_HARNESS":
       
  1186             harness0 = harness1 = "STIF"
       
  1187             if "MULTI_HARNESS" in harness:
       
  1188                 harness1 = "EUNIT"
       
  1189                 self.src_dst1 = [
       
  1190                     (TEST_PATH.joinpath(r"tsrc" + os.sep + "testmodules" + os.sep + "file1.dll"), path(r"c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.dll"), "testmodule"),
       
  1191                     (TEST_PATH.joinpath(r"tsrc" + os.sep + "testmodules" + os.sep + "file2.dll"), path(r"c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.dll"), "testmodule"),
       
  1192                     (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file1"), path(r"e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1"), "data"),
       
  1193                     (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file2"), path(r"e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2"), "data"),
       
  1194                     (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file3"), path(r"e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file3"), "data"),
       
  1195                     ] 
       
  1196             self.src_dst0 = [
       
  1197                 (TEST_PATH.joinpath(r"tsrc" + os.sep + "testmodules" + os.sep + "file1.dll"), path(r"c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.dll"), "testmodule"),
       
  1198                 (TEST_PATH.joinpath(r"tsrc" + os.sep + "testmodules" + os.sep + "file2.dll"), path(r"c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.dll"), "testmodule"),
       
  1199                 (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file1"), path(r"e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1"), "data"),
       
  1200                 (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file2"), path(r"e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2"), "data"),
       
  1201                 (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file3"), path(r"e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file3"), "data"),
       
  1202                 (TEST_PATH.joinpath(r"tsrc" + os.sep + "conf" + os.sep + "file1.cfg"), path(r"c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.cfg"), "conf"),
       
  1203                 (TEST_PATH.joinpath(r"tsrc" + os.sep + "conf" + os.sep + "file2.cfg"), path(r"c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.cfg"), "conf"),
       
  1204                 (TEST_PATH.joinpath(r"tsrc" + os.sep + "init" + os.sep + "TestFramework.ini"), path(r"c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "TestFramework.ini"), "engine_ini"),
       
  1205                 ]
       
  1206             if "STIF" in harness:
       
  1207                 self.src_dst1 = self.src_dst0
       
  1208             
       
  1209         elif harness == "EUNIT":
       
  1210             harness0 = harness1 = harness
       
  1211             self.src_dst1 = self.src_dst0
       
  1212             
       
  1213         self.mocker.restore()
       
  1214         test_plan = self.mocker.mock(count=False)
       
  1215         mocker.expect(test_plan["testrun_name"]).result("test")
       
  1216         mocker.expect(test_plan["harness"]).result(harness)
       
  1217         mocker.expect(test_plan["device_type"]).result("product")
       
  1218         mocker.expect(test_plan["plan_name"]).result("test plan")
       
  1219         mocker.expect(test_plan["diamonds_build_url"]).result(self.diamonds_build_url)
       
  1220         mocker.expect(test_plan["test_timeout"]).result("60")
       
  1221         mocker.expect(test_plan["eunitexerunner_flags"]).result("/E S60AppEnv /R Off")
       
  1222         mocker.expect(test_plan["eunitexerunner?flags"]).result(self.eunitexerunner_flags)
       
  1223         mocker.expect(test_plan["device_hwid"]).result("5425")
       
  1224         mocker.expect(test_plan["trace_enabled"]).result(self.trace_enabled)
       
  1225         mocker.expect(test_plan["ctc_enabled"]).result(self.ctc_enabled)
       
  1226         mocker.expect(test_plan["custom_dir"]).result("custom1A")
       
  1227         mocker.expect(test_plan.custom_dir).result(path(r"self.custom_dir"))
       
  1228         mocker.expect(test_plan["ctc_run_process_params"]).result(self.ctc_run_process_params)
       
  1229         if self.trace_enabled == "False":
       
  1230             mocker.expect(test_plan.sets).result([
       
  1231                 dict(name="set0", image_files=self.image_files, data_files=self.data_files,
       
  1232                      config_files=self.config_files, testmodule_files=self.testmodule_files,
       
  1233                      engine_ini_file=self.engine_ini_file, test_harness=harness0,src_dst=self.src_dst0,
       
  1234                      ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags,
       
  1235                      custom_dir = self.custom_dir, component_path=self.component_path),
       
  1236                 dict(name="set1", image_files=self.image_files, data_files=self.data_files,
       
  1237                      config_files=self.config_files, testmodule_files=self.testmodule_files,
       
  1238                      engine_ini_file=self.engine_ini_file, test_harness=harness1, src_dst=self.src_dst1,
       
  1239                      ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags,
       
  1240                      custom_dir = self.custom_dir, component_path=self.component_path),
       
  1241             ])
       
  1242         else:
       
  1243             mocker.expect(test_plan.sets).result([
       
  1244                 dict(name="set0", image_files=self.image_files, data_files=self.data_files,
       
  1245                      config_files=self.config_files, testmodule_files=self.testmodule_files,
       
  1246                      engine_ini_file=self.engine_ini_file, test_harness=harness0, src_dst=self.src_dst0,
       
  1247                      pmd_files=self.pmd_files, trace_activation_files=self.trace_activation_files,
       
  1248                      trace_path=self.file_store.joinpath("traces", "set0", "tracelog.blx"),
       
  1249                      ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags,
       
  1250                      custom_dir = self.custom_dir, component_path=self.component_path),
       
  1251                 dict(name="set1", image_files=self.image_files, data_files=self.data_files,
       
  1252                      config_files=self.config_files, testmodule_files=self.testmodule_files,
       
  1253                      engine_ini_file=self.engine_ini_file, test_harness=harness1, src_dst=self.src_dst1,
       
  1254                      pmd_files=self.pmd_files, trace_activation_files=self.trace_activation_files,
       
  1255                      trace_path=self.file_store.joinpath("traces", "set1", "tracelog.blx"),
       
  1256                      ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags,
       
  1257                      custom_dir = self.custom_dir, component_path=self.component_path),
       
  1258             ])
       
  1259         mocker.expect(test_plan.post_actions).result([
       
  1260             ("SendEmailAction", (("subject", "email subject"),
       
  1261                                  ("type", "ATS3_REPORT"),
       
  1262                                  ("send-files", "true"),
       
  1263                                  ("to", self.report_email))),
       
  1264             ("FileStoreAction", (("to-folder", self.file_store),
       
  1265                                  ("report-type", "ATS_REPORT"),
       
  1266                                  ("date-format", "yyyyMMdd"),
       
  1267                                  ("time-format", "HHmmss"))),
       
  1268             ("FileStoreAction", (("to-folder", self.file_store),
       
  1269                                  ("report-type", "STIF_COMPONENT_REPORT_ALL_CASES"),
       
  1270                                  ("run-log", "true"),
       
  1271                                  ("date-format", "yyyyMMdd"),
       
  1272                                  ("time-format", "HHmmss"))),
       
  1273             ("DiamondsAction", ())
       
  1274         ])
       
  1275         
       
  1276         self.mocker.replay()
       
  1277         self.test_plan = test_plan
       
  1278         
       
  1279         self.gen = adg.Ats3TestDropGenerator()
       
  1280         return self.gen.generate_xml(test_plan)
       
  1281 
       
  1282     def test_basic_structure(self):
       
  1283         "Check that the overall test.xml structure is valid."
       
  1284         
       
  1285         test_harness = ["STIF", "EUNIT", "MULTI_HARNESS"]
       
  1286         
       
  1287         for thar in test_harness:
       
  1288             xml = self.generate_xml(thar)
       
  1289             # Check basics.
       
  1290             assert xml.find(".").tag == "test"
       
  1291             assert xml.find("./name").text == "test"
       
  1292             assert xml.find("./buildid").text == self.diamonds_build_url
       
  1293             assert xml.find("./target").tag
       
  1294             assert xml.find("./target/device").tag
       
  1295             if self.test_plan["harness"] == "MULTI_HARNESS":
       
  1296                 harness_1, type_1, device_hwid_1, harness_2, type_2, device_hwid_2 = xml.findall("./target/device/property")
       
  1297             else:
       
  1298                 harness_1, type_1, device_hwid_1 = xml.findall("./target/device/property")
       
  1299             
       
  1300             if self.test_plan["harness"] == "MULTI_HARNESS":
       
  1301                 assert harness_1.get("value") == "STIF"
       
  1302                 assert type_1.get("value") == "product"
       
  1303                 assert device_hwid_1.get("value") == "5425"
       
  1304                 assert harness_2.get("value") == "EUNIT"
       
  1305                 assert type_2.get("value") == "product"
       
  1306                 assert device_hwid_2.get("value") == "5425"
       
  1307             else:
       
  1308                 assert harness_1.get("value") == thar
       
  1309                 assert type_1.get("value") == "product"
       
  1310                 assert device_hwid_1.get("value") == "5425"
       
  1311 
       
  1312         # Check generation of the test plan.
       
  1313         assert xml.find("./plan").get("name") == "test Plan"
       
  1314         assert xml.find("./plan/session").tag 
       
  1315         sets = xml.findall("./plan/session/set")
       
  1316         assert len(sets) == 2
       
  1317         assert sets[0].get("name") == "set0-"+str(TEST_PATH.joinpath("tsrc", "group"))
       
  1318         assert sets[0].find("./target/device").tag
       
  1319     
       
  1320     def test_set_structure(self):
       
  1321         "Check that a <set> element's structure is valid."
       
  1322         xml = self.generate_xml("STIF")
       
  1323         tstset = xml.find("./plan/session/set")
       
  1324         assert tstset.tag
       
  1325         case = tstset.find("./case")
       
  1326         assert case.tag
       
  1327         assert case.get("name") == "set0 case"
       
  1328         
       
  1329     def test_case_flash_elems(self):
       
  1330         """Checks flash target element in the test.xml file"""
       
  1331         xml = self.generate_xml("STIF")
       
  1332         case = xml.find("./plan/session/set/case")
       
  1333         flashes = case.findall("./flash")
       
  1334         assert len(flashes) == len(self.image_files)
       
  1335         for i, flash_file in enumerate(self.image_files):
       
  1336             assert flashes[i].get("target-alias") == "DEFAULT_STIF"
       
  1337             assert flashes[i].get("images") == path(r"ATS3Drop" + os.sep + "images") / flash_file.name
       
  1338         
       
  1339     def test_case_steps(self):
       
  1340         """Checks cases in steps in the test.xml file"""
       
  1341         test_harness = ["STIF", "EUNIT", "MULTI_HARNESS"]
       
  1342         for thar in test_harness:
       
  1343             xml = self.generate_xml(thar)
       
  1344             steps = iter(xml.findall("./plan/session/set/case/step"))
       
  1345             check_ctc_start(steps)
       
  1346             check_log_dir(steps)
       
  1347             if "MULTI_HARNESS" in thar:            
       
  1348                 self.check_install_step(steps, "STIF")
       
  1349                 self.check_run_cases(steps)
       
  1350                 check_ctc_write(steps)
       
  1351                 check_ctc_log(steps)
       
  1352                 check_fetch_logs(steps)
       
  1353                 check_ctc_start(steps)
       
  1354                 check_log_dir(steps)
       
  1355                 self.check_install_step(steps, "EUNIT", set_count="1")
       
  1356                 self.check_run_cases(steps)
       
  1357                 check_ctc_write(steps)
       
  1358                 check_ctc_log(steps, "withpkgfiles")
       
  1359                 check_fetch_logs(steps)
       
  1360             else:
       
  1361                 self.check_install_step(steps, thar)
       
  1362                 self.check_run_cases(steps)
       
  1363                 check_ctc_write(steps)
       
  1364                 check_ctc_log(steps)
       
  1365                 check_fetch_logs(steps)
       
  1366 
       
  1367     def check_install_step(self, steps, harness, set_count="0"):
       
  1368         """Checks install steps in the test.xml file"""
       
  1369         if harness == "MULTI_HARNESS":
       
  1370             dst = [self.src_dst0, self.src_dst1]
       
  1371         else:
       
  1372             dst = [self.src_dst0]
       
  1373         if set_count == "1":
       
  1374             dst = [self.src_dst1]
       
  1375         
       
  1376         for dest in dst:
       
  1377             for file1 in dest:
       
  1378                 step = steps.next()
       
  1379                 filename = file1[1]
       
  1380                 letter = filename[filename.rfind(":")-1:filename.rfind(":")]
       
  1381                 filename = filename[filename.rfind(os.sep)+1:]
       
  1382                 if "Install" in step.get("name"):
       
  1383                     assert step.get("name") == "Install %s: %s" %  (file1[2], filename)
       
  1384                     assert step.findtext("./command") == "install"
       
  1385                     params = step.findall("./params/param")            
       
  1386                     src = params[0].get("src")
       
  1387                     assert src.name == filename
       
  1388                     assert src.parent == path(r"ATS3Drop" + os.sep + "set" + set_count + os.sep + letter + os.sep + "sys" + os.sep + "bin")
       
  1389                     dst = params[1].get("dst")
       
  1390                     assert dst.name == filename
       
  1391                     assert dst.parent == path(letter + ":" + os.sep + "sys" + os.sep + "bin")
       
  1392             
       
  1393     
       
  1394     def check_run_cases(self, steps):
       
  1395         """Checks run cases in the test.xml file"""
       
  1396         step = steps.next()
       
  1397         if step.get("harness") == "STIF":
       
  1398             file_ = self.engine_ini_file 
       
  1399             assert step.get("name") == "Execute test: %s" % file_.name
       
  1400             assert step.findtext("./command") == "run-cases"
       
  1401             params = step.findall("./params/param")
       
  1402             assert params[0].get("filter") == "*"
       
  1403             assert params[1].get("timeout") == "60"
       
  1404             assert params[2].get("engineini") == path(r"c:" + os.sep + "sys" + os.sep + "bin") / self.engine_ini_file.name
       
  1405         elif step.get("harness") == "EUNIT":
       
  1406             file_ = self.testmodule_files[0]
       
  1407             if "Execute" in step.get("name"):
       
  1408                 assert step.get("name") == "Execute test: %s" % file_.name
       
  1409                 assert step.findtext("./command") == "execute"
       
  1410                 params = step.findall("./params/param")
       
  1411                 assert params[0].get("file") == path(r"z:" + os.sep + "sys" + os.sep + "bin" + os.sep + "EUNITEXERUNNER.EXE")
       
  1412                 assert params[1].get("result-file") == path(r"c:" + os.sep + "Shared" + os.sep + "EUnit" + os.sep + "logs" + os.sep + "file1_log.xml")
       
  1413                 assert params[2].get("parameters") == "/E S60AppEnv /R Off /F file1 /l xml file1.dll"
       
  1414                 assert params[3].get("timeout") == "60"
       
  1415                 step = steps.next()
       
  1416                 file_ = self.testmodule_files[1]
       
  1417                 assert step.get("name") == "Execute test: %s" % file_.name
       
  1418                 assert step.findtext("./command") == "execute"
       
  1419                 params = step.findall("./params/param")
       
  1420                 assert params[0].get("file") == path(r"z:" + os.sep + "sys" + os.sep + "bin" + os.sep + "EUNITEXERUNNER.EXE")
       
  1421                 assert params[1].get("result-file") == path(r"c:" + os.sep + "Shared" + os.sep + "EUnit" + os.sep + "logs" + os.sep + "file2_log.xml")
       
  1422                 assert params[2].get("parameters") == "/E S60AppEnv /R Off /F file2 /l xml file2.dll"
       
  1423                 assert params[3].get("timeout") == "60"
       
  1424 
       
  1425     def test_steps_trace_enabled(self):
       
  1426         """checks if traing is enabled"""
       
  1427         test_harness = ["STIF"]
       
  1428         for thar in test_harness:
       
  1429             xml = self.generate_xml(thar, trace_enabled="True")
       
  1430             steps = iter(xml.findall("./plan/session/set/case/step"))
       
  1431             check_ctc_start(steps)
       
  1432             check_log_dir(steps)
       
  1433             self.check_install_step(steps, thar)
       
  1434             check_trace_start(steps, self.file_store)
       
  1435             self.check_run_cases(steps)
       
  1436             check_trace_end_steps(steps, self.file_store)
       
  1437             check_ctc_write(steps)
       
  1438             check_ctc_log(steps)
       
  1439             check_fetch_logs(steps)
       
  1440         
       
  1441     def test_post_actions(self):
       
  1442         "Post actions are inserted into XML."
       
  1443         xml = self.generate_xml("STIF")
       
  1444         post_actions = xml.findall("./postAction")
       
  1445         check_send_email_action(post_actions[0], self.report_email)
       
  1446         check_ats_report_action(post_actions[1], self.file_store)
       
  1447         check_stif_report_action(post_actions[2], self.file_store)
       
  1448         check_diamonds_action(post_actions[3])
       
  1449         
       
  1450     def test_files(self):
       
  1451         """Tests if the files are created for mock"""
       
  1452         xml = self.generate_xml("STIF")
       
  1453         files = iter(xml.findall("./files/file"))
       
  1454         assert files.next().text == r"ATS3Drop" + os.sep + "images" + os.sep + "file1.fpsx"
       
  1455         assert files.next().text == r"ATS3Drop" + os.sep + "images" + os.sep + "file2.fpsx"
       
  1456         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.dll"
       
  1457         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.dll"
       
  1458         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1"
       
  1459         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2"
       
  1460         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file3"
       
  1461         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.cfg"
       
  1462         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.cfg"        
       
  1463         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "TestFramework.ini"
       
  1464         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.dll"
       
  1465         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.dll"
       
  1466         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1"
       
  1467         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2"
       
  1468         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file3"
       
  1469         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.cfg"
       
  1470         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.cfg"
       
  1471         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "TestFramework.ini"
       
  1472         self.assertRaises(StopIteration, files.next)
       
  1473         xml = self.generate_xml(harness="STIF", trace_enabled="True")
       
  1474         files = iter(xml.findall("./files/file"))
       
  1475         assert files.next().text == r"ATS3Drop" + os.sep + "images" + os.sep + "file1.fpsx"
       
  1476         assert files.next().text == r"ATS3Drop" + os.sep + "images" + os.sep + "file2.fpsx"
       
  1477         assert files.next().text == r"ATS3Drop" + os.sep + "pmds" + os.sep + "pmd_file.pmd"
       
  1478         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "trace_init" + os.sep + "trace_activation_1.xml"
       
  1479         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.dll"
       
  1480         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.dll"
       
  1481         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1"
       
  1482         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2"
       
  1483         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file3"
       
  1484         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.cfg"
       
  1485         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.cfg"
       
  1486         assert files.next().text == r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "TestFramework.ini"
       
  1487         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "trace_init" + os.sep + "trace_activation_1.xml"
       
  1488         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.dll"
       
  1489         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.dll"
       
  1490         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1"
       
  1491         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2"
       
  1492         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file3"
       
  1493         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.cfg"
       
  1494         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.cfg"
       
  1495         assert files.next().text == r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "TestFramework.ini"
       
  1496 
       
  1497         self.assertRaises(StopIteration, files.next)
       
  1498         
       
  1499     def test_generate_drop(self):
       
  1500         "Manifest for ATS3Drop directory structure is generated."        
       
  1501         xml = self.generate_xml("STIF")
       
  1502         strbuffer = StringIO()
       
  1503         self.gen.generate_drop(self.test_plan, xml, strbuffer)
       
  1504         
       
  1505         zfile = zipfile.ZipFile(strbuffer, "r")
       
  1506         try:
       
  1507             contents = sorted(path(tpath).normpath() for tpath in zfile.namelist())
       
  1508             expected = sorted(path(tpath).normpath()
       
  1509                            for tpath in [r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.cfg",
       
  1510                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.cfg",
       
  1511                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1",
       
  1512                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2",
       
  1513                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file3",
       
  1514                                      r"ATS3Drop" + os.sep + "images" + os.sep + "file1.fpsx",
       
  1515                                      r"ATS3Drop" + os.sep + "images" + os.sep + "file2.fpsx",
       
  1516                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "TestFramework.ini",
       
  1517                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.dll",
       
  1518                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.dll",
       
  1519                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.cfg",
       
  1520                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.cfg",
       
  1521                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1",
       
  1522                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2",
       
  1523                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file3",
       
  1524                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "TestFramework.ini",
       
  1525                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.dll",
       
  1526                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.dll",
       
  1527                                      r"test.xml"])
       
  1528             diff = difflib.context_diff(expected, contents)
       
  1529             assert contents == expected, "\n".join(diff)
       
  1530         finally:
       
  1531             zfile.close()
       
  1532 
       
  1533     def test_generate_drop_trace_enabled(self):
       
  1534         "Manifest for ATS3Drop directory structure is generated when trace enabled."
       
  1535         xml = self.generate_xml(harness="STIF", trace_enabled="True")
       
  1536         strbuffer = StringIO()
       
  1537         
       
  1538         self.gen.generate_drop(self.test_plan, xml, strbuffer)
       
  1539         zfile = zipfile.ZipFile(strbuffer, "r")
       
  1540         try:
       
  1541             contents = sorted(path(tpath).normpath() for tpath in zfile.namelist())
       
  1542             expected = sorted(path(tpath).normpath()
       
  1543                            for tpath in [r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.cfg",
       
  1544                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.cfg",
       
  1545                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1",
       
  1546                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2",
       
  1547                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file3",
       
  1548                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "trace_init" + os.sep + "trace_activation_1.xml",
       
  1549                                      r"ATS3Drop" + os.sep + "images" + os.sep + "file1.fpsx",
       
  1550                                      r"ATS3Drop" + os.sep + "images" + os.sep + "file2.fpsx",
       
  1551                                      r"ATS3Drop" + os.sep + "pmds" + os.sep + "pmd_file.pmd",
       
  1552                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "TestFramework.ini",
       
  1553                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.dll",
       
  1554                                      r"ATS3Drop" + os.sep + "set0" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.dll",
       
  1555                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.cfg",
       
  1556                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.cfg",
       
  1557                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1",
       
  1558                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2",
       
  1559                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "e" + os.sep + "sys" + os.sep + "bin" + os.sep + "file3",
       
  1560                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "trace_init" + os.sep + "trace_activation_1.xml",
       
  1561                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "TestFramework.ini",
       
  1562                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.dll",
       
  1563                                      r"ATS3Drop" + os.sep + "set1" + os.sep + "c" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.dll",
       
  1564                                      r"test.xml"])
       
  1565             diff = difflib.context_diff(expected, contents)
       
  1566             assert contents == expected, "\n".join(diff)
       
  1567         finally:
       
  1568             zfile.close()
       
  1569             
       
  1570 class TestDropGenerationWithSis(mocker.MockerTestCase):
       
  1571     """
       
  1572     Unit tests for the test.xml generation with sis files.
       
  1573     """
       
  1574     def __init__(self, methodName="runTest"):
       
  1575         mocker.MockerTestCase.__init__(self, methodName)
       
  1576         self.sis_files = None
       
  1577         self.image_files = None
       
  1578         self.engine_ini_file = None
       
  1579         self.report_email = None
       
  1580         self.file_store = None
       
  1581         self.diamonds_build_url = None
       
  1582         self.harness = None
       
  1583         self.test_plan = None
       
  1584         self.gen = None
       
  1585         self.src_dst = []
       
  1586         
       
  1587     def generate_xml(self):
       
  1588         """Geberates XML if sis files"""
       
  1589         def files(*paths):
       
  1590             """generates paths for the files"""
       
  1591             return [TEST_PATH.joinpath("tsrc", tpath) for tpath in paths]
       
  1592         self.sis_files = files("sis/file1.sisx", "sis/file2.sisx", "sis/file3.sisx")
       
  1593         self.image_files = files("output/images/file1.fpsx", "output/images/file2.fpsx")
       
  1594         self.engine_ini_file = files("init/TestFramework.ini")[0]
       
  1595         self.report_email = "test.receiver@company.com"
       
  1596         self.file_store = path("path/to/reports")
       
  1597         self.diamonds_build_url = "http://diamonds.nmp.company.com/diamonds/builds/1234"
       
  1598         self.harness = "STIF"
       
  1599         self.component_path = str(TEST_PATH.joinpath("tsrc", "group"))
       
  1600         self.ctc_run_process_params = r"10.0.0.1#x:\ats\drop0.zip#1"
       
  1601         
       
  1602         test_plan = self.mocker.mock(count=False)
       
  1603         mocker.expect(test_plan["testrun_name"]).result("test")
       
  1604         mocker.expect(test_plan["harness"]).result("STIF")
       
  1605         mocker.expect(test_plan["device_type"]).result("product")
       
  1606         mocker.expect(test_plan["plan_name"]).result("test plan")
       
  1607         mocker.expect(test_plan["diamonds_build_url"]).result(self.diamonds_build_url)
       
  1608         mocker.expect(test_plan["test_timeout"]).result("60")
       
  1609         mocker.expect(test_plan["device_hwid"]).result("5425")
       
  1610         mocker.expect(test_plan["ctc_enabled"]).result("False")
       
  1611         mocker.expect(test_plan["trace_enabled"]).result("False")
       
  1612         mocker.expect(test_plan["custom_dir"]).result("CustomC")
       
  1613         mocker.expect(test_plan.custom_dir).result(path(r"self.custom_dir"))
       
  1614         mocker.expect(test_plan["ctc_run_process_params"]).result(self.ctc_run_process_params)
       
  1615         mocker.expect(test_plan.sets).result([
       
  1616             dict(name="set0", image_files=self.image_files, sis_files=self.sis_files,
       
  1617                  engine_ini_file=self.engine_ini_file, test_harness=self.harness, ctc_enabled="False", component_path=self.component_path),
       
  1618              ])
       
  1619         mocker.expect(test_plan.post_actions).result([])
       
  1620         self.mocker.replay()
       
  1621         self.test_plan = test_plan
       
  1622         
       
  1623         self.gen = adg.Ats3TestDropGenerator()
       
  1624         return self.gen.generate_xml(test_plan)
       
  1625 
       
  1626     def test_case_steps(self):
       
  1627         """Checks cases in steps in the test.xml file"""
       
  1628         xml = self.generate_xml()
       
  1629         #print doc.xml(indent="yes")        
       
  1630         steps = iter(xml.findall("./plan/session/set/case/step"))
       
  1631         steps.next() # Stif log dir creation.
       
  1632         self.check_install_sis_files(steps)
       
  1633         steps.next() # Install engine ini.
       
  1634         self.check_install_sis_to_device(steps)
       
  1635         steps.next() # Run cases.
       
  1636         steps.next() # Fetch logs.
       
  1637         self.assertRaises(StopIteration, steps.next)
       
  1638 
       
  1639     def check_install_sis_files(self, steps):
       
  1640         """Checks sis files install steps in the test.xml file"""
       
  1641         for filename in self.sis_files:
       
  1642             step = steps.next()
       
  1643             assert step.get("name") == "Install sis: %s" % filename.name
       
  1644             assert step.findtext("./command") == "install"
       
  1645             params = step.findall("./params/param")
       
  1646             # TO DO: Should sis files be specified outside of the set?
       
  1647             assert params[0].get("src") == path(r"ATS3Drop" + os.sep + "set0" + os.sep + "sis") / filename.name
       
  1648             assert params[1].get("dst") == path(r"c:" + os.sep + "testframework") / filename.name
       
  1649 
       
  1650     def check_install_sis_to_device(self, steps):
       
  1651         """Checks sis files installation on the device"""
       
  1652         for filename in self.sis_files:
       
  1653             step = steps.next()
       
  1654             assert step.get("name") == "Install SIS to the device: %s" % filename.name
       
  1655             assert step.findtext("./command") == "install-software"
       
  1656             params = step.findall("./params/param")
       
  1657             assert params[-1].get("sisPackageName") == path(r"c:" + os.sep + "testframework") / filename.name