Ejemplo n.º 1
0
    def test_create_implementation_data_type_with_symbol_props(self):
        ws = autosar.workspace(version="4.2.2")
        _create_packages(ws)
        _create_base_types(ws)

        package = ws['DataTypes']
        dt1 = package.createImplementationDataType(
            'RTCTime_T',
            '/DataTypes/BaseTypes/uint32',
            lowerLimit=0,
            upperLimit=0xFFFFFFFF,
            typeEmitter='RTE')
        dt1.setSymbolProps('TimeStamp', 'TimeStampSym')
        self.assertEqual(dt1.symbolProps.name, 'TimeStamp')
        self.assertEqual(dt1.symbolProps.symbol, 'TimeStampSym')

        file_name = 'ar4_implementation_data_type_with_symbol_props.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join('expected_gen', 'datatype', file_name)
        self.save_and_check(ws, expected_file, generated_file, ['/DataTypes'])

        ws2 = autosar.workspace(ws.version_str)
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        dt2 = ws2.find(dt1.ref)
        self.assertIsInstance(dt2, autosar.datatype.ImplementationDataType)
        self.assertIsInstance(dt2.symbolProps, autosar.base.SymbolProps)
        self.assertEqual(dt2.symbolProps.name, dt1.symbolProps.name)
        self.assertEqual(dt2.symbolProps.symbol, dt1.symbolProps.symbol)
Ejemplo n.º 2
0
 def test_create_phys_to_int_compu_method_rational(self):
     ws = autosar.workspace(version="4.2.2")
     _create_packages(ws)
     package = ws.find('/DataTypes')
     compuMethod = package.createCompuMethodRationalPhys('SensorToRaw_T', 0, 256, 0, 65535, unit = 'Raw', defaultValue = 65535, forceFloat = True)
     self.assertIsInstance(compuMethod, autosar.datatype.CompuMethod)
     self.assertEqual(compuMethod.unitRef, '/DataTypes/Units/Raw')
     self.assertIsInstance(ws.find(compuMethod.unitRef), autosar.datatype.Unit)
     self.assertIsInstance(compuMethod.physToInt, autosar.datatype.Computation)
     self.assertIsNone(compuMethod.intToPhys)
     self.assertEqual(compuMethod.physToInt.elements[0].numerator, 256)
     self.assertEqual(1, compuMethod.physToInt.elements[0].denominator)
     file_name = 'ar4_phys_to_int_rational_compu_method.arxml'
     generated_file = os.path.join(self.output_dir, file_name)
     expected_file = os.path.join( 'expected_gen', 'datatype', file_name)
     self.save_and_check(ws, expected_file, generated_file, ['/DataTypes'])
     ws2 = autosar.workspace(ws.version_str)
     ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
     compu2 = ws2.find('/DataTypes/CompuMethods/SensorToRaw_T')
     self.assertIsInstance(compu2, autosar.datatype.CompuMethod)
     self.assertEqual(compu2.name, 'SensorToRaw_T')
     self.assertEqual(compu2.unitRef, '/DataTypes/Units/Raw')
     compuScale = compu2.physToInt.elements[0]
     self.assertEqual(compu2.physToInt.defaultValue, 65535)
     self.assertEqual(compuScale.lowerLimit, 0)
     self.assertEqual(compuScale.upperLimit, 65535)
     self.assertEqual(compuScale.offset, 0)
     self.assertEqual(compuScale.numerator, 256)
     self.assertEqual(compuScale.denominator, 1)
Ejemplo n.º 3
0
    def test_create_integer_types_with_unit(self):
        ws = autosar.workspace(version="3.0.2")
        _create_packages(ws)
        package = ws.find('/DataType')
        dt11 = package.createIntegerDataType('Percent_T', min=0, max=255, offset=0, scaling=0.4, unit='Percent')
        dt12 = package.createIntegerDataType('VehicleSpeed_T', min=0, max=65535, offset=0, scaling=1/64, unit='KmPerHour')

        file_name = 'ar3_integer_types_with_unit.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join( 'expected_gen', 'datatype', file_name)
        self.save_and_check(ws, expected_file, generated_file, ['/DataType'])

        ws2 = autosar.workspace(ws.version_str)
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        dt21 = ws2.find('/DataType/Percent_T')
        dt22 = ws2.find('/DataType/VehicleSpeed_T')
        self.assertIsInstance(dt21, autosar.datatype.IntegerDataType)
        self.assertIsInstance(dt22, autosar.datatype.IntegerDataType)
        self.assertEqual(dt21.minVal, 0)
        self.assertEqual(dt21.maxVal, 255)
        self.assertEqual(dt22.minVal, 0)
        self.assertEqual(dt22.maxVal, 65535)
        compu21 = ws2.find(dt21.compuMethodRef)
        compu22 = ws2.find(dt22.compuMethodRef)
        self.assertEqual(compu21.intToPhys.elements[0].offset, 0)
        self.assertEqual(compu21.intToPhys.elements[0].numerator, 0.4)
        self.assertEqual(compu21.unitRef, '/DataType/Units/Percent')
        self.assertEqual(compu22.intToPhys.elements[0].offset, 0)
        self.assertEqual(compu22.intToPhys.elements[0].numerator, 1)
        self.assertEqual(compu22.intToPhys.elements[0].denominator, 64)
        self.assertEqual(compu22.unitRef, '/DataType/Units/KmPerHour')
