|
5 | 5 | #include "foundation/compat.h" |
6 | 6 | #include "foundation/constants.h" |
7 | 7 | #include "foundation/index_policy.h" |
| 8 | +#include "foundation/log.h" |
8 | 9 | #include "mcp/index_supervisor.h" |
9 | 10 | #include "mcp/mcp.h" |
10 | 11 | #include "mcp/mcp_internal.h" |
@@ -153,22 +154,43 @@ TEST(index_policy_explicit_override_and_off_replace_profile_dimensions) { |
153 | 154 | PASS(); |
154 | 155 | } |
155 | 156 |
|
| 157 | +static char g_host_clamp_log[512]; |
| 158 | + |
| 159 | +static void capture_host_clamp_log(const char *line) { |
| 160 | + (void)snprintf(g_host_clamp_log, sizeof(g_host_clamp_log), "%s", line ? line : ""); |
| 161 | +} |
| 162 | + |
156 | 163 | TEST(index_policy_host_clamp_only_tightens_explicit_rss) { |
157 | 164 | cbm_index_resource_policy_t policy; |
158 | 165 | cbm_index_policy_init(&policy); |
159 | 166 | char error[256]; |
| 167 | + CBMLogLevel saved_level = cbm_log_get_level(); |
160 | 168 |
|
161 | 169 | ASSERT_TRUE( |
162 | 170 | cbm_index_policy_set(&policy, CBM_INDEX_CONFIG_MAX_RSS_MB, "4096", error, sizeof(error))); |
| 171 | + g_host_clamp_log[0] = '\0'; |
| 172 | + cbm_log_set_level(CBM_LOG_WARN); |
| 173 | + cbm_log_set_sink(capture_host_clamp_log); |
163 | 174 | cbm_index_policy_finalize(&policy, UINT64_C(2048) * CBM_INDEX_MIB_BYTES, 0); |
| 175 | + cbm_log_set_sink(NULL); |
| 176 | + cbm_log_set_level(saved_level); |
164 | 177 | ASSERT_EQ(policy.max_rss_bytes.value, |
165 | 178 | (UINT64_C(2048) * CBM_INDEX_MIB_BYTES * UINT64_C(4)) / UINT64_C(5)); |
| 179 | + ASSERT_NOT_NULL(strstr(g_host_clamp_log, "index.policy.host_rss_clamp")); |
| 180 | + ASSERT_NOT_NULL(strstr(g_host_clamp_log, "requested_bytes=4294967296")); |
| 181 | + ASSERT_NOT_NULL(strstr(g_host_clamp_log, "applied_bytes=1717986918")); |
166 | 182 |
|
167 | 183 | cbm_index_policy_init(&policy); |
168 | 184 | ASSERT_TRUE( |
169 | 185 | cbm_index_policy_set(&policy, CBM_INDEX_CONFIG_MAX_RSS_MB, "512", error, sizeof(error))); |
| 186 | + g_host_clamp_log[0] = '\0'; |
| 187 | + cbm_log_set_level(CBM_LOG_WARN); |
| 188 | + cbm_log_set_sink(capture_host_clamp_log); |
170 | 189 | cbm_index_policy_finalize(&policy, UINT64_C(2048) * CBM_INDEX_MIB_BYTES, 0); |
| 190 | + cbm_log_set_sink(NULL); |
| 191 | + cbm_log_set_level(saved_level); |
171 | 192 | ASSERT_EQ(policy.max_rss_bytes.value, UINT64_C(512) * CBM_INDEX_MIB_BYTES); |
| 193 | + ASSERT_EQ(g_host_clamp_log[0], '\0'); |
172 | 194 | PASS(); |
173 | 195 | } |
174 | 196 |
|
|
0 commit comments