Parse driver related information from a given path.
| 34 | |
| 35 | |
| 36 | class DriverParser: |
| 37 | """ |
| 38 | Parse driver related information from a given path. |
| 39 | """ |
| 40 | |
| 41 | def __init__(self, basedir: Path): |
| 42 | """ |
| 43 | Construct DriverParser |
| 44 | |
| 45 | :param basedir: The base directory to parse |
| 46 | """ |
| 47 | |
| 48 | name = basedir.name |
| 49 | if not name.startswith("gen_"): |
| 50 | raise RuntimeError("Unexpected Program State") |
| 51 | |
| 52 | self.basedir = basedir |
| 53 | self.name = name[4:] |
| 54 | |
| 55 | def parse(self) -> List[Driver]: |
| 56 | """ |
| 57 | Parse a given path to get driver information. |
| 58 | |
| 59 | :return: returns list of Drivers sorted with name. |
| 60 | """ |
| 61 | drivers = self.load_drivers() |
| 62 | report = self.load_gen_report() |
| 63 | drivers = [ |
| 64 | Driver(driver_name, driver_path, report[driver_name]) |
| 65 | for driver_name, driver_path in drivers.items() |
| 66 | ] |
| 67 | drivers.sort(key=lambda x: x.name) |
| 68 | return drivers |
| 69 | |
| 70 | def load_drivers(self) -> dict: |
| 71 | """ |
| 72 | Parse a given path to initialize driver dictionary. |
| 73 | |
| 74 | :return: returns dictionary whose key is driver name and value is path |
| 75 | of its directory. |
| 76 | """ |
| 77 | driver_paths = [] |
| 78 | for entry in self.basedir.iterdir(): |
| 79 | if entry.is_dir() and entry.name != "corpus": |
| 80 | driver_paths.append(entry) |
| 81 | |
| 82 | return {path.name: path for path in driver_paths} |
| 83 | |
| 84 | def load_gen_report(self) -> dict: |
| 85 | """ |
| 86 | Parse a given path to load fuzzgen report. |
| 87 | |
| 88 | :return: returns dictionary whose key is driver name and value for its |
| 89 | main UT source path. |
| 90 | """ |
| 91 | report_path = self.basedir / "fuzzGen_Report.json" |
| 92 | |
| 93 | with open(report_path) as f: |