def test_output(self): # Test the kernel before weaving. out = StringIO() elf = PreparedElfFile(filename="data/eg_weave/l4kernel") kcp = find_kernel_config(elf) kcp.output(out) # Test the kernel in a build image. out = StringIO() elf = PreparedElfFile(filename="data/eg_weave/image_ia32.elf") kcp = find_kernel_config(elf) kcp.output(out)
def test_lots_add_mapping(self): """Add more mappings than are allowed in the outout image.""" kconfig = find_kernel_config(PreparedElfFile(filename="data/eg_weave/l4kernel")) for i in range(0, 10): kconfig.add_mapping((0x1000, 0x100000, 0x4000)) self.assertRaises(weaver.MergeError, kconfig.update_data)
def test_lots_memory_descriptor(self): """Add more descriptors than are allowed in the outout image.""" kconfig = find_kernel_config( PreparedElfFile(filename="data/eg_weave/l4kernel")) for i in range(0x1000, 0x600000, 0x20000): kconfig.add_meminfo(0x1, 0x2, True, i, i + 0x1000) self.assertRaises(weaver.MergeError, kconfig.update_data)
def test_set_config(self): kconfig = find_kernel_config( PreparedElfFile(filename="data/eg_weave/l4kernel")) kconfig.set_config("spaces", 10) kconfig.set_config("mutexes", 10) kconfig.set_config("root_caps", 10) self.assertRaises(weaver.MergeError, kconfig.set_config, "unknown", 10)
def test_lots_add_mapping(self): """Add more mappings than are allowed in the outout image.""" kconfig = find_kernel_config( PreparedElfFile(filename="data/eg_weave/l4kernel")) for i in range(0, 10): kconfig.add_mapping((0x1000, 0x100000, 0x4000)) self.assertRaises(weaver.MergeError, kconfig.update_data)
def test_add_memory_descriptor(self): kconfig = find_kernel_config( PreparedElfFile(filename="data/eg_weave/l4kernel")) kconfig.add_meminfo(0x1, 0x2, True, 0x1000, 0x2000) # This will merge with the previous descriptor. kconfig.add_meminfo(0x1, 0x2, True, 0x3000, 0x4000) kconfig.add_mem_descriptor( MemoryDescriptor(0x1, 0x2, True, 0x1000, 0x2000))
def test_find_kcp_valid(self): elf = PreparedElfFile(filename="data/eg_weave/l4kernel") find_kernel_config(elf)
def test_set_config(self): kconfig = find_kernel_config(PreparedElfFile(filename="data/eg_weave/l4kernel")) kconfig.set_config("spaces", 10) kconfig.set_config("mutexes", 10) kconfig.set_config("root_caps", 10) self.assertRaises(weaver.MergeError, kconfig.set_config, "unknown", 10)
def test_set_stack(self): kconfig = find_kernel_config(PreparedElfFile(filename="data/eg_weave/l4kernel")) kconfig.set_stack(0x20000000)
def print_cmd(args): """Display an ELF file. args contains command line arguments passed from sys.argv. These are parsed using option parser.""" parser = OptionParser("%prog print [options] file", add_help_option=0) parser.add_option("-H", "--help", action="help") parser.add_option("-a", "--all", action="store_true", dest="all", help="Print all information") parser.add_option("-h", "--header", action="store_true", dest="header", help="Print ELF header") parser.add_option("-l", "--pheaders", action="store_true", dest="pheaders", help="Print ELF sections headers") parser.add_option("-S", "--sheaders", action="store_true", dest="sheaders", help="Print ELF sections headers") parser.add_option("-k", "--kconfig", action="store_true", dest="kconfig", help="Print L4 kernel config data structure (Default)") parser.add_option("-B", "--bootinfo", action="store_true", dest="bootinfo", help="Print L4 Bootinfo") parser.add_option("-s", "--segnames", action="store_true", dest="segnames", help="Print segment names") (options, args) = parser.parse_args(args) if len(args) != 1: parser.error("incorrect number of arguments") if options.all: options.header = options.pheaders = options.sheaders = \ options.kconfig = options.bootinfo = True elf = PreparedElfFile(filename=args[0]) if options.header: elf.get_elf_header().output(sys.stdout) if options.sheaders: print_sheaders(elf, not options.header, sys.stdout) if options.pheaders: print_pheaders(elf, not options.header, sys.stdout) if options.kconfig: print kconfig = find_kernel_config(elf) if kconfig: kconfig.output(sys.stdout) else: print "There is no kernel configuration in this file." if options.bootinfo: print bootinfo = find_bootinfo(elf) if bootinfo: bootinfo.output(sys.stdout) else: print "There is no Bootinfo section in this file." if options.segnames: print segnames = get_segnames(elf) if segnames: for segname in segnames.strings: idx = segname.index('\x00') segname = segname[:idx] segname = segname.strip() if segname == "": continue print segname else: # TODO - use the first section in each segment # as the segment name and print that. print "There is no .segnames section in this file" return 0
def test_add_memory_descriptor(self): kconfig = find_kernel_config(PreparedElfFile(filename="data/eg_weave/l4kernel")) kconfig.add_meminfo(0x1, 0x2, True, 0x1000, 0x2000) # This will merge with the previous descriptor. kconfig.add_meminfo(0x1, 0x2, True, 0x3000, 0x4000) kconfig.add_mem_descriptor(MemoryDescriptor(0x1, 0x2, True, 0x1000, 0x2000))
def test_find_kcp_valid(self): elf = PreparedElfFile(filename="data/arm_object") self.assertEquals(find_kernel_config(elf), None)
def test_set_stack(self): kconfig = find_kernel_config( PreparedElfFile(filename="data/eg_weave/l4kernel")) kconfig.set_stack(0x20000000)
def test_add_mapping(self): kconfig = find_kernel_config( PreparedElfFile(filename="data/eg_weave/l4kernel")) kconfig.add_mapping((0x1000, 0x100000, 0x4000)) kconfig.update_data()
def test_lots_memory_descriptor(self): """Add more descriptors than are allowed in the outout image.""" kconfig = find_kernel_config(PreparedElfFile(filename="data/eg_weave/l4kernel")) for i in range(0x1000, 0x600000, 0x20000): kconfig.add_meminfo(0x1, 0x2, True, i, i + 0x1000) self.assertRaises(weaver.MergeError, kconfig.update_data)
def test_updated_data(self): kconfig = find_kernel_config(PreparedElfFile(filename="data/eg_weave/l4kernel")) kconfig.add_meminfo(0x1, 0x2, True, 0x1000, 0x2000) kconfig.update_data()
def test_add_mapping(self): kconfig = find_kernel_config(PreparedElfFile(filename="data/eg_weave/l4kernel")) kconfig.add_mapping((0x1000, 0x100000, 0x4000)) kconfig.update_data()
def test_updated_data(self): kconfig = find_kernel_config( PreparedElfFile(filename="data/eg_weave/l4kernel")) kconfig.add_meminfo(0x1, 0x2, True, 0x1000, 0x2000) kconfig.update_data()