Ejemplo n.º 4
0
    def test_create_linear_compu_method(self):
        ws = autosar.workspace(version="4.2.2")
        _create_packages(ws)
        package = ws['DataTypes']
        unit_deg = package.createUnit('deg')
        compuMethod1 = package.createCompuMethodLinear('Pitch_T', lowerLimit=0, upperLimit = 20340, offset = -90, scaling = 1/128, unit = 'deg', forceFloat=False)
        self.assertIsInstance(compuMethod1, autosar.datatype.CompuMethod)
        self.assertEqual('/DataTypes/CompuMethods/Pitch_T', compuMethod1.ref)
        self.assertIsInstance(compuMethod1.intToPhys, autosar.datatype.Computation)
        self.assertIsNone(compuMethod1.physToInt)
        self.assertEqual(-90, compuMethod1.intToPhys.elements[0].offset)
        self.assertEqual(1, compuMethod1.intToPhys.elements[0].numerator)
        self.assertEqual(128, compuMethod1.intToPhys.elements[0].denominator)
        self.assertEqual(0, compuMethod1.intToPhys.elements[0].lowerLimit)
        self.assertEqual(20340, compuMethod1.intToPhys.elements[0].upperLimit)

        file_name = 'ar4_linear_compu_method.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join( 'expected_gen', 'datatype', file_name)
        self.save_and_check(ws, expected_file, generated_file, ['/DataTypes'])
        ws2 = autosar.workspace(ws.version_str)

        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        compuMethod2 = ws.find(compuMethod1.ref)
        self.assertIsInstance(compuMethod2, autosar.datatype.CompuMethod)
        self.assertIsInstance(compuMethod2.intToPhys, autosar.datatype.Computation)
        self.assertIsNone(compuMethod2.physToInt)
        self.assertEqual(compuMethod2.intToPhys.elements[0].offset, compuMethod1.intToPhys.elements[0].offset)
        self.assertEqual(compuMethod2.intToPhys.elements[0].numerator, compuMethod1.intToPhys.elements[0].numerator)
        self.assertEqual(compuMethod2.intToPhys.elements[0].denominator, compuMethod1.intToPhys.elements[0].denominator)
        self.assertEqual(compuMethod2.intToPhys.elements[0].lowerLimit, compuMethod1.intToPhys.elements[0].lowerLimit)
        self.assertEqual(compuMethod2.intToPhys.elements[0].upperLimit, compuMethod1.intToPhys.elements[0].upperLimit)
Ejemplo n.º 5
0
 def test_create_u8_application_array_data_type(self):
     ws = autosar.workspace(version="4.2.2")
     _create_packages(ws)
     package = ws['DataTypes/DataConstrs']
     constraint = package.createPhysicalDataConstraint(
         'UINT8_ADT_DataConstr', 0, 255)
     package = ws['DataTypes']
     adt_elem = package.createApplicationPrimitiveDataType(
         'UINT8_ADT',
         dataConstraint=constraint.ref,
         swCalibrationAccess='READ-ONLY',
         category='VALUE')
     array_elem = autosar.datatype.ApplicationArrayElement(
         name='Data2ByteType_ADTElement',
         category='VALUE',
         typeRef=adt_elem.ref,
         arraySize=2)
     array_dt = package.createApplicationArrayDataType(
         'Data2ByteType_ADT',
         array_elem,
         category='ARRAY',
         swCalibrationAccess='READ-ONLY')
     self.assertEqual('/DataTypes/Data2ByteType_ADT', array_dt.ref)
     file_name = 'ar4_u8_array_adt.arxml'
     generated_file = os.path.join(self.output_dir, file_name)
     expected_file = os.path.join('expected_gen', 'datatype', file_name)
     self.save_and_check(ws, expected_file, generated_file, ['/DataTypes'])
     ws2 = autosar.workspace(ws.version_str)
     ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
     array_dt2 = ws2.find('/DataTypes/Data2ByteType_ADT')
     self.assertIsInstance(array_dt2,
                           autosar.datatype.ApplicationArrayDataType)
Ejemplo n.º 6
0
 def test_create_physical_constraint(self):
     ws = autosar.workspace(version="4.2.2")
     _create_packages(ws)
     package = ws.find('/DataTypes')
     constr = package.createPhysicalDataConstraint(
         'VehicleSpeedPhys_DataConstr', 0, 65535)
     self.assertIsInstance(constr, autosar.datatype.DataConstraint)
     self.assertIsInstance(constr.rules[0],
                           autosar.datatype.PhysicalConstraint)
     self.assertEqual(constr.ref,
                      '/DataTypes/DataConstrs/VehicleSpeedPhys_DataConstr')
     self.assertEqual(constr.lowerLimit, 0)
     self.assertEqual(constr.upperLimit, 65535)
     file_name = 'ar4_phys_constraint.arxml'
     generated_file = os.path.join(self.output_dir, file_name)
     expected_file = os.path.join('expected_gen', 'datatype', file_name)
     self.save_and_check(ws, expected_file, generated_file, ['/DataTypes'])
     ws2 = autosar.workspace(ws.version_str)
     ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
     constr2 = ws2.find(constr.ref)
     self.assertIsInstance(constr2, autosar.datatype.DataConstraint)
     self.assertIsInstance(constr2.rules[0],
                           autosar.datatype.PhysicalConstraint)
     self.assertEqual(constr2.lowerLimit, constr.lowerLimit)
     self.assertEqual(constr2.upperLimit, constr.upperLimit)
