From f2d50ad38d51c63e145a146657eb32dda022cfb1 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 23 Dec 2016 17:24:53 +0100 Subject: [PATCH] moving VLLASfpga tests to Criterion unit tests --- src/fpga.c | 7 +- src/fpga-tests.c => tests/fpga.c | 193 +++++++++++++++---------------- 2 files changed, 97 insertions(+), 103 deletions(-) rename src/fpga-tests.c => tests/fpga.c (63%) diff --git a/src/fpga.c b/src/fpga.c index 46895c0f6..9cd7137a1 100644 --- a/src/fpga.c +++ b/src/fpga.c @@ -27,7 +27,6 @@ /* Declarations */ int fpga_benchmarks(int argc, char *argv[], struct fpga *f); -int fpga_tests(int argc, char *argv[], struct fpga *f); struct settings settings; @@ -35,7 +34,6 @@ void usage(char *name) { printf("Usage: %s CONFIGFILE CMD [OPTIONS]\n", name); printf(" Commands:\n"); - printf(" tests Test functionality of VILLASfpga card\n"); printf(" benchmarks Do benchmarks\n\n"); printf(" Options:\n"); printf(" -d Set log level\n\n"); @@ -58,9 +56,7 @@ int main(int argc, char *argv[]) if (argc < 3) usage(argv[0]); - if (strcmp(argv[2], "tests") == 0) - subcommand = FPGA_TESTS; - else if (strcmp(argv[2], "benchmarks") == 0) + if (strcmp(argv[2], "benchmarks") == 0) subcommand = FPGA_BENCH; else usage(argv[0]); @@ -96,7 +92,6 @@ int main(int argc, char *argv[]) /* Start subcommand */ switch (subcommand) { - case FPGA_TESTS: fpga_tests(argc-optind-1, argv+optind+1, fpga); break; case FPGA_BENCH: fpga_benchmarks(argc-optind-1, argv+optind+1, fpga); break; } diff --git a/src/fpga-tests.c b/tests/fpga.c similarity index 63% rename from src/fpga-tests.c rename to tests/fpga.c index 0790a2607..c738e7410 100644 --- a/src/fpga-tests.c +++ b/tests/fpga.c @@ -13,8 +13,12 @@ #include #include +#include +#include + #include +#include #include #include @@ -23,75 +27,81 @@ #include "config.h" +#define TEST_CONFIG "/villas/etc/fpga.conf" #define TEST_LEN 0x1000 #define CPU_HZ 3392389000 -/* Forward Declarations */ -int fpga_test_intc(struct fpga *f); -int fpga_test_timer(struct fpga *f); -int fpga_test_fifo(struct fpga *f); -int fpga_test_dma(struct fpga *f); -int fpga_test_xsg(struct fpga *f); -int fpga_test_hls_dft(struct fpga *f); -int fpga_test_rtds_rtt(struct fpga *f); +static struct fpga *fpga; -int fpga_tests(int argc, char *argv[], struct fpga *f) +static config_t config; +static struct settings settings; + +static void init() { int ret; + int argc = 1; + char *argv[] = { "tests" }; + config_setting_t *cfg_root; - struct { - const char *name; - int (*func)(struct fpga *f); - } tests[] = { - { "Interrupt Controller", fpga_test_intc }, - { "Timer Counter", fpga_test_timer }, - { "FIFO", fpga_test_fifo }, - { "DMA", fpga_test_dma }, - { "XSG: multiply_add", fpga_test_xsg }, - { "HLS: hls_dft", fpga_test_hls_dft }, - { "RTDS: tight rtt", fpga_test_rtds_rtt } - }; + cfg_parse(TEST_CONFIG, &config, &settings, NULL, NULL); - for (int i = 0; i < ARRAY_LEN(tests); i++) { - ret = tests[i].func(f); + cfg_root = config_root_setting(&config); - info("%s: %s", tests[i].name, (ret == 0) ? GRN("passed") : RED("failed")); - } + ret = fpga_init(argc, argv, cfg_root); + cr_assert_eq(ret, 0, "Failed to initilize FPGA"); - return 0; + fpga = fpga_get(); + + if (criterion_options.logging_threshold < CRITERION_IMPORTANT) + fpga_dump(fpga); } -int fpga_test_intc(struct fpga *f) +static void fini() +{ + int ret; + + ret = fpga_deinit(&fpga); + cr_assert_eq(ret, 0, "Failed to de-initilize FPGA"); + + cfg_destroy(&config); + +} + +TestSuite(fpga, + .init = init, + .fini = fini, + .description = "VILLASfpga"); + +Test(fpga, intc, .description = "Interrupt Controller") { int ret; uint32_t isr; - if (!f->intc) - return -1; + cr_assert(fpga->intc); - ret = intc_enable(f->intc, 0xFF00, 0); + ret = intc_enable(fpga->intc, 0xFF00, 0); if (ret) error("Failed to enable interrupt"); /* Fake IRQs in software by writing to ISR */ - XIntc_Out32((uintptr_t) f->map + f->intc->baseaddr + XIN_ISR_OFFSET, 0xFF00); + XIntc_Out32((uintptr_t) fpga->map + fpga->intc->baseaddr + XIN_ISR_OFFSET, 0xFF00); /* Wait for 8 SW triggered IRQs */ for (int i = 0; i < 8; i++) - intc_wait(f->intc, i+8); + intc_wait(fpga->intc, i+8); /* Check ISR if all SW IRQs have been deliverd */ - isr = XIntc_In32((uintptr_t) f->map + f->intc->baseaddr + XIN_ISR_OFFSET); + isr = XIntc_In32((uintptr_t) fpga->map + fpga->intc->baseaddr + XIN_ISR_OFFSET); - ret = intc_disable(f->intc, 0xFF00); + ret = intc_disable(fpga->intc, 0xFF00); if (ret) error("Failed to disable interrupt"); - return (isr & 0xFF00) ? -1 : 0; /* ISR should get cleared by MSI_Grant_signal */ + cr_assert_eq(isr & 0xFF00, 0); /* ISR should get cleared by MSI_Grant_signal */ } -int fpga_test_xsg(struct fpga *f) +Test(fpga, xsg, .description = "XSG: multiply_add") { int ret; double factor, err = 0; @@ -100,12 +110,11 @@ int fpga_test_xsg(struct fpga *f) struct model_param *p; struct dma_mem mem; - xsg = ip_vlnv_lookup(&f->ips, NULL, "sysgen", "xsg_multiply", NULL); - dma = ip_vlnv_lookup(&f->ips, "xilinx.com", "ip", "axi_dma", NULL); + xsg = ip_vlnv_lookup(&fpga->ips, NULL, "sysgen", "xsg_multiply", NULL); + dma = ip_vlnv_lookup(&fpga->ips, "xilinx.com", "ip", "axi_dma", NULL); /* Check if required IP is available on FPGA */ - if (!dma || !xsg || !dma) - return -1; + cr_assert_neq(!dma || !xsg || !dma, 0); p = list_lookup(&xsg->model.parameters, "factor"); if (!p) @@ -117,10 +126,10 @@ int fpga_test_xsg(struct fpga *f) info("Model param: factor = %f", factor); - ret = switch_connect(f->sw, dma, xsg); + ret = switch_connect(fpga->sw, dma, xsg); if (ret) error("Failed to configure switch"); - ret = switch_connect(f->sw, xsg, dma); + ret = switch_connect(fpga->sw, xsg, dma); if (ret) error("Failed to configure switch"); @@ -143,10 +152,10 @@ int fpga_test_xsg(struct fpga *f) info("Error after FPGA operation: err = %f", err); - ret = switch_disconnect(f->sw, dma, xsg); + ret = switch_disconnect(fpga->sw, dma, xsg); if (ret) error("Failed to configure switch"); - ret = switch_disconnect(f->sw, xsg, dma); + ret = switch_disconnect(fpga->sw, xsg, dma); if (ret) error("Failed to configure switch"); @@ -154,29 +163,28 @@ int fpga_test_xsg(struct fpga *f) if (ret) error("Failed to release DMA memory"); - return err > 1e-3; + cr_assert(err < 1e-3); } -int fpga_test_hls_dft(struct fpga *f) +Test(fpga, hls_dft, .description = "HLS: hls_dft") { int ret; struct ip *hls, *rtds; - rtds = ip_vlnv_lookup(&f->ips, "acs.eonerc.rwth-aachen.de", "user", "rtds_axis", NULL); - hls = ip_vlnv_lookup(&f->ips, NULL, "hls", "hls_dft", NULL); + rtds = ip_vlnv_lookup(&fpga->ips, "acs.eonerc.rwth-aachen.de", "user", "rtds_axis", NULL); + hls = ip_vlnv_lookup(&fpga->ips, NULL, "hls", "hls_dft", NULL); /* Check if required IP is available on FPGA */ - if (!hls || !rtds) - return -1; + cr_assert(hls && rtds); - ret = intc_enable(f->intc, (1 << rtds->irq), 0); + ret = intc_enable(fpga->intc, (1 << rtds->irq), 0); if (ret) error("Failed to enable interrupt"); - ret = switch_connect(f->sw, rtds, hls); + ret = switch_connect(fpga->sw, rtds, hls); if (ret) error("Failed to configure switch"); - ret = switch_connect(f->sw, hls, rtds); + ret = switch_connect(fpga->sw, hls, rtds); if (ret) error("Failed to configure switch"); @@ -201,32 +209,29 @@ int fpga_test_hls_dft(struct fpga *f) } #endif - ret = switch_disconnect(f->sw, rtds, hls); + ret = switch_disconnect(fpga->sw, rtds, hls); if (ret) error("Failed to configure switch"); - ret = switch_disconnect(f->sw, hls, rtds); + ret = switch_disconnect(fpga->sw, hls, rtds); if (ret) error("Failed to configure switch"); - - return 0; } -int fpga_test_fifo(struct fpga *f) +Test(fpga, fifo, .description = "FIFO") { int ret; ssize_t len; char src[255], dst[255]; struct ip *fifo; - fifo = ip_vlnv_lookup(&f->ips, "xilinx.com", "ip", "axi_fifo_mm_s", NULL); - if (!fifo) - return -1; + fifo = ip_vlnv_lookup(&fpga->ips, "xilinx.com", "ip", "axi_fifo_mm_s", NULL); + cr_assert(fifo); - ret = intc_enable(f->intc, (1 << fifo->irq), 0); + ret = intc_enable(fpga->intc, (1 << fifo->irq), 0); if (ret) error("Failed to enable interrupt"); - ret = switch_connect(f->sw, fifo, fifo); + ret = switch_connect(fpga->sw, fifo, fifo); if (ret) error("Failed to configure switch"); @@ -244,24 +249,24 @@ int fpga_test_fifo(struct fpga *f) if (len != sizeof(dst)) error("Failed to read from FIFO"); - ret = intc_disable(f->intc, (1 << fifo->irq)); + ret = intc_disable(fpga->intc, (1 << fifo->irq)); if (ret) error("Failed to disable interrupt"); - ret = switch_disconnect(f->sw, fifo, fifo); + ret = switch_disconnect(fpga->sw, fifo, fifo); if (ret) error("Failed to configure switch"); /* Compare data */ - return memcmp(src, dst, sizeof(src)); + cr_assert_eq(memcmp(src, dst, sizeof(src)), 0); } -int fpga_test_dma(struct fpga *f) +Test(fpga, dma, .description = "DMA") { int ret = -1; struct dma_mem mem, src, dst; - list_foreach(struct ip *dma, &f->ips) { INDENT + list_foreach(struct ip *dma, &fpga->ips) { INDENT if (!ip_vlnv_match(dma, "xilinx.com", "ip", "axi_dma", NULL)) continue; /* skip non DMA IP cores */ @@ -270,12 +275,10 @@ int fpga_test_dma(struct fpga *f) ssize_t len = dma->dma.inst.HasSg ? 64 << 20 : 1 << 2; ret = dma_alloc(dma, &mem, 2 * len, 0); - if (ret) - return -1; + cr_assert_eq(ret, 0); ret = dma_mem_split(&mem, &src, &dst); - if (ret) - return -1; + cr_assert_eq(ret, 0); /* Get new random data */ ret = read_random(src.base_virt, len); @@ -285,11 +288,11 @@ int fpga_test_dma(struct fpga *f) int irq_mm2s = dma->irq; int irq_s2mm = dma->irq + 1; - ret = intc_enable(f->intc, (1 << irq_mm2s) | (1 << irq_s2mm), 0); + ret = intc_enable(fpga->intc, (1 << irq_mm2s) | (1 << irq_s2mm), 0); if (ret) error("Failed to enable interrupt"); - ret = switch_connect(f->sw, dma, dma); + ret = switch_connect(fpga->sw, dma, dma); if (ret) error("Failed to configure switch"); @@ -302,11 +305,11 @@ int fpga_test_dma(struct fpga *f) info("DMA %s (%s): %s", dma->name, dma->dma.inst.HasSg ? "scatter-gather" : "simple", ret ? RED("failed") : GRN("passed")); - ret = switch_disconnect(f->sw, dma, dma); + ret = switch_disconnect(fpga->sw, dma, dma); if (ret) error("Failed to configure switch"); - ret = intc_disable(f->intc, (1 << irq_mm2s) | (1 << irq_s2mm)); + ret = intc_disable(fpga->intc, (1 << irq_mm2s) | (1 << irq_s2mm)); if (ret) error("Failed to disable interrupt"); @@ -315,21 +318,20 @@ int fpga_test_dma(struct fpga *f) error("Failed to release DMA memory"); } - return ret; + cr_assert_eq(ret, 0); } -int fpga_test_timer(struct fpga *f) +Test(fpga, timer, .description = "Timer Counter") { int ret; struct ip *tmr; - tmr = ip_vlnv_lookup(&f->ips, "xilinx.com", "ip", "axi_timer", NULL); - if (!tmr) - return -1; + tmr = ip_vlnv_lookup(&fpga->ips, "xilinx.com", "ip", "axi_timer", NULL); + cr_assert(tmr); XTmrCtr *xtmr = &tmr->timer.inst; - ret = intc_enable(f->intc, (1 << tmr->irq), 0); + ret = intc_enable(fpga->intc, (1 << tmr->irq), 0); if (ret) error("Failed to enable interrupt"); @@ -337,22 +339,22 @@ int fpga_test_timer(struct fpga *f) XTmrCtr_SetResetValue(xtmr, 0, FPGA_AXI_HZ / 125); XTmrCtr_Start(xtmr, 0); - uint64_t counter = intc_wait(f->intc, tmr->irq); + uint64_t counter = intc_wait(fpga->intc, tmr->irq); info("Got IRQ: counter = %ju", counter); if (counter == 1) - return 0; + return; else warn("Counter was not 1"); - intc_disable(f->intc, (1 << tmr->irq)); + intc_disable(fpga->intc, (1 << tmr->irq)); if (ret) error("Failed to disable interrupt"); - return -1; + return; } -int fpga_test_rtds_rtt(struct fpga *f) +Test(fpga, rtds_rtt, .description = "RTDS: tight rtt") { int ret; struct ip *dma, *rtds; @@ -360,17 +362,16 @@ int fpga_test_rtds_rtt(struct fpga *f) size_t recvlen; /* Get IP cores */ - rtds = ip_vlnv_lookup(&f->ips, "acs.eonerc.rwth-aachen.de", "user", "rtds_axis", NULL); - dma = list_lookup(&f->ips, "dma_1"); + rtds = ip_vlnv_lookup(&fpga->ips, "acs.eonerc.rwth-aachen.de", "user", "rtds_axis", NULL); + dma = list_lookup(&fpga->ips, "dma_1"); /* Check if required IP is available on FPGA */ - if (!dma || !rtds) - return -1; + cr_assert (dma && rtds); - ret = switch_connect(f->sw, rtds, dma); + ret = switch_connect(fpga->sw, rtds, dma); if (ret) error("Failed to configure switch"); - ret = switch_connect(f->sw, dma, rtds); + ret = switch_connect(fpga->sw, dma, rtds); if (ret) error("Failed to configure switch"); @@ -397,16 +398,14 @@ int fpga_test_rtds_rtt(struct fpga *f) error("Failed to complete DMA write: %d", ret); } - ret = switch_disconnect(f->sw, rtds, dma); + ret = switch_disconnect(fpga->sw, rtds, dma); if (ret) error("Failed to configure switch"); - ret = switch_disconnect(f->sw, dma, rtds); + ret = switch_disconnect(fpga->sw, dma, rtds); if (ret) error("Failed to configure switch"); ret = dma_free(dma, &buf); if (ret) error("Failed to release DMA memory"); - - return 0; } \ No newline at end of file