diff --git a/tests/test_monitor_graph_json.py b/tests/test_monitor_graph_json.py index f9e958f..1b40ee9 100644 --- a/tests/test_monitor_graph_json.py +++ b/tests/test_monitor_graph_json.py @@ -484,6 +484,98 @@ class TestGraphJsonFinished: assert result["finished"] is True +class TestTagStoreSerialisation: + """Test non-empty tag_store JSON serialization in PE state.""" + + def test_non_empty_tag_store_serialization(self): + """Test that tag_store with non-empty mapping serializes correctly.""" + node = IRNode( + name="&add", + opcode=ArithOp.ADD, + pe=0, + iram_offset=0, + act_id=0, + ) + ir_graph = IRGraph(nodes={"&add": node}) + + inst = Instruction(opcode=ArithOp.ADD, output=OutputStyle.INHERIT, has_const=False, dest_count=2, wide=False, fref=0) + + # Create PESnapshot with non-empty tag_store: act_id 0 maps to frame 2, lane 1 + pe_snap = PESnapshot( + pe_id=0, + iram={0: inst}, + frames=(), + tag_store={0: (2, 1)}, # act_id=0 -> (frame_id=2, lane=1) + presence=(), + port_store=(), + match_data=(), + free_frames=(), + lane_count=4, + input_queue=(), + output_log=(), + ) + snapshot = StateSnapshot( + sim_time=0.0, + next_time=1.0, + pes={0: pe_snap}, + sms={}, + ) + + result = graph_loaded_json(ir_graph, snapshot) + pe_state = result["state"]["pes"]["0"] + + # Verify tag_store is correctly serialized + assert "tag_store" in pe_state + assert "0" in pe_state["tag_store"] # act_id 0 should be a string key "0" + assert pe_state["tag_store"]["0"]["frame_id"] == 2 + assert pe_state["tag_store"]["0"]["lane"] == 1 + assert pe_state["lane_count"] == 4 + + def test_multiple_entries_tag_store_serialization(self): + """Test tag_store with multiple act_id entries serializes correctly.""" + ir_graph = IRGraph() + + inst = Instruction(opcode=ArithOp.ADD, output=OutputStyle.INHERIT, has_const=False, dest_count=2, wide=False, fref=0) + + # Create PESnapshot with multiple tag_store entries + pe_snap = PESnapshot( + pe_id=0, + iram={0: inst}, + frames=(), + tag_store={ + 0: (2, 1), + 1: (3, 0), + 5: (7, 2), + }, + presence=(), + port_store=(), + match_data=(), + free_frames=(), + lane_count=4, + input_queue=(), + output_log=(), + ) + snapshot = StateSnapshot( + sim_time=0.0, + next_time=1.0, + pes={0: pe_snap}, + sms={}, + ) + + result = graph_loaded_json(ir_graph, snapshot) + pe_state = result["state"]["pes"]["0"] + + # Verify all entries are correctly serialized + assert "tag_store" in pe_state + assert pe_state["tag_store"]["0"]["frame_id"] == 2 + assert pe_state["tag_store"]["0"]["lane"] == 1 + assert pe_state["tag_store"]["1"]["frame_id"] == 3 + assert pe_state["tag_store"]["1"]["lane"] == 0 + assert pe_state["tag_store"]["5"]["frame_id"] == 7 + assert pe_state["tag_store"]["5"]["lane"] == 2 + assert pe_state["lane_count"] == 4 + + class TestAC72_NewEventTypesSerialization: """AC7.2: Verify new frame-based event types serialize correctly to JSON."""