MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / test_affinity_other_task

Function test_affinity_other_task

tests/system_test/affinity_test.cpp:125–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123}
124
125void test_affinity_other_task(void* /*arg*/) {
126 klog::Info("=== Affinity Other Task Test ===");
127
128 bool passed = true;
129 g_sleeper_pid = 0;
130
131 // Spawn a sleeping task
132 auto sleeper = kstd::make_unique<TaskControlBlock>("AffinitySleeper", 10,
133 sleeper_work, nullptr);
134 TaskManagerSingleton::instance().AddTask(std::move(sleeper));
135
136 // Wait for the sleeper to start and publish its PID
137 int timeout = 100;
138 while (timeout > 0 && g_sleeper_pid.load() == 0) {
139 (void)sys_sleep(10);
140 timeout--;
141 }
142
143 Pid other_pid = g_sleeper_pid.load();
144 if (other_pid == 0) {
145 klog::Err("test_affinity_other_task: sleeper did not start");
146 passed = false;
147 }
148
149 // Read the sleeper's affinity by PID
150 uint64_t mask = 0;
151 if (passed) {
152 int ret = sys_sched_getaffinity(static_cast<int>(other_pid),
153 sizeof(uint64_t), &mask);
154 if (ret != 0) {
155 klog::Err(
156 "test_affinity_other_task: getaffinity(pid={}) returned {}, "
157 "expected 0",
158 other_pid, ret);
159 passed = false;
160 }
161 }
162
163 if (passed && mask != UINT64_MAX) {
164 klog::Err("test_affinity_other_task: mask={:#x}, expected {:#x}", mask,
165 static_cast<uint64_t>(UINT64_MAX));
166 passed = false;
167 }
168
169 if (passed) {
170 klog::Info("Affinity Other Task Test: PASSED");
171 } else {
172 klog::Err("Affinity Other Task Test: FAILED");
173 g_tests_failed++;
174 }
175
176 g_tests_completed++;
177 sys_exit(passed ? 0 : 1);
178}
179
180// ===========================================================================
181// test_affinity_errors

Callers

nothing calls this directly

Calls 6

InfoFunction · 0.85
sys_sleepFunction · 0.85
ErrFunction · 0.85
sys_sched_getaffinityFunction · 0.85
sys_exitFunction · 0.85
AddTaskMethod · 0.80

Tested by

no test coverage detected