Ejemplo n.º 7
0
    def test_create_parameter_interface(self):
        ws = autosar.workspace(version="4.2.2")
        _init_ws(ws)
        package = ws.find('/PortInterfaces')
        pif1 = package.createParameterInterface(
            'CruiseControlEnable_I',
            autosar.element.ParameterDataPrototype('v', 'boolean'))

        file_name = 'ar4_create_parameter_interface.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join('expected_gen', 'portinterface',
                                     file_name)
        self.save_and_check(ws,
                            expected_file,
                            generated_file,
                            filters=['/PortInterfaces'])

        ws2 = autosar.workspace(ws.version_str)
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        pif2 = ws2.find(pif1.ref)
        self.assertIsInstance(pif2, autosar.portinterface.ParameterInterface)
        self.assertEqual(len(pif2.parameters), 1)
        param = pif2.parameters[0]
        self.assertEqual(param.name, 'v')
        self.assertEqual(param.typeRef, '/DataTypes/boolean')
Ejemplo n.º 8
0
    def test_create_mode_declaration_with_assigned_values(self):
        ws = autosar.workspace(version="4.2.2")
        _init_ws(ws)
        modeDeclarationPackage = ws.find('/ModeDclrGroups')
        elem1 = modeDeclarationPackage.createModeDeclarationGroup(
            'BswM_ESH_Mode', [(0, "STARTUP"), (1, "RUN"), (2, "POSTRUN"),
                              (3, "WAKEUP"), (4, "SHUTDOWN")], "STARTUP")

        file_name = 'ar4_mode_declaration_with_assigned_values.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join('expected_gen', 'mode', file_name)
        self.save_and_check(ws, expected_file, generated_file,
                            ['/ModeDclrGroups'])
        ws2 = autosar.workspace(version="4.2.2")
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        elem2 = ws2.find(elem1.ref)
        self.assertIsInstance(elem2, autosar.mode.ModeDeclarationGroup)
        self.assertEqual(elem2.modeDeclarations[0].value, 0)
        self.assertEqual(elem2.modeDeclarations[0].name, "STARTUP")
        self.assertEqual(elem2.modeDeclarations[1].value, 1)
        self.assertEqual(elem2.modeDeclarations[1].name, "RUN")
        self.assertEqual(elem2.modeDeclarations[2].value, 2)
        self.assertEqual(elem2.modeDeclarations[2].name, "POSTRUN")
        self.assertEqual(elem2.modeDeclarations[3].value, 3)
        self.assertEqual(elem2.modeDeclarations[3].name, "WAKEUP")
        self.assertEqual(elem2.modeDeclarations[4].value, 4)
        self.assertEqual(elem2.modeDeclarations[4].name, "SHUTDOWN")
Ejemplo n.º 9
0
 def test_create_boolean_compu_method(self):
     ws = autosar.workspace(version="4.2.2")
     _create_packages(ws)
     package = ws.find('/DataTypes')
     basetypes = package.createSubPackage('BaseTypes')
     basetypes.createSwBaseType('boolean', 1, 'BOOLEAN')
     compuMethod = package.createCompuMethodConst('boolean',
                                                  ['FALSE', 'TRUE'])
     self.assertEqual(compuMethod.ref, '/DataTypes/CompuMethods/boolean')
     self.assertIsNone(compuMethod.intToPhys.defaultValue)
     compuScales = compuMethod.intToPhys.elements
     self.assertEqual(compuScales[0].lowerLimit, 0)
     self.assertEqual(compuScales[0].upperLimit, 0)
     self.assertEqual(compuScales[0].textValue, 'FALSE')
     self.assertEqual(compuScales[1].lowerLimit, 1)
     self.assertEqual(compuScales[1].upperLimit, 1)
     self.assertEqual(compuScales[1].textValue, 'TRUE')
     #test helper propterties
     self.assertEqual(compuMethod.intToPhys.lowerLimit, 0)
     self.assertEqual(compuMethod.intToPhys.upperLimit, 1)
     file_name = 'ar4_boolean_compu_method.arxml'
     generated_file = os.path.join(self.output_dir, file_name)
     expected_file = os.path.join('expected_gen', 'datatype', file_name)
     self.save_and_check(ws, expected_file, generated_file, ['/DataTypes'])
     ws2 = autosar.workspace(ws.version_str)
     ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
     compu2 = ws2.find(compuMethod.ref)
     self.assertIsInstance(compu2, autosar.datatype.CompuMethod)
     compuScales2 = compuMethod.intToPhys.elements
     self.assertEqual(compuScales2[0].lowerLimit, compuScales[0].lowerLimit)
     self.assertEqual(compuScales2[0].upperLimit, compuScales[0].upperLimit)
     self.assertEqual(compuScales2[0].textValue, compuScales[0].textValue)
     self.assertEqual(compuScales2[1].lowerLimit, compuScales[1].lowerLimit)
     self.assertEqual(compuScales2[1].upperLimit, compuScales[1].upperLimit)
     self.assertEqual(compuScales2[1].textValue, compuScales[1].textValue)
