diff --git a/spinnman/model/cpu_info.py b/spinnman/model/cpu_info.py index 101db2fd0..51362c003 100644 --- a/spinnman/model/cpu_info.py +++ b/spinnman/model/cpu_info.py @@ -329,3 +329,24 @@ def __str__(self): return "{}:{}:{:02n} ({:02n}) {:18} {:16s} {:3n}".format( self.x, self.y, self.p, self.physical_cpu_id, self._state.name, self._application_name, self._application_id) + + def get_status_string(self): + """ + Get a string indicating the status of the given core. + + :rtype: str + """ + if self.state == CPUState.RUN_TIME_EXCEPTION: + return ( + f"{self._x}:{self._y}:{self._p} " + f"(ph: {self._physical_cpu_id}) " + f"in state {self._state.name}:{self._run_time_error.name}\n" + f" r0={self._registers[0]}, r1={self._registers[1]}, " + f"r2={self._registers[2]}, r3={self._registers[3]}\n" + f" r4={self._registers[4]}, r5={self._registers[5]}, " + f"r6={self._registers[6]}, r7={self._registers[7]}\n" + f" PSR={self._processor_state_register}, " + f"SP={self._stack_pointer}, LR={self._link_register}\n") + else: + return ( + f"{self._x}:{self._y}:{self._p} in state {self._state.name}\n") diff --git a/spinnman/model/cpu_infos.py b/spinnman/model/cpu_infos.py index 181d8cc51..3903cb186 100644 --- a/spinnman/model/cpu_infos.py +++ b/spinnman/model/cpu_infos.py @@ -128,24 +128,9 @@ def get_status_string(self): :param CPUInfos cpu_infos: A CPUInfos objects :rtype: str """ - break_down = "\n" - for (x, y, p), core_info in self.cpu_infos: - if core_info.state == CPUState.RUN_TIME_EXCEPTION: - break_down += " {}:{}:{} (ph: {}) in state {}:{}\n".format( - x, y, p, core_info.physical_cpu_id, core_info.state.name, - core_info.run_time_error.name) - break_down += " r0={}, r1={}, r2={}, r3={}\n".format( - core_info.registers[0], core_info.registers[1], - core_info.registers[2], core_info.registers[3]) - break_down += " r4={}, r5={}, r6={}, r7={}\n".format( - core_info.registers[4], core_info.registers[5], - core_info.registers[6], core_info.registers[7]) - break_down += " PSR={}, SP={}, LR={}\n".format( - core_info.processor_state_register, - core_info.stack_pointer, core_info.link_register) - else: - break_down += " {}:{}:{} in state {}\n".format( - x, y, p, core_info.state.name) + break_down = "" + for core_info in self._cpu_infos.values(): + break_down += core_info.get_status_string() return break_down def __str__(self): diff --git a/unittests/model_tests/test_cpu_infos.py b/unittests/model_tests/test_cpu_infos.py index 37dbcc294..370f70f45 100644 --- a/unittests/model_tests/test_cpu_infos.py +++ b/unittests/model_tests/test_cpu_infos.py @@ -43,9 +43,12 @@ def test_cpu_infos(self): infos.add_info(info) info = CPUInfo(1, 0, 1, self.make_info_data(7, CPUState.FINISHED)) infos.add_info(info) + info = CPUInfo(1, 1, 2, self.make_info_data(4, CPUState.RUN_TIME_EXCEPTION)) + infos.add_info(info) + self.assertSetEqual(set(infos), {(1, 0, 1), (0, 0, 1), (0, 0, 2), (1, 1, 2)}) self.assertEqual( - "['0, 0, 1 (ph: 5)', '0, 0, 2 (ph: 6)', '1, 0, 1 (ph: 7)']", + "['0, 0, 1 (ph: 5)', '0, 0, 2 (ph: 6)', '1, 0, 1 (ph: 7)', '1, 1, 2 (ph: 4)']", str(infos)) finished = infos.infos_for_state(CPUState.FINISHED) @@ -60,9 +63,14 @@ def test_cpu_infos(self): self.assertEqual( "0:0:02 (06) FINISHED scamp-3 0", str(info)) - a = set(infos) - b = str(a) - print(b) + self.assertEqual(infos.get_status_string(), + "0:0:1 in state RUNNING\n" + "0:0:2 in state FINISHED\n" + "1:0:1 in state FINISHED\n" + "1:1:2 (ph: 4) in state RUN_TIME_EXCEPTION:NONE\n" + " r0=134676544, r1=255, r2=8388608, r3=173\n" + " r4=0, r5=0, r6=0, r7=0\n" + " PSR=0, SP=0, LR=0\n") if __name__ == '__main__':