expected_value = bytes(bytearray(raw_value)) else: value = random.randint(0, 1 << (8 * num_bytes) - 1) expected_value = value members += '%s %s;\n' % (self._smap[num_bytes], name) data += '{%d, %s},\n' % (tid, str(value)) self.expected[name] = expected_value program = self._template.format(members=members, data=data) self.tempdir = tempfile.mkdtemp('bootinfo') sourcefile = os.path.join(self.tempdir, 'test.c') programfile = os.path.join(self.tempdir, 'test') f = open(sourcefile, 'w') f.write(program) f.close() p = subprocess.Popen(['gcc', '-m32', sourcefile, '-o', programfile]) p.wait() p = subprocess.Popen([programfile], stdout=subprocess.PIPE) self.data = p.stdout.read().decode('ascii') p.stdout.close() def tearDown(self): shutil.rmtree(self.tempdir) load_tests = repeatable.make_load_tests([ MikromediaSTM32, MikromediaDSPIC33, MultiMediaBoardPIC32MX7, PIC18Board, RandomBootInfo ])
Kerekes Szilard is written as expected onto a PIC18 devkit.""" bootinfo = """2b010208008000000340000420000500120600630000074e 4f204e414d4500000000000000000000000000000000000000000000000000 000000000000000000""" hexfile = 'pic18ledblink.hex.gz' capfile = 'pic18ledblink.cap.gz' class DSPIC33Program(DevKitCase): """Test if the calculator sample kindly provided by Toni Petrovič is written as expected onto a DSPIC33 devkit.""" bootinfo = """32010b000800000408000300000c04008001050000130600 00400500076d696b726f6d6564696100000000000000000000000000000000 000000000000000000""" hexfile = 'dspic33calc.hex.gz' capfile = 'dspic33calc.cap.gz' class PIC32Program(DevKitCase): """Test if the calculator sample kindly provided by John Comeau is written as expected onto a PIC32 devkit.""" bootinfo = """380114000300001004000002050000130600000000c0079d07 4d4d42204d58370000000000000000000000000000000008000000000008 000000000000000000""" hexfile = 'pic32calc.hex.gz' capfile = 'pic32calc.cap.gz' load_tests = repeatable.make_load_tests([STM32Program, PIC18Program, DSPIC33Program, PIC32Program])
self.assertEqual(b''.join([bytes(kit.blocks[i]) for i,_ in enumerate(kit.blockaddr)]), bytes(randmem)) class STM32RandomWrites(unittest.TestCase): """Do self.blkcount random block writes to flash, and check if data does not corrupt""" count = 10 blkcount = 5 def runTest(self): kit = devkit.factory(_stm32) memsize = _stm32['BootStart'] randmem = bytearray(memsize) for i in xrange(memsize): randmem[i] = 255 for i in xrange(self.blkcount): size = random.randint(1, memsize) addr = random.randint(0, memsize - size) randblk = bytearray(size) for j in xrange(size): randblk[i] = random.randint(0, 255) randmem[addr:addr+size] = randblk kit.write(0x08000000 + addr, randblk) self.assertEqual(b''.join([bytes(kit.blocks[i] if i in kit.blocks else b'\xff'*(end_addr - start_addr)) for i, (start_addr, end_addr) in enumerate(kit.blockaddr)]), bytes(randmem)) load_tests = repeatable.make_load_tests([ EncodeInstr, STM32Factory, STM32Bootloader, STM32IndexError, STM32FullFlashBlock, STM32RandomWrites ])
elif num_bytes > 4: raw_value = [random.randint(0, 255) for i in xrange(num_bytes)] value = '"' + ''.join(['\\x%02x'%x for x in raw_value]) + '"' expected_value = bytes(bytearray(raw_value)) else: value = random.randint(0, 1<<(8*num_bytes)-1) expected_value = value members += '%s %s;\n' % (self._smap[num_bytes], name) data += '{%d, %s},\n' % (tid, str(value)) self.expected[name] = expected_value program = self._template.format(members=members, data=data) self.tempdir = tempfile.mkdtemp('bootinfo') sourcefile = os.path.join(self.tempdir, 'test.c') programfile = os.path.join(self.tempdir, 'test') f = open(sourcefile, 'w') f.write(program) f.close() p = subprocess.Popen(['gcc', '-m32', sourcefile, '-o', programfile]) p.wait() p = subprocess.Popen([programfile], stdout=subprocess.PIPE) self.data = p.stdout.read().decode('ascii') p.stdout.close() def tearDown(self): shutil.rmtree(self.tempdir) load_tests = repeatable.make_load_tests([MikromediaSTM32, MikromediaDSPIC33, MultiMediaBoardPIC32MX7, PIC18Board, RandomBootInfo])