Ejemplo n.º 10
0
    def test_create_mode_type_mapping(self):
        ws = autosar.workspace(version="4.2.2")
        _init_ws(ws)
        modeDeclarationPackage = ws.find('/ModeDclrGroups')
        dataTypePackage = ws.find('/DataTypes')
        BswM_ESH_Mode_Group = modeDeclarationPackage.createModeDeclarationGroup(
            'BswM_ESH_Mode',
            ["POSTRUN", "RUN", "SHUTDOWN", "STARTUP", "WAKEUP"], "STARTUP")

        BswM_ESH_Mode_Type = dataTypePackage.createImplementationDataTypeRef(
            'BswM_ESH_Mode',
            '/DataTypes/uint8',
            valueTable=['STARTUP', 'RUN', 'POSTRUN', 'WAKEUP', 'SHUTDOWN'])
        mappingSet1 = modeDeclarationPackage.createDataTypeMappingSet(
            'BswMMappingSet')
        mapping1 = mappingSet1.createModeRequestMapping(
            BswM_ESH_Mode_Group.ref, BswM_ESH_Mode_Type.ref)
        file_name = 'ar4_mode_request_mapping.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join('expected_gen', 'mode', file_name)
        self.save_and_check(ws, expected_file, generated_file,
                            ['/ModeDclrGroups'])
        ws2 = autosar.workspace(version="4.2.2")
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        mappingSet2 = ws2.find('/ModeDclrGroups/BswMMappingSet')
        self.assertIsInstance(mappingSet2, autosar.datatype.DataTypeMappingSet)
        self.assertEqual(
            mappingSet2.findMappedModeRequestRef(
                mapping1.modeDeclarationGroupRef),
            mapping1.implementationDataTypeRef)
Ejemplo n.º 11
0
    def test_create_implementation_ref_type_implicit_constraint(self):
        ws = autosar.workspace(version="4.2.2")
        _create_packages(ws)
        _create_base_types(ws)

        package = ws['DataTypes']
        dt1 = package.createImplementationDataTypeRef('VehicleSpeed_T',
                                                      '/DataTypes/uint16',
                                                      offset=0,
                                                      scaling=1 / 256,
                                                      unit="KmPerHour",
                                                      forceFloat=True)
        self.assertIsInstance(dt1, autosar.datatype.ImplementationDataType)
        self.assertEqual(dt1.ref, '/DataTypes/VehicleSpeed_T')
        constraint1 = ws.find(dt1.dataConstraintRef)
        self.assertEqual(constraint1.name, 'VehicleSpeed_T_DataConstr')
        self.assertEqual(constraint1.lowerLimit, 0)
        self.assertEqual(constraint1.upperLimit, 65535)
        file_name = 'ar4_implementation_type_ref2.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join('expected_gen', 'datatype', file_name)
        self.save_and_check(ws,
                            expected_file,
                            generated_file, ['/DataTypes'],
                            force=True)

        ws2 = autosar.workspace(ws.version_str)
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        dt2 = ws2.find(dt1.ref)
        self.assertIsInstance(dt2, autosar.datatype.ImplementationDataType)
    def test_create_client_server_interface_single_operation_no_return_is_service(
            self):
        ws = autosar.workspace(version="4.2.2")
        _init_ws(ws)
        package = ws.find('/PortInterfaces')
        pif1 = package.createClientServerInterface('FreeRunningTimer_I',
                                                   ['GetTimeStamp'],
                                                   isService=True)
        arg = pif1['GetTimeStamp'].createOutArgument('value',
                                                     '/DataTypes/uint32',
                                                     'NOT-ACCESSIBLE',
                                                     'USE-ARGUMENT-TYPE')

        file_name = 'ar4_client_server_interface_single_operation_no_return_is_service.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join('expected_gen', 'portinterface',
                                     file_name)
        self.save_and_check(ws, expected_file, generated_file)

        ws2 = autosar.workspace(version="4.2.2")
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        pif2 = portInterface = ws2.find(pif1.ref)
        self.assertIsInstance(pif2,
                              autosar.portinterface.ClientServerInterface)
        self.assertEqual(pif2.isService, True)
        self.assertEqual(len(pif2.operations), 1)
        operation = pif2['GetTimeStamp']
        self.assertIsInstance(operation, autosar.portinterface.Operation)
Ejemplo n.º 13
0
    def test_create_adt_with_auto_constraint(self):
        ws = autosar.workspace(version="4.2.2")
        _create_packages(ws)
        package = ws['DataTypes']
        package.createUnit('deg')
        package.createCompuMethodLinear('Pitch_T',
                                        lowerLimit=0,
                                        upperLimit=20340,
                                        offset=-90,
                                        scaling=1 / 128,
                                        unit='deg')
        dt1 = package.createApplicationPrimitiveDataType('Pitch_ADT',
                                                         compuMethod='Pitch_T',
                                                         unit='deg')
        self.assertIsInstance(dt1,
                              autosar.datatype.ApplicationPrimitiveDataType)
        self.assertEqual(dt1.ref, '/DataTypes/Pitch_ADT')
        self.assertEqual(dt1.unitRef, '/DataTypes/Units/deg')
        self.assertEqual(dt1.compuMethodRef, '/DataTypes/CompuMethods/Pitch_T')
        self.assertEqual(dt1.dataConstraintRef,
                         '/DataTypes/DataConstrs/Pitch_ADT_DataConstr')

        file_name = 'ar4_adt_with_auto_constraint.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join('expected_gen', 'datatype', file_name)
        self.save_and_check(ws, expected_file, generated_file, ['/DataTypes'])

        ws2 = autosar.workspace(ws.version_str)
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        dt2 = ws2.find(dt1.ref)
        self.assertIsInstance(dt2,
                              autosar.datatype.ApplicationPrimitiveDataType)
