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-01-25 18:11:13 +01:00
|
|
|
#include "emu/loom.h"
|
2023-03-22 16:01:55 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include "common.h"
|
2023-01-25 18:11:13 +01:00
|
|
|
#include "emu/cpu.h"
|
|
|
|
#include "emu/proc.h"
|
2023-02-27 12:30:36 +01:00
|
|
|
#include "unittest.h"
|
2023-01-25 18:11:13 +01:00
|
|
|
|
2024-09-10 11:21:44 +02:00
|
|
|
char testloom[] = "node1";
|
|
|
|
int testproc = 1;
|
2023-01-25 18:11:13 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
test_bad_name(struct loom *loom)
|
|
|
|
{
|
2023-02-27 12:30:36 +01:00
|
|
|
ERR(loom_init_begin(loom, "loom/blah"));
|
|
|
|
ERR(loom_init_begin(loom, "/loom.123"));
|
|
|
|
ERR(loom_init_begin(loom, "./loom.123"));
|
|
|
|
OK(loom_init_begin(loom, "loom.123"));
|
2024-09-10 11:21:44 +02:00
|
|
|
OK(loom_init_begin(loom, "foo"));
|
2023-01-25 18:11:13 +01:00
|
|
|
|
|
|
|
err("ok");
|
|
|
|
}
|
|
|
|
|
2023-02-16 16:54:25 +01:00
|
|
|
static void
|
|
|
|
test_hostname(struct loom *loom)
|
|
|
|
{
|
2024-09-10 11:21:44 +02:00
|
|
|
OK(loom_init_begin(loom, "node1.blah"));
|
2023-02-16 16:54:25 +01:00
|
|
|
|
|
|
|
if (strcmp(loom->hostname, "node1") != 0)
|
|
|
|
die("wrong hostname: %s", loom->hostname);
|
|
|
|
|
|
|
|
err("ok");
|
|
|
|
}
|
|
|
|
|
2023-01-25 18:11:13 +01:00
|
|
|
static void
|
|
|
|
test_negative_cpu(struct loom *loom)
|
|
|
|
{
|
2023-02-27 12:30:36 +01:00
|
|
|
OK(loom_init_begin(loom, testloom));
|
2023-01-25 18:11:13 +01:00
|
|
|
|
|
|
|
struct cpu cpu;
|
2023-02-22 12:04:08 +01:00
|
|
|
cpu_init_begin(&cpu, -1, -1, 0);
|
2023-01-25 18:11:13 +01:00
|
|
|
|
2023-02-27 12:30:36 +01:00
|
|
|
ERR(loom_add_cpu(loom, &cpu));
|
2023-01-25 18:11:13 +01:00
|
|
|
|
|
|
|
err("ok");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_duplicate_cpus(struct loom *loom)
|
|
|
|
{
|
|
|
|
struct cpu cpu;
|
2023-02-27 12:30:36 +01:00
|
|
|
OK(loom_init_begin(loom, testloom));
|
2023-02-22 12:04:08 +01:00
|
|
|
cpu_init_begin(&cpu, 123, 123, 0);
|
2023-02-27 12:30:36 +01:00
|
|
|
OK(loom_add_cpu(loom, &cpu));
|
|
|
|
ERR(loom_add_cpu(loom, &cpu));
|
2023-01-25 18:11:13 +01:00
|
|
|
|
|
|
|
err("ok");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_duplicate_procs(struct loom *loom)
|
|
|
|
{
|
|
|
|
struct proc proc;
|
2023-02-27 12:30:36 +01:00
|
|
|
OK(loom_init_begin(loom, testloom));
|
|
|
|
OK(proc_init_begin(&proc, testproc));
|
2023-04-06 19:27:43 +02:00
|
|
|
proc.metadata_loaded = 1;
|
2023-02-27 12:30:36 +01:00
|
|
|
OK(loom_add_proc(loom, &proc));
|
|
|
|
ERR(loom_add_proc(loom, &proc));
|
2023-01-25 18:11:13 +01:00
|
|
|
|
|
|
|
err("ok");
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
struct loom loom;
|
|
|
|
|
|
|
|
test_bad_name(&loom);
|
2023-02-16 16:54:25 +01:00
|
|
|
test_hostname(&loom);
|
2023-01-25 18:11:13 +01:00
|
|
|
test_negative_cpu(&loom);
|
|
|
|
test_duplicate_cpus(&loom);
|
|
|
|
test_duplicate_procs(&loom);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|