|
Packit |
534379 |
# Copyright(c) 2018, 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 |
import json
|
|
Packit |
534379 |
import select
|
|
Packit |
534379 |
import struct
|
|
Packit |
534379 |
import subprocess
|
|
Packit |
534379 |
import threading
|
|
Packit |
534379 |
import time
|
|
Packit |
534379 |
import unittest
|
|
Packit |
534379 |
import uuid
|
|
Packit |
534379 |
import sys
|
|
Packit |
534379 |
import opae.fpga
|
|
Packit |
534379 |
|
|
Packit |
534379 |
NLB0 = "d8424dc4-a4a3-c413-f89e-433683f9040b"
|
|
Packit |
534379 |
|
|
Packit |
534379 |
MOCK_PORT_ERROR = "/tmp/class/fpga/intel-fpga-dev.0/intel-fpga-port.0/errors/errors"
|
|
Packit |
534379 |
|
|
Packit |
534379 |
NLB0_MDATA = {"version": 640,
|
|
Packit |
534379 |
"afu-image": {"clock-frequency-high": 312,
|
|
Packit |
534379 |
"clock-frequency-low": 156,
|
|
Packit |
534379 |
"power": 50,
|
|
Packit |
534379 |
"interface-uuid": "1a422218-6dba-448e-b302-425cbcde1406",
|
|
Packit |
534379 |
"magic-no": 488605312,
|
|
Packit |
534379 |
"accelerator-clusters": [{"total-contexts": 1,
|
|
Packit |
534379 |
"name": "nlb_400",
|
|
Packit |
534379 |
"accelerator-type-uuid": "d8424dc4-a4a3-c413-f89e-433683f9040b"}]},
|
|
Packit |
534379 |
"platform-name": "MCP"}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
class TestProperties(unittest.TestCase):
|
|
Packit |
534379 |
def test_set_parent(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(type=opae.fpga.DEVICE)
|
|
Packit |
534379 |
toks = opae.fpga.enumerate([props])
|
|
Packit |
534379 |
props2 = opae.fpga.properties(type=opae.fpga.ACCELERATOR,
|
|
Packit |
534379 |
parent=toks[0])
|
|
Packit |
534379 |
assert props2.parent
|
|
Packit |
534379 |
props2 = opae.fpga.properties(type=opae.fpga.ACCELERATOR)
|
|
Packit |
534379 |
props2.parent = toks[0]
|
|
Packit |
534379 |
assert props2.parent
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_guid(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(guid=NLB0)
|
|
Packit |
534379 |
guid_str = props.guid
|
|
Packit |
534379 |
guid = uuid.UUID(guid_str)
|
|
Packit |
534379 |
assert str(guid).lower() == NLB0
|
|
Packit |
534379 |
props = opae.fpga.properties()
|
|
Packit |
534379 |
props.guid = NLB0
|
|
Packit |
534379 |
guid_str = props.guid
|
|
Packit |
534379 |
guid = uuid.UUID(guid_str)
|
|
Packit |
534379 |
assert str(guid).lower() == NLB0
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_objtype_accelerator(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(type=opae.fpga.ACCELERATOR)
|
|
Packit |
534379 |
assert props.type == opae.fpga.ACCELERATOR
|
|
Packit |
534379 |
props = opae.fpga.properties(type=opae.fpga.DEVICE)
|
|
Packit |
534379 |
props.type = opae.fpga.ACCELERATOR
|
|
Packit |
534379 |
assert props.type == opae.fpga.ACCELERATOR
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_objtype_device(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(type=opae.fpga.DEVICE)
|
|
Packit |
534379 |
assert props.type == opae.fpga.DEVICE
|
|
Packit |
534379 |
props = opae.fpga.properties(type=opae.fpga.ACCELERATOR)
|
|
Packit |
534379 |
props.type = opae.fpga.DEVICE
|
|
Packit |
534379 |
assert props.type == opae.fpga.DEVICE
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_segment(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(segment=0x9090)
|
|
Packit |
534379 |
assert props.segment == 0x9090
|
|
Packit |
534379 |
props.segment = 0xA1A1
|
|
Packit |
534379 |
assert props.segment == 0xA1A1
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_bus(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(bus=0x5e)
|
|
Packit |
534379 |
assert props.bus == 0x5e
|
|
Packit |
534379 |
props.bus = 0xbe
|
|
Packit |
534379 |
assert props.bus == 0xbe
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_device(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(device=0xe)
|
|
Packit |
534379 |
assert props.device == 0xe
|
|
Packit |
534379 |
props.device = 0xf
|
|
Packit |
534379 |
assert props.device == 0xf
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_function(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(function=0x7)
|
|
Packit |
534379 |
assert props.function == 0x7
|
|
Packit |
534379 |
props.function = 0x6
|
|
Packit |
534379 |
assert props.function == 0x6
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_socket_id(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(socket_id=1)
|
|
Packit |
534379 |
assert props.socket_id == 1
|
|
Packit |
534379 |
props.socket_id = 0
|
|
Packit |
534379 |
assert props.socket_id == 0
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_object_id(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(object_id=0xcafe)
|
|
Packit |
534379 |
assert props.object_id == 0xcafe
|
|
Packit |
534379 |
props.object_id = 0xfade
|
|
Packit |
534379 |
assert props.object_id == 0xfade
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_num_errors(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(num_errors=8)
|
|
Packit |
534379 |
assert props.num_errors == 8
|
|
Packit |
534379 |
props.num_errors = 4
|
|
Packit |
534379 |
assert props.num_errors == 4
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_num_slots(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(type=opae.fpga.DEVICE,
|
|
Packit |
534379 |
num_slots=3)
|
|
Packit |
534379 |
assert props.num_slots == 3
|
|
Packit |
534379 |
props.num_slots = 2
|
|
Packit |
534379 |
assert props.num_slots == 2
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_bbs_id(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(type=opae.fpga.DEVICE,
|
|
Packit |
534379 |
bbs_id=0xc0c0cafe)
|
|
Packit |
534379 |
assert props.bbs_id == 0xc0c0cafe
|
|
Packit |
534379 |
props.bbs_id = 0xb0b0fade
|
|
Packit |
534379 |
assert props.bbs_id == 0xb0b0fade
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_bbs_version(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(type=opae.fpga.DEVICE,
|
|
Packit |
534379 |
bbs_version=(0, 1, 2))
|
|
Packit |
534379 |
assert props.bbs_version == (0, 1, 2)
|
|
Packit |
534379 |
props.bbs_version = (1, 2, 3)
|
|
Packit |
534379 |
assert props.bbs_version == (1, 2, 3)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_vendor_id(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(vendor_id=0xfafa)
|
|
Packit |
534379 |
assert props.vendor_id == 0xfafa
|
|
Packit |
534379 |
props.vendor_id = 0xdada
|
|
Packit |
534379 |
assert props.vendor_id == 0xdada
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_device_id(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(device_id=0xfa)
|
|
Packit |
534379 |
assert props.device_id == 0xfa
|
|
Packit |
534379 |
props.device_id = 0xda
|
|
Packit |
534379 |
assert props.device_id == 0xda
|
|
Packit |
534379 |
|
|
Packit |
534379 |
@unittest.skip("model not implemented yet")
|
|
Packit |
534379 |
def test_set_model(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(model="intel skxp")
|
|
Packit |
534379 |
assert props.model == "intel skxp"
|
|
Packit |
534379 |
props.model = "intel skxp 2"
|
|
Packit |
534379 |
assert props.model == "intel skxp 2"
|
|
Packit |
534379 |
|
|
Packit |
534379 |
@unittest.skip("local_memory_size not implemented yet")
|
|
Packit |
534379 |
def test_set_local_memory_size(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(local_memory_size=0xffff)
|
|
Packit |
534379 |
assert props.local_memory_size == 0xffff
|
|
Packit |
534379 |
props.local_memory_size = 0xaaaa
|
|
Packit |
534379 |
assert props.local_memory_size == 0xaaaa
|
|
Packit |
534379 |
|
|
Packit |
534379 |
@unittest.skip("capabilities not implemented yet")
|
|
Packit |
534379 |
def test_set_capabilities(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(capabilities=0xdeadbeef)
|
|
Packit |
534379 |
assert props.capabilities == 0xdeadbeef
|
|
Packit |
534379 |
props.capabilities = 0xfeebdaed
|
|
Packit |
534379 |
assert props.capabilities == 0xfeebdaed
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_num_mmio(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(type=opae.fpga.ACCELERATOR,
|
|
Packit |
534379 |
num_mmio=4)
|
|
Packit |
534379 |
assert props.num_mmio == 4
|
|
Packit |
534379 |
props.num_mmio = 5
|
|
Packit |
534379 |
assert props.num_mmio == 5
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_num_interrupts(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(type=opae.fpga.ACCELERATOR,
|
|
Packit |
534379 |
num_interrupts=9)
|
|
Packit |
534379 |
assert props.num_interrupts == 9
|
|
Packit |
534379 |
props.num_interrupts = 8
|
|
Packit |
534379 |
assert props.num_interrupts == 8
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_set_accelerator_state(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(
|
|
Packit |
534379 |
type=opae.fpga.ACCELERATOR,
|
|
Packit |
534379 |
accelerator_state=opae.fpga.ACCELERATOR_ASSIGNED)
|
|
Packit |
534379 |
assert props.accelerator_state == opae.fpga.ACCELERATOR_ASSIGNED
|
|
Packit |
534379 |
props.accelerator_state = opae.fpga.ACCELERATOR_UNASSIGNED
|
|
Packit |
534379 |
assert props.accelerator_state == opae.fpga.ACCELERATOR_UNASSIGNED
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
class TestToken(unittest.TestCase):
|
|
Packit |
534379 |
def test_enumerate(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(guid=NLB0)
|
|
Packit |
534379 |
toks = opae.fpga.enumerate([props])
|
|
Packit |
534379 |
assert toks
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_enumerate_kwargs(self):
|
|
Packit |
534379 |
toks = opae.fpga.enumerate(guid=NLB0)
|
|
Packit |
534379 |
assert toks
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_enumerate_empty_kwargs(self):
|
|
Packit |
534379 |
toks = opae.fpga.enumerate()
|
|
Packit |
534379 |
assert toks
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_token_properties(self):
|
|
Packit |
534379 |
props = opae.fpga.properties(guid=NLB0)
|
|
Packit |
534379 |
toks = opae.fpga.enumerate([props])
|
|
Packit |
534379 |
assert toks
|
|
Packit |
534379 |
for tok in toks:
|
|
Packit |
534379 |
token_props = opae.fpga.properties(tok)
|
|
Packit |
534379 |
assert token_props
|
|
Packit |
534379 |
assert token_props.guid and token_props.guid != ""
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
class TestHandle(unittest.TestCase):
|
|
Packit |
534379 |
def setUp(self):
|
|
Packit |
534379 |
self.props = opae.fpga.properties(type=opae.fpga.ACCELERATOR)
|
|
Packit |
534379 |
self.toks = opae.fpga.enumerate([self.props])
|
|
Packit |
534379 |
assert self.toks
|
|
Packit |
534379 |
self.handle = opae.fpga.open(self.toks[0])
|
|
Packit |
534379 |
assert self.handle
|
|
Packit |
534379 |
with open('m0.gbs', 'w+b') as fd:
|
|
Packit |
534379 |
if sys.version_info[0] == 3:
|
|
Packit |
534379 |
fd.write(bytes("XeonFPGA\b7GBSv001\53\02\00\00", 'UTF-8'))
|
|
Packit |
534379 |
fd.write(bytes(json.dumps(NLB0_MDATA), 'UTF-8'))
|
|
Packit |
534379 |
else:
|
|
Packit |
534379 |
fd.write("XeonFPGA\b7GBSv001\53\02\00\00")
|
|
Packit |
534379 |
fd.write(json.dumps(NLB0_MDATA))
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_open_null_token(self):
|
|
Packit |
534379 |
with self.assertRaises(ValueError):
|
|
Packit |
534379 |
hndl = opae.fpga.open(None)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_open(self):
|
|
Packit |
534379 |
assert self.handle
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_reconfigure(self):
|
|
Packit |
534379 |
with open('m0.gbs', 'r') as fd:
|
|
Packit |
534379 |
self.handle.reconfigure(0, fd)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_close(self):
|
|
Packit |
534379 |
self.handle.close()
|
|
Packit |
534379 |
assert not self.handle
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_context(self):
|
|
Packit |
534379 |
self.handle.close()
|
|
Packit |
534379 |
assert not self.handle
|
|
Packit |
534379 |
with opae.fpga.open(self.toks[0]) as h:
|
|
Packit |
534379 |
assert h
|
|
Packit |
534379 |
assert not h
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_reset(self):
|
|
Packit |
534379 |
self.handle.reset()
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_close_reset(self):
|
|
Packit |
534379 |
self.handle.close()
|
|
Packit |
534379 |
assert not self.handle
|
|
Packit |
534379 |
with self.assertRaises(RuntimeError):
|
|
Packit |
534379 |
self.handle.reset()
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_mmio(self):
|
|
Packit |
534379 |
offset = 0x100
|
|
Packit |
534379 |
write_value = 10
|
|
Packit |
534379 |
self.handle.write_csr32(offset, write_value)
|
|
Packit |
534379 |
read_value = self.handle.read_csr32(offset)
|
|
Packit |
534379 |
assert read_value == write_value
|
|
Packit |
534379 |
self.handle.write_csr64(offset, write_value)
|
|
Packit |
534379 |
read_value = self.handle.read_csr64(offset)
|
|
Packit |
534379 |
assert read_value == write_value
|
|
Packit |
534379 |
write_value = 0
|
|
Packit |
534379 |
self.handle.write_csr32(offset, write_value)
|
|
Packit |
534379 |
read_value = self.handle.read_csr32(offset)
|
|
Packit |
534379 |
assert read_value == write_value
|
|
Packit |
534379 |
self.handle.write_csr64(offset, write_value)
|
|
Packit |
534379 |
read_value = self.handle.read_csr64(offset)
|
|
Packit |
534379 |
assert read_value == write_value
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_close_mmio(self):
|
|
Packit |
534379 |
self.handle.close()
|
|
Packit |
534379 |
assert not self.handle
|
|
Packit |
534379 |
with self.assertRaises(RuntimeError):
|
|
Packit |
534379 |
self.handle.write_csr32(0x100, 0xbeef)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
with self.assertRaises(RuntimeError):
|
|
Packit |
534379 |
self.handle.write_csr64(0x100, 0xbeef)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
with self.assertRaises(RuntimeError):
|
|
Packit |
534379 |
self.handle.read_csr32(0x100)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
with self.assertRaises(RuntimeError):
|
|
Packit |
534379 |
self.handle.read_csr64(0x100)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
class TestSharedBuffer(unittest.TestCase):
|
|
Packit |
534379 |
def setUp(self):
|
|
Packit |
534379 |
self.props = opae.fpga.properties(type=opae.fpga.ACCELERATOR)
|
|
Packit |
534379 |
self.toks = opae.fpga.enumerate([self.props])
|
|
Packit |
534379 |
assert self.toks
|
|
Packit |
534379 |
self.handle = opae.fpga.open(self.toks[0])
|
|
Packit |
534379 |
assert self.handle
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_allocate(self):
|
|
Packit |
534379 |
buff1 = opae.fpga.allocate_shared_buffer(self.handle, 4096)
|
|
Packit |
534379 |
buff2 = opae.fpga.allocate_shared_buffer(self.handle, 4096)
|
|
Packit |
534379 |
assert buff1
|
|
Packit |
534379 |
assert buff2
|
|
Packit |
534379 |
assert buff1.size() == 4096
|
|
Packit |
534379 |
assert buff1.wsid() != 0
|
|
Packit |
534379 |
assert buff1.io_address() != 0
|
|
Packit |
534379 |
mv = memoryview(buff1)
|
|
Packit |
534379 |
assert mv
|
|
Packit |
534379 |
assert not buff1.compare(buff2, 4096)
|
|
Packit |
534379 |
buff1.fill(0xAA)
|
|
Packit |
534379 |
buff2.fill(0xEE)
|
|
Packit |
534379 |
assert buff1.compare(buff2, 4096)
|
|
Packit |
534379 |
if sys.version_info[0] == 2:
|
|
Packit |
534379 |
assert mv[0] == '\xaa'
|
|
Packit |
534379 |
assert mv[-1] == '\xaa'
|
|
Packit |
534379 |
else:
|
|
Packit |
534379 |
assert mv[0] == 0xaa
|
|
Packit |
534379 |
assert mv[-1] == 0xaa
|
|
Packit |
534379 |
ba = bytearray(buff1)
|
|
Packit |
534379 |
assert ba[0] == 0xaa
|
|
Packit |
534379 |
buff1[42] = int(65536)
|
|
Packit |
534379 |
assert struct.unpack('
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_conext_release(self):
|
|
Packit |
534379 |
assert self.handle
|
|
Packit |
534379 |
self.handle.close()
|
|
Packit |
534379 |
with opae.fpga.open(self.toks[0]) as h:
|
|
Packit |
534379 |
buff = opae.fpga.allocate_shared_buffer(h, 4096)
|
|
Packit |
534379 |
assert buff
|
|
Packit |
534379 |
assert buff.size() == 4096
|
|
Packit |
534379 |
assert buff.wsid() != 0
|
|
Packit |
534379 |
assert not h
|
|
Packit |
534379 |
assert buff.size() == 0
|
|
Packit |
534379 |
assert buff.wsid() == 0
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def trigger_port_error(value=1):
|
|
Packit |
534379 |
with open(MOCK_PORT_ERROR, 'w') as fd:
|
|
Packit |
534379 |
fd.write('0\n')
|
|
Packit |
534379 |
if value:
|
|
Packit |
534379 |
with open(MOCK_PORT_ERROR, 'w') as fd:
|
|
Packit |
534379 |
fd.write('{}\n'.format(value))
|
|
Packit |
534379 |
|
|
Packit |
534379 |
class TestEvent(unittest.TestCase):
|
|
Packit |
534379 |
def setUp(self):
|
|
Packit |
534379 |
trigger_port_error(0)
|
|
Packit |
534379 |
self.props = opae.fpga.properties(type=opae.fpga.ACCELERATOR,
|
|
Packit |
534379 |
socket_id=0)
|
|
Packit |
534379 |
self.toks = opae.fpga.enumerate([self.props])
|
|
Packit |
534379 |
assert self.toks
|
|
Packit |
534379 |
self.handle = opae.fpga.open(self.toks[0])
|
|
Packit |
534379 |
assert self.handle
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def tearDown(self):
|
|
Packit |
534379 |
trigger_port_error(0)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_events(self):
|
|
Packit |
534379 |
err_ev = opae.fpga.register_event(self.handle,
|
|
Packit |
534379 |
opae.fpga.EVENT_ERROR)
|
|
Packit |
534379 |
assert err_ev
|
|
Packit |
534379 |
# FIXME: os_object returns long
|
|
Packit |
534379 |
# WA is to cast it to int
|
|
Packit |
534379 |
os_object = int(err_ev.os_object())
|
|
Packit |
534379 |
assert isinstance(os_object, int)
|
|
Packit |
534379 |
assert os_object > -1
|
|
Packit |
534379 |
epoll = select.epoll()
|
|
Packit |
534379 |
epoll.register(os_object, select.EPOLLIN)
|
|
Packit |
534379 |
received_event = False
|
|
Packit |
534379 |
count = 0
|
|
Packit |
534379 |
trigger_error_timer = threading.Timer(1, trigger_port_error)
|
|
Packit |
534379 |
trigger_error_timer.start()
|
|
Packit |
534379 |
for _ in range(10):
|
|
Packit |
534379 |
for fileno, ev in epoll.poll(1):
|
|
Packit |
534379 |
if fileno == os_object:
|
|
Packit |
534379 |
received_event = True
|
|
Packit |
534379 |
break
|
|
Packit |
534379 |
if received_event:
|
|
Packit |
534379 |
break
|
|
Packit |
534379 |
time.sleep(1)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
trigger_error_timer.cancel()
|
|
Packit |
534379 |
# temporarily disalbe this assertion
|
|
Packit |
534379 |
#assert received_event
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
class TestError(unittest.TestCase):
|
|
Packit |
534379 |
def setUp(self):
|
|
Packit |
534379 |
self.port_errors = {"errors": {"can_clear": True},
|
|
Packit |
534379 |
"first_error": {"can_clear": False},
|
|
Packit |
534379 |
"first_malformed_req": {"can_clear": False}}
|
|
Packit |
534379 |
self.fme_errors = {"pcie0_errors": {"can_clear": True},
|
|
Packit |
534379 |
"warning_errors": {"can_clear": True},
|
|
Packit |
534379 |
"pcie1_errors": {"can_clear": True},
|
|
Packit |
534379 |
"gbs_errors": {"can_clear": False},
|
|
Packit |
534379 |
"bbs_errors": {"can_clear": False},
|
|
Packit |
534379 |
"next_error": {"can_clear": False},
|
|
Packit |
534379 |
"errors": {"can_clear": False},
|
|
Packit |
534379 |
"first_error": {"can_clear": False},
|
|
Packit |
534379 |
"inject_error": {"can_clear": True}}
|
|
Packit |
534379 |
props = opae.fpga.properties(type=opae.fpga.ACCELERATOR)
|
|
Packit |
534379 |
toks = opae.fpga.enumerate([props])
|
|
Packit |
534379 |
assert toks
|
|
Packit |
534379 |
self.acc_token = toks[0]
|
|
Packit |
534379 |
props.type = opae.fpga.DEVICE
|
|
Packit |
534379 |
toks = opae.fpga.enumerate([props])
|
|
Packit |
534379 |
assert toks
|
|
Packit |
534379 |
self.dev_token = toks[0]
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_port_errors(self):
|
|
Packit |
534379 |
for err in opae.fpga.errors(self.acc_token):
|
|
Packit |
534379 |
assert self.port_errors[err.name]["can_clear"] == err.can_clear
|
|
Packit |
534379 |
self.port_errors.pop(err.name)
|
|
Packit |
534379 |
assert not self.port_errors
|
|
Packit |
534379 |
|
|
Packit |
534379 |
def test_fme_errors(self):
|
|
Packit |
534379 |
for err in opae.fpga.errors(self.dev_token):
|
|
Packit |
534379 |
assert self.fme_errors[err.name]["can_clear"] == err.can_clear
|
|
Packit |
534379 |
self.fme_errors.pop(err.name)
|
|
Packit |
534379 |
assert not self.fme_errors
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if __name__ == "__main__":
|
|
Packit |
534379 |
test = TestEvent('test_events')
|
|
Packit |
534379 |
test.run()
|
|
Packit |
534379 |
|