|
Packit |
534379 |
// Copyright(c) 2017-2020, Intel Corporation
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
534379 |
// modification, are permitted provided that the following conditions are met:
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// * Redistributions of source code must retain the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer.
|
|
Packit |
534379 |
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer in the documentation
|
|
Packit |
534379 |
// and/or other materials provided with the distribution.
|
|
Packit |
534379 |
// * Neither the name of Intel Corporation nor the names of its contributors
|
|
Packit |
534379 |
// may be used to endorse or promote products derived from this software
|
|
Packit |
534379 |
// without specific prior written permission.
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
534379 |
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
534379 |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
534379 |
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
Packit |
534379 |
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
534379 |
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
534379 |
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
534379 |
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
534379 |
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
534379 |
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit |
534379 |
// POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
534379 |
#include <opae/fpga.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
extern "C" {
|
|
Packit |
534379 |
fpga_result buffer_allocate(void*,uint64_t,int);
|
|
Packit |
534379 |
fpga_result buffer_release(void*,uint64_t);
|
|
Packit |
534379 |
int xfpga_plugin_initialize(void);
|
|
Packit |
534379 |
int xfpga_plugin_finalize(void);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include "error_int.h"
|
|
Packit |
534379 |
#include "common_int.h"
|
|
Packit |
534379 |
#include <tuple>
|
|
Packit |
534379 |
#include "xfpga.h"
|
|
Packit |
534379 |
#include "gtest/gtest.h"
|
|
Packit |
534379 |
#include "mock/test_system.h"
|
|
Packit |
534379 |
#include "intel-fpga.h"
|
|
Packit |
534379 |
#include "fpga-dfl.h"
|
|
Packit |
534379 |
#include <linux/ioctl.h>
|
|
Packit |
534379 |
#include <cstdarg>
|
|
Packit |
534379 |
#include "types_int.h"
|
|
Packit |
534379 |
#include <sys/mman.h>
|
|
Packit |
534379 |
#include <opae/buffer.h>
|
|
Packit |
534379 |
#include <opae/mmio.h>
|
|
Packit |
534379 |
#include <string>
|
|
Packit |
534379 |
#include <algorithm>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#define NLB_DSM_SIZE (2 * 1024 * 1024)
|
|
Packit |
534379 |
#define KB 1024
|
|
Packit |
534379 |
#define MB (1024 * KB)
|
|
Packit |
534379 |
#define GB (1024UL * MB)
|
|
Packit |
534379 |
#define FPGA_MOCK_IOVA 0xDECAFBADDEADBEEF
|
|
Packit |
534379 |
#undef FPGA_MSG
|
|
Packit |
534379 |
#define FPGA_MSG(fmt, ...) \
|
|
Packit |
534379 |
printf("MOCK " fmt "\n", ## __VA_ARGS__)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#pragma pack(push, 1)
|
|
Packit |
534379 |
struct buffer_params {
|
|
Packit |
534379 |
fpga_result result;
|
|
Packit |
534379 |
size_t size;
|
|
Packit |
534379 |
int flags;
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
#pragma pack(pop)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
using namespace opae::testing;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
int dma_map_ioctl(mock_object * m, int request, va_list argp){
|
|
Packit |
534379 |
UNUSED_PARAM(m);
|
|
Packit |
534379 |
UNUSED_PARAM(request);
|
|
Packit |
534379 |
int retval = -1;
|
|
Packit |
534379 |
errno = EINVAL;
|
|
Packit |
534379 |
struct fpga_port_dma_map *dma_map = va_arg(argp, struct fpga_port_dma_map *);
|
|
Packit |
534379 |
if (!dma_map) {
|
|
Packit |
534379 |
FPGA_MSG("dma_map is NULL");
|
|
Packit |
534379 |
goto out_EINVAL;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
if (dma_map->argsz != sizeof(*dma_map)) {
|
|
Packit |
534379 |
FPGA_MSG("wrong structure size");
|
|
Packit |
534379 |
goto out_EINVAL;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
if (!dma_map->user_addr) {
|
|
Packit |
534379 |
FPGA_MSG("mapping address is NULL");
|
|
Packit |
534379 |
goto out_EINVAL;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
/* TODO: check alignment */
|
|
Packit |
534379 |
if (dma_map->length == 0) {
|
|
Packit |
534379 |
FPGA_MSG("mapping size is 0");
|
|
Packit |
534379 |
goto out_EINVAL;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
dma_map->iova = FPGA_MOCK_IOVA; /* return something */
|
|
Packit |
534379 |
out:
|
|
Packit |
534379 |
return retval;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
out_EINVAL:
|
|
Packit |
534379 |
retval = -1;
|
|
Packit |
534379 |
errno = EINVAL;
|
|
Packit |
534379 |
goto out;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
int dma_unmap_ioctl(mock_object * m, int request, va_list argp){
|
|
Packit |
534379 |
UNUSED_PARAM(m);
|
|
Packit |
534379 |
UNUSED_PARAM(request);
|
|
Packit |
534379 |
int retval = -1;
|
|
Packit |
534379 |
errno = EINVAL;
|
|
Packit |
534379 |
struct fpga_port_dma_unmap *dma_unmap = va_arg(argp, struct fpga_port_dma_unmap *);
|
|
Packit |
534379 |
if (!dma_unmap) {
|
|
Packit |
534379 |
FPGA_MSG("dma_unmap is NULL");
|
|
Packit |
534379 |
goto out_EINVAL;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
if (dma_unmap->argsz != sizeof(*dma_unmap)) {
|
|
Packit |
534379 |
FPGA_MSG("wrong structure size");
|
|
Packit |
534379 |
goto out_EINVAL;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
if (dma_unmap->iova != FPGA_MOCK_IOVA) {
|
|
Packit |
534379 |
FPGA_MSG("unexpected IOVA (0x%llx)", dma_unmap->iova);
|
|
Packit |
534379 |
goto out_EINVAL;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
retval = 0;
|
|
Packit |
534379 |
errno = 0;
|
|
Packit |
534379 |
out:
|
|
Packit |
534379 |
return retval;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
out_EINVAL:
|
|
Packit |
534379 |
retval = -1;
|
|
Packit |
534379 |
errno = EINVAL;
|
|
Packit |
534379 |
goto out;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
class buffer_prepare : public ::testing::TestWithParam<std::tuple<std::string, buffer_params>> {
|
|
Packit |
534379 |
protected:
|
|
Packit |
534379 |
buffer_prepare()
|
|
Packit |
534379 |
: tokens_{{nullptr, nullptr}},
|
|
Packit |
534379 |
handle_(nullptr) {}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
virtual void SetUp() override {
|
|
Packit |
534379 |
auto tpl = GetParam();
|
|
Packit |
534379 |
std::string platform_key = std::get<0>(tpl);
|
|
Packit |
534379 |
ASSERT_TRUE(test_platform::exists(platform_key));
|
|
Packit |
534379 |
platform_ = test_platform::get(platform_key);
|
|
Packit |
534379 |
system_ = test_system::instance();
|
|
Packit |
534379 |
system_->initialize();
|
|
Packit |
534379 |
system_->prepare_syfs(platform_);
|
|
Packit |
534379 |
ASSERT_EQ(xfpga_plugin_initialize(), FPGA_OK);
|
|
Packit |
534379 |
ASSERT_EQ(xfpga_fpgaGetProperties(nullptr, &filter_), FPGA_OK);
|
|
Packit |
534379 |
ASSERT_EQ(fpgaPropertiesSetObjectType(filter_, FPGA_ACCELERATOR), FPGA_OK);
|
|
Packit |
534379 |
ASSERT_EQ(xfpga_fpgaEnumerate(&filter_, 1, tokens_.data(), tokens_.size(),
|
|
Packit |
534379 |
&num_matches_), FPGA_OK);
|
|
Packit |
534379 |
ASSERT_GT(num_matches_, 0);
|
|
Packit |
534379 |
ASSERT_EQ(xfpga_fpgaOpen(tokens_[0], &handle_, 0), FPGA_OK);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
virtual void TearDown() override {
|
|
Packit |
534379 |
EXPECT_EQ(fpgaDestroyProperties(&filter_), FPGA_OK);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
for (auto &t : tokens_) {
|
|
Packit |
534379 |
if (t) {
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_OK,xfpga_fpgaDestroyToken(&t);;
|
|
Packit |
534379 |
t = nullptr;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (handle_ != nullptr) {
|
|
Packit |
534379 |
EXPECT_EQ(xfpga_fpgaClose(handle_), FPGA_OK);
|
|
Packit |
534379 |
handle_ = nullptr;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
xfpga_plugin_finalize();
|
|
Packit |
534379 |
system_->finalize();
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
std::array<fpga_token, 2> tokens_;
|
|
Packit |
534379 |
fpga_handle handle_;
|
|
Packit |
534379 |
fpga_properties filter_;
|
|
Packit |
534379 |
uint32_t num_matches_;
|
|
Packit |
534379 |
test_platform platform_;
|
|
Packit |
534379 |
test_system *system_;
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test PrepPre2MB01
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @brief When the parameters are valid and the drivers are loaded:
|
|
Packit |
534379 |
* with pre-allocated buffer, fpgaPrepareBuffer must
|
|
Packit |
534379 |
* allocate a shared memory buffer. fpgaReleaseBuffer must
|
|
Packit |
534379 |
* release a shared memory buffer.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(buffer_prepare, PrepPre2MB01) {
|
|
Packit |
534379 |
uint64_t buf_len;
|
|
Packit |
534379 |
uint64_t* buf_addr = nullptr;
|
|
Packit |
534379 |
uint64_t wsid;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Allocate buffer in MB range
|
|
Packit |
534379 |
buf_len = 2 * 1024 * 1024;
|
|
Packit |
534379 |
buf_addr = (uint64_t*)mmap(ADDR, buf_len, PROTECTION, FLAGS_2M, 0, 0);
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_OK, xfpga_fpgaPrepareBuffer(handle_, buf_len, (void**)&buf_addr, &wsid,
|
|
Packit |
534379 |
FPGA_BUF_PREALLOCATED));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Release buffer in MB range
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_OK, xfpga_fpgaReleaseBuffer(handle_, wsid));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// buf_addr was preallocated, do not touch it
|
|
Packit |
534379 |
ASSERT_NE(buf_addr, (void*)nullptr);
|
|
Packit |
534379 |
munmap(buf_addr, buf_len);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
TEST_P(buffer_prepare, prepare_buf_err) {
|
|
Packit |
534379 |
uint64_t buf_len = 1024;
|
|
Packit |
534379 |
uint64_t* buf_addr = nullptr;
|
|
Packit |
534379 |
uint64_t wsid;
|
|
Packit |
534379 |
int flags = 0;
|
|
Packit |
534379 |
uint64_t *ioaddr = nullptr;
|
|
Packit |
534379 |
uint64_t* invalid_buf_addr = nullptr;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// NULL Handle
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_INVALID_PARAM, xfpga_fpgaPrepareBuffer(nullptr, 0, (void**) &buf_addr, &wsid, 0));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// NULL wsid
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_INVALID_PARAM, xfpga_fpgaPrepareBuffer(handle_, 0, (void**) &buf_addr, nullptr, flags));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Invlaid Flags
|
|
Packit |
534379 |
flags = 0x100;
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_INVALID_PARAM, xfpga_fpgaPrepareBuffer(handle_, buf_len, (void**) &buf_addr, &wsid, flags));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Buffer lenth is zero
|
|
Packit |
534379 |
flags = FPGA_BUF_PREALLOCATED;
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_INVALID_PARAM, xfpga_fpgaPrepareBuffer(handle_, 0, (void**) &buf_addr, &wsid, flags));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Not Page aligned buffer
|
|
Packit |
534379 |
buf_len = 11247;
|
|
Packit |
534379 |
flags = FPGA_BUF_PREALLOCATED;
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_INVALID_PARAM, xfpga_fpgaPrepareBuffer(handle_, buf_len, (void**) &buf_addr, &wsid, flags));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Invalid input buffer pointer
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_INVALID_PARAM, xfpga_fpgaPrepareBuffer(handle_, buf_len, (void**) &invalid_buf_addr, &wsid, flags));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// special test case
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_OK, xfpga_fpgaPrepareBuffer(handle_, 0, (void**) nullptr, &wsid, flags));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Buffer lenth is zero
|
|
Packit |
534379 |
flags = FPGA_BUF_QUIET;
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_INVALID_PARAM, xfpga_fpgaPrepareBuffer(handle_, 0, (void**) nullptr, &wsid, flags));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Invalid Handle
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_INVALID_PARAM, xfpga_fpgaGetIOAddress(nullptr, wsid, ioaddr));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Invalid workspace id
|
|
Packit |
534379 |
EXPECT_NE(FPGA_OK, xfpga_fpgaGetIOAddress(handle_, 0x10000, ioaddr));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// NULL Handle
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_INVALID_PARAM, xfpga_fpgaReleaseBuffer(nullptr, wsid));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Invalid workspace id
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_INVALID_PARAM, xfpga_fpgaReleaseBuffer(handle_, 0x10001));
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
TEST_P(buffer_prepare, xfpga_fpgaPrepareBuffer) {
|
|
Packit |
534379 |
buffer_params params = std::get<1>(GetParam());
|
|
Packit |
534379 |
void *buf_addr = nullptr;
|
|
Packit |
534379 |
uint64_t wsid = 0;
|
|
Packit |
534379 |
uint64_t ioaddr = 0;
|
|
Packit |
534379 |
auto res = xfpga_fpgaPrepareBuffer(handle_, params.size, (void **)&buf_addr, &wsid, params.flags);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
EXPECT_EQ(res, params.result) << "result is " << fpgaErrStr(res);
|
|
Packit |
534379 |
if (params.size > 0 && params.result == FPGA_OK) {
|
|
Packit |
534379 |
EXPECT_EQ(res = xfpga_fpgaGetIOAddress(handle_, wsid, &ioaddr), FPGA_OK)
|
|
Packit |
534379 |
<< "result is " << fpgaErrStr(res);
|
|
Packit |
534379 |
EXPECT_EQ(res = xfpga_fpgaReleaseBuffer(handle_, wsid), FPGA_OK)
|
|
Packit |
534379 |
<< "result is " << fpgaErrStr(res);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test release_neg
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @brief When the parameters are valid and the drivers are loaded:
|
|
Packit |
534379 |
* fpgaReleaseBuffer must fail if fpga_buffer was not
|
|
Packit |
534379 |
* prepared.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(buffer_prepare, release_neg) {
|
|
Packit |
534379 |
uint64_t wsid= 1;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
EXPECT_EQ(xfpga_fpgaReleaseBuffer(handle_, wsid), FPGA_INVALID_PARAM);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test not_aligned
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @brief When FPGA_BUF_PREALLOCATED is not given and the buffer
|
|
Packit |
534379 |
* len is not a multiple of the page size, fpgaPrepareBuffer
|
|
Packit |
534379 |
* allocates the next multiple of page size and returns
|
|
Packit |
534379 |
* FPGA_OK.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(buffer_prepare, not_aligned) {
|
|
Packit |
534379 |
uint64_t buf_len = (4 * 1024) - 1;
|
|
Packit |
534379 |
void *buf_addr = nullptr;
|
|
Packit |
534379 |
uint64_t wsid = 1;
|
|
Packit |
534379 |
int flags = 0;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
EXPECT_EQ(xfpga_fpgaPrepareBuffer(handle_, buf_len, &buf_addr, &wsid, flags),
|
|
Packit |
534379 |
FPGA_OK);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
EXPECT_EQ(xfpga_fpgaReleaseBuffer(handle_, wsid), FPGA_OK);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @test write_read
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @brief When the parameters are valid and the drivers are loaded:
|
|
Packit |
534379 |
* Test writing and reading to/from a shared memory buffer.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
TEST_P(buffer_prepare, write_read) {
|
|
Packit |
534379 |
uint64_t buf_len = NLB_DSM_SIZE;
|
|
Packit |
534379 |
void *buf_addr = nullptr;
|
|
Packit |
534379 |
uint64_t wsid = 2;
|
|
Packit |
534379 |
int flags = 0;
|
|
Packit |
534379 |
uint64_t offset;
|
|
Packit |
534379 |
uint64_t value;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Allocate buffer
|
|
Packit |
534379 |
ASSERT_EQ(xfpga_fpgaPrepareBuffer(handle_, buf_len, &buf_addr, &wsid, flags),
|
|
Packit |
534379 |
FPGA_OK);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Write test
|
|
Packit |
534379 |
memset(buf_addr, 0, buf_len);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
for (offset = 0; offset < buf_len - sizeof(uint64_t);
|
|
Packit |
534379 |
offset += sizeof(uint64_t)) {
|
|
Packit |
534379 |
value = offset;
|
|
Packit |
534379 |
*((volatile uint64_t*)((uint64_t)buf_addr + offset)) = value;
|
|
Packit |
534379 |
EXPECT_EQ(*((volatile uint64_t*)((uint64_t)buf_addr + offset)), offset);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
// Release buffer
|
|
Packit |
534379 |
EXPECT_EQ(xfpga_fpgaReleaseBuffer(handle_, wsid), FPGA_OK);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
namespace {
|
|
Packit |
534379 |
std::vector<buffer_params> params{
|
|
Packit |
534379 |
buffer_params{FPGA_INVALID_PARAM, 0, 0},
|
|
Packit |
534379 |
buffer_params{FPGA_OK, KiB(1), 0},
|
|
Packit |
534379 |
buffer_params{FPGA_OK, KiB(4), 0},
|
|
Packit |
534379 |
buffer_params{FPGA_OK, MiB(1), 0},
|
|
Packit |
534379 |
buffer_params{FPGA_OK, MiB(2), 0},
|
|
Packit |
534379 |
buffer_params{FPGA_INVALID_PARAM, 11247, FPGA_BUF_PREALLOCATED}};
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
INSTANTIATE_TEST_CASE_P(buffer_c, buffer_prepare,
|
|
Packit |
534379 |
::testing::Combine(::testing::ValuesIn(test_platform::keys()),
|
|
Packit |
534379 |
::testing::ValuesIn(params)));
|
|
Packit |
534379 |
|
|
Packit |
534379 |
class buffer_c_mock_p : public ::testing::TestWithParam<std::string> {
|
|
Packit |
534379 |
protected:
|
|
Packit |
534379 |
buffer_c_mock_p()
|
|
Packit |
534379 |
: tokens_{{nullptr, nullptr}},
|
|
Packit |
534379 |
handle_(nullptr) {}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
virtual void SetUp() override {
|
|
Packit |
534379 |
ASSERT_TRUE(test_platform::exists(GetParam()));
|
|
Packit |
534379 |
platform_ = test_platform::get(GetParam());
|
|
Packit |
534379 |
system_ = test_system::instance();
|
|
Packit |
534379 |
system_->initialize();
|
|
Packit |
534379 |
system_->prepare_syfs(platform_);
|
|
Packit |
534379 |
ASSERT_EQ(xfpga_plugin_initialize(), FPGA_OK);
|
|
Packit |
534379 |
ASSERT_EQ(xfpga_fpgaGetProperties(nullptr, &filter_), FPGA_OK);
|
|
Packit |
534379 |
ASSERT_EQ(fpgaPropertiesSetObjectType(filter_, FPGA_ACCELERATOR), FPGA_OK);
|
|
Packit |
534379 |
ASSERT_EQ(xfpga_fpgaEnumerate(&filter_, 1, tokens_.data(), tokens_.size(),
|
|
Packit |
534379 |
&num_matches_), FPGA_OK);
|
|
Packit |
534379 |
ASSERT_GT(num_matches_, 0);
|
|
Packit |
534379 |
ASSERT_EQ(xfpga_fpgaOpen(tokens_[0], &handle_, 0), FPGA_OK);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
virtual void TearDown() override {
|
|
Packit |
534379 |
EXPECT_EQ(fpgaDestroyProperties(&filter_), FPGA_OK);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
for (auto &t : tokens_) {
|
|
Packit |
534379 |
if (t) {
|
|
Packit |
534379 |
EXPECT_EQ(FPGA_OK,xfpga_fpgaDestroyToken(&t);;
|
|
Packit |
534379 |
t = nullptr;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (handle_ != nullptr) {
|
|
Packit |
534379 |
EXPECT_EQ(xfpga_fpgaClose(handle_), FPGA_OK);
|
|
Packit |
534379 |
handle_ = nullptr;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
xfpga_plugin_finalize();
|
|
Packit |
534379 |
system_->finalize();
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
std::array<fpga_token, 2> tokens_;
|
|
Packit |
534379 |
fpga_handle handle_;
|
|
Packit |
534379 |
fpga_properties filter_;
|
|
Packit |
534379 |
uint32_t num_matches_;
|
|
Packit |
534379 |
test_platform platform_;
|
|
Packit |
534379 |
test_system *system_;
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
|
|
Packit |
534379 |
TEST_P(buffer_c_mock_p, port_dma_unmap) {
|
|
Packit |
534379 |
void *buf_addr = nullptr;
|
|
Packit |
534379 |
uint64_t wsid = 0;
|
|
Packit |
534379 |
uint64_t buf_len = KiB(1);
|
|
Packit |
534379 |
auto res = xfpga_fpgaPrepareBuffer(handle_, buf_len, (void **)&buf_addr, &wsid, 0);
|
|
Packit |
534379 |
EXPECT_EQ(res, FPGA_OK);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
system_->register_ioctl_handler(FPGA_PORT_DMA_UNMAP, dummy_ioctl<-1,EINVAL>);
|
|
Packit |
534379 |
system_->register_ioctl_handler(DFL_FPGA_PORT_DMA_UNMAP, dummy_ioctl<-1, EINVAL>);
|
|
Packit |
534379 |
EXPECT_EQ(res = xfpga_fpgaReleaseBuffer(handle_, wsid), FPGA_INVALID_PARAM)
|
|
Packit |
534379 |
<< "result is " << fpgaErrStr(res);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
buf_addr = nullptr;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
TEST_P(buffer_c_mock_p, port_dma_map) {
|
|
Packit |
534379 |
void *buf_addr = nullptr;
|
|
Packit |
534379 |
uint64_t wsid = 0;
|
|
Packit |
534379 |
uint64_t buf_len = KiB(1);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
system_->register_ioctl_handler(FPGA_PORT_DMA_MAP, dummy_ioctl<-1,EINVAL>);
|
|
Packit |
534379 |
system_->register_ioctl_handler(DFL_FPGA_PORT_DMA_MAP, dummy_ioctl<-1, EINVAL>);
|
|
Packit |
534379 |
auto res = xfpga_fpgaPrepareBuffer(handle_, buf_len, (void **)&buf_addr, &wsid, 0);
|
|
Packit |
534379 |
EXPECT_EQ(res, FPGA_INVALID_PARAM) << "result is " << fpgaErrStr(res);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
INSTANTIATE_TEST_CASE_P(buffer_c, buffer_c_mock_p,
|
|
Packit |
534379 |
::testing::ValuesIn(test_platform::mock_platforms()));
|