Use OK() and ERR() macros in cpu and loom tests

Some return checks were missing too.
This commit is contained in:
Rodrigo Arias 2023-02-27 12:30:36 +01:00 committed by Rodrigo Arias Mallo
parent dc2a016c6b
commit a4452dee8c
2 changed files with 20 additions and 82 deletions

View File

@ -1,12 +1,13 @@
#include "emu/cpu.h" #include "emu/cpu.h"
#include "emu/loom.h" #include "emu/loom.h"
#include "common.h" #include "common.h"
#include "unittest.h"
static void static void
test_oversubscription(void) test_oversubscription(void)
{ {
struct loom loom; struct loom loom;
loom_init_begin(&loom, "loom.0"); OK(loom_init_begin(&loom, "loom.0"));
struct cpu cpu; struct cpu cpu;

View File

@ -3,6 +3,7 @@
#include "emu/proc.h" #include "emu/proc.h"
#include "common.h" #include "common.h"
#include "utlist.h" #include "utlist.h"
#include "unittest.h"
char testloom[] = "loom.0"; char testloom[] = "loom.0";
char testproc[] = "loom.0/proc.1"; char testproc[] = "loom.0/proc.1";
@ -10,26 +11,13 @@ char testproc[] = "loom.0/proc.1";
static void static void
test_bad_name(struct loom *loom) test_bad_name(struct loom *loom)
{ {
if (loom_init_begin(loom, "blah") == 0) ERR(loom_init_begin(loom, "blah"));
die("loom_init_begin didn't fail"); ERR(loom_init_begin(loom, "loom/blah"));
ERR(loom_init_begin(loom, "loom.123/testloom"));
if (loom_init_begin(loom, "loom/blah") == 0) ERR(loom_init_begin(loom, "loom.123/"));
die("loom_init_begin didn't fail"); ERR(loom_init_begin(loom, "/loom.123"));
ERR(loom_init_begin(loom, "./loom.123"));
if (loom_init_begin(loom, "loom.123/testloom") == 0) OK(loom_init_begin(loom, "loom.123"));
die("loom_init_begin didn't fail");
if (loom_init_begin(loom, "loom.123/") == 0)
die("loom_init_begin didn't fail");
if (loom_init_begin(loom, "/loom.123") == 0)
die("loom_init_begin didn't fail");
if (loom_init_begin(loom, "./loom.123") == 0)
die("loom_init_begin didn't fail");
if (loom_init_begin(loom, "loom.123") != 0)
die("loom_init_begin failed");
err("ok"); err("ok");
} }
@ -37,8 +25,7 @@ test_bad_name(struct loom *loom)
static void static void
test_hostname(struct loom *loom) test_hostname(struct loom *loom)
{ {
if (loom_init_begin(loom, "loom.node1.blah") != 0) OK(loom_init_begin(loom, "loom.node1.blah"));
die("loom_init_begin failed");
if (strcmp(loom->hostname, "node1") != 0) if (strcmp(loom->hostname, "node1") != 0)
die("wrong hostname: %s", loom->hostname); die("wrong hostname: %s", loom->hostname);
@ -49,14 +36,12 @@ test_hostname(struct loom *loom)
static void static void
test_negative_cpu(struct loom *loom) test_negative_cpu(struct loom *loom)
{ {
if (loom_init_begin(loom, testloom) != 0) OK(loom_init_begin(loom, testloom));
die("loom_init_begin failed");
struct cpu cpu; struct cpu cpu;
cpu_init_begin(&cpu, -1, -1, 0); cpu_init_begin(&cpu, -1, -1, 0);
if (loom_add_cpu(loom, &cpu) == 0) ERR(loom_add_cpu(loom, &cpu));
die("loom_add_cpu didn't fail");
err("ok"); err("ok");
} }
@ -64,70 +49,23 @@ test_negative_cpu(struct loom *loom)
static void static void
test_duplicate_cpus(struct loom *loom) test_duplicate_cpus(struct loom *loom)
{ {
if (loom_init_begin(loom, testloom) != 0)
die("loom_init_begin failed");
struct cpu cpu; struct cpu cpu;
OK(loom_init_begin(loom, testloom));
cpu_init_begin(&cpu, 123, 123, 0); cpu_init_begin(&cpu, 123, 123, 0);
if (loom_add_cpu(loom, &cpu) != 0) OK(loom_add_cpu(loom, &cpu));
die("loom_add_cpu failed"); ERR(loom_add_cpu(loom, &cpu));
if (loom_add_cpu(loom, &cpu) == 0)
die("loom_add_cpu didn't fail");
err("ok"); err("ok");
} }
//static void
//test_sort_cpus(struct loom *loom)
//{
// int ncpus = 10;
//
// if (loom_init_begin(loom, testloom) != 0)
// die("loom_init_begin failed");
//
// for (int i = 0; i < ncpus; i++) {
// int phyid = 1000 - i * i;
// struct cpu *cpu = malloc(sizeof(struct cpu));
// if (cpu == NULL)
// die("malloc failed:");
//
// cpu_init(cpu, phyid);
// if (loom_add_cpu(loom, cpu) != 0)
// die("loom_add_cpu failed");
// }
//
// if (loom_init_end(loom) != 0)
// die("loom_init_end failed");
//
// if (loom->ncpus != (size_t) ncpus)
// die("ncpus mismatch");
//
// struct cpu *cpu = NULL;
// int lastphyid = -1;
// DL_FOREACH2(loom->scpus, cpu, lnext) {
// int phyid = cpu_get_phyid(cpu);
// if (lastphyid >= phyid)
// die("unsorted scpus");
// lastphyid = phyid;
// }
//
// err("ok");
//}
static void static void
test_duplicate_procs(struct loom *loom) test_duplicate_procs(struct loom *loom)
{ {
if (loom_init_begin(loom, testloom) != 0)
die("loom_init_begin failed");
struct proc proc; struct proc proc;
proc_init_begin(&proc, testproc); OK(loom_init_begin(loom, testloom));
if (loom_add_proc(loom, &proc) != 0) OK(proc_init_begin(&proc, testproc));
die("loom_add_proc failed"); OK(loom_add_proc(loom, &proc));
ERR(loom_add_proc(loom, &proc));
if (loom_add_proc(loom, &proc) == 0)
die("loom_add_proc didn't fail");
err("ok"); err("ok");
} }
@ -140,7 +78,6 @@ int main(void)
test_hostname(&loom); test_hostname(&loom);
test_negative_cpu(&loom); test_negative_cpu(&loom);
test_duplicate_cpus(&loom); test_duplicate_cpus(&loom);
//test_sort_cpus(&loom);
test_duplicate_procs(&loom); test_duplicate_procs(&loom);
return 0; return 0;