예제 #1
0
def mount(fs, mount_point):
    if not isinstance(fs, NativeFileSystem):
        raise ValueError(
            "Only NativeFileSystems are supported on Raspberry Pi.")

    sh.pmount(fs.device_path, mount_point)
    return AutoUnmount(mount_point)
예제 #2
0
 def __init__(self, dev):
     self.dev = os.path.realpath(dev)
     self.mountpoint = None
     with open("/etc/mtab", "r") as f:
         mtab = f.read()
     mount = [
         mount.split(" ") for mount in mtab.splitlines()
         if mount.startswith(self.dev)
     ]
     if mount:
         self._path = mount[0][1]
     else:
         name = os.path.basename(dev)
         sh.pmount("-tvfat", dev, name, _timeout=10)
         self.mountpoint = "/media/" + name
         self._path = self.mountpoint
예제 #3
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