2023-09-08 11:35:18 +02:00
|
|
|
/* FPGA related code for bootstrapping the unit-tests
|
2018-01-31 15:11:13 +01:00
|
|
|
*
|
2023-01-07 17:20:15 +01:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
2023-01-07 17:32:48 +01:00
|
|
|
* SPDX-FileCopyrightText: 2018 Steffen Vogel <post@steffenvogel.de>
|
2023-12-12 11:40:12 +01:00
|
|
|
* Author: Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
|
|
|
|
* SPDX-FileCopyrightText: 2023 Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
|
2023-01-07 17:20:15 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2023-09-08 11:35:18 +02:00
|
|
|
*/
|
2018-01-31 15:11:13 +01:00
|
|
|
|
|
|
|
#include <criterion/criterion.h>
|
|
|
|
|
2020-06-12 00:05:03 +02:00
|
|
|
#include <villas/fpga/core.hpp>
|
2023-01-26 18:11:25 +01:00
|
|
|
#include <villas/fpga/pcie_card.hpp>
|
2023-12-12 11:40:12 +01:00
|
|
|
#include <villas/fpga/utils.hpp>
|
2018-03-26 15:39:26 +02:00
|
|
|
#include <villas/fpga/vlnv.hpp>
|
2018-01-31 15:11:13 +01:00
|
|
|
|
|
|
|
#include "global.hpp"
|
|
|
|
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
#define FPGA_CARD "vc707"
|
|
|
|
#define TEST_CONFIG "../etc/fpga.json"
|
|
|
|
#define TEST_LEN 0x1000
|
2018-01-31 15:11:13 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
#define CPU_HZ 3392389000
|
|
|
|
#define FPGA_AXI_HZ 125000000
|
2018-01-31 15:11:13 +01:00
|
|
|
|
2020-06-11 14:20:33 +02:00
|
|
|
using namespace villas;
|
|
|
|
|
2024-08-22 14:37:22 +02:00
|
|
|
static kernel::devices::PciDeviceList *pciDevices;
|
2018-01-31 15:11:13 +01:00
|
|
|
|
|
|
|
FpgaState state;
|
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
static void init() {
|
|
|
|
FILE *f;
|
|
|
|
json_error_t err;
|
2018-01-31 15:11:13 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
spdlog::set_level(spdlog::level::debug);
|
|
|
|
spdlog::set_pattern("[%T] [%l] [%n] %v");
|
2018-02-13 15:39:03 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
plugin::registry->dump();
|
2018-01-31 15:11:13 +01:00
|
|
|
|
2024-08-22 14:37:22 +02:00
|
|
|
pciDevices = kernel::devices::PciDeviceList::getInstance();
|
2018-01-31 15:11:13 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
auto vfioContainer = std::make_shared<kernel::vfio::Container>();
|
2018-01-31 15:11:13 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
// Parse FPGA configuration
|
|
|
|
char *fn = getenv("TEST_CONFIG");
|
|
|
|
f = fopen(fn ? fn : TEST_CONFIG, "r");
|
|
|
|
cr_assert_not_null(f, "Cannot open config file");
|
2018-01-31 15:11:13 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
json_t *json = json_loadf(f, 0, &err);
|
|
|
|
cr_assert_not_null(json, "Cannot load JSON config");
|
2018-01-31 15:11:13 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
fclose(f);
|
2018-01-31 15:11:13 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
json_t *fpgas = json_object_get(json, "fpgas");
|
|
|
|
cr_assert_not_null(fpgas, "No section 'fpgas' found in config");
|
|
|
|
cr_assert(json_object_size(json) > 0, "No FPGAs defined in config");
|
2018-01-31 15:11:13 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
// Get the FPGA card plugin
|
|
|
|
auto fpgaCardFactory =
|
|
|
|
plugin::registry->lookup<fpga::PCIeCardFactory>("pcie");
|
|
|
|
cr_assert_not_null(fpgaCardFactory, "No plugin for FPGA card found");
|
2018-01-31 15:11:13 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
// Create all FPGA card instances using the corresponding plugin
|
|
|
|
auto configDir = std::filesystem::path(fn).parent_path();
|
|
|
|
auto cards = std::list<std::shared_ptr<fpga::Card>>();
|
|
|
|
fpga::createCards(json, cards, configDir);
|
|
|
|
state.cards = cards;
|
2018-01-31 15:11:13 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
cr_assert(state.cards.size() != 0, "No FPGA cards found!");
|
2018-01-31 15:11:13 +01:00
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
json_decref(json);
|
2018-01-31 15:11:13 +01:00
|
|
|
}
|
|
|
|
|
2024-02-29 19:34:27 +01:00
|
|
|
static void fini() {
|
|
|
|
// Release all cards
|
|
|
|
state.cards.clear();
|
2018-01-31 15:11:13 +01:00
|
|
|
}
|
|
|
|
|
2020-09-21 09:35:41 +02:00
|
|
|
// cppcheck-suppress unknownMacro
|
2024-02-29 19:34:27 +01:00
|
|
|
TestSuite(fpga, .init = init, .fini = fini, .description = "VILLASfpga");
|