Example #1
0
 def test_optional_attributes(self):
     doc = Element("root",  bar=(bool_attr, "optional"))
     dom = doc.parse_xml_str('<root />')
     self.assertEquals(hasattr(dom, "bar"), False)
     dom = doc.parse_xml_str('<root bar="true" />')
     self.assertEquals(hasattr(dom, "bar"), True)
     self.assertEquals(dom.bar, True)
Example #2
0
 def test_bool_attributes(self):
     doc = Element("root", foo=(bool_attr, "required"))
     dom = doc.parse_xml_str('<root foo="true" />')
     self.assertEquals(dom.foo, True)
     dom = doc.parse_xml_str('<root foo="false" />')
     self.assertEquals(dom.foo, False)
     self.assertRaises(EzXMLError, doc.parse_xml_str, '<root foo="foo" />')
Example #3
0
 def test_optional_attributes(self):
     doc = Element("root", bar=(bool_attr, "optional"))
     dom = doc.parse_xml_str('<root />')
     self.assertEquals(hasattr(dom, "bar"), False)
     dom = doc.parse_xml_str('<root bar="true" />')
     self.assertEquals(hasattr(dom, "bar"), True)
     self.assertEquals(dom.bar, True)
Example #4
0
 def test_invalid_child(self):
     doc = Element("root")
     self.assertRaises(EzXMLError, doc.parse_xml_str,
                       '<root><child /></root>')
     doc = Element("root", Element("foobar"))
     self.assertRaises(EzXMLError, doc.parse_xml_str,
                       '<root><child /></root>')
Example #5
0
    def test_inclusion(self):
        """Test the processing of the include element."""
        child = Element("child", name=(str_attr, "required"))
        doc = Element("root", child)

        # Test file not found.
        self.assertRaises(EzXMLError, doc.parse_xml_str,
                          '<root><include file="nofile" /></root>')

        # Test a simple include.
        dom = doc.parse_xml_str(
            '<root><include file="data/ezxml_include.xml" /></root>')
        # Include element should have been removed.
        includes = dom.find_children("include")
        self.assertEqual(len(includes), 0)
        child_els = dom.find_children("child")
        self.assertEqual(len(child_els), 1)
        self.assertEqual(child_els[0].name, "included")

        # Test including a file with multiple elements and thatalso
        # includes another file.
        dom = doc.parse_xml_str(
            '<root><include file="data/ezxml_include2.xml" /></root>')
        # Include element should have been removed.
        includes = dom.find_children("include")
        self.assertEqual(len(includes), 0)
        child_els = dom.find_children("child")
        self.assertEqual(len(child_els), 7)
        self.assertEqual(child_els[0].name, "included1")
        self.assertEqual(child_els[6].name, "included")
Example #6
0
    def test_inclusion(self):
        """Test the processing of the include element."""
        child = Element("child", name=(str_attr, "required"))
        doc = Element("root", child)

        # Test file not found.
        self.assertRaises(EzXMLError, doc.parse_xml_str,
                          '<root><include file="nofile" /></root>')

        # Test a simple include.
        dom = doc.parse_xml_str('<root><include file="data/ezxml_include.xml" /></root>')
        # Include element should have been removed.
        includes = dom.find_children("include")
        self.assertEqual(len(includes), 0)
        child_els = dom.find_children("child")
        self.assertEqual(len(child_els), 1)
        self.assertEqual(child_els[0].name, "included")

        # Test including a file with multiple elements and thatalso
        # includes another file.
        dom = doc.parse_xml_str('<root><include file="data/ezxml_include2.xml" /></root>')
        # Include element should have been removed.
        includes = dom.find_children("include")
        self.assertEqual(len(includes), 0)
        child_els = dom.find_children("child")
        self.assertEqual(len(child_els), 7)
        self.assertEqual(child_els[0].name, "included1")
        self.assertEqual(child_els[6].name, "included")