Ejemplo n.º 14
0
 def test_create_boolean_implementation_datatype(self):
     ws = autosar.workspace(version="4.2.2")
     _create_packages(ws)
     package = ws.find('/DataTypes')
     basetypes = package.find('BaseTypes')
     basetypes.createSwBaseType('boolean', 1, 'BOOLEAN')
     dt1 = package.createImplementationDataType(
         'boolean',
         valueTable=['FALSE', 'TRUE'],
         baseTypeRef='/DataTypes/BaseTypes/boolean',
         typeEmitter='Platform_Type')
     self.assertIsInstance(dt1, autosar.datatype.ImplementationDataType)
     self.assertEqual(dt1.ref, '/DataTypes/boolean')
     constr = ws.find(dt1.dataConstraintRef)
     self.assertIsInstance(constr, autosar.datatype.DataConstraint)
     self.assertIsInstance(constr.rules[0],
                           autosar.datatype.InternalConstraint)
     self.assertEqual(constr.lowerLimit, 0)
     self.assertEqual(constr.upperLimit, 1)
     file_name = 'ar4_boolean_implementation_datatype.arxml'
     generated_file = os.path.join(self.output_dir, file_name)
     expected_file = os.path.join('expected_gen', 'datatype', file_name)
     self.save_and_check(ws, expected_file, generated_file, ['/DataTypes'])
     ws2 = autosar.workspace(ws.version_str)
     ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
     dt2 = ws2.find(dt1.ref)
     self.assertIsInstance(dt2, autosar.datatype.ImplementationDataType)
Ejemplo n.º 15
0
    def test_create_ref_type_with_valueTable(self):
        ws = autosar.workspace(version="4.2.2")
        _create_packages(ws)
        _create_base_types(ws)

        package = ws['DataTypes']
        dt1 = package.createImplementationDataTypeRef('OffOn_T',
                                                      '/DataTypes/uint8',
                                                      valueTable=[
                                                          'OffOn_Off',
                                                          'OffOn_On',
                                                          'OffOn_Error',
                                                          'OffOn_NotAvailable'
                                                      ])
        self.assertEqual(dt1.ref, '/DataTypes/OffOn_T')

        file_name = 'ar4_impl_ref_type_vt.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join('expected_gen', 'datatype', file_name)
        self.save_and_check(ws, expected_file, generated_file, ['/DataTypes'])

        ws2 = autosar.workspace(ws.version_str)
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        dt2 = ws2.find(dt1.ref)
        self.assertIsInstance(dt2, autosar.datatype.ImplementationDataType)
Ejemplo n.º 16
0
    def test_create_float_value_type(self):
        ws = autosar.workspace(version="4.2.2")
        _create_packages(ws)
        _create_base_types(ws)

        package = ws['DataTypes']
        dt1 = package.createImplementationDataType(
            'float32',
            '/DataTypes/BaseTypes/float32',
            '-INF',
            'INF',
            lowerLimitType='OPEN',
            upperLimitType='OPEN')
        self.assertIsInstance(dt1, autosar.datatype.ImplementationDataType)
        dc1 = ws.find(dt1.dataConstraintRef)
        self.assertIsInstance(dc1, autosar.datatype.DataConstraint)
        file_name = 'ar4_float_value_type.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join('expected_gen', 'datatype', file_name)
        self.save_and_check(ws, expected_file, generated_file, ['/DataTypes'])

        ws2 = autosar.workspace(ws.version_str)
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        dt2 = ws2.find(dt1.ref)
        self.assertIsInstance(dt2, autosar.datatype.ImplementationDataType)
Ejemplo n.º 17
0
    def test_create_record_constant3(self):
        #same as test_create_record_constant2 but uses an empty string as initializer
        ws = autosar.workspace(version="4.2.2")
        _init_ws(ws)
        package = ws['DataTypes']
        package.createImplementationDataTypeRef('U32Type_T',
                                                '/DataTypes/uint32')
        package.createImplementationArrayDataType('UserName_T',
                                                  '/DataTypes/uint8', 32)
        package.createImplementationRecordDataType(
            'RecordType2_T', [('Elem1', '/DataTypes/U32Type_T'),
                              ('Elem2', '/DataTypes/UserName_T')])
        package = ws['Constants']
        c1 = package.createConstant('Record2_IV', '/DataTypes/RecordType2_T', {
            'Elem1': 2**32 - 1,
            'Elem2': ''
        })
        self.assertIsInstance(c1, autosar.constant.Constant)

        file_name = 'ar4_record_constant3.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join('expected_gen', 'constant', file_name)
        self.save_and_check(ws, expected_file, generated_file, ['/Constants'])

        ws2 = autosar.workspace(ws.version_str)
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        c2 = ws2.find(c1.ref)
        self.assertIsInstance(c2, autosar.constant.Constant)
