예제 #1
0
 def test_big_binary(self):
     """
         This test checks flashing big binaries works.
         1) Create test binary file of the most possible size.
         2) Fill it with random data.
         3) Write the file to the flash.
         4) Read written data to another file.
         5) Compare files.
     """
     fhnd, fname1 = tempfile.mkstemp()
     fbin = os.fdopen(fhnd, 'wb')
     size = (ESP32_FLASH_SZ -
             (ESP32_APP_FLASH_OFF + ESP32_APP_FLASH_SZ)) / 1024
     get_logger().debug('Generate random file %dKB "%s"', size, fname1)
     for i in range(size):
         fbin.write(os.urandom(1024))
     fbin.close()
     self.gdb.target_program(fname1,
                             ESP32_APP_FLASH_OFF + ESP32_APP_FLASH_SZ,
                             actions='',
                             tmo=130)
     # since we can not get result from OpenOCD (output parsing seems not to be good idea),
     # we need to read written flash and compare data manually
     fhnd, fname2 = tempfile.mkstemp()
     fbin = os.fdopen(fhnd, 'wb')
     fbin.close()
     self.gdb.monitor_run('flash read_bank 0 %s 0x%x %d' %
                          (dbg.fixup_path(fname2), ESP32_APP_FLASH_OFF +
                           ESP32_APP_FLASH_SZ, size * 1024),
                          tmo=120)
     self.assertTrue(filecmp.cmp(fname1, fname2))
예제 #2
0
    def test_program_esp_bins(self):
        """
            This test checks flashing complete app works using flasher_args.json.
            1) Generate a dummy flasher_args.json file
            2) Create random binaries based on the flasher_args.json
            3) Write the files to the flash.
            4) Read written data to another file.
            5) Compare files.
        """
        # Temp Folder where everything will be contained
        tmp = tempfile.mkdtemp(prefix="esp")

        obj = generate_flasher_args_json()
        flash_files = obj["flash_files"]

        # Write dummy data to bin files
        for offset in flash_files:
            fname = "esp_%s.bin" % (offset)
            fpath = os.path.join(tmp, fname)

            flash_files[offset] = fname

            fbin = open(fpath, 'wb')
            fbin.write(os.urandom(1024))
            fbin.close()

        # Write the flasher_args file
        json_fname = "flasher_args.json"
        json_fpath = os.path.join(tmp, json_fname)
        json_fp = open(json_fpath, "w")
        json.dump(obj, fp=json_fp, indent=2)
        json_fp.close()

        # Flash the chip
        self.gdb.monitor_run("program_esp_bins %s %s reset verify" %
                             (tmp, json_fname))
        # Halt Reset
        self.gdb.target_reset(action='halt')

        # Read the chip back to verify if flash was successful
        for offset in flash_files:
            fname = "esp_%s.bin.verify" % (offset)
            fpath = os.path.join(tmp, fname)
            fbin = open(fpath, "wb")
            fbin.close()
            self.gdb.monitor_run("flash read_bank 0 %s %s 1024" %
                                 (dbg.fixup_path(fpath), offset),
                                 tmo=120)

            # Verify the content
            og_fname = "esp_%s.bin" % (offset)
            og_fpath = os.path.join(tmp, og_fname)
            self.assertTrue(filecmp.cmp(og_fpath, fpath))

        # Remove the tmp folder for cleanup
        shutil.rmtree(tmp)
예제 #3
0
 def setUp(self):
     semi_dir = tempfile.gettempdir()
     self.gdb.monitor_run('esp32 semihost_basedir %s' % dbg.fixup_path(semi_dir))
     self.fout_names = []
     self.fin_names = []
     for i in range(self.CORES_NUM):
         fname = os.path.join(semi_dir, 'test_read.%d' % i)
         fout = open(fname, 'w')
         size = 1
         get_logger().info('Generate random file %dKB', size)
         for k in range(size):
             fout.write(os.urandom(1024))
         fout.write(os.urandom(3))
         fout.close()
         self.fout_names.append(fname)
         fname = os.path.join(semi_dir, 'test_write.%d' % i)
         get_logger().info('In File %d %s', i, fname)
         self.fin_names.append(fname)
     get_logger().info('Files0 %s, %s', self.fout_names, self.fin_names)
예제 #4
0
 def program_big_binary(self, actions):
     fhnd, fname1 = tempfile.mkstemp()
     fbin = os.fdopen(fhnd, 'wb')
     size = int((ESP32_FLASH_SZ -
                 (ESP32_APP_FLASH_OFF + ESP32_APP_FLASH_SZ)) / 1024)
     get_logger().debug('Generate random file %dKB "%s"', size, fname1)
     for i in range(size):
         fbin.write(os.urandom(1024))
     fbin.close()
     self.gdb.target_program(fname1,
                             ESP32_APP_FLASH_OFF + ESP32_APP_FLASH_SZ,
                             actions=actions,
                             tmo=130)
     # since we can not get result from OpenOCD (output parsing seems not to be good idea),
     # we need to read written flash and compare data manually
     fhnd, fname2 = tempfile.mkstemp()
     fbin = os.fdopen(fhnd, 'wb')
     fbin.close()
     self.gdb.monitor_run('flash read_bank 0 %s 0x%x %d' %
                          (dbg.fixup_path(fname2), ESP32_APP_FLASH_OFF +
                           ESP32_APP_FLASH_SZ, size * 1024),
                          tmo=120)
     self.assertTrue(filecmp.cmp(fname1, fname2))