ovni/test/unit/cpu.c

95 lines
1.9 KiB
C
Raw Normal View History

2024-09-10 11:21:44 +02:00
/* Copyright (c) 2021-2024 Barcelona Supercomputing Center (BSC)
2023-02-27 13:40:20 +01:00
* SPDX-License-Identifier: GPL-3.0-or-later */
2023-02-07 16:17:25 +01:00
#include "emu/cpu.h"
2023-01-25 18:11:13 +01:00
#include "common.h"
#include "emu/loom.h"
#include "emu/proc.h"
#include "emu/thread.h"
#include "unittest.h"
#include "parson.h"
2023-01-25 18:11:13 +01:00
static void
2023-02-07 16:17:25 +01:00
test_oversubscription(void)
2023-01-25 18:11:13 +01:00
{
struct loom loom;
OK(loom_init_begin(&loom, "loom.0"));
2023-02-07 16:17:25 +01:00
struct cpu cpu;
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
int phyid = 0;
int index = 0;
cpu_init_begin(&cpu, index, phyid, 0);
2023-02-07 16:17:25 +01:00
cpu_set_gindex(&cpu, 0);
cpu_set_loom(&cpu, &loom);
2023-02-07 16:17:25 +01:00
if (cpu_init_end(&cpu) != 0)
die("cpu_init_end failed");
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
struct proc proc;
2023-01-25 18:11:13 +01:00
2024-09-10 11:21:44 +02:00
if (proc_init_begin(&proc, 1) != 0)
2023-02-07 16:17:25 +01:00
die("proc_init_begin failed");
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
proc_set_gindex(&proc, 0);
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
/* FIXME: We shouldn't need to recreate a full process to test the CPU
* affinity rules */
proc.metadata_loaded = 1;
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
struct thread th0, th1;
2023-01-25 18:11:13 +01:00
2024-09-10 11:21:44 +02:00
if (thread_init_begin(&th0, 1) != 0)
2023-02-07 16:17:25 +01:00
die("thread_init_begin failed");
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
thread_set_gindex(&th0, 0);
th0.meta = (JSON_Object *) 666;
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
if (thread_init_end(&th0) != 0)
die("thread_init_end failed");
2023-01-25 18:11:13 +01:00
2024-09-10 11:21:44 +02:00
if (thread_init_begin(&th1, 2) != 0)
2023-02-07 16:17:25 +01:00
die("thread_init_begin failed");
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
thread_set_gindex(&th1, 1);
th1.meta = (JSON_Object *) 666;
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
if (thread_init_end(&th1) != 0)
die("thread_init_end failed");
2023-01-25 18:11:13 +01:00
if (proc_add_thread(&proc, &th0) != 0)
die("proc_add_thread failed");
if (proc_add_thread(&proc, &th1) != 0)
die("proc_add_thread failed");
if (proc_init_end(&proc) != 0)
die("proc_init_end failed");
2023-02-07 16:17:25 +01:00
if (thread_set_cpu(&th0, &cpu) != 0)
die("thread_set_cpu failed");
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
if (thread_set_cpu(&th1, &cpu) != 0)
die("thread_set_cpu failed");
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
if (thread_set_state(&th0, TH_ST_RUNNING) != 0)
die("thread_set_state failed");
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
if (thread_set_state(&th1, TH_ST_RUNNING) != 0)
die("thread_set_state failed");
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
if (cpu_add_thread(&cpu, &th0) != 0)
die("cpu_add_thread failed");
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
if (cpu_add_thread(&cpu, &th1) == 0)
die("cpu_add_thread didn't fail");
2023-01-25 18:11:13 +01:00
2023-02-07 16:17:25 +01:00
err("ok");
2023-01-25 18:11:13 +01:00
}
int main(void)
{
2023-02-07 16:17:25 +01:00
test_oversubscription();
2023-01-25 18:11:13 +01:00
return 0;
}