def _extract_iobuf(expander_cores, transceiver, provenance_file_path, display=False): """ Extract IOBuf from the cores """ io_buffers = transceiver.get_iobuf(expander_cores.all_core_subsets) core_to_replacer = dict() for binary in expander_cores.binaries: replacer = Replacer(binary) for core_subset in expander_cores.get_cores_for_binary(binary): x = core_subset.x y = core_subset.y for p in core_subset.processor_ids: core_to_replacer[x, y, p] = replacer for io_buf in io_buffers: file_path = os.path.join( provenance_file_path, "expander_{}_{}_{}.txt".format(io_buf.x, io_buf.y, io_buf.p)) replacer = core_to_replacer[io_buf.x, io_buf.y, io_buf.p] text = "" for line in io_buf.iobuf.split("\n"): text += replacer.replace(line) + "\n" with open(file_path, "w") as writer: writer.write(text) if display: print("{}:{}:{} {}".format(io_buf.x, io_buf.y, io_buf.p, text))
def _run_for_core_subsets(self, core_subsets, binary, transceiver, provenance_file_path, error_entries, warn_entries): replacer = Replacer(binary) # extract iobuf io_buffers = list(transceiver.get_iobuf(core_subsets)) # write iobuf for iobuf in io_buffers: file_name = os.path.join( provenance_file_path, "iobuf_for_chip_{}_{}_processor_id_{}.txt".format( iobuf.x, iobuf.y, iobuf.p)) # set mode of the file based off if the file already exists mode = "w" if os.path.exists(file_name): mode = "a" # write iobuf to file. with open(file_name, mode) as f: for line in iobuf.iobuf.split("\n"): f.write(replacer.replace(line)) f.write("\n") self._check_iobuf_for_error(iobuf, error_entries, warn_entries)
def _run_for_core_subsets( self, core_subsets, binary, transceiver, provenance_file_path, error_entries, warn_entries): replacer = Replacer(binary) # extract iobuf io_buffers = list(transceiver.get_iobuf(core_subsets)) # write iobuf for iobuf in io_buffers: file_name = os.path.join( provenance_file_path, "iobuf_for_chip_{}_{}_processor_id_{}.txt".format( iobuf.x, iobuf.y, iobuf.p)) # set mode of the file based off if the file already exists mode = "w" if os.path.exists(file_name): mode = "a" # write iobuf to file and call out errors and warnings. with open(file_name, mode) as f: for line in iobuf.iobuf.split("\n"): replaced = replacer.replace(line) f.write(replaced) f.write("\n") self._add_value_if_match( ERROR_ENTRY, replaced, error_entries, iobuf) self._add_value_if_match( WARNING_ENTRY, replaced, warn_entries, iobuf)
def _run_for_core_subsets( self, core_subsets, binary, transceiver, provenance_file_path, error_entries, warn_entries): replacer = Replacer(binary) # extract iobuf if self._recovery_mode: io_buffers = self.__recover_iobufs(transceiver, core_subsets) else: io_buffers = list(transceiver.get_iobuf(core_subsets)) # write iobuf for iobuf in io_buffers: file_name = os.path.join( provenance_file_path, self._filename_template.format(iobuf.x, iobuf.y, iobuf.p)) # set mode of the file based off if the file already exists mode = "a" if os.path.exists(file_name) else "w" # write iobuf to file and call out errors and warnings. with open(file_name, mode) as f: for line in iobuf.iobuf.split("\n"): replaced = replacer.replace(line) f.write(replaced) f.write("\n") self.__add_value_if_match( ERROR_ENTRY, replaced, error_entries, iobuf) self.__add_value_if_match( WARNING_ENTRY, replaced, warn_entries, iobuf)
def _extract_iobuf(expander_cores, transceiver, provenance_file_path, display=False): """ Extract IOBuf from the cores """ io_buffers = transceiver.get_iobuf(expander_cores.all_core_subsets) core_to_replacer = dict() for binary in expander_cores.binaries: replacer = Replacer(binary) for core_subset in expander_cores.get_cores_for_binary(binary): x = core_subset.x y = core_subset.y for p in core_subset.processor_ids: core_to_replacer[x, y, p] = replacer for io_buf in io_buffers: file_path = os.path.join( provenance_file_path, "expander_{}_{}_{}.txt".format( io_buf.x, io_buf.y, io_buf.p)) replacer = core_to_replacer[io_buf.x, io_buf.y, io_buf.p] text = "" for line in io_buf.iobuf.split("\n"): text += replacer.replace(line) + "\n" with open(file_path, "w") as writer: writer.write(text) if display: print("{}:{}:{} {}".format(io_buf.x, io_buf.y, io_buf.p, text))
def test_hexes_to_double(self): """ Test the convertor against hexes values returned from Spinnaker """ replacer = Replacer(os.path.join(PATH, "test")) assert self.near_equals( 0, replacer._hexes_to_double("0", "0")) assert self.near_equals( 455424364531.3463460, replacer._hexes_to_double("425a825a", "13fcd62b")) assert self.near_equals( -455424364531.3463460, replacer._hexes_to_double("c25a825a", "13fcd62b")) assert self.near_equals( 23.60, replacer._hexes_to_double("40379999", "9999999a")) assert self.near_equals( -1, replacer._hexes_to_double("bff00000", "0")) assert self.near_equals( 1, replacer._hexes_to_double("3ff00000", "0")) assert self.near_equals( 0.0000000004, replacer._hexes_to_double("3dfb7cdf", "d9d7bdbb"))
def __extract_iobufs_for_binary( self, core_subsets, binary, error_entries, warn_entries): """ :param ~.CoreSubsets core_subsets: Where the binary is deployed :param str binary: What binary was deployed there. This is used to determine how to decompress the IOBUF output. :param list(str) error_entries: :param list(str) warn_entries: """ replacer = Replacer(binary) prov_path = self.__prov_path(binary) # extract iobuf if self._recovery_mode: io_buffers = self.__recover_iobufs(core_subsets) else: io_buffers = list(self.__transceiver.get_iobuf(core_subsets)) # write iobuf for iobuf in io_buffers: self.__process_one_iobuf(iobuf, prov_path, replacer, error_entries, warn_entries)
def test_hex_to_float(self): """ Test the convertor against hex values returned from Spinnaker """ replacer = Replacer(os.path.join(PATH, "test")) assert self.near_equals( -345443332234.13432143, replacer._hex_to_float("d2a0dc0e")) assert self.near_equals( -2000, replacer._hex_to_float("c4fa0000")) assert self.near_equals( -1, replacer._hex_to_float("bf800000")) assert self.near_equals( 0, replacer._hex_to_float("0")) assert self.near_equals( 0.00014, replacer._hex_to_float("3912ccf7")) assert self.near_equals( 1, replacer._hex_to_float("3f800000")) assert self.near_equals( 200, replacer._hex_to_float("43480000")) assert self.near_equals( 455424364531.3463460, replacer._hex_to_float("52d412d1")) assert float("Inf") == replacer._hex_to_float("7f800000") assert 0-float("Inf") == replacer._hex_to_float("ff800000") assert math.isnan(replacer._hex_to_float("7fc00000"))
def test_bad(self): replacer = Replacer(os.path.join(PATH, "test")) new = replacer.replace("1007" + TOKEN + "10") # An exception so just output the input message = "1007" + TOKEN + "10" assert (message == new)
def test_double(self): replacer = Replacer(os.path.join(PATH, "test")) new = replacer.replace( "1022" + TOKEN + "40379999" + TOKEN + "9999999a") message = "[INFO] (weird;file.c: 34): a double 23.6" assert (message == new)
def test_float(self): replacer = Replacer(os.path.join(PATH, "test")) new = replacer.replace("1021" + TOKEN + "3f800000") message = "[INFO] (weird;file.c: 32): a float 1.0" assert (message == new)
def test_tab(self): replacer = Replacer(os.path.join(PATH, "test")) new = replacer.replace("1007" + TOKEN + "10" + TOKEN + "20") message = "[INFO] (weird;file.c: 29): \t back off = 10, time between"\ " spikes 20" assert (message == new)
def test_not_extension(self): replacer = Replacer(os.path.join(PATH, "test")) new = replacer.replace("1014" + TOKEN + "123") assert ("[INFO] (weird;file.c: 47): second 123" == new)
def test_not_there(self): replacer = Replacer("not_there.pointer") assert ("1001" == replacer.replace("1001"))
def test_replacer(self): replacer = Replacer(os.path.join(PATH, "test.aplx")) new = replacer.replace("1001") assert ("[INFO] (weird;file.c: 9): this is ok" == new)