Beispiel #1
0
    def startCanoe(self):
        #parse the Configuration File to pick the configuration path and tse path
        config = configparser.RawConfigParser()
        config.read('usecase02_configuration.properties')
        configurationPath = config.get('TESTCONFIGURATION',
                                       'configurationpath')
        testspec = config.get('TESTCONFIGURATION', 'testspecification')

        CANoe = win32.DispatchEx("CANoe.Application")
        CANoe.Open(configurationPath)

        testSetup = CANoe.Configuration.TestSetup
        testSetup.TestEnvironments.Add(testspec)
        test_env = testSetup.TestEnvironments.Item(1)
        test_env = win32.CastTo(test_env, "ITestEnvironment2")

        CANoe.Measurement.Start()
        sleep(5)  # Sleep because measurement start is not instantaneous

        testModules = test_env.TestModules
        for i in range(1, testModules.Count + 1):
            test_module = test_env.TestModules.Item(i)
            self.executeTestModule(win32, test_module)

        exit()
Beispiel #2
0
 def TurnOffLINNetwork(self):
     try:
         BusItemArray = self.CANoe.Configuration.SimulationSetup.Buses
         BusItem = BusItemArray('LIN test network')
         BusVB2Item = comclient.CastTo(BusItem, "IBusVB2")
         BusVB2Item.Active = False
     except Exception as e:
         self.log.error(str(e))
         sys.exit("Could not deactivate 'LIN test network'. Exiting!")
Beispiel #3
0
 def TurnOffAllBusNodes(self, busName):
     BusItemArray = self.CANoe.Configuration.SimulationSetup.Buses
     BusItem = BusItemArray(busName)
     BusVB2Item = comclient.CastTo(BusItem, "IBusVB2")
     self.WriteMessage("TurnOffAllBusNodes(self)")
     for i in range(BusVB2Item.Nodes.Count):
         Node = BusVB2Item.Nodes.Item(i + 1)
         self.log.info("Turn off node name: %s" % Node.Name)
         Node.Active = False
Beispiel #4
0
 def TurnOnPartnerNodes(self, busName, nodes):
     BusItemArray = self.CANoe.Configuration.SimulationSetup.Buses
     BusItem = BusItemArray(busName)
     BusVB2Item = comclient.CastTo(BusItem, "IBusVB2")
     self.CANoe.UI.Write.Output("TurnOnPartnerNodes(self)")
     for nodeName in nodes:
         for i in range(BusVB2Item.Nodes.Count):
             Node = BusVB2Item.Nodes.Item(i + 1)
             if nodeName == Node.Name:
                 self.log.info("Turn on node name: %s" % Node.Name)
                 Node.Active = True
Beispiel #5
0
 def TurnOnCANNetwork(self, networkName):
     # CAN network can be always turned on
     self.CANoe.UI.Write.Output("TurnOnCANNetwork")
     try:
         BusItemArray = self.CANoe.Configuration.SimulationSetup.Buses
         BusItem = BusItemArray(networkName)
         BusVB2Item = comclient.CastTo(BusItem, "IBusVB2")
         BusVB2Item.Active = True
     except Exception as e:
         self.log.error(str(e))
         sys.exit("Could not activate 'CAN test network'. Exiting!")
Beispiel #6
0
 def _SwitchNetwork(self, net_name, active):
     result = True
     try:
         BusItemArray = self.CANoe.Configuration.SimulationSetup.Buses
         BusItem = BusItemArray(net_name)
         BusVB2Item = comclient.CastTo(BusItem, "IBusVB2")
         BusVB2Item.Active = active
     except Exception as e:
         result = False
         self.log.error(str(e))
         self.log.error("Could not activate %s network'." % net_name)
     return result