Example #7
0
 def test_bool_attributes(self):
     doc = Element("root", foo=(bool_attr, "required"))
     dom = doc.parse_xml_str('<root foo="true" />')
     self.assertEquals(dom.foo, True)
     dom = doc.parse_xml_str('<root foo="false" />')
     self.assertEquals(dom.foo, False)
     self.assertRaises(EzXMLError, doc.parse_xml_str, '<root foo="foo" />')
Example #8
0
 def test_size_attributes(self):
     doc = Element("root", foo=(size_attr, "required"))
     dom = doc.parse_xml_str('<root foo="1234" />')
     self.assertEquals(dom.foo, 1234)
     dom = doc.parse_xml_str('<root foo="1K" />')
     self.assertEquals(dom.foo, 1024L)
     dom = doc.parse_xml_str('<root foo="1M" />')
     self.assertEquals(dom.foo, 1024L * 1024L)
     dom = doc.parse_xml_str('<root foo="1g" />')
     self.assertEquals(dom.foo, 1024L * 1024L * 1024L)
     self.assertRaises(EzXMLError, doc.parse_xml_str, '<root foo="foo" />')
Example #9
0
 def test_bogus_attribute_option(self):
     Element("root", bar=(bool_attr, "required"))
     Element("root", bar=(bool_attr, "optional"))
     self.assertRaises(EzXMLError, Element, "root", bar=bool_attr)
     self.assertRaises(EzXMLError, Element, "root", bar=(bool_attr, "asdf"))
     self.assertRaises(EzXMLError,
                       Element,
                       "root",
                       bar=("asdf", "required", "asdf"))
     self.assertRaises(EzXMLError,
                       Element,
                       "root",
                       bar=("asdf", "required"))
Example #10
0
    def test_dump(self):
        # Test the dumped output.
        output = """\
<root >
    <child name="1" >
    </child>
    <child value="0x32" name="2" >
    </child>
</root>
"""
        child = Element("child", name=(str_attr, "required"), value=(long_attr, "optional"))
        doc = Element("root", child)
        dom = doc.parse_xml_str('<root><child name="1" /><child name="2" value="50"/></root>')
        self.assertEqual(dom.dump(), output)
Example #11
0
    def test_dump(self):
        # Test the dumped output.
        output = """\
<root >
    <child name="1" >
    </child>
    <child value="0x32" name="2" >
    </child>
</root>
"""
        child = Element("child",
                        name=(str_attr, "required"),
                        value=(long_attr, "optional"))
        doc = Element("root", child)
        dom = doc.parse_xml_str(
            '<root><child name="1" /><child name="2" value="50"/></root>')
        self.assertEqual(dom.dump(), output)
Example #12
0
    def test_find_children(self):
        child = Element("child", name=(str_attr, "required"))
        doc = Element("root", child)

        dom = doc.parse_xml_str('<root><child name="1" /></root>')
        child_els = dom.find_children("child")
        self.assertEqual(len(child_els), 1)
        self.assertEqual(child_els[0].name, "1")

        dom = doc.parse_xml_str('<root></root>')
        child_els = dom.find_children("child")
        self.assertEqual(len(child_els), 0)

        dom = doc.parse_xml_str('<root><child name="1" /><child name="2" /></root>')
        child_els = dom.find_children("child")
        self.assertEqual(len(child_els), 2)
        self.assertEqual(child_els[0].name, "1")
        self.assertEqual(child_els[1].name, "2")
Example #13
0
    def test_find_child(self):
        child = Element("child", name=(str_attr, "required"))
        doc = Element("root", child)

        # 1 child
        dom = doc.parse_xml_str('<root><child name="1" /></root>')
        child_el = dom.find_child("child")
        self.assertEquals(child_el.tag, "child")

        # 0 children
        dom = doc.parse_xml_str('<root></root>')
        child_el = dom.find_child("child")
        self.assertEquals(child_el, None)

        # Multiple chidren
        dom = doc.parse_xml_str('<root><child name="2" /><child name="1" /></root>')
        child_el = dom.find_child("child")
        self.assertEquals(child_el.tag, "child")
        self.assertEquals(child_el.name, "2")
