From a4452dee8c55b3011658df0aa73b1e33c01593e5 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Mon, 27 Feb 2023 12:30:36 +0100 Subject: [PATCH] Use OK() and ERR() macros in cpu and loom tests Some return checks were missing too. --- test/unit/cpu.c | 3 +- test/unit/loom.c | 99 +++++++++--------------------------------------- 2 files changed, 20 insertions(+), 82 deletions(-) diff --git a/test/unit/cpu.c b/test/unit/cpu.c index 4a80425..ca5a495 100644 --- a/test/unit/cpu.c +++ b/test/unit/cpu.c @@ -1,12 +1,13 @@ #include "emu/cpu.h" #include "emu/loom.h" #include "common.h" +#include "unittest.h" static void test_oversubscription(void) { struct loom loom; - loom_init_begin(&loom, "loom.0"); + OK(loom_init_begin(&loom, "loom.0")); struct cpu cpu; diff --git a/test/unit/loom.c b/test/unit/loom.c index 49cee03..1d3be05 100644 --- a/test/unit/loom.c +++ b/test/unit/loom.c @@ -3,6 +3,7 @@ #include "emu/proc.h" #include "common.h" #include "utlist.h" +#include "unittest.h" char testloom[] = "loom.0"; char testproc[] = "loom.0/proc.1"; @@ -10,26 +11,13 @@ char testproc[] = "loom.0/proc.1"; static void test_bad_name(struct loom *loom) { - if (loom_init_begin(loom, "blah") == 0) - die("loom_init_begin didn't fail"); - - if (loom_init_begin(loom, "loom/blah") == 0) - die("loom_init_begin didn't fail"); - - if (loom_init_begin(loom, "loom.123/testloom") == 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 didn't fail"); - - if (loom_init_begin(loom, "loom.123") != 0) - die("loom_init_begin failed"); + ERR(loom_init_begin(loom, "blah")); + ERR(loom_init_begin(loom, "loom/blah")); + ERR(loom_init_begin(loom, "loom.123/testloom")); + ERR(loom_init_begin(loom, "loom.123/")); + ERR(loom_init_begin(loom, "/loom.123")); + ERR(loom_init_begin(loom, "./loom.123")); + OK(loom_init_begin(loom, "loom.123")); err("ok"); } @@ -37,8 +25,7 @@ test_bad_name(struct loom *loom) static void test_hostname(struct loom *loom) { - if (loom_init_begin(loom, "loom.node1.blah") != 0) - die("loom_init_begin failed"); + OK(loom_init_begin(loom, "loom.node1.blah")); if (strcmp(loom->hostname, "node1") != 0) die("wrong hostname: %s", loom->hostname); @@ -49,14 +36,12 @@ test_hostname(struct loom *loom) static void test_negative_cpu(struct loom *loom) { - if (loom_init_begin(loom, testloom) != 0) - die("loom_init_begin failed"); + OK(loom_init_begin(loom, testloom)); struct cpu cpu; cpu_init_begin(&cpu, -1, -1, 0); - if (loom_add_cpu(loom, &cpu) == 0) - die("loom_add_cpu didn't fail"); + ERR(loom_add_cpu(loom, &cpu)); err("ok"); } @@ -64,70 +49,23 @@ test_negative_cpu(struct loom *loom) static void test_duplicate_cpus(struct loom *loom) { - if (loom_init_begin(loom, testloom) != 0) - die("loom_init_begin failed"); - struct cpu cpu; + OK(loom_init_begin(loom, testloom)); cpu_init_begin(&cpu, 123, 123, 0); - if (loom_add_cpu(loom, &cpu) != 0) - die("loom_add_cpu failed"); - - if (loom_add_cpu(loom, &cpu) == 0) - die("loom_add_cpu didn't fail"); + OK(loom_add_cpu(loom, &cpu)); + ERR(loom_add_cpu(loom, &cpu)); 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 test_duplicate_procs(struct loom *loom) { - if (loom_init_begin(loom, testloom) != 0) - die("loom_init_begin failed"); - struct proc proc; - proc_init_begin(&proc, testproc); - if (loom_add_proc(loom, &proc) != 0) - die("loom_add_proc failed"); - - if (loom_add_proc(loom, &proc) == 0) - die("loom_add_proc didn't fail"); + OK(loom_init_begin(loom, testloom)); + OK(proc_init_begin(&proc, testproc)); + OK(loom_add_proc(loom, &proc)); + ERR(loom_add_proc(loom, &proc)); err("ok"); } @@ -140,7 +78,6 @@ int main(void) test_hostname(&loom); test_negative_cpu(&loom); test_duplicate_cpus(&loom); - //test_sort_cpus(&loom); test_duplicate_procs(&loom); return 0;