Ejemplo n.º 18
0
    def test_create_record_constant1(self):
        ws = autosar.workspace(version="4.2.2")
        _init_ws(ws)
        package = ws['DataTypes']
        package.createImplementationDataTypeRef('U32Test_T',
                                                '/DataTypes/uint32')
        package.createImplementationArrayDataType('Array4_T',
                                                  '/DataTypes/U32Test_T', 4)
        package.createImplementationRecordDataType(
            'RecordType1_T', [('Elem1', '/DataTypes/Array4_T'),
                              ('Elem2', '/DataTypes/U32Test_T')])
        package = ws['Constants']
        c1 = package.createConstant('Record1_IV', '/DataTypes/RecordType1_T', {
            'Elem1': [2**32 - 1, 2**32 - 1, 0, 0],
            'Elem2': 2**32 - 1
        })
        self.assertIsInstance(c1, autosar.constant.Constant)

        file_name = 'ar4_record_constant1.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join('expected_gen', 'constant', file_name)
        self.save_and_check(ws, expected_file, generated_file, ['/Constants'])

        ws2 = autosar.workspace(ws.version_str)
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        c2 = ws2.find(c1.ref)
        self.assertIsInstance(c2, autosar.constant.Constant)
Ejemplo n.º 19
0
    def test_create_integer_implementation_types(self):
        ws = autosar.workspace(version="4.2.2")
        _create_packages(ws)
        package = ws.find('/DataTypes')
        basetypes = package.find('BaseTypes')
        basetypes.createSwBaseType('uint8', 8, nativeDeclaration='uint8')
        basetypes.createSwBaseType('uint16', 16, nativeDeclaration='uint16')
        basetypes.createSwBaseType('uint32', 32, nativeDeclaration='uint32')
        uint8_dt1 = package.createImplementationDataType(
            'uint8',
            lowerLimit=0,
            upperLimit=255,
            baseTypeRef='/DataTypes/BaseTypes/uint8',
            typeEmitter='Platform_Type')
        uint16_dt1 = package.createImplementationDataType(
            'uint16',
            lowerLimit=0,
            upperLimit=65535,
            baseTypeRef='/DataTypes/BaseTypes/uint16',
            typeEmitter='Platform_Type')
        uint32_dt1 = package.createImplementationDataType(
            'uint32',
            lowerLimit=0,
            upperLimit=4294967295,
            baseTypeRef='/DataTypes/BaseTypes/uint32',
            typeEmitter='Platform_Type')

        self.assertIsInstance(uint8_dt1,
                              autosar.datatype.ImplementationDataType)
        self.assertIsInstance(uint16_dt1,
                              autosar.datatype.ImplementationDataType)
        self.assertIsInstance(uint32_dt1,
                              autosar.datatype.ImplementationDataType)
        self.assertEqual(uint8_dt1.ref, '/DataTypes/uint8')
        self.assertEqual(uint16_dt1.ref, '/DataTypes/uint16')
        self.assertEqual(uint32_dt1.ref, '/DataTypes/uint32')
        self.assertEqual(uint8_dt1.baseTypeRef, '/DataTypes/BaseTypes/uint8')
        self.assertEqual(uint16_dt1.baseTypeRef, '/DataTypes/BaseTypes/uint16')
        self.assertEqual(uint32_dt1.baseTypeRef, '/DataTypes/BaseTypes/uint32')
        file_name = 'ar4_integer_implementation_datatypes.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join('expected_gen', 'datatype', file_name)
        self.save_and_check(ws, expected_file, generated_file, ['/DataTypes'])
        ws2 = autosar.workspace(ws.version_str)
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        uint8_dt2 = ws2.find(uint8_dt1.ref)
        uint16_dt2 = ws2.find(uint16_dt1.ref)
        uint32_dt2 = ws2.find(uint32_dt1.ref)
        self.assertIsInstance(uint8_dt2,
                              autosar.datatype.ImplementationDataType)
        self.assertIsInstance(uint16_dt2,
                              autosar.datatype.ImplementationDataType)
        self.assertIsInstance(uint32_dt2,
                              autosar.datatype.ImplementationDataType)
        self.assertEqual(uint8_dt2.baseTypeRef, uint8_dt1.baseTypeRef)
        self.assertEqual(uint16_dt2.baseTypeRef, uint16_dt1.baseTypeRef)
        self.assertEqual(uint32_dt2.baseTypeRef, uint32_dt1.baseTypeRef)
Ejemplo n.º 20
0
 def test_create_composition_component(self):
     ws = autosar.workspace(version="4.2.2")
     _init_ws(ws)
     package = ws.find('/ComponentTypes')
     swc = package.createCompositionComponent('MyComposition')
     swc.createRequirePort('VehicleSpeed', 'VehicleSpeed_I', initValueRef = 'VehicleSpeed_IV')
     file_name = 'ar4_composition_swc.arxml'
     generated_file = os.path.join(self.output_dir, file_name)
     expected_file = os.path.join( 'expected_gen', 'component', file_name)
     self.save_and_check(ws, expected_file, generated_file, ['/ComponentTypes'])
     ws2 = autosar.workspace(ws.version_str)
     ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
