def _get_driver(self): """ Find out whether the PCI device is bound to any driver. If it is not, returns the '(None, None)' tuple. Otherwise returns a tuple of: * driver name * driver sysfs path """ drvpath = Path(f"{self._devpath}/driver") if not FSHelpers.exists(drvpath, proc=self._proc): return (None, None) drvpath = FSHelpers.abspath(drvpath, proc=self._proc) drvname = Path(drvpath).name return (drvname, drvpath)
def _get_hw_addr(self): """ Return the hardware address for the NIC corresponding to the network interface. Typically the hardware address is a PCI address, such as '0000:04:00.0'. """ # The "device" symlink leads to the sysfs subdirectory corresponding to the underlying NIC. path = self._sysfsbase / "device" if not FSHelpers.exists(path, proc=self._proc): raise ErrorNotFound( f"cannot find network interface '{self.ifname}':\n" f"path '{path}' does not exist{self._proc.hostmsg}'") # The name of the subdirectory is the hardware address. path = FSHelpers.abspath(path, proc=self._proc) return path.name
def __init__(self, devid, cpunum, proc, dmesg=None): """The class constructor. The arguments are the same as in '_WultDeviceBase.__init__()'.""" super().__init__(devid, cpunum, proc, dmesg=dmesg) self._pci_info = None self._devpath = None path = Path(f"/sys/bus/pci/devices/{self._devid}") if not FSHelpers.exists(path, proc=proc): raise ErrorNotFound( f"cannot find device '{self._devid}'{self._proc.hostmsg}:\n" f"path {path} does not exist") self._devpath = FSHelpers.abspath(path, proc=self._proc) self._pci_info = LsPCI.LsPCI(proc).get_info(Path(self._devpath).name) if self.supported_devices and self._pci_info[ "devid"] not in self.supported_devices: supported = [ "%s - %s" % (key, val) for key, val in self.supported_devices.items() ] supported = "\n * ".join(supported) raise ErrorNotSupported( f"PCI device '{self._pci_info['pciaddr']}' (PCI ID " f"{self._pci_info['devid']}) is not supported by wult driver " f"{self.drvname}.\nHere is the list of supported PCI IDs:\n* " f"{supported}") self.info["name"] = "Intel I210" self.info["devid"] = self._pci_info["pciaddr"] if self.supported_devices: self.info["descr"] = self.supported_devices[ self._pci_info["devid"]] else: self.info["name"] = self._pci_info["name"] self.info["descr"] = self.info['name'].capitalize() self.info["descr"] += f". PCI address {self._pci_info['pciaddr']}, Vendor ID " \ f"{self._pci_info['vendorid']}, Device ID {self._pci_info['devid']}." self.info["aspm_enabled"] = self._pci_info["aspm_enabled"]
def _get_ifinfos(proc): """ For every network interfaces backed by a real device on the system defined by 'proc', yield the following tuples: * interface name * device HW address """ for ifname, path, typ in FSHelpers.lsdir(_SYSFSBASE, proc=proc): if typ != "@": # We expect a symlink. continue devpath = None with contextlib.suppress(Error): devpath = FSHelpers.abspath(path / "device", proc=proc) if not devpath: continue yield ifname, devpath.name
def _deploy_drivers(args, proc): """Deploy drivers to the SUT represented by 'proc'.""" drvsrc = find_app_data("wult", _DRV_SRC_SUBPATH/f"{args.toolname}", descr=f"{args.toolname} drivers sources") if not drvsrc.is_dir(): raise Error(f"path '{drvsrc}' does not exist or it is not a directory") kver = None if not args.ksrc: kver = KernelVersion.get_kver(proc=proc) if not args.ksrc: args.ksrc = Path(f"/lib/modules/{kver}/build") else: args.ksrc = FSHelpers.abspath(args.ksrc, proc=proc) if not FSHelpers.isdir(args.ksrc, proc=proc): raise Error(f"kernel sources directory '{args.ksrc}' does not exist{proc.hostmsg}") if not kver: kver = KernelVersion.get_kver_ktree(args.ksrc, proc=proc) _LOG.info("Kernel sources path: %s", args.ksrc) _LOG.info("Kernel version: %s", kver) if KernelVersion.kver_lt(kver, args.minkver): raise Error(f"version of the kernel{proc.hostmsg} is {kver}, and it is not new enough.\n" f"Please, use kernel version {args.minkver} or newer.") _LOG.debug("copying the drivers to %s:\n '%s' -> '%s'", proc.hostname, drvsrc, args.stmpdir) proc.rsync(f"{drvsrc}/", args.stmpdir / "drivers", remotesrc=False, remotedst=True) drvsrc = args.stmpdir / "drivers" kmodpath = Path(f"/lib/modules/{kver}") if not FSHelpers.isdir(kmodpath, proc=proc): raise Error(f"kernel modules directory '{kmodpath}' does not exist{proc.hostmsg}") # Build the drivers on the SUT. _LOG.info("Compiling the drivers%s", proc.hostmsg) cmd = f"make -C '{drvsrc}' KSRC='{args.ksrc}'" if args.debug: cmd += " V=1" stdout, stderr, exitcode = proc.run(cmd) if exitcode != 0: msg = proc.cmd_failed_msg(cmd, stdout, stderr, exitcode) if "synth_event_" in stderr: msg += "\n\nLooks like synthetic events support is disabled in your kernel, enable " \ "the 'CONFIG_SYNTH_EVENTS' kernel configuration option." raise Error(msg) _log_cmd_output(args, stdout, stderr) # Deploy the drivers. dstdir = kmodpath / _DRV_SRC_SUBPATH FSHelpers.mkdir(dstdir, parents=True, exist_ok=True, proc=proc) for name in _get_deployables(drvsrc, proc): installed_module = _get_module_path(proc, name) srcpath = drvsrc / f"{name}.ko" dstpath = dstdir / f"{name}.ko" _LOG.info("Deploying driver '%s' to '%s'%s", name, dstpath, proc.hostmsg) proc.rsync(srcpath, dstpath, remotesrc=True, remotedst=True) if installed_module and installed_module.resolve() != dstpath.resolve(): _LOG.debug("removing old module '%s'%s", installed_module, proc.hostmsg) proc.run_verify(f"rm -f '{installed_module}'") stdout, stderr = proc.run_verify(f"depmod -a -- '{kver}'") _log_cmd_output(args, stdout, stderr) # Potentially the deployed driver may crash the system before it gets to write-back data # to the file-system (e.g., what 'depmod' modified). This may lead to subsequent boot # problems. So sync the file-system now. proc.run_verify("sync")