Beispiel #7
0
 def DeactivateAllNodes(self):
     self.WriteMessage("DeactivateAllNodes")
     try:
         for i in range(
                 self.CANoe.Configuration.SimulationSetup.Buses.Count):
             BusItemArray = self.CANoe.Configuration.SimulationSetup.Buses
             BusItem = BusItemArray(i + 1)
             BusVB2Item = comclient.CastTo(BusItem, "IBusVB2")
             BusVB2Item.Active = False
     except Exception as e:
         self.log.error(str(e))
         sys.exit("Could not deactivate networks. Exiting!")
Beispiel #8
0
    def connect(self, event_driven=True):
        """
        Connects to the RTD server.

        Set event_driven to false if you to disable update notifications.
        In this case you'll need to call refresh_data manually.

        """

        dispatch = client.Dispatch(self._classid)
        self._rtd = client.CastTo(dispatch, 'IRtdServer')
        if event_driven:
            self._rtd.ServerStart(wrap(self))
        else:
            self._rtd.ServerStart(None)
Beispiel #9
0
    def executeTestModule(self, win32, test_module):
        print(test_module)
        seq = test_module.Sequence
        for i in range(1, seq.Count + 1):
            tc = win32.CastTo(seq.Item(i), "ITestCase")
            print(tc)

    #
        win32.WithEvents(test_module, TestModuleEvents)
        test_module.Start()
        global testComplete
        while not testComplete:
            pythoncom.PumpWaitingMessages()
            time.sleep(1)

        print(self.getVerdict(test_module.Verdict))
"""Execute XML Test Cases without a pass verdict"""
import sys
from time import sleep
import win32com.client as win32

CANoe = win32.DispatchEx("CANoe.Application")
CANoe.Open("E:/ancit-projects/canoe-autoit/CentralLockingSystem/CentralLockingSystem.cfg")

test_env = CANoe.Configuration.TestSetup.TestEnvironments.Item('Test Environment')
test_env = win32.CastTo(test_env, "ITestEnvironment2")

# Get the XML TestModule (type <TSTestModule>) in the test setup
test_module = test_env.TestModules.Item('Tester')

# {.Sequence} property returns a collection of <TestCases> or <TestGroup>
# or <TestSequenceItem> which is more generic
seq = test_module.Sequence
for i in range(1, seq.Count+1):
    # Cast from <ITestSequenceItem> to <ITestCase> to access {.Verdict}
    # and the {.Enabled} property
    tc = win32.CastTo(seq.Item(i), "ITestCase")
    print(tc)
#     if tc.Verdict != 1: # Verdict 1 is pass
#         tc.Enabled = True
#         print(f"Enabling Test Case {tc.Ident} with verdict {tc.Verdict}")
#     else:
#         tc.Enabled = False
#         print(f"Disabling Test Case {tc.Ident} since it has already passed")


