Beispiel #1
0
def padding_before_attribute_reference():
    template_description = """
        <template padding-before="{nowhere}"></template>
    """
    template = XMLTemplateParser(template_description).parse()
    assert template.padding_before.reference_name == "nowhere"
    assert isinstance(template.padding_before, ReferenceProperty)
Beispiel #2
0
def padding_before_attribute_value():
    template_description = """
        <template padding-before="0x20"></template>
    """
    template = XMLTemplateParser(template_description).parse()
    assert template.padding_before == 0x20
    assert isinstance(template.padding_before_property, ValueProperty)
Beispiel #3
0
def test_boundary_attribute_value():
    template_description = """
        <template boundary="0x100"></template>
    """
    template = XMLTemplateParser(template_description).parse()
    assert template.boundary == 0x100
    assert isinstance(template.boundary_property, ValueProperty)
Beispiel #4
0
def padding_after_attribute_referenced_value():
    template_description = """
        <template padding-after="0x30"></template>
    """
    template = XMLTemplateParser(template_description).parse()
    assert template.padding_after == 0x30
    assert isinstance(template.padding_after_property, ValueProperty)
Beispiel #5
0
def padding_after_attribute_referenced_value():
    template_description = """
        <template padding-after="{nowhere}"></template>
    """
    template = XMLTemplateParser(template_description).parse()
    assert template.padding_after.reference_name == "nowhere"
    assert isinstance(template.padding_after, ReferenceProperty)
Beispiel #6
0
def test_size_aggregation_using_same_offsets():
    template = XMLTemplateParser("""
        <template name="template0">
            <layout name="layout0">
                <area name="area00">
                    <field name="field1" size="1"></field>
                    <field name="field2" size="1"></field>
                    <field name="field3" size="1"></field>
                    <field name="field4" size="1"></field>
                </area>
                <area name="area01" offset="0x20">
                    <field name="field5" size="2"></field>
                    <field name="field6" size="2"></field>
                    <field name="field7" size="2"></field>
                    <field name="field8" size="2"></field>
                </area>
                <area name="area02" offset="0x20">
                    <field name="field9" size="8"></field>
                    <field name="field10" size="8"></field>
                    <field name="field11" size="8"></field>
                    <field name="field12" size="8"></field>
                </area>
            </layout>
        </template>""").parse()
    assert template.layout0.area00.size == 4
    assert template.layout0.area00.field1.size == 1
    assert template.layout0.area00.field2.size == 1
    assert template.layout0.area00.field3.size == 1
    assert template.layout0.area00.field4.size == 1
    assert template.layout0.area01.size == 8
    assert template.layout0.area02.size == 32
    assert template.layout0.size == 64
    assert template.size == 64
Beispiel #7
0
def test_name_attribute_optional():
    template = XMLTemplateParser("""
        <template>
        </template>
    """).parse()
    assert isinstance(template, Template)
    assert template.name is None
Beispiel #8
0
def test_name_attribute():
    template = XMLTemplateParser("""
        <template name="test-template0">
        </template>
    """).parse()
    assert isinstance(template, Template)
    assert template.name == "test-template0"
def test_sizing_fix_override_with_sizing_set_to_stretch():
    template = XMLTemplateParser("""
        <template name="root" sizing="stretch" size="256">
        </template>
    """).parse()
    binalyzer = Binalyzer(template)
    assert binalyzer.template.root.size == 256
Beispiel #10
0
def test_addressing_mode_relative_value():
    template_description = """
        <template offset="{nowhere}" adressing-mode="relative"></template>
    """
    template = XMLTemplateParser(template_description).parse()
    assert isinstance(template.offset_property,
                      RelativeOffsetReferenceProperty)
Beispiel #11
0
def test_boundary_attribute_reference():
    template_description = """
        <template boundary="{nowhere}"></template>
    """
    template = XMLTemplateParser(template_description).parse()
    assert template.boundary_property.reference_name == "nowhere"
    assert isinstance(template.boundary_property, ReferenceProperty)
Beispiel #12
0
def test_size_attribute_value():
    template_description = """
        <template size="16"></template>
    """
    template = XMLTemplateParser(template_description).parse()
    assert template.size == 16
    assert isinstance(template.size_property, ValueProperty)
Beispiel #13
0
def test_name_attribute_no_reference_allowed():
    template_description = """
        <template name="{nowhere}"></template>
    """
    with pytest.raises(RuntimeError) as excinfo:
        XMLTemplateParser(template_description).parse()
    assert "Using a reference for a name attribute is not allowed." in str(
        excinfo.value)
def test_sizing_explicit_fix():
    template = XMLTemplateParser("""
        <template name="root" sizing="fix" size="256">
        </template>
    """).parse()
    binalyzer = Binalyzer(template)

    assert binalyzer.template.root.size == 256
def test_sizing_implicit_auto_root_no_children():
    template = XMLTemplateParser("""
        <template name="root">
        </template>
    """).parse()
    binalyzer = Binalyzer(template)

    assert binalyzer.template.root.size == 0
Beispiel #16
0
def test_size_attribute():
    template = XMLTemplateParser("""
        <template size="512">
        </template>
    """).parse()
    assert isinstance(template, Template)
    assert template.size == 512
    assert isinstance(template.size_property, ValueProperty)