Ejemplo n.º 21
0
 def test_create_cdd_software_component(self):
     ws1 = autosar.workspace(version="4.2.2")
     _init_ws(ws1)
     package = ws1.find('/ComponentTypes')
     swc1 = package.createComplexDeviceDriverComponent('MyService')
     swc1.createRequirePort('VehicleSpeed', 'VehicleSpeed_I', initValueRef = 'VehicleSpeed_IV')
     file_name = 'ar4_cdd_swc.arxml'
     generated_file = os.path.join(self.output_dir, file_name)
     expected_file = os.path.join( 'expected_gen', 'component', file_name)
     self.save_and_check(ws1, expected_file, generated_file, ['/ComponentTypes'])
     ws2 = autosar.workspace(ws1.version_str)
     ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
     swc2 = ws2.find(swc1.ref)
     self.assertIsInstance(swc2, autosar.component.ComplexDeviceDriverComponent)
Ejemplo n.º 22
0
 def test_create_non_queued_receiver_port_single_data_element(self):
     ws = autosar.workspace(version="4.2.2")
     _init_ws(ws)
     package = ws.find('/ComponentTypes')
     swc1 = package.createApplicationSoftwareComponent('MyApplication')
     swc1.createRequirePort('VehicleSpeed', 'VehicleSpeed_I', initValueRef = 'VehicleSpeed_IV')
     file_name = 'ar4_non_queued_receiver_port_single_data_element.arxml'
     generated_file = os.path.join(self.output_dir, file_name)
     expected_file = os.path.join( 'expected_gen', 'port', file_name)
     self.save_and_check(ws, expected_file, generated_file, ['/ComponentTypes'])
     ws2 = autosar.workspace(ws.version_str)
     ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
     swc2 = ws2.find(swc1.ref)
     self.assertIsInstance(swc2, autosar.component.ApplicationSoftwareComponent)
Ejemplo n.º 23
0
 def test_ws_version(self):
    ws = autosar.workspace(version="4.2.2")
    self.assertEqual(ws.version, 4.2)
    self.assertEqual(ws.patch, 2)
    ws.version = "3.0.5"
    self.assertEqual(ws.version, 3.0)
    self.assertEqual(ws.patch, 5)
    ws.version = 4.1
    ws.patch = 4
    self.assertEqual(ws.version, 4.1)
    self.assertEqual(ws.patch, 4)
    ws = autosar.workspace(version=4.2, patch = 2)
    self.assertEqual(ws.version, 4.2)
    self.assertEqual(ws.patch, 2)
Ejemplo n.º 24
0
    def test_create_num_value_constant(self):
        ws = autosar.workspace(version="4.2.2")
        _create_packages(ws)
        package = ws['Constants']
        c1 = package.createNumericalValueConstant('U32Value_IV', 2**32 - 1)
        self.assertIsInstance(c1, autosar.constant.Constant)
        file_name = 'ar4_num_value_constant.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join('expected_gen', 'constant', file_name)
        self.save_and_check(ws, expected_file, generated_file, ['/Constants'])

        ws2 = autosar.workspace(ws.version_str)
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        c2 = ws2.find(c1.ref)
        self.assertIsInstance(c2, autosar.constant.Constant)
Ejemplo n.º 25
0
    def test_auto_create_constraint(self):
        ws = autosar.workspace(version="4.2.2")
        _create_packages(ws)
        _create_base_types(ws)

        datatypes = ws['DataTypes']
        dt1 = datatypes.createImplementationDataTypeRef('Seconds_T', '/DataTypes/uint8', lowerLimit=0, upperLimit=63)
        file_name = 'ar4_auto_create_constraint.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join( 'expected_gen', 'datatype', file_name)
        self.save_and_check(ws, expected_file, generated_file, ['/DataTypes'])

        ws2 = autosar.workspace(ws.version_str)
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
        dt2 = ws2.find(dt1.ref)
Ejemplo n.º 26
0
    def test_create_swc_with_queued_receiver_com_spec(self):

        ws = autosar.workspace(version="4.2.2")
        _init_ws(ws)
        package = ws.find('/ComponentTypes')
        swc = package.createApplicationSoftwareComponent('ButtonPressListener')
        swc.createRequirePort('ButtonPressUp', 'PushButtonStatus_I', queueLength=10)
        swc.createRequirePort('ButtonPressDown', 'PushButtonStatus_I', queueLength=10)

        file_name = 'ar4_swc_with_queued_receiver_com_spec.arxml'
        generated_file = os.path.join(self.output_dir, file_name)
        expected_file = os.path.join( 'expected_gen', 'component', file_name)
        self.save_and_check(ws, expected_file, generated_file, ['/ComponentTypes'])
        ws2 = autosar.workspace(ws.version_str)
        ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
