1#include <asm.h>
2#include <nightmare/nightmare.h>
3#include <sch/sched.h>
4#include <thread/thread.h>
5
6struct harness_smoke_options {
7 bool stall;
8 bool plateau;
9 bool blocked_drain;
10 bool starve_one;
11 time_ns_t park_delay_ms;
12};
13
14static struct harness_smoke_options harness_smoke_options;
15
16NIGHTMARE_OPTIONS_DECLARE(
17 harness_smoke, struct harness_smoke_options, harness_smoke_options,
18 CMDLINE_SCHEMA_PROP(struct harness_smoke_options, stall),
19 CMDLINE_SCHEMA_PROP(struct harness_smoke_options, plateau),
20 CMDLINE_SCHEMA_PROP(struct harness_smoke_options, blocked_drain),
21 CMDLINE_SCHEMA_PROP(struct harness_smoke_options, starve_one),
22 CMDLINE_SCHEMA_PROP(struct harness_smoke_options, park_delay_ms,
23 .types = CMDLINE_TYPES(CMDLINE_TYPE_DURATION)));
24
25#ifdef TEST_NIGHTMARE_SMOKE
26NIGHTMARE_WORKER(harness_smoke_worker) {
27 if (harness_smoke_options.blocked_drain) {
28 while (true)
29 cpu_relax();
30 }
31
32 if (harness_smoke_options.plateau ||
33 (harness_smoke_options.starve_one && NM_SELF->index == 0)) {
34 while (!nightmare_must_stop())
35 scheduler_yield();
36 return;
37 }
38
39 if (harness_smoke_options.stall) {
40 while (true) {
41 NIGHTMARE_PROGRESS();
42 cpu_relax();
43 }
44 }
45
46 while (!nightmare_must_stop()) {
47 if (nightmare_must_park()) {
48 if (harness_smoke_options.park_delay_ms)
49 thread_sleep_for_ms(
50 NS_TO_MS(harness_smoke_options.park_delay_ms));
51 nightmare_park(worker: NM_SELF);
52 }
53 NIGHTMARE_PROGRESS();
54 scheduler_yield();
55 }
56}
57
58static struct nightmare_verdict
59harness_smoke_quiesce(struct nightmare_ctx *ctx) {
60 (void) ctx;
61 return NIGHTMARE_OK;
62}
63
64static const struct nightmare_ops harness_smoke_ops = {
65 .worker = harness_smoke_worker,
66 .quiesce_check = harness_smoke_quiesce,
67};
68
69NIGHTMARE_DECLARE(harness_smoke,
70 .desc = "Temporary P4 harness lifecycle smoke subject",
71 .ops = &harness_smoke_ops,
72 .seed_policy = NIGHTMARE_SEED_IGNORED,
73 NIGHTMARE_INTENSITY_CORES(1, 1, 1, "workers/core"),
74 .default_duration_ms = 1000);
75#endif
76