Conservative SmartOS global-zone memory pressure guard with dry-run-first policy and SMF integration.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

369 lignes
20 KiB

  1. /* Exercise the actual daemon selection/action path. Native backend NOT linked. */
  2. #define main guard_program_main
  3. #include "../src/main.c"
  4. #undef main
  5. static double fake_now = 100;
  6. static sample_t fake_sample;
  7. static process_t fixtures[32];
  8. static unsigned nfixtures, real_requests, validation_requests, walk_requests, checks;
  9. static int fail_validation, fail_sample, partial, invalid_pid;
  10. typedef struct { int priority; char message[1536]; } syslog_record_t;
  11. static syslog_record_t syslog_records[64];
  12. static unsigned syslog_count, syslog_open_count, syslog_close_count;
  13. static int syslog_facility, fail_syslog;
  14. static char syslog_ident[64];
  15. #define CHECK(x) do { if (!(x)) { fprintf(stderr, "FAIL runtime line %d: %s\n", __LINE__, #x); exit(1); } checks++; } while (0)
  16. double monotime(void) { return fake_now; }
  17. int secure_file(const char *p, int flags, unsigned mode)
  18. { (void)p; (void)flags; (void)mode; errno = EPERM; return -1; }
  19. int secure_directory(const char *p) { (void)p; return -1; }
  20. int platform_init(void) { return 0; }
  21. void platform_fini(void) { }
  22. int platform_syslog_open(const char *ident, int facility)
  23. {
  24. syslog_open_count++; syslog_facility = facility;
  25. snprintf(syslog_ident, sizeof (syslog_ident), "%s", ident);
  26. return fail_syslog ? -1 : 0;
  27. }
  28. int platform_syslog_write(int priority, const char *message)
  29. {
  30. if (fail_syslog) { errno = EIO; return -1; }
  31. CHECK(syslog_count < sizeof (syslog_records) / sizeof (syslog_records[0]));
  32. syslog_records[syslog_count].priority = priority;
  33. snprintf(syslog_records[syslog_count].message,
  34. sizeof (syslog_records[syslog_count].message), "%s", message);
  35. syslog_count++;
  36. return 0;
  37. }
  38. void platform_syslog_close(void) { syslog_close_count++; }
  39. int platform_sample(sample_t *s)
  40. { *s = fake_sample; s->at = fake_now; return fail_sample ? -1 : 0; }
  41. int platform_walk(int (*fn)(const process_t *, void *), void *arg, unsigned budget)
  42. {
  43. unsigned j; (void)budget;
  44. walk_requests++;
  45. for (j = 0; j < nfixtures; j++) if (fn(&fixtures[j], arg)) return -1;
  46. return partial ? -1 : 0;
  47. }
  48. int platform_signal(const config_t *c, const process_t *p, enum action action,
  49. int real, uint64_t ceiling)
  50. {
  51. unsigned j; int found = 0;
  52. CHECK(action == TERM || action == KILL);
  53. CHECK(!protected_process(c, p));
  54. for (j = 0; j < nfixtures; j++)
  55. if (fixtures[j].pid == p->pid && same_process(&fixtures[j], p)) { found = 1; break; }
  56. if (real) { CHECK(c->armed && fake_sample.free < ceiling); real_requests++; }
  57. else validation_requests++;
  58. if (fail_validation || p->pid == invalid_pid || !found) { errno = ESTALE; return -1; }
  59. return 0; /* This test backend cannot send any signal. */
  60. }
  61. static void reset(void)
  62. {
  63. defaults(&cfg); cfg.log_mib = 100;
  64. cfg.nzones = 2;
  65. strcpy(cfg.zones[0].uuid, "11111111-1111-4111-8111-111111111111");
  66. strcpy(cfg.zones[0].alias, "web-a"); cfg.zones[0].policy = ALLOW;
  67. strcpy(cfg.zones[1].uuid, "22222222-2222-4222-8222-222222222222");
  68. strcpy(cfg.zones[1].alias, "web-b"); cfg.zones[1].policy = ALLOW;
  69. memset(processes, 0, sizeof (processes)); memset(zone_stats, 0, sizeof (zone_stats));
  70. memset(candidate_cache, 0, sizeof (candidate_cache));
  71. memset(metrics, 0, sizeof (metrics));
  72. memset(&controller, 0, sizeof (controller)); memset(fixtures, 0, sizeof (fixtures));
  73. engine_init(&engine); engine.state = CRITICAL; engine.danger = 1;
  74. stopping = 0; started = 0; log_ok = 1; log_bytes = 0;
  75. syslog_ready = syslog_init_failed = 0;
  76. syslog_count = syslog_open_count = syslog_close_count = 0;
  77. syslog_facility = -1; fail_syslog = 0; syslog_ident[0] = 0;
  78. scan_generation = 0; scan_complete = 0; latest_complete_scan_at = 0;
  79. fake_now = 100; partial = fail_sample = fail_validation = invalid_pid = 0;
  80. real_requests = validation_requests = walk_requests = 0;
  81. memset(&fake_sample, 0, sizeof (fake_sample)); fake_sample.at = fake_now;
  82. fake_sample.free = 60000; fake_sample.lots = 130875;
  83. fake_sample.des = 65437; fake_sample.min = 49077;
  84. fixtures[0].pid = 123; fixtures[0].ppid = 100; fixtures[0].zid = 9;
  85. fixtures[0].initpid = 99; fixtures[0].nlwp = 1; fixtures[0].start_sec = 1000;
  86. fixtures[0].zone_generation = 20; fixtures[0].rss_kib = 100000;
  87. strcpy(fixtures[0].uuid, cfg.zones[0].uuid); strcpy(fixtures[0].name, "php-fpm");
  88. nfixtures = 1;
  89. scan_processes(0);
  90. }
  91. static void load_global_ranking_fixture(void)
  92. {
  93. FILE *f;
  94. char line[256], uuid[64], alias[64], name[32];
  95. int zid, pid;
  96. uint64_t generation, rss;
  97. reset();
  98. cfg.nzones = cfg.nnames = 0;
  99. strcpy(cfg.protected_names[cfg.nnames++], "mysqld");
  100. strcpy(cfg.protected_names[cfg.nnames++], "zone-overhead");
  101. memset(processes, 0, sizeof (processes));
  102. memset(zone_stats, 0, sizeof (zone_stats));
  103. memset(candidate_cache, 0, sizeof (candidate_cache));
  104. memset(&controller, 0, sizeof (controller));
  105. memset(fixtures, 0, sizeof (fixtures));
  106. scan_generation = 0; scan_complete = 0; latest_complete_scan_at = 0;
  107. nfixtures = 0; fake_now = 100;
  108. f = fopen("tests/fixtures/global_victim_ranking_smartos_2026_09.csv", "r");
  109. CHECK(f != NULL); CHECK(fgets(line, sizeof (line), f) != NULL);
  110. while (fscanf(f, " %63[^,],%63[^,],%d,%" SCNu64 ",%d,%31[^,],%" SCNu64,
  111. uuid, alias, &zid, &generation, &pid, name, &rss) == 7) {
  112. process_t *p;
  113. const zone_rule_t *rule = zone_rule(&cfg, uuid);
  114. CHECK(nfixtures < sizeof (fixtures) / sizeof (fixtures[0]));
  115. if (!rule) {
  116. zone_rule_t *z;
  117. CHECK(cfg.nzones < MAX_ZONES); z = &cfg.zones[cfg.nzones++];
  118. strcpy(z->uuid, uuid); strcpy(z->alias, alias); z->policy = ALLOW;
  119. }
  120. p = &fixtures[nfixtures++];
  121. p->pid = pid; p->ppid = 100; p->zid = zid; p->initpid = 9000 + zid;
  122. p->nlwp = 1; p->start_sec = 1000 + pid; p->start_nsec = pid;
  123. p->zone_generation = generation; p->rss_kib = rss;
  124. strcpy(p->uuid, uuid); strcpy(p->name, name);
  125. }
  126. fclose(f); CHECK(nfixtures == 16 && cfg.nzones == 5);
  127. scan_processes(1);
  128. }
  129. int main(void)
  130. {
  131. FILE *log = tmpfile(); char contents[65536]; size_t n;
  132. const process_t *chosen;
  133. unsigned second;
  134. CHECK(log != NULL); logfd = fileno(log);
  135. reset(); act(&fake_sample);
  136. CHECK(real_requests == 0 && validation_requests == 1 && controller.has_pending);
  137. fake_now += 5; scan_processes(0); act(&fake_sample);
  138. CHECK(real_requests == 0 && !controller.has_pending);
  139. rewind(log); n = fread(contents, 1, sizeof (contents) - 1, log); contents[n] = 0;
  140. CHECK(strstr(contents, "WOULD_ACTION=SIGTERM") != NULL);
  141. CHECK(strstr(contents, "WOULD_ACTION=SIGKILL") != NULL);
  142. CHECK(strstr(contents, "ACTION_INTENT=") == NULL);
  143. CHECK(fseek(log, 0, SEEK_END) == 0);
  144. puts("PASS actual daemon dry-run path records WOULD_ACTION=SIGTERM/SIGKILL; zero real requests");
  145. reset();
  146. fake_sample.arc_ok = 1;
  147. fake_sample.swap_virtual_ok = fake_sample.swap_physical_ok = fake_sample.pageout_ok = 1;
  148. for (second = 0; second <= 60; second++) {
  149. fake_sample.at = 100 + second;
  150. fake_sample.arc = UINT64_C(6000000000) + 1000 * second;
  151. fake_sample.swap_alloc = 7000000 + 3 * second;
  152. fake_sample.swap_reserved = 480000 + 2 * second;
  153. fake_sample.swap_available = 6200000 - second;
  154. fake_sample.swap_physical_used_bytes = UINT64_C(4143648768) + 4096 * second;
  155. fake_sample.anon_pageout_pages = 1000 + 2 * second;
  156. record_metrics(&fake_sample);
  157. }
  158. log_sample(&fake_sample);
  159. CHECK(fflush(log) == 0 && fseek(log, 0, SEEK_SET) == 0);
  160. n = fread(contents, 1, sizeof (contents) - 1, log); contents[n] = 0;
  161. CHECK(strstr(contents, "swap_committed_ok=1 swap_committed_pages=7480300") != NULL);
  162. CHECK(strstr(contents, "swap_physical_used_ok=1 swap_physical_used_bytes=4143894528") != NULL);
  163. CHECK(strstr(contents, "anon_pageout_ok=1 anon_pageout_pages=1120") != NULL);
  164. CHECK(strstr(contents, "swap_alloc_pages=7000180 swap_reserved_pages=480120 swap_available_pages=6199940") != NULL);
  165. CHECK(strstr(contents, "metric=swap_committed_pages d5=+25@5.00s d15=+75@15.00s d60=+300@60.00s") != NULL);
  166. CHECK(strstr(contents, "metric=swap_physical_used_bytes d5=+20480@5.00s d15=+61440@15.00s d60=+245760@60.00s") != NULL);
  167. CHECK(strstr(contents, "metric=anon_pageout_pages d5=+10@5.00s d15=+30@15.00s d60=+120@60.00s") != NULL);
  168. CHECK(strstr(contents, "swap_used_pages") == NULL);
  169. CHECK(fseek(log, 0, SEEK_END) == 0);
  170. puts("PASS continuous sample contract and 5/15/60 deltas for commitment, physical swap and pageout");
  171. reset(); cfg.armed = 1; act(&fake_sample);
  172. CHECK(real_requests == 1);
  173. fake_now += 5; scan_processes(0); act(&fake_sample); CHECK(real_requests == 2);
  174. reset(); cfg.armed = 1; started = 80; fake_now = 101; scan_processes(0);
  175. CHECK(candidate_cache[0].valid && engine.danger && walk_requests == 2);
  176. act(&fake_sample); CHECK(real_requests == 0 && candidate_cache[0].valid);
  177. CHECK(fflush(log) == 0 && fseek(log, 0, SEEK_SET) == 0);
  178. n = fread(contents, 1, sizeof (contents) - 1, log); contents[n] = 0;
  179. CHECK(strstr(contents, "event=action_blocked reason=armed_warmup") != NULL);
  180. CHECK(fseek(log, 0, SEEK_END) == 0);
  181. reset(); cfg.armed = 1; log_ok = 0; act(&fake_sample); CHECK(real_requests == 0);
  182. reset(); cfg.armed = 1; partial = 1; fake_now++; scan_processes(0);
  183. act(&fake_sample); CHECK(real_requests == 1 && !scan_complete);
  184. reset(); cfg.armed = 1; fail_sample = 1; act(&fake_sample); CHECK(real_requests == 0);
  185. reset(); cfg.armed = 1; fail_validation = 1; act(&fake_sample); CHECK(real_requests == 0);
  186. reset(); cfg.armed = 1; fake_sample.free = 150000; act(&fake_sample); CHECK(real_requests == 0);
  187. reset(); cfg.armed = 1; fake_now += 16; act(&fake_sample); CHECK(real_requests == 0);
  188. reset(); cfg.armed = 1; stopping = 1; act(&fake_sample); CHECK(real_requests == 0);
  189. reset(); fake_sample.free = 20000; act(&fake_sample);
  190. CHECK(!controller.has_pending && controller.nvictims == 1);
  191. puts("PASS armed-path mock requests, explicit warmup, stale cache, logging/sampling failures, stop and fresh floor");
  192. reset(); fixtures[1] = fixtures[0]; fixtures[1].pid = 124;
  193. fixtures[1].rss_kib = 900000; fixtures[1].zid = 10;
  194. strcpy(fixtures[1].uuid, cfg.zones[1].uuid); nfixtures = 2;
  195. fake_now = 101; scan_processes(0); chosen = candidate(); CHECK(chosen && chosen->pid == 124);
  196. /* Small zone grows fast enough to outweigh a larger steady zone. */
  197. fixtures[0].rss_kib = 600000; fake_now = 161; scan_processes(0);
  198. chosen = candidate(); CHECK(chosen && chosen->pid == 123);
  199. cfg.zones[0].policy = PROTECT; fake_now = 162; scan_processes(0);
  200. chosen = candidate(); CHECK(chosen && chosen->pid == 124);
  201. fixtures[1].zid = 0; fake_now = 163; scan_processes(0); CHECK(candidate() == NULL);
  202. puts("PASS global score uses process RSS/growth; protected zones and global zone excluded");
  203. load_global_ranking_fixture();
  204. CHECK(candidate_cache[0].valid && candidate_cache[1].valid && candidate_cache[2].valid);
  205. CHECK(!strcmp(candidate_cache[0].p.name, "clamd"));
  206. CHECK(!strcmp(candidate_cache[1].p.name, "clamd"));
  207. CHECK(!strcmp(candidate_cache[2].p.name, "clamd"));
  208. CHECK(candidate_cache[0].p.rss_kib > 1300000 &&
  209. candidate_cache[2].p.rss_kib > 1300000);
  210. CHECK(strcmp(candidate_cache[0].p.uuid, candidate_cache[1].p.uuid));
  211. CHECK(strcmp(candidate_cache[1].p.uuid, candidate_cache[2].p.uuid));
  212. for (second = 0; second < CACHED_CANDIDATES; second++) {
  213. CHECK(strcmp(candidate_cache[second].p.name, "mysqld"));
  214. CHECK(strcmp(candidate_cache[second].p.name, "zone-overhead"));
  215. }
  216. for (second = 0; second < nfixtures; second++)
  217. if (!strcmp(fixtures[second].name, "mysqld"))
  218. CHECK(protected_process(&cfg, &fixtures[second]));
  219. CHECK(fflush(log) == 0 && fseek(log, 0, SEEK_SET) == 0);
  220. n = fread(contents, 1, sizeof (contents) - 1, log); contents[n] = 0;
  221. {
  222. char *mysql = strstr(contents, "comm=mysqld");
  223. char *ineligible = mysql ? strstr(mysql, "eligible=0") : NULL;
  224. char *line_end = mysql ? strchr(mysql, '\n') : NULL;
  225. CHECK(mysql && ineligible && line_end && ineligible < line_end);
  226. }
  227. CHECK(fseek(log, 0, SEEK_END) == 0);
  228. fixtures[nfixtures] = fixtures[0]; fixtures[nfixtures].pid = 9001;
  229. fixtures[nfixtures].zid = 90; fixtures[nfixtures].zone_generation = 900;
  230. fixtures[nfixtures].rss_kib = UINT64_C(9000000);
  231. strcpy(fixtures[nfixtures].uuid, "66666666-6666-4666-8666-666666666666");
  232. strcpy(fixtures[nfixtures].name, "unmapped-hog"); nfixtures++;
  233. fixtures[nfixtures] = fixtures[0]; fixtures[nfixtures].pid = 9002;
  234. fixtures[nfixtures].zid = 0; fixtures[nfixtures].rss_kib = UINT64_C(11000000);
  235. strcpy(fixtures[nfixtures].name, "global-hog"); nfixtures++;
  236. fake_now = 101; scan_processes(0);
  237. for (second = 0; second < CACHED_CANDIDATES; second++)
  238. CHECK(candidate_cache[second].p.pid != 9001 && candidate_cache[second].p.pid != 9002);
  239. for (second = 0; second < nfixtures; second++)
  240. if (fixtures[second].pid == 1103) fixtures[second].rss_kib = 600000;
  241. fake_now = 106; scan_processes(0);
  242. CHECK(candidate_cache[0].p.pid == 1103);
  243. CHECK(candidate_cache[0].growth5_component > 0 &&
  244. candidate_cache[0].total_score > candidate_cache[1].total_score);
  245. {
  246. cached_candidate_t scored;
  247. zone_t zone;
  248. memset(&scored, 0, sizeof (scored)); memset(&zone, 0, sizeof (zone));
  249. scored.p.rss_kib = 100000; scored.d5.valid = scored.d15.valid = 1;
  250. scored.d60.valid = 1; scored.d5.value = 1000;
  251. scored.d15.value = 2000; scored.d60.value = 3000;
  252. scan_at = 60; history_add(&zone.history, 0, 1000000);
  253. history_add(&zone.history, 60, 1100000); zone.rss = 1100000;
  254. score_candidate(&scored, &zone);
  255. CHECK(scored.growth5_component == 4000);
  256. CHECK(scored.growth15_component == 4000);
  257. CHECK(scored.growth60_component == 3000);
  258. CHECK(scored.zone_component <= scored.p.rss_kib / 4);
  259. }
  260. CHECK(fflush(log) == 0 && fseek(log, 0, SEEK_SET) == 0);
  261. n = fread(contents, 1, sizeof (contents) - 1, log); contents[n] = 0;
  262. CHECK(strstr(contents, "rss_component=") != NULL);
  263. CHECK(strstr(contents, "growth5_component=") != NULL);
  264. CHECK(strstr(contents, "growth15_component=") != NULL);
  265. CHECK(strstr(contents, "growth60_component=") != NULL);
  266. CHECK(strstr(contents, "zone_component=") != NULL);
  267. CHECK(strstr(contents, "total_score=") != NULL);
  268. CHECK(fseek(log, 0, SEEK_END) == 0);
  269. puts("PASS SmartOS fixture produces a global cross-zone top-3 and bounded zone context");
  270. reset(); fixtures[1] = fixtures[0]; fixtures[1].pid = 124;
  271. fixtures[1].rss_kib = 900000; fixtures[1].zid = 10;
  272. strcpy(fixtures[1].uuid, cfg.zones[1].uuid);
  273. fixtures[2] = fixtures[0]; fixtures[2].pid = 125; fixtures[2].rss_kib = 800000;
  274. nfixtures = 3; fake_now = 101; scan_processes(0);
  275. CHECK(candidate_cache[0].valid && candidate_cache[1].valid && candidate_cache[2].valid);
  276. invalid_pid = candidate_cache[0].p.pid;
  277. partial = 1; fake_now = 102; scan_processes(0);
  278. CHECK(!scan_complete && candidate_cache[0].p.pid == invalid_pid);
  279. {
  280. unsigned walks_before = walk_requests;
  281. engine.state = EMERGENCY; engine.danger = 1; fake_sample.free = 40000;
  282. act(&fake_sample);
  283. CHECK(walk_requests == walks_before); /* O(1): no /proc walk in action path. */
  284. CHECK(controller.has_pending && controller.pending.pid != invalid_pid);
  285. CHECK(validation_requests >= 2 && real_requests == 0);
  286. }
  287. CHECK(fflush(log) == 0 && fseek(log, 0, SEEK_SET) == 0);
  288. n = fread(contents, 1, sizeof (contents) - 1, log); contents[n] = 0;
  289. CHECK(strstr(contents, "candidate_source=fallback_candidate") != NULL);
  290. CHECK(strstr(contents, "scan_complete=0") != NULL);
  291. CHECK(fseek(log, 0, SEEK_END) == 0);
  292. puts("PASS incomplete scan preserves cache; emergency uses O(1) fallback without a new walk");
  293. reset(); fixtures[1] = fixtures[0]; fixtures[1].pid = 124;
  294. fixtures[1].rss_kib = 900000; fixtures[1].zid = 10;
  295. strcpy(fixtures[1].uuid, cfg.zones[1].uuid); nfixtures = 2;
  296. fake_now = 101; scan_processes(0);
  297. for (second = 0; second < nfixtures; second++)
  298. if (fixtures[second].pid == candidate_cache[0].p.pid) fixtures[second].start_nsec++;
  299. engine.state = EMERGENCY; engine.danger = 1; fake_sample.free = 40000;
  300. act(&fake_sample);
  301. CHECK(controller.has_pending && !same_process(&controller.pending, &candidate_cache[0].p));
  302. puts("PASS PID/start-time reuse rejects rank 1 and selects cached fallback");
  303. reset();
  304. CHECK(platform_syslog_open("o6h-memory-guard", cfg.syslog_facility) == 0);
  305. syslog_ready = 1;
  306. CHECK(!strcmp(syslog_ident, "o6h-memory-guard") && syslog_facility == 5 &&
  307. syslog_open_count == 1);
  308. emit_important(LOG_INFO, "event=start version=%s mode=dry-run", VERSION);
  309. CHECK(syslog_count == 1 && syslog_records[0].priority == LOG_INFO &&
  310. strstr(syslog_records[0].message, "event=start version=1.0.6") != NULL);
  311. log_sample(&fake_sample); scan_processes(0);
  312. CHECK(syslog_count == 1); /* High-volume sample/delta/proc/cache events stay local. */
  313. {
  314. char message[512]; sample_t s = fake_sample;
  315. s.free = s.min;
  316. CHECK(!transition_message(message, sizeof (message), NORMAL, EMERGENCY, &s, 1));
  317. CHECK(strstr(message, "reason=threshold_jump") != NULL);
  318. CHECK(strstr(message, "skipped_states=PRE-PRESSURE,PRESSURE,CRITICAL") != NULL);
  319. syslog_event(state_priority(EMERGENCY, 0), "%s", message);
  320. CHECK(syslog_count == 2 && syslog_records[1].priority == LOG_CRIT);
  321. }
  322. cfg.armed = 0; act(&fake_sample);
  323. CHECK(syslog_count == 2 && real_requests == 0);
  324. reset(); cfg.armed = 1; started = 80; fake_now = 100;
  325. CHECK(platform_syslog_open("o6h-memory-guard", cfg.syslog_facility) == 0);
  326. syslog_ready = 1; act(&fake_sample);
  327. CHECK(real_requests == 0 && syslog_count == 1 &&
  328. syslog_records[0].priority == LOG_WARNING &&
  329. strstr(syslog_records[0].message, "event=action_blocked reason=armed_warmup") != NULL);
  330. reset(); cfg.armed = 1;
  331. CHECK(platform_syslog_open("o6h-memory-guard", cfg.syslog_facility) == 0);
  332. syslog_ready = 1; act(&fake_sample);
  333. CHECK(real_requests == 1 && syslog_count == 2);
  334. CHECK(syslog_records[0].priority == LOG_ERR &&
  335. strstr(syslog_records[0].message, "event=action_decision state=CRITICAL") != NULL &&
  336. strstr(syslog_records[0].message, "result=sent") != NULL);
  337. CHECK(syslog_records[1].priority == LOG_ERR &&
  338. strstr(syslog_records[1].message, "event=signal_sent state=CRITICAL") != NULL &&
  339. strstr(syslog_records[1].message, "signal=SIGTERM") != NULL &&
  340. strstr(syslog_records[1].message, "UUID=") != NULL &&
  341. strstr(syslog_records[1].message, "alias=web-a") != NULL &&
  342. strstr(syslog_records[1].message, "pid=123") != NULL &&
  343. strstr(syslog_records[1].message, "comm=php-fpm") != NULL &&
  344. strstr(syslog_records[1].message, "rss_kib=100000") != NULL &&
  345. strstr(syslog_records[1].message, "free_pages=60000") != NULL);
  346. reset(); cfg.armed = 1; fail_syslog = 1; syslog_ready = 1;
  347. act(&fake_sample); CHECK(real_requests == 1 && controller.has_pending);
  348. reset(); cfg.syslog_enabled = 0; syslog_ready = 0;
  349. emit_important(LOG_INFO, "event=start disabled_test=yes"); CHECK(syslog_count == 0);
  350. CHECK(state_priority(PRE_PRESSURE, 0) == LOG_NOTICE);
  351. CHECK(state_priority(PRESSURE, 0) == LOG_WARNING);
  352. CHECK(state_priority(CRITICAL, 0) == LOG_ERR);
  353. CHECK(state_priority(EMERGENCY, 0) == LOG_CRIT);
  354. CHECK(state_priority(RECOVERY, 0) == LOG_INFO);
  355. CHECK(state_priority(NORMAL, 1) == LOG_CRIT);
  356. log_sampling_overrun(4.459, &fake_sample);
  357. CHECK(fflush(log) == 0 && fseek(log, 0, SEEK_SET) == 0);
  358. n = fread(contents, 1, sizeof (contents) - 1, log); contents[n] = 0;
  359. CHECK(strstr(contents, "event=sampling_overrun late_seconds=4.459 state=CRITICAL free_pages=60000") != NULL);
  360. puts("PASS selective native syslog ident/facility/severity, exclusions, signal ordering, disable and failure isolation");
  361. fclose(log);
  362. printf("PASS %u runtime checks; all platform calls mocked, no signals sent\n", checks);
  363. return 0;
  364. }