|
| 1 | +// Issue #45 Step 1: DeviceProfileData carries server-measured fields. |
| 2 | +// |
| 3 | +// Locks in two contracts: |
| 4 | +// - Legacy payloads (without measured_* fields) deserialize cleanly, |
| 5 | +// leaving the new optional fields at their default value 0. |
| 6 | +// - Round-tripping a struct with measured_* set preserves all 12 fields. |
| 7 | + |
| 8 | +#include <gtest/gtest.h> |
| 9 | + |
| 10 | +#include <memory> |
| 11 | + |
| 12 | +#include "backend/serialization_buffer.h" |
| 13 | +#include "backend/server_base.h" |
| 14 | + |
| 15 | +namespace { |
| 16 | + |
| 17 | +DeviceProfileData LegacyProfile() { |
| 18 | + DeviceProfileData p{}; |
| 19 | + p.uuid = 0x1122334455667788ULL; |
| 20 | + p.flops = 100000000000ULL; |
| 21 | + p.memory = 16ULL * 1024 * 1024 * 1024; |
| 22 | + p.ul_bw = 10ULL * 1024 * 1024 * 1024; |
| 23 | + p.dl_bw = 10ULL * 1024 * 1024 * 1024; |
| 24 | + p.ul_lat = 1000; |
| 25 | + p.dl_lat = 1000; |
| 26 | + return p; |
| 27 | +} |
| 28 | + |
| 29 | +TEST(DeviceProfileDataRoundtrip, LegacyFieldsOnly) { |
| 30 | + DeviceProfileData src = LegacyProfile(); |
| 31 | + auto buf = src.Serialize(); |
| 32 | + ASSERT_TRUE(buf != nullptr); |
| 33 | + |
| 34 | + DeviceProfileData dst{}; |
| 35 | + dst.Deserialize(buf->GetBuffer(), buf->GetSize()); |
| 36 | + |
| 37 | + EXPECT_EQ(dst.uuid, src.uuid); |
| 38 | + EXPECT_EQ(dst.flops, src.flops); |
| 39 | + EXPECT_EQ(dst.memory, src.memory); |
| 40 | + EXPECT_EQ(dst.ul_bw, src.ul_bw); |
| 41 | + EXPECT_EQ(dst.dl_bw, src.dl_bw); |
| 42 | + EXPECT_EQ(dst.ul_lat, src.ul_lat); |
| 43 | + EXPECT_EQ(dst.dl_lat, src.dl_lat); |
| 44 | + |
| 45 | + // New optional fields default to 0 when sender omits them. |
| 46 | + EXPECT_EQ(dst.measured_flops, 0ULL); |
| 47 | + EXPECT_EQ(dst.measured_lat_ns, 0ULL); |
| 48 | + EXPECT_EQ(dst.measured_ul_bw_bps, 0ULL); |
| 49 | + EXPECT_EQ(dst.measured_dl_bw_bps, 0ULL); |
| 50 | + EXPECT_FALSE(dst.measured_flops_verified); |
| 51 | +} |
| 52 | + |
| 53 | +TEST(DeviceProfileDataRoundtrip, LegacyPlusMeasured) { |
| 54 | + DeviceProfileData src = LegacyProfile(); |
| 55 | + src.measured_flops = 95000000000ULL; |
| 56 | + src.measured_flops_verified = true; |
| 57 | + src.measured_lat_ns = 250000ULL; |
| 58 | + src.measured_ul_bw_bps = 9ULL * 1024 * 1024 * 1024; |
| 59 | + src.measured_dl_bw_bps = 8ULL * 1024 * 1024 * 1024; |
| 60 | + |
| 61 | + auto buf = src.Serialize(); |
| 62 | + ASSERT_TRUE(buf != nullptr); |
| 63 | + |
| 64 | + DeviceProfileData dst{}; |
| 65 | + dst.Deserialize(buf->GetBuffer(), buf->GetSize()); |
| 66 | + |
| 67 | + EXPECT_EQ(dst.uuid, src.uuid); |
| 68 | + EXPECT_EQ(dst.measured_flops, src.measured_flops); |
| 69 | + EXPECT_TRUE(dst.measured_flops_verified); |
| 70 | + EXPECT_EQ(dst.measured_lat_ns, src.measured_lat_ns); |
| 71 | + EXPECT_EQ(dst.measured_ul_bw_bps, src.measured_ul_bw_bps); |
| 72 | + EXPECT_EQ(dst.measured_dl_bw_bps, src.measured_dl_bw_bps); |
| 73 | +} |
| 74 | + |
| 75 | +TEST(DeviceProfileDataRoundtrip, DebugStringMentionsMeasuredWhenSet) { |
| 76 | + DeviceProfileData src = LegacyProfile(); |
| 77 | + src.measured_flops = 95000000000ULL; |
| 78 | + src.measured_flops_verified = true; |
| 79 | + |
| 80 | + const auto s = src.DebugString(); |
| 81 | + EXPECT_NE(s.find("measured_flops"), std::string::npos); |
| 82 | + EXPECT_NE(s.find("95000000000"), std::string::npos); |
| 83 | +} |
| 84 | + |
| 85 | +} // namespace |
0 commit comments