Example #14
0
    def test_find_all_children(self):
        leaf = Element("leaf", name=(str_attr, "required"))
        child = Element("child", leaf, name=(str_attr, "required"))
        doc = Element("root", child, leaf)

        dom = doc.parse_xml_str("""
        <root>
            <child name="1">
                <leaf name="bottom_leaf" />
            </child>
            <leaf name="top_leaf" />
            </root>""")
        leaf_els = dom.find_all_children("leaf")
        self.assertEqual(len(leaf_els), 2)
        self.assertEqual(leaf_els[0].name, "bottom_leaf")
        self.assertEqual(leaf_els[1].name, "top_leaf")

        dom = doc.parse_xml_str('<root></root>')
        leaf_els = dom.find_children("leaf")
        self.assertEqual(len(leaf_els), 0)
Example #15
0
 def test_size_attributes(self):
     doc = Element("root", foo=(size_attr, "required"))
     dom = doc.parse_xml_str('<root foo="1234" />')
     self.assertEquals(dom.foo, 1234)
     dom = doc.parse_xml_str('<root foo="1K" />')
     self.assertEquals(dom.foo, 1024L)
     dom = doc.parse_xml_str('<root foo="1M" />')
     self.assertEquals(dom.foo, 1024L * 1024L)
     dom = doc.parse_xml_str('<root foo="1g" />')
     self.assertEquals(dom.foo, 1024L * 1024L * 1024L)
     self.assertRaises(EzXMLError, doc.parse_xml_str, '<root foo="foo" />')
Example #16
0
    def test_unknown_node_type(self):
        """This test is a bit hacky, because there is no real way this error
        could be triggered, but we want to ensure we test that exception raise
        somehow, this goes to lengths to do that."""
        class Empty:
            pass

        empty = Empty
        doc = Element("root")
        empty.tagName = "root"
        empty.attributes = {}
        empty2 = Empty
        empty2.nodeType = 37
        empty2.ELEMENT_NODE = 1
        empty2.TEXT_NODE = 3
        empty2.COMMENT_NODE = 8
        empty.childNodes = [empty2]
        self.assertRaises(EzXMLError, doc.walkdom, empty)
Example #17
0
class XmlCollector(object):
    element = NotImplemented
    COLLECTORS = {}
    image = Element("image")

    def register(cls):
        """
	Register the cell implementation class with an element (and its name).
	"""
        cls.COLLECTORS[cls.element.name] = cls
        cls.image.append_element(cls.element)
    register = classmethod(register)

    def collect_xml(self, elem, *args, **kwargs):
        """
        Parse XML elements and create an intermediate representation of
        the system.
        """
        raise NotImplementedError
Example #18
0
    def test_find_children(self):
        child = Element("child", name=(str_attr, "required"))
        doc = Element("root", child)

        dom = doc.parse_xml_str('<root><child name="1" /></root>')
        child_els = dom.find_children("child")
        self.assertEqual(len(child_els), 1)
        self.assertEqual(child_els[0].name, "1")

        dom = doc.parse_xml_str('<root></root>')
        child_els = dom.find_children("child")
        self.assertEqual(len(child_els), 0)

        dom = doc.parse_xml_str(
            '<root><child name="1" /><child name="2" /></root>')
        child_els = dom.find_children("child")
        self.assertEqual(len(child_els), 2)
        self.assertEqual(child_els[0].name, "1")
        self.assertEqual(child_els[1].name, "2")
Example #19
0
    def test_find_all_children(self):
        leaf = Element("leaf", name=(str_attr, "required"))
        child = Element("child", leaf, name=(str_attr, "required"))
        doc = Element("root", child, leaf)

        dom = doc.parse_xml_str("""
        <root>
            <child name="1">
                <leaf name="bottom_leaf" />
            </child>
            <leaf name="top_leaf" />
            </root>""")
        leaf_els = dom.find_all_children("leaf")
        self.assertEqual(len(leaf_els), 2)
        self.assertEqual(leaf_els[0].name, "bottom_leaf")
        self.assertEqual(leaf_els[1].name, "top_leaf")

        dom = doc.parse_xml_str('<root></root>')
        leaf_els = dom.find_children("leaf")
        self.assertEqual(len(leaf_els), 0)