Ejemplo n.º 27
0
 def test_create_sender_receiver_interface_single_element(self):
     ws = autosar.workspace(version="4.2.2")
     _init_ws(ws)
     package = ws.find('/PortInterfaces')
     pif1 =  package.createSenderReceiverInterface('HeaterPwrStat_I', autosar.element.DataElement('HeaterPwrStat', 'OffOn_T'))
     self.assertEqual(pif1.dataElements[0].typeRef, '/DataTypes/OffOn_T')
     file_name = 'ar4_sender_receiver_interface_single_element.arxml'
     generated_file = os.path.join(self.output_dir, file_name)
     expected_file = os.path.join( 'expected_gen', 'portinterface', file_name)
     self.save_and_check(ws, expected_file, generated_file)
     ws2 = autosar.workspace(version="4.2.2")
     ws2.loadXML(os.path.join(os.path.dirname(__file__), expected_file))
     pif2 = portInterface = ws2.find(pif1.ref)
     self.assertIsInstance(pif2, autosar.portinterface.SenderReceiverInterface)
     self.assertEqual(len(pif2.dataElements), 1)
Ejemplo n.º 28
0
def setup():
    ws = autosar.workspace(version="4.2.2")
    #Application Types
    dataTypePackage = ws.createPackage('ApplicationTypes', role='DataType')
    dataConstraintPackage = dataTypePackage.createSubPackage(
        'DataConstrs', role='DataConstraint')
    compuMethodPackage = dataTypePackage.createSubPackage('CompuMethods',
                                                          role='CompuMethod')
    onOffDataConstraint = dataConstraintPackage.createInternalDataConstraint(
        'OnOff_DataConstraint', 0, 3)
    onOffCompuMethod = compuMethodPackage.createCompuMethodConst(
        'OnOff_CompuMethod',
        ['OnOff_Off', 'OnOff_On', 'OnOff_Error', 'OnOff_NotAvailable'],
        defaultValue='OnOff_NotAvailable')
    dataTypePackage.createApplicationPrimitiveDataType(
        'OnOff_T',
        dataConstraint=onOffDataConstraint.ref,
        compuMethod=onOffCompuMethod.ref)
    #Base Types
    baseTypes = ws.createPackage('BaseTypes')
    baseTypeUint8 = baseTypes.createSwBaseType('uint8',
                                               8,
                                               nativeDeclaration='uint8')
    #Implementation Types
    dataTypePackage = ws.createPackage('ImplementationTypes', role='DataType')
    dataTypePackage.createSubPackage('DataConstrs', role='DataConstraint')
    dataTypePackage.createSubPackage('CompuMethods', role='CompuMethod')
    dataTypePackage.createImplementationDataType('OnOff_T',
                                                 baseTypeUint8.ref,
                                                 valueTable=[
                                                     'OnOff_Off', 'OnOff_On',
                                                     'OnOff_Error',
                                                     'OnOff_NotAvailable'
                                                 ])
    return ws
Ejemplo n.º 29
0
 def test_addComponent(self):
     ws = autosar.workspace()
     apply_test_data(ws)
     partition = autosar.rte.Partition()
     partition.addComponent(
         ws.find('/ComponentType/SteeringWheelButtonReader'))
     self.assertEqual(len(partition.components), 1)
Ejemplo n.º 30
0
    def loadReferences(self, ws=None, external=True):
        """
        Loads ARXML from referenced files into an AUTOSAR workspace.
        Returns the workspace object.
        Parameters:

        * ws: Workspace object where ARXML will be loaded
        * external: If True it will recursively load externally referenced DCF files (DCF inside DCF)

        """
        parser = DcfParser()
        if ws is None:
            ws = autosar.workspace()
        for xml_path in [x['path'] for x in self.file_ref]:
            ws.loadXML(xml_path)
        if external:
            for external_dcf in self.external_file_ref:
                child_path = external_dcf['path']
                if os.path.exists(child_path):
                    root, ext = os.path.splitext(child_path)
                    if ext == '.dcf':
                        child_dcf = parser.parse(child_path)
                        child_dcf.loadReferences(ws)
                else:
                    print("No such file: " + child_path, file=sys.stderr)
        return ws
Ejemplo n.º 31
0
 def test_unconnected(self):
    ws = autosar.workspace()
    apply_test_data(ws)
    partition = autosar.rte.Partition()
    partition.addComponent(ws.find('/ComponentType/SteeringWheelButtonReader'))
    self.assertEqual(len(partition.components), 1)
    unconnected = list(partition.unconnectedPorts())
    self.assertEqual(len(unconnected), 10)
Ejemplo n.º 32
0
 def test_addComponent(self):
    ws = autosar.workspace()
    apply_test_data(ws)
    partition = autosar.rte.Partition()
    partition.addComponent(ws.find('/ComponentType/SteeringWheelButtonReader'))
    self.assertEqual(len(partition.components), 1)
Ejemplo n.º 33
0
import autosar

ws = autosar.workspace()
package=ws.createPackage("DataType", role="DataType")
package.createSubPackage('DataTypeSemantics', role='CompuMethod')
package.createSubPackage('DataTypeUnits', role='Unit')
package.createIntegerDataType('InactiveActive_T',valueTable=[
        'InactiveActive_Inactive',
        'InactiveActive_Active',
        'InactiveActive_Error',
        'InactiveActive_NotAvailable'])

ws.saveXML('DataTypes.arxml', packages=['DataType'])

ws2 = autosar.workspace()
ws2.loadXML('DataTypes.arxml')
print(ws2['DataType/InactiveActive_T'].name)