From 31e8fb071f31dd12843a7bb1b1b3cac6776161e9 Mon Sep 17 00:00:00 2001 From: Orual Date: Sat, 7 Mar 2026 12:39:15 -0500 Subject: [PATCH] test: add test for tag_store JSON serialisation with non-empty entries Add two tests in TestTagStoreSerialisation class that verify the new tag_store JSON serialisation format for non-empty tag stores: - test_non_empty_tag_store_serialization: Single entry {0: (2, 1)} - test_multiple_entries_tag_store_serialization: Multiple entries with different act_id values and lane assignments These tests verify that: - tag_store entries are serialized as {"act_id_str": {"frame_id": N, "lane": M}} - lane_count is present in the PE state JSON - All entries are correctly converted to string keys and nested objects Fixes: No test asserts the new tag_store JSON serialisation format for non-empty tag stores (Phase 5 code review issue) --- tests/test_monitor_graph_json.py | 92 ++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) 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.""" -- 2.51.2