1+ /* *
2+ * Copyright (C) Advanced Micro Devices, Inc. 2025. ALL RIGHTS RESERVED.
3+ * See file LICENSE for terms.
4+ */
5+ #include < common/test.h>
6+ #include < cstdint>
7+ #include " uct/sm/mm/base/mm_iface.h"
8+ #include " uct/sm/mm/base/mm_ep.h"
9+
10+ namespace {
11+
12+ static constexpr uint64_t EA = UCT_MM_IFACE_FIFO_HEAD_EVENT_ARMED;
13+
14+ /* Practical upper bound for head/tail in real deployments: 2^62.
15+ * Rationale: head advances roughly once per nanosecond in the worst case.
16+ * The signed-63 midpoint is 2^62 (~4.61e18). At 1 tick/ns, reaching 2^62
17+ * takes ~146 years. Therefore tests cap counters at <= 2^62 to reflect
18+ * realistic long-running processes while still exercising wrap-related logic.
19+ */
20+ static constexpr uint64_t LIM = 1ull << 62 ;
21+ /* 2^31 constant to guard against regressions to 32-bit comparisons */
22+ static constexpr uint64_t POW2_31 = 1ull << 31 ;
23+
24+ struct case_item {
25+ const char *name;
26+ uint64_t head;
27+ uint64_t tail;
28+ unsigned fifo;
29+ bool expect;
30+ };
31+
32+ static const case_item k_cases[] = {
33+ /* head < tail */
34+ {" lt:<fifo" , 512 , 600 , 256 , true },
35+ {" lt:==fifo" , 512 , 768 , 256 , true },
36+ {" lt:>fifo" , 512 , 900 , 256 , true },
37+ {" EA lt:<fifo" , EA | 512 , 600 , 256 , true },
38+ {" EA lt:==fifo" , EA | 512 , 768 , 256 , true },
39+ {" EA lt:>fifo" , EA | 512 , 900 , 256 , true },
40+
41+ /* head > tail */
42+ {" gt:<fifo" , 100 , 0 , 256 , true },
43+ {" gt:==fifo" , 256 , 0 , 256 , false },
44+ {" gt:>fifo" , 300 , 0 , 256 , false },
45+ {" EA gt:<fifo" , EA | 100 , 0 , 256 , true },
46+ {" EA gt:==fifo" , EA | 256 , 0 , 256 , false },
47+ {" EA gt:>fifo" , EA | 300 , 0 , 256 , false },
48+
49+ /* Large deltas around 2^31 to catch regressions to 32-bit compare */
50+ {" gt:d=2^31-1@t0" , POW2_31 - 1ull , 0 , 256 , false },
51+ {" gt:d=2^31@t0" , POW2_31, 0 , 256 , false },
52+ {" gt:d=2^31+1@t0" , POW2_31 + 1ull , 0 , 256 , false },
53+ {" EA gt:d=2^31@t0" , EA | POW2_31, 0 , 256 , false },
54+
55+ /* head == tail */
56+ {" eq:zero" , 0 , 0 , 256 , true },
57+ {" eq:EA" , EA, 0 , 256 , true },
58+
59+ /* Around 2^62 boundaries (head < tail deltas) */
60+ {" lt:2^62-1" , 512 , 512 + LIM - 1 , 256 , true },
61+ {" lt:2^62" , 512 , 512 + LIM, 256 , true },
62+ {" lt:2^62+1" , 512 , 512 + LIM + 1 , 256 , true },
63+
64+ /* Special tail at MSB (robustness) */
65+ {" tailEA:+255" , 0xff , EA, 256 , true },
66+ {" tailEA:+256" , 0x100 , EA, 256 , true },
67+
68+ /* Practical cap at 2^62 */
69+ {" cap:eq" , LIM, LIM, 256 , true },
70+ {" cap:eq EA" , EA | LIM, LIM, 256 , true }
71+ };
72+
73+ }
74+
75+ class test_mm_fifo_room : public ucs ::test {
76+ protected:
77+ void check_case (const case_item &c) {
78+ bool got = UCT_MM_EP_IS_ABLE_TO_SEND (c.head , c.tail , c.fifo );
79+ EXPECT_EQ (c.expect , got) << c.name ;
80+ }
81+ };
82+
83+ UCS_TEST_F (test_mm_fifo_room, predicate_matrix) {
84+ for (const auto &c : k_cases) {
85+ check_case (c);
86+ }
87+
88+ }
0 commit comments