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

Function test_clone_thread

tests/system_test/clone_test.cpp:172–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170}
171
172void test_clone_thread(void* /*arg*/) {
173 klog::Info("=== Clone Thread Test ===");
174
175 bool passed = true;
176 g_thread_done = 0;
177 g_threads_may_exit = false;
178 g_leader_pid = 0;
179 g_thread1_pid = 0;
180 g_thread1_tgid = 0;
181 g_thread2_pid = 0;
182 g_thread2_tgid = 0;
183
184 auto leader_ptr = kstd::make_unique<TaskControlBlock>("CloneThreadLeader", 10,
185 leader_work, nullptr);
186 TaskManagerSingleton::instance().AddTask(std::move(leader_ptr));
187
188 for (int i = 0; i < 100 && g_leader_pid.load() == 0; ++i) {
189 (void)sys_sleep(10);
190 }
191
192 Pid leader_pid = g_leader_pid.load();
193 if (leader_pid == 0) {
194 klog::Err("Leader did not start");
195 g_tests_failed++;
196 g_tests_completed++;
197 sys_exit(1);
198 }
199
200 auto* leader = TaskManagerSingleton::instance().FindTask(leader_pid);
201 if (!leader) {
202 klog::Err("Leader not found in task table");
203 g_tests_failed++;
204 g_tests_completed++;
205 sys_exit(1);
206 }
207
208 uint64_t flags = clone_flag::kThread | clone_flag::kVm | clone_flag::kFiles |
209 clone_flag::kSighand;
210
211 auto thread1 = kstd::make_unique<TaskControlBlock>(
212 "CloneThread1", 10, child_thread_work, reinterpret_cast<void*>(1));
213 thread1->aux->parent_pid = leader_pid;
214 thread1->aux->tgid = leader_pid;
215 thread1->aux->clone_flags = static_cast<CloneFlags>(flags);
216 thread1->JoinThreadGroup(leader);
217 TaskManagerSingleton::instance().AddTask(std::move(thread1));
218
219 auto thread2 = kstd::make_unique<TaskControlBlock>(
220 "CloneThread2", 10, child_thread_work, reinterpret_cast<void*>(2));
221 thread2->aux->parent_pid = leader_pid;
222 thread2->aux->tgid = leader_pid;
223 thread2->aux->clone_flags = static_cast<CloneFlags>(flags);
224 thread2->JoinThreadGroup(leader);
225 TaskManagerSingleton::instance().AddTask(std::move(thread2));
226
227 for (int i = 0; i < 100 && g_thread_done.load() < 2; ++i) {
228 (void)sys_sleep(10);
229 }

Callers

nothing calls this directly

Calls 8

InfoFunction · 0.85
sys_sleepFunction · 0.85
ErrFunction · 0.85
sys_exitFunction · 0.85
AddTaskMethod · 0.80
FindTaskMethod · 0.80
JoinThreadGroupMethod · 0.80
GetThreadGroupSizeMethod · 0.80

Tested by

no test coverage detected