Example #20
0
    def test_find_child(self):
        child = Element("child", name=(str_attr, "required"))
        doc = Element("root", child)

        # 1 child
        dom = doc.parse_xml_str('<root><child name="1" /></root>')
        child_el = dom.find_child("child")
        self.assertEquals(child_el.tag, "child")

        # 0 children
        dom = doc.parse_xml_str('<root></root>')
        child_el = dom.find_child("child")
        self.assertEquals(child_el, None)

        # Multiple chidren
        dom = doc.parse_xml_str(
            '<root><child name="2" /><child name="1" /></root>')
        child_el = dom.find_child("child")
        self.assertEquals(child_el.tag, "child")
        self.assertEquals(child_el.name, "2")
Example #21
0
 def test_repr(self):
     doc = Element("root", foo=(bool_attr, "required"),
                   bar=(long_attr, "required"))
     parse = doc.parse_xml_str("<root foo='true' bar='16' />")
     self.assertEquals(repr(parse), '<root foo="True" bar="0x10" >')
Example #22
0
 def test_basic_usage(self):
     doc = Element("root")
     parsed = doc.parse_xml_str("<root />")
     self.assertEquals(parsed.tag, "root")
     parsed = doc.parse_xml_file("data/ezxml.1")
     self.assertEquals(parsed.tag, "root")
Example #23
0
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
Processing of the memstats XML element.
"""

from weaver.ezxml import Element, str_attr, size_attr

#############################################################################
#
# Declare the XML elements
#
#############################################################################
RevisionStats_el = Element("revision",
                           repository=(str_attr, "optional"),
                           changeset=(str_attr, "optional"))

#
# Construction of elements leading to environment
#
ID_Range_el = Element("id_range",
                      name=(str_attr, "required"),
                      node=(str_attr, "required"))

Pool_el = Element("pool",
                  id=(str_attr, "required"),
                  vmid=(str_attr, "required"))

Thread_el = Element("thread",
                    pool_id=(str_attr, "required"),
Example #24
0
 def test_ignoring_comments(self):
     doc = Element("root")
     parsed = doc.parse_xml_str("<root><!-- This is a comment --></root>")
     self.assertEquals(parsed.tag, "root")
     self.assertEquals(len(parsed.children), 0)
Example #25
0
 def test_str_attributes(self):
     doc = Element("root", foo=(str_attr, "required"))
     dom = doc.parse_xml_str('<root foo="1234" />')
     self.assertEquals(dom.foo, "1234")
Example #26
0
 def test_str_attributes(self):
     doc = Element("root", foo=(str_attr, "required"))
     dom = doc.parse_xml_str('<root foo="1234" />')
     self.assertEquals(dom.foo, "1234")
Example #27
0
 def test_invalidroot(self):
     doc = Element("root")
     self.assertRaises(EzXMLError, doc.parse_xml_str, "<bar />")
Example #28
0
 def test_basic_usage(self):
     doc = Element("root")
     parsed = doc.parse_xml_str("<root />")
     self.assertEquals(parsed.tag, "root")
     parsed = doc.parse_xml_file("data/ezxml.1")
     self.assertEquals(parsed.tag, "root")
Example #29
0
 def test_long_attributes(self):
     doc = Element("root", foo=(long_attr, "required"))
     dom = doc.parse_xml_str('<root foo="1234" />')
     self.assertEquals(dom.foo, 1234)
     self.assertRaises(EzXMLError, doc.parse_xml_str, '<root foo="foo" />')
Example #30
0
"""
from elf.core import UnpreparedElfFile
from elf.constants import ET_EXEC
from weaver import MergeError
from weaver.ezxml import ParsedElement, Element, long_attr, bool_attr, str_attr
from weaver.segments_xml import collect_patches, collect_elf_segments, \
     attach_to_elf_flags, Segment_el, Heap_el, Patch_el, \
     start_to_value, make_pager_attr
