def setup_env(self, gdb_unix_socket_path=None): self.rom_addr = None self.arch = None self.setup_arch() self.avatar = Avatar(arch=self.arch, output_directory=TEST_DIR, configure_logging=False) self.qemu = QemuTarget( self.avatar, name='qemu_test', #firmware="./tests/binaries/qemu_arm_test", firmware='%s/firmware' % TEST_DIR, gdb_unix_socket_path=gdb_unix_socket_path, ) self.fake_target = FakeTarget() dev1 = self.avatar.add_memory_range(0x101f2000, 0x1000, 'dev1', forwarded=True, forwarded_to=self.fake_target, qemu_name='avatar-rmemory') mem1 = self.avatar.add_memory_range( self.rom_addr, 0x1000, 'mem1', #file='%s/tests/binaries/qemu_arm_test' % # os.getcwd()) file='%s/firmware' % TEST_DIR)
def setup(): global qemu global avatar global fake_target arch = setup_ARCH() avatar = Avatar(arch=arch, output_directory=test_dir) qemu = QemuTarget( avatar, name='qemu_test', #firmware="./tests/binaries/qemu_arm_test", firmware='%s/firmware' % test_dir, ) fake_target = FakeTarget() dev1 = avatar.add_memory_range(0x101f2000, 0x1000, 'dev1', forwarded=True, forwarded_to=fake_target, qemu_name='avatar-rmemory') mem1 = avatar.add_memory_range( rom_addr, 0x1000, 'mem1', #file='%s/tests/binaries/qemu_arm_test' % # os.getcwd()) file='%s/firmware' % test_dir)
def setup(): global qemu global avatar avatar = FakeAvatar() qemu = QemuTarget(avatar, name='qemu_test', firmware="./tests/binaries/qemu_arm_test", gdb_executable=GDB_EXECUTABLE, executable=QEMU_EXECUTABLE) fake_target = FakeTarget() dev1 = avatar.add_memory_range(0x101f2000, 0x1000, 'dev1', forwarded=True, forwarded_to=fake_target, qemu_name='avatar-rmemory') mem1 = avatar.add_memory_range(0x8000000, 0x1000, 'mem1', file='%s/tests/binaries/qemu_arm_test' % os.getcwd())
def setup(): global qemu global avatar avatar = FakeAvatar() qemu = QemuTarget(avatar, name='qemu_test', gdb_executable="arm-none-eabi-gdb", firmware="./tests/binaries/qemu_arm_test", executable="targets/build/qemu/arm-softmmu/qemu-system-") fake_target = FakeTarget() dev1 = avatar.add_memory_range(0x101f2000, 0x1000, 'dev1', forwarded=True, forwarded_to=fake_target, qemu_name='avatar-rmemory') mem1 = avatar.add_memory_range(0x8000000, 0x1000, 'mem1', file='%s/tests/binaries/qemu_arm_test' % os.getcwd())
def setup(): global qemu global avatar global fake_target avatar = Avatar(output_directory='/tmp/testava') qemu = QemuTarget( avatar, name='qemu_test', firmware="./tests/binaries/qemu_arm_test", ) fake_target = FakeTarget() dev1 = avatar.add_memory_range(0x101f2000, 0x1000, 'dev1', forwarded=True, forwarded_to=fake_target, qemu_name='avatar-rmemory') mem1 = avatar.add_memory_range(0x8000000, 0x1000, 'mem1', file='%s/tests/binaries/qemu_arm_test' % os.getcwd())
class QemuTargetTestCase(unittest.TestCase): def setUp(self): self.setup_env() def setup_env(self, gdb_unix_socket_path=None): self.rom_addr = None self.arch = None self.setup_arch() self.avatar = Avatar(arch=self.arch, output_directory=TEST_DIR, configure_logging=False) self.qemu = QemuTarget( self.avatar, name='qemu_test', #firmware="./tests/binaries/qemu_arm_test", firmware='%s/firmware' % TEST_DIR, gdb_unix_socket_path=gdb_unix_socket_path, ) self.fake_target = FakeTarget() dev1 = self.avatar.add_memory_range(0x101f2000, 0x1000, 'dev1', forwarded=True, forwarded_to=self.fake_target, qemu_name='avatar-rmemory') mem1 = self.avatar.add_memory_range( self.rom_addr, 0x1000, 'mem1', #file='%s/tests/binaries/qemu_arm_test' % # os.getcwd()) file='%s/firmware' % TEST_DIR) def setup_arch(self): ARCH = os.getenv('AVATAR2_ARCH') if ARCH == 'ARM': self.arch = ARM self.rom_addr = ARM_BASE_ADDR firmware = ARM_BIN elif ARCH == 'MIPS': self.arch = MIPS_24KF self.rom_addr = MIPS_BASE_ADDR firmware = MIPS_BIN else: self.assertTrue(False, 'Invalid Achitecture') if not os.path.exists(TEST_DIR): os.makedirs(TEST_DIR) with open('%s/firmware' % TEST_DIR, 'wb') as f: f.write(firmware) def tearDown(self): self.qemu.shutdown() def test_initilization(self): self.qemu.init() self.qemu.wait() self.assertEqual(self.qemu.state, TargetStates.STOPPED, self.qemu.state) def test_step(self): self.qemu.init() self.qemu.wait() self.qemu.regs.pc = self.rom_addr self.qemu.step() pc = self.qemu.regs.pc self.assertEqual(pc, self.rom_addr + 4, pc) def test_memory_read(self): self.qemu.init() self.qemu.wait() mem = self.qemu.read_memory(self.rom_addr, 4) if self.arch == ARM: self.assertEqual(mem, 0xe3a0101e, mem) elif self.arch == MIPS_24KF: #self.assertEqual(mem, 0x2409001e, mem) self.assertEqual(mem, 0x1e000924, mem) else: self.assertTrue(False, "Architecture not supported") def test_memory_write(self): self.qemu.init() self.qemu.wait() self.qemu.write_memory(self.rom_addr, 4, 0x41414141) mem = self.qemu.read_memory(self.rom_addr, 4) self.assertEqual(mem, 0x41414141, mem) def test_remote_memory_write(self): self.qemu.init() self.qemu.wait() remote_memory_write = self.qemu.write_memory(0x101f2000, 4, 0x41414141) self.assertEqual(remote_memory_write, True) addr = self.fake_target.fake_write_addr size = self.fake_target.fake_write_size val = self.fake_target.fake_write_val self.assertEqual(addr, 0x101f2000, addr) self.assertEqual(size, 4, size) self.assertEqual(val, 0x41414141, val) def test_remote_memory_read(self): self.qemu.init() self.qemu.wait() self.assertEqual(self.qemu.state, TargetStates.STOPPED, self.qemu.state) remote_memory_read = self.qemu.read_memory(0x101f2000, 4) self.assertEqual(remote_memory_read, 0xdeadbeef, remote_memory_read)