1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/fpga/tests/unit/dma.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

99 lines
2.8 KiB
C++
Raw Permalink Normal View History

/* DMA unit test.
2018-06-25 17:03:09 +02:00
*
* Author: Steffen Vogel <post@steffenvogel.de>
* SPDX-FileCopyrightText: 2017 Steffen Vogel <post@steffenvogel.de>
* SPDX-License-Identifier: Apache-2.0
*/
2018-06-25 17:03:09 +02:00
2018-03-26 16:15:31 +02:00
#include <criterion/criterion.h>
#include <villas/fpga/card.hpp>
#include <villas/fpga/ips/bram.hpp>
#include <villas/fpga/ips/dma.hpp>
#include <villas/log.hpp>
#include <villas/memory.hpp>
#include <villas/utils.hpp>
2018-03-26 16:15:31 +02:00
#include "global.hpp"
using namespace villas;
2018-03-26 16:15:31 +02:00
2020-09-21 09:35:41 +02:00
// cppcheck-suppress unknownMacro
Test(fpga, dma, .description = "DMA") {
auto logger = logging.get("unit-test:dma");
2020-06-11 23:55:05 +02:00
std::list<std::shared_ptr<fpga::ip::Dma>> dmaIps;
2022-08-30 12:01:47 -04:00
for (auto &ip : state.cards.front()->ips) {
if (*ip == fpga::Vlnv("xilinx.com:ip:axi_dma:")) {
auto dma = std::dynamic_pointer_cast<fpga::ip::Dma>(ip);
dmaIps.push_back(dma);
}
}
2018-03-26 16:15:31 +02:00
size_t count = 0;
for (auto &dma : dmaIps) {
logger->info("Testing {}", *dma);
2018-03-26 16:15:31 +02:00
if (not dma->loopbackPossible()) {
logger->info("Loopback test not possible for {}", *dma);
continue;
}
2018-03-26 16:15:31 +02:00
dma->connectLoopback();
2018-05-15 17:54:37 +02:00
// Simple DMA can only transfer up to 4 kb due to PCIe page size burst
// limitation
size_t len = 4 * (1 << 10);
2018-03-26 16:15:31 +02:00
2020-06-11 23:55:05 +02:00
#if 0
// Allocate memory to use with DMA
auto src = HostDmaRam::getAllocator().allocate<char>(len);
auto dst = HostDmaRam::getAllocator().allocate<char>(len);
2020-06-11 23:55:05 +02:00
#elif 0
// ... only works with IOMMU enabled currently
2018-05-15 17:54:37 +02:00
// Find a block RAM IP to write to
auto bramIp = state.cards.front()->lookupIp(
fpga::Vlnv("xilinx.com:ip:axi_bram_ctrl:"));
auto bram = std::dynamic_pointer_cast<fpga::ip::Bram>(bramIp);
cr_assert_not_null(bram, "Couldn't find BRAM");
2018-05-15 17:54:37 +02:00
auto src = bram->getAllocator().allocate<char>(len);
auto dst = bram->getAllocator().allocate<char>(len);
2020-06-11 23:55:05 +02:00
#else
// ... only works with IOMMU enabled currently
auto &alloc = villas::HostRam::getAllocator();
const std::shared_ptr<villas::MemoryBlock> srcBlock =
alloc.allocateBlock(len);
const std::shared_ptr<villas::MemoryBlock> dstBlock =
alloc.allocateBlock(len);
villas::MemoryAccessor<char> src(*srcBlock);
villas::MemoryAccessor<char> dst(*dstBlock);
2020-06-11 23:55:05 +02:00
#endif
// Make sure memory is accessible for DMA
dma->makeAccesibleFromVA(srcBlock);
dma->makeAccesibleFromVA(dstBlock);
2018-03-26 16:15:31 +02:00
// Get new random data
const size_t lenRandom = utils::readRandom(&src, len);
cr_assert(len == lenRandom, "Failed to get random data");
2018-03-26 16:15:31 +02:00
// Start transfer
cr_assert(dma->memcpy(src.getMemoryBlock(), dst.getMemoryBlock(), len),
"DMA ping pong failed");
2018-03-26 16:15:31 +02:00
// Compare data
cr_assert(memcmp(&src, &dst, len) == 0, "Data not equal");
2018-03-26 16:15:31 +02:00
logger->info(CLR_GRN("Passed"));
2020-06-11 23:55:05 +02:00
count++;
}
2018-03-26 16:15:31 +02:00
cr_assert(count > 0, "No DMA found");
2018-03-26 16:15:31 +02:00
MemoryManager::get().getGraph().dump();
fpga::ip::Node::getGraph().dump();
2018-03-26 16:15:31 +02:00
}