from weaver.memobjs_xml import Stack_el
from weaver.cells.iguana.memobjs_xml import Memsection_el, \
     collect_memsection_element, create_standard_caps, create_alias_cap

from weaver.cells.iguana.bootinfo import Thread, Zone, PD, Environment, Cap
import os

Argv_el = Element("arg",
                  value = (str_attr, "required"))

CommandLine_el = Element("commandline", Argv_el)

Thread_el = Element("thread", Stack_el, CommandLine_el,
                    name     = (str_attr, "required"),
                    start    = (str_attr, "required"),
                    priority = (long_attr, "optional"),
                    physpool = (str_attr, "optional"),
                    virtpool = (str_attr, "optional"))

Entry_el = Element("entry",
                        key    = (str_attr, "required"),
                        value  = (long_attr, "optional"),
                        cap    = (str_attr, "optional"),
                        attach = (str_attr, "optional"))
Example #31
0
 def test_empty_tag(self):
     doc = Element("root")
     doc.parse_xml_str('<root> </root>')
Example #32
0
 def test_empty_tag(self):
     doc = Element("root")
     doc.parse_xml_str('<root> </root>')
Example #33
0
 def test_call(self):
     doc = Element("foo")
     dom = doc(ParsedElement("child"), bar=True)
     self.assertEquals(len(dom.children), 1)
     self.assertEquals(dom.bar, True)
Example #34
0
 def test_repr(self):
     doc = Element("root",
                   foo=(bool_attr, "required"),
                   bar=(long_attr, "required"))
     parse = doc.parse_xml_str("<root foo='true' bar='16' />")
     self.assertEquals(repr(parse), '<root bar="0x10" foo="True" >')
Example #35
0
 def test_simple_child(self):
     doc = Element("root", Element("child"))
     dom = doc.parse_xml_str('<root><child /></root>')
     self.assertEquals(len(dom.children), 1)
Example #36
0
 def test_malformed_xml(self):
     doc = Element("root")
     self.assertRaises(EzXMLError, doc.parse_xml_str, "asdf")
     self.assertRaises(EzXMLError, doc.parse_xml_file, "data/ezxml.2")
Example #37
0
     collect_thread, Environment_el, collect_program_pd_elements, \
     Program_el, PD_el, Environment_el
import weaver.cells.iguana.bootinfo
from weaver.memobjs_xml import Stack_el
from weaver.cells.iguana.memobjs_xml import collect_memsection_element, \
     create_standard_caps
from weaver.ezxml import Element, bool_attr, str_attr, long_attr, \
     size_attr, ParsedElement
from weaver.segments_xml import Segment_el, Patch_el, Heap_el, \
     collect_elf_segments, collect_patches
from weaver.cell_environment import CellEnvironment

Extension_el = Element("extension", Segment_el, Patch_el,
        name     = (str_attr, "required"),
        file     = (str_attr, "optional"),
        start    = (str_attr, "optional"),
        direct   = (bool_attr, "optional"),
        pager    = (str_attr, "optional"),
        physpool = (str_attr, "optional"))

IRQ_el = Element("irq",
                 value = (long_attr, "required"))