CANoe.Measurement.Start()
Beispiel #11
0
    def ActivateSingleTest(
            self,
            TCname,
            WaitForFinish=True,
            TimeOut=(120 * 60),  # default time-out 2h
            testEnvName="APHFlashReboot",
            restart_measurement_if_time_out=True):
        """
        This method activates single TestModule from selected test environment.
        If test environment is no passed as argument default test envronment
        name is used. Default time-ot is 2h because several test modules in
        default test environment can run for a while.
        TCname = name of the test module.
        WaitForFinish = True if we want to wait for test to finish
        TimeOut - time-out in seconds
        testEnvName - name of the test environment which holds test case module
        """
        nodeFound = 0
        verdict = -1  # timeout
        self.ReportPath = ""
        ProblematicTests = ""
        tstCnt = 0
        self.log.info("Running test %s.%s" % (testEnvName, TCname))
        canoeCfg = self.CANoe.Configuration
        tstEnvCnt = canoeCfg.TestSetup.TestEnvironments.Count + 1
        for i in range(1, tstEnvCnt):
            tstEnv = canoeCfg.TestSetup.TestEnvironments.Item(i)
            tEnvName = tstEnv.Name.encode("ascii")
            if tEnvName == testEnvName:
                tstCnt = tstEnv.Items.Count
                break
        else:
            self.log.error("CANoe test environment '%s' not found!" %
                           testEnvName)

        for j in range(tstCnt):
            selTest = tstEnv.Items(j + 1)
            Name = selTest.Name.encode("ascii")
            if Name == TCname:
                nodeFound = 1
                SelectedTest = comclient.CastTo(selTest, "ITSTestModule")
                self.ReportGenerated = False
                self.ReportPath = SelectedTest.Report.FullName
                if WaitForFinish:
                    tEvents = comclient.DispatchWithEvents(
                        SelectedTest, CANoeTestConfigurationEvents)

                    SelectedTest.Start()
                    # waiting for test to finish in CANoe
                    rc = win32event.WaitForSingleObject(
                        tEvents.testDone, TimeOut * 1000)
                    if rc != win32event.WAIT_OBJECT_0:
                        self.log.error("TEST TIME OUT!!!")
                        if restart_measurement_if_time_out:
                            # recovery procedure. if not executed the state of
                            # the canot test is unknown it could still run
                            self.log.warning("Restarting measurement to "
                                             "stop test!")
                            self.StartMeasurement(False)
                            self.StartMeasurement(True)

                    if SelectedTest.Report.Enabled:
                        # wait for report generation 5 sec should be enough
                        rc = win32event.WaitForSingleObject(
                            tEvents.reportDone, 5000)
                        if rc != win32event.WAIT_OBJECT_0:
                            self.log.error("REPORT NOT GENERATED!!!")
                    else:
                        if _CANOE_API_DEBUG_:
                            self.log.info("Test report not enabled")

                    self.ReportGenerated = tEvents.CTRInfo["success"]
                    if self.ReportGenerated:
                        tcReport, unused_ext = splitext(
                            tEvents.CTRInfo["reportPath"])
                        self.ReportPath = ("%s.xml" % tcReport)
                    if _CANOE_API_DEBUG_:
                        self.log.info("Test report --> %s" % self.ReportPath)

                    if (tEvents.finishReason == 0):
                        verdict = SelectedTest.Verdict
                        if verdict == 1:
                            self.log.info("Test passed!")
                        elif verdict == 2:
                            self.log.info("Test failed!")
                        else:
                            self.log.info("End of test! "
                                          "Verdict not available!")
                    elif (tEvents.finishReason == 1):
                        self.log.error("The test module was stopped by "
                                       "the user.")
                    elif (tEvents.finishReason == 2):
                        self.log.error("The test module was stopped by "
                                       "measurement stop.")
                    elif (tEvents.finishReason == -1):
                        self.log.error("CANoe test time out error!")
                else:
                    SelectedTest.Start()
                break

        if nodeFound == 0:
            self.log.error("%s.%s test not found!" % (testEnvName, TCname))
            ProblematicTests = ProblematicTests + TCname + ", "
        return verdict
Beispiel #12
0
import win32com.client as win32
import configparser

config = configparser.RawConfigParser()
config.read('usecase02_configuration.properties')
configurationPath = config.get('TESTCONFIGURATION', 'configurationpath')
testspec = config.get('TESTCONFIGURATION', 'testspecification')

CANoe = win32.DispatchEx("CANoe.Application")
CANoe.Open(configurationPath)

testSetup = CANoe.Configuration.TestSetup
testSetup.TestEnvironments.Add(testspec)
test_env = testSetup.TestEnvironments.Item('Test Environment')
report = test_env.Report
report = win32.CastTo(test_env, "ITestReport5")
test_env = win32.CastTo(test_env, "ITestEnvironment2")


print(report.FullName)

# Get the XML TestModule (type <TSTestModule>) in the test setup
test_module = test_env.TestModules.Item('Tester')
print(test_module.Path)
report = win32.CastTo(test_module.Report, "ITestReport5")
print(report.FullName)

# {.Sequence} property returns a collection of <TestCases> or <TestGroup>
# or <TestSequenceItem> which is more generic
seq = test_module.Sequence
for i in range(1, seq.Count+1):