Ejemplo n.º 1
0
    def close(self):
        if not self.mountpoint:
            return
        mountpoint = self.mountpoint
        self.mountpoint = None

        start_time = time.monotonic()
        unmounted = False
        while not unmounted and start_time - time.monotonic() < 30:
            try:
                sh.pumount(mountpoint)
                unmounted = True
            except sh.ErrorReturnCode_5:
                time.sleep(0.1)
Ejemplo n.º 2
0
def run_tests(board, binary, tests, log_key=None):
    serial_device_name = None
    for port in list_ports.comports():
        if port.location and port.location[2:] == board["path"]:
            serial_device_name = port.name
    if not serial_device_name:
        raise RuntimeError("Board not found at path: " + board["path"])

    bootloader = board["bootloader"]
    tests_ok = True

    with redis.lock("lock:device@" + board["path"], timeout=60 * 20) as lock:
        # Trigger the bootloader.
        if bootloader in ("uf2", "samba"):
            s = serial.Serial("/dev/" + serial_device_name,
                              1200,
                              write_timeout=4,
                              timeout=4)
            s.close()

        time.sleep(5)

        if bootloader == "uf2":
            # Mount the filesystem.
            disk_path = None
            for disk in os.listdir("/dev/disk/by-path"):
                if board["path"] in disk:
                    disk_path = disk
            if not disk_path:
                raise RuntimeError("Disk not found for board: " +
                                   board["path"])

            disk_path = "/dev/disk/by-path/" + disk_path
            if os.path.isfile(disk_path + "-part1"):
                raise RuntimeError(
                    "MCU not in bootloader because part1 exists.")

            sh.pmount(disk_path, "fs-" + board["path"])
            mountpoint = "/media/fs-" + board["path"]
            redis_log(
                log_key, "Successfully mounted UF2 bootloader at {0}\n".format(
                    mountpoint))
            with open(mountpoint + "/INFO_UF2.TXT", "r") as f:
                redis_log(log_key, f.read() + "\n")
            shutil.copy(binary, mountpoint)
            # Unmount the mountpoint in case the device has disappeared already after the UF2
            # was flashed.
            sh.pumount(mountpoint)

        if "circuitpython_tests" in tests:
            # First find our CircuitPython disk.
            start_time = time.monotonic()
            disk_path = None
            while not disk_path and time.monotonic() - start_time < 10:
                for disk in os.listdir("/dev/disk/by-path"):
                    if board["path"] in disk and disk.endswith("part1"):
                        disk_path = disk
            if not disk_path:
                raise RuntimeError("Cannot find CIRCUITPY disk for device: " +
                                   board["path"])

            disk_path = "/dev/disk/by-path/" + disk_path
            disk_device = os.path.basename(os.readlink(disk_path))[:-1]

            with storage.mount(storage.NativeFileSystem(disk_path),
                               "/media/cpy-" + board["path"]):
                mountpoint = "/media/cpy-" + board["path"]
                redis_log(
                    log_key,
                    "Successfully mounted CIRCUITPY disk at {0}\n".format(
                        mountpoint))

                # Now find the serial.
                serial_device_name = None
                for port in list_ports.comports():
                    if port.location and port.location[2:] == board["path"]:
                        serial_device_name = port.name
                if not serial_device_name:
                    raise RuntimeError(
                        "No CircuitPython serial connection found at path: " +
                        board["path"])
                with serial.Serial("/dev/" + serial_device_name,
                                   write_timeout=4,
                                   timeout=4) as conn:
                    tests_ok = run_circuitpython_tests(
                        log_key, board["board"], board["test_env"], mountpoint,
                        disk_device, conn,
                        tests["circuitpython_tests"]) and tests_ok

    return tests_ok
Ejemplo n.º 3
0
 def __exit__(self, exc_type, exc_value, traceback):
     sh.pumount(self.mount_point)
     return False