Iguana_el = Element("iguana", Segment_el, Patch_el, Extension_el,
                    Environment_el, Stack_el, Heap_el, Program_el,
                    PD_el, IRQ_el,
                    name     = (str_attr, "required"),
                    file     = (str_attr, "required"),
                    physpool = (str_attr, "optional"),
                    virtpool = (str_attr, "optional"),
                    pager    = (str_attr, "optional"),
Example #38
0
 def test_ignoring_comments(self):
     doc = Element("root")
     parsed = doc.parse_xml_str("<root><!-- This is a comment --></root>")
     self.assertEquals(parsed.tag, "root")
     self.assertEquals(len(parsed.children), 0)
Example #39
0
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
Processing of the memory object XML tags.
"""

from weaver.ezxml import Element, long_attr, bool_attr, str_attr, size_attr
from weaver.memobjs_xml import collect_memobj_attrs
import weaver.cells.iguana.bootinfo

Right_el = Element("right", value=(str_attr, "required"))

Cap_el = Element("cap", Right_el, name=(str_attr, "required"))

Memsection_el = Element("memsection",
                        Cap_el,
                        name=(str_attr, "required"),
                        file=(str_attr, "optional"),
                        size=(size_attr, "optional"),
                        virt_addr=(long_attr, "optional"),
                        phys_addr=(long_attr, "optional"),
                        physpool=(str_attr, "optional"),
                        virtpool=(str_attr, "optional"),
                        align=(size_attr, "optional"),
                        attach=(str_attr, "optional"),
                        direct=(bool_attr, "optional"),
Example #40
0
    def test_invalid_attributes(self):
        doc = Element("root")
        self.assertRaises(EzXMLError, doc.parse_xml_str, '<root bar="1234" />')

        doc = Element("root", foo=(long_attr, "required"))
        self.assertRaises(EzXMLError, doc.parse_xml_str, '<root bar="1234" />')
Example #41
0
 def test_simple_child(self):
     doc = Element("root", Element("child"))
     dom = doc.parse_xml_str('<root><child /></root>')
     self.assertEquals(len(dom.children), 1)
Example #42
0
"""Collect data from the kernel element."""

from weaver import MergeError
from weaver import util
from weaver.ezxml import Element, long_attr, str_attr
from weaver.segments_xml import Segment_el, Patch_el, Heap_el

DEFAULT_KERNEL_HEAP_SIZE = 4 * 1024 * 1024
DEFAULT_KERNEL_MAX_THREADS = 1024

UseDevice_el = Element("use_device", name=(str_attr, "required"))

Option_el = Element("option",
                    key=(str_attr, "required"),
                    value=(long_attr, "required"))

Config_el = Element("config", Option_el)

# Compound Elements
Kernel_el = Element("kernel",
                    Segment_el,
                    Patch_el,
                    Heap_el,
                    Config_el,
                    UseDevice_el,
                    file=(str_attr, "optional"),
                    sdk=(str_attr, "optional"),
                    configuration=(str_attr, "optional"),
                    platform=(str_attr, "optional"),
                    linker=(str_attr, "optional"),
                    kernel=(str_attr, "optional"),
Example #43
0
 def test_required_attributes(self):
     doc = Element("root", bar=(bool_attr, "required"))
     self.assertRaises(EzXMLError, doc.parse_xml_str, '<root />')
Example #44
0
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Process segment XML elements."""

import re
from elf.constants import PF_X, PF_W, PF_R, EM_386
from weaver import MergeError
from weaver.ezxml import Element, long_attr, bool_attr, str_attr, size_attr

# General element
Segment_el = Element("segment",
                     name=(str_attr, "required"),
                     phys_addr=(long_attr, "optional"),
                     physpool=(str_attr, "optional"),
                     align=(size_attr, "optional"),
                     attach=(str_attr, "optional"),
                     direct=(bool_attr, "optional"),
                     pager=(str_attr, "optional"),
                     protected=(bool_attr, "optional"),
                     cache_policy=(str_attr, "optional"))

Heap_el = Element("heap",
                  size=(size_attr, "optional"),
                  virt_addr=(long_attr, "optional"),
                  phys_addr=(long_attr, "optional"),
                  physpool=(str_attr, "optional"),
                  virtpool=(str_attr, "optional"),
                  align=(size_attr, "optional"),
                  attach=(str_attr, "optional"),
                  direct=(bool_attr, "optional"),
                  zero=(bool_attr, "optional"),
Example #45
0
 def test_long_attributes(self):
     doc = Element("root", foo=(long_attr, "required"))
     dom = doc.parse_xml_str('<root foo="1234" />')
     self.assertEquals(dom.foo, 1234)
     self.assertRaises(EzXMLError, doc.parse_xml_str, '<root foo="foo" />')