def test_add_to_empty_db(self): mydb = pyhwdb.database() fpga_coord = coord.FPGAGlobal(self.FPGA_COORD, self.WAFER_COORD) hicann_coord = coord.HICANNGlobal(self.HICANN_COORD, self.WAFER_COORD) with self.assertRaises(IndexError): mydb.add_fpga_entry(fpga_coord, pyhwdb.FPGAEntry()) with self.assertRaises(IndexError): mydb.add_hicann_entry(hicann_coord, pyhwdb.HICANNEntry())
def test_hxcube_entries_have_serial(self): path = os.path.join(os.getcwd(), "db.yaml") db = pyhwdb.database() self.assertTrue(os.path.exists(path)) db.load(path) unique_serial_numbers = set() all_ids = db.get_hxcube_ids() for hxcube_id in all_ids: entry = db.get_hxcube_setup_entry(hxcube_id) self.assertNotEqual(entry.usb_serial, "", "USB serial number is present for setup {}".format(hxcube_id)) unique_serial_numbers.add(entry.usb_serial) self.assertEqual(len(all_ids), len(unique_serial_numbers), "HX cube setups have unique USB serial")
def test_custom_db(self): db = pyhwdb.database() wafer = pyhwdb.WaferEntry() wafer.setup_type = coord.SetupType.BSSWafer wafer_coord = coord.Wafer(10) db.add_wafer_entry(wafer_coord, wafer) fpga = pyhwdb.FPGAEntry() fpga_coord = coord.FPGAGlobal(coord.FPGAOnWafer(0), wafer_coord) db.add_fpga_entry(fpga_coord, fpga) licenses, tres = generate_license_strings(db) # licenses is generated from set -> order not guaranteed self.assertTrue(licenses == "Licenses=W10F0,W10T8" or licenses == "Licenses=W10T8,W10F0") self.assertTrue( tres == "AccountingStorageTRES=License/W10F0,License/W10T8" or tres == "AccountingStorageTRES=License/W10T8,License/W10F0") try: tmpdirname = tempfile.mkdtemp() lic_tmp_file = os.path.join(tmpdirname, str(uuid.uuid4())) tres_tmp_file = os.path.join(tmpdirname, str(uuid.uuid4())) create_license_files(db, lic_tmp_file, tres_tmp_file) with open(lic_tmp_file, "r") as file: content = file.read() self.assertTrue( any(lic in content for lic in ["Licenses=W10F0,W10T8", "Licenses=W10T8,W10F0"])) with open(tres_tmp_file, "r") as file: content = file.read() self.assertTrue( any(tres in content for tres in [ "AccountingStorageTRES=License/W10F0,License/W10T8", "AccountingStorageTRES=License/W10T8,License/W10F0" ])) finally: shutil.rmtree(tmpdirname)
file.write(license_header + license_tres_out) if __name__ == "__main__": default_path = pyhwdb.database.get_default_path() parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--hwdb", type=str, default=default_path, help="path to hwdb yaml file") parser.add_argument( "--license_file", type=str, default="licenses", help="full path and name of licenses output file", ) parser.add_argument( "--tres_file", type=str, default="accountingStorageTRES", help="full path and name of tres output file", ) args = parser.parse_args() db = pyhwdb.database() db.load(args.hwdb) create_license_files(db, args.license_file, args.tres_file)
def test_convert_local_hwdb(self): path = os.path.join(os.getcwd(), "db.yaml") db = pyhwdb.database() self.assertTrue(os.path.exists(path)) db.load(path) generate_license_strings(db)
def test_empty_db(self): db = pyhwdb.database() licenses, tres = generate_license_strings(db) self.assertEqual(licenses, "Licenses=")
def test_database_access(self): mydb = pyhwdb.database() if IS_PYPLUSPLUS: wafer = pyhwdb.WaferEntry() wafer_coord = self.WAFER_COORD wafer.setup_type = self.WAFER_SETUP_TYPE self.assertFalse(mydb.has_wafer_entry(wafer_coord)) mydb.add_wafer_entry(wafer_coord, wafer) self.assertTrue(mydb.has_wafer_entry(wafer_coord)) self.assertEqual(mydb.get_wafer_entry(wafer_coord).setup_type, wafer.setup_type) wafer_coords = mydb.get_wafer_coordinates() self.assertEqual(len(wafer_coords), 1) mydb.remove_wafer_entry(wafer_coord) self.assertFalse(mydb.has_wafer_entry(wafer_coord)) dls_entry = pyhwdb.DLSSetupEntry() dls_setup_id = self.DLS_SETUP_ID self.assertFalse(mydb.has_dls_entry(dls_setup_id)) mydb.add_dls_entry(dls_setup_id, dls_entry) self.assertTrue(mydb.has_dls_entry(dls_setup_id)) mydb.remove_dls_entry(dls_setup_id) self.assertFalse(mydb.has_dls_entry(dls_setup_id)) if not IS_PYPLUSPLUS: hxcube_entry = pyhwdb.HXCubeSetupEntry() hxcube_id = self.HXCUBE_ID hxcube_entry.hxcube_id = hxcube_id hxcube_entry.usb_host = "fantasy" hxcube_entry.usb_serial = "ABACD1243" fpga_entry = pyhwdb.HXCubeFPGAEntry() fpga_entry.ip = self.FPGA_IP wing_entry = pyhwdb.HXCubeWingEntry() wing_entry.ldo_version = 8 wing_entry.eeprom_chip_serial = 0x987DE wing_entry.handwritten_chip_serial = 12 wing_entry.chip_revision = 42 fpga_entry.wing = wing_entry fpga_entry2 = pyhwdb.HXCubeFPGAEntry() hxcube_entry.fpgas = {0: fpga_entry, 3: fpga_entry2} self.assertFalse(mydb.has_hxcube_setup_entry(hxcube_id)) mydb.add_hxcube_setup_entry(hxcube_id, hxcube_entry) self.assertTrue(mydb.has_hxcube_setup_entry(hxcube_id)) mydb.remove_hxcube_setup_entry(hxcube_id) self.assertFalse(mydb.has_hxcube_setup_entry(hxcube_id)) self.assertEqual(hxcube_entry.get_unique_branch_identifier(12), "hxcube9fpga0chip12_1") with self.assertRaises(RuntimeError): hxcube_entry.get_unique_branch_identifier(108) if IS_PYPLUSPLUS: # require wafer entry to write other entry typed into mydb.add_wafer_entry(wafer_coord, wafer) fpga = pyhwdb.FPGAEntry() fpga_coord = coord.FPGAGlobal(self.FPGA_COORD, self.WAFER_COORD) fpga.ip = self.FPGA_IP self.assertFalse(mydb.has_fpga_entry(fpga_coord)) mydb.add_fpga_entry(fpga_coord, fpga) self.assertTrue(mydb.has_fpga_entry(fpga_coord)) self.assertEqual(mydb.get_fpga_entry(fpga_coord).ip, fpga.ip) mydb.remove_fpga_entry(fpga_coord) self.assertFalse(mydb.has_fpga_entry(fpga_coord)) reticle = pyhwdb.ReticleEntry() reticle_coord = coord.DNCGlobal(self.RETICLE_COORD, self.WAFER_COORD) reticle.to_be_powered = self.RETICLE_TO_BE_POWERED self.assertFalse(mydb.has_reticle_entry(reticle_coord)) mydb.add_reticle_entry(reticle_coord, reticle) self.assertTrue(mydb.has_reticle_entry(reticle_coord)) self.assertEqual(mydb.get_reticle_entry(reticle_coord).to_be_powered, reticle.to_be_powered) mydb.remove_reticle_entry(reticle_coord) self.assertFalse(mydb.has_reticle_entry(reticle_coord)) # require fpga entry to add hicann entry mydb.add_fpga_entry(fpga_coord, fpga) hicann = pyhwdb.HICANNEntry() hicann_coord = coord.HICANNGlobal(self.HICANN_COORD, self.WAFER_COORD) hicann.version = self.HICANN_VERSION self.assertFalse(mydb.has_hicann_entry(hicann_coord)) mydb.add_hicann_entry(hicann_coord, hicann) self.assertTrue(mydb.has_hicann_entry(hicann_coord)) self.assertEqual(mydb.get_hicann_entry(hicann_coord).version, hicann.version) mydb.remove_hicann_entry(hicann_coord) self.assertFalse(mydb.has_hicann_entry(hicann_coord)) # test clear() mydb.add_hicann_entry(hicann_coord, hicann) mydb.clear() self.assertFalse(mydb.has_hicann_entry(hicann_coord)) self.assertFalse(mydb.has_fpga_entry(fpga_coord)) self.assertFalse(mydb.has_wafer_entry(wafer_coord))
def test_default_path_valid(self): db = pyhwdb.database() default_path = db.get_default_path() self.assertTrue(os.path.exists(default_path)) db.load(default_path)