Beispiel #17
0
def test_offset_attribute_reference():
    template_description = """
        <template offset="{nowhere}"></template>
    """
    template = XMLTemplateParser(template_description).parse()
    assert template.offset_property.reference_name == "nowhere"
    assert isinstance(template.offset_property,
                      RelativeOffsetReferenceProperty)
Beispiel #18
0
def test_name_attribut_no_reference_allowed():
    with pytest.raises(RuntimeError):
        template = XMLTemplateParser("""
            <template>
                <template name="a"></template>
                <template name="{a}"></template>
            </template>
        """).parse()
Beispiel #19
0
def test_addressing_mode_relative_with_offset_attribute():
    template = XMLTemplateParser("""
        <template offset="0x1" addressing-mode="relative">
        </template>
    """).parse()
    assert template.offset == 0x1
    assert template.absolute_address == 0x1
    assert isinstance(template, Template)
    assert isinstance(template.offset_property, OffsetValueProperty)
def test_sizing_explicit_auto_root_children():
    template = XMLTemplateParser("""
        <template name="root" sizing="auto">
            <area name="child" size="128"></area>
        </template>
    """).parse()
    binalyzer = Binalyzer(template)

    assert binalyzer.template.root.size == 128
def test_sizing_stretch_root_template():
    template = XMLTemplateParser("""
        <template name="root" sizing="stretch">
        </template>
    """).parse()
    binalyzer = Binalyzer(template, bytes([0] * 512))
    binalyzer.data = io.BytesIO(bytes([0] * 512))

    assert binalyzer.template.root.size == 512
Beispiel #22
0
def test_addressing_mode_absolute_without_offset_attribute():
    template = XMLTemplateParser("""
        <template addressing-mode="absolute">
        </template>
    """).parse()
    assert template.offset == 0
    assert template.absolute_address == 0
    assert isinstance(template, Template)
    assert isinstance(template.offset_property, RelativeOffsetValueProperty)
Beispiel #23
0
def test_offset_attribute():
    template = XMLTemplateParser("""
        <template offset="0x100">
        </template>
    """).parse()
    assert isinstance(template, Template)
    assert template.offset == 0x100
    assert template.absolute_address == 0x100
    assert isinstance(template.offset_property, OffsetValueProperty)
def test_sizing_stretch_to_parent():
    template = XMLTemplateParser("""
        <template name="root" size="96">
            <area size="32"></area>
            <area name="area1" sizing="stretch"></area>
        </template>
    """).parse()
    binalyzer = Binalyzer(template)

    assert binalyzer.template.root.area1.size == 64
Beispiel #25
0
def test_size_override():
    template = XMLTemplateParser("""
        <template name="template0">
            <layout name="layout0" offset="0x300">
                <area name="area0" size="0x500" boundary="0x200">
                </area>
            </layout>
        </template>""").parse()
    assert template.layout0.area0.boundary == 0x200
    assert template.layout0.area0.size == 0x500
def test_sizing_stretch_to_sibling():
    template = XMLTemplateParser("""
        <template name="root" size="96">
            <area name="area0" size="32"></area>
            <area name="area1" sizing="stretch"></area>
            <area name="area2" origin="end" size="4"></area>
        </template>
    """).parse()
    binalyzer = Binalyzer(template)

    assert binalyzer.template.root.area1.size == 60
Beispiel #27
0
def test_size_without_children():
    template = XMLTemplateParser("""
        <template name="template0">
            <layout name="layout0">
                <area name="area0">
                </area>
            </layout>
        </template>""").parse()
    assert template.size == 0
    assert template.layout0.size == 0
    assert template.layout0.area0.size == 0
Beispiel #28
0
def test_size_and_boundary_without_leaf_node():
    template = XMLTemplateParser("""
        <template name="template0">
            <layout name="layout0" offset="0x300">
                <area name="area0" boundary="0x200">
                </area>
            </layout>
        </template>""").parse()
    assert template.layout0.area0.offset == 0x100
    assert template.layout0.area0.absolute_address == 0x400
    assert template.layout0.area0.size == 0x0
Beispiel #29
0
def test_size_and_boundary_with_leaf_node():
    template = XMLTemplateParser("""
        <template name="template0">
            <layout name="layout0" offset="0x300">
                <area name="area0" boundary="0x200">
                    <field name="field6" size="2"></field>
                </area>
            </layout>
        </template>""").parse()
    # Start on boundary
    assert template.layout0.area0.offset == 0x100
    assert template.layout0.area0.absolute_address == 0x400
    # End on boundary
    assert template.layout0.area0.size == 0x200
Beispiel #30
0
def test_size_with_children_and_uneven_boundary():
    template = XMLTemplateParser("""
        <template name="template0">
            <layout name="layout0" offset="0x300">
                <area name="area0" boundary="0x200">
                    <field name="field0" size="0x100"></field>
                    <field name="field1" size="0x100"></field>
                    <field name="field2" size="0x100"></field>
                    <field name="field3" size="0x200"></field>
                </area>
            </layout>
        </template>""").parse()
    assert template.layout0.area0.boundary == 0x200
    assert template.layout0.area0.size == 0x600