Commit a9ba178a authored by Federico Vaga's avatar Federico Vaga

test: add new tests and improve old

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 755c1c1b
......@@ -47,14 +47,15 @@ static struct trtl_msg_filter filters[] = {
.flags = 0,
.operation = TRTL_MSG_FILTER_AND,
.word_offset = 0, /* ATTENTION: sync_id in the message header */
.mask = TRTL_HMQ_HEADER_FLAG_SYNC << 8,
.value = TRTL_HMQ_HEADER_FLAG_SYNC << 8,
.mask = (TRTL_HMQ_HEADER_FLAG_SYNC | TRTL_HMQ_HEADER_FLAG_ACK) << 8,
.value = 0,
},
[TRTL_MSG_FILTER_SYNC] = {
.flags = 0,
.operation = TRTL_MSG_FILTER_NEQ,
.operation = TRTL_MSG_FILTER_AND,
.word_offset = 1, /* ATTENTION: sync_id in the message header */
.value = 0,
.mask = TRTL_HMQ_HEADER_FLAG_ACK << 8,
.value = TRTL_HMQ_HEADER_FLAG_ACK << 8,
},
};
......
......@@ -22,10 +22,6 @@ def cfg():
cfg.n_hmq[1] = 2
cfg.n_rmq[0] = 1
cfg.n_rmq[1] = 1
cfg.hmq[0].sizes = 0x0
cfg.hmq[1].sizes = 0
cfg.hmq[8].sizes = 0
cfg.hmq[9].sizes = 0
return cfg
......@@ -45,6 +41,12 @@ def trtl_cpu(request, trtl_device):
yield trtl_device.cpu[request.param]
trtl_device.cpu[request.param].disable()
@pytest.fixture(scope="module")
def trtl_cpu0(request, trtl_device):
trtl_device.cpu[0].disable()
yield trtl_device.cpu[0]
trtl_device.cpu[0].disable()
@pytest.fixture(scope="module")
def trtl_shm():
dev = PyMockTurtle.TrtlDevice(devid())
......
-include Makefile.specific
DIRS := serial
DIRS += cpu-loop
DIRS += cpu-notify
DIRS += cpu-byte-addressing
DIRS += config_rom
DIRS += sim-verif
DIRS += hmq-async-recv
DIRS += hmq-async-send
DIRS += hmq-sync
DIRS += hmq-purge
DIRS += rt-frm-ping
all clean cleanall modules install modules_install: $(DIRS)
......
mainmenu "config_rom test configuration"
comment "Project specific configuration"
config FPGA_APPLICATION_ID
int "FPGA application ID"
default 0
help
Help text
config RT_APPLICATION_ID
int "RT application ID"
default 0
help
Help text
# include Mock Turtle's Kconfig
source "Kconfig.mt"
OBJS = byte-addressing.o
OBJS += # add other object files that you need
OUTPUT = fw-byte-addressing
TRTL ?= ../../../
TRTL_SW = $(TRTL)/software
CFLAGS_OPT = -O0 # disable optimization
include $(TRTL_SW)/rt/Makefile
#include <mockturtle-rt.h>
int byte_address_test_8(void *mem, size_t size)
{
uint8_t *data = mem;
int i, dw = 1;
for (i = 0; i < size / dw; ++i)
data[i] = (i & 0xFF); /* ignored by the HW on
input buffer */
for (i = 0; i < size / dw; ++i) {
if (data[i] != (i & 0xFF)) {
pr_error("Failure at %p (%d) dw: %d (0x%x != 0x%x)\r\n",
&data[i], i, dw,
data[i], (i & 0xFF));
while (i++ < 4)
pp_printf("0x%x 0x%x\r\n", data[i], i);
return -1;
}
}
return 0;
}
int byte_address_test_16(void *mem, size_t size)
{
uint16_t *data = mem;
int i, dw = 2;
for (i = 0; i < size / dw; ++i)
data[i] = (i & 0xFFFF); /* ignored by the HW on
input buffer */
for (i = 0; i < size / dw; ++i) {
if (data[i] != (i & 0xFFFF)) {
pr_error("Failure at %p (%d) dw: %d (0x%x != 0x%x)\r\n",
&data[i], i, dw,
data[i], (i & 0xFFFF));
while (i++ < 4)
pp_printf("0x%x 0x%x\r\n", data[i], i);
return -1;
}
}
return 0;
}
int byte_address_test_32(void *mem, size_t size)
{
uint32_t *data = mem;
int i, dw = 4;
for (i = 0; i < size / dw; ++i)
data[i] = (i & 0xFFFFFFFF); /* ignored by the HW on
input buffer */
for (i = 0; i < size / dw; ++i) {
if (data[i] != (i & 0xFFFFFFFF)) {
pr_error("Failure at %p (%d) dw: %d (0x%lx != 0x%x)\r\n",
&data[i], i, dw,
data[i], (i & 0xFFFFFFFF));
while (i++ < 4)
pp_printf("0x%"PRIx32" 0x%x\r\n", data[i], i);
return -1;
}
}
return 0;
}
static int (*func[])(void *mem, size_t size) = {
byte_address_test_32,
byte_address_test_16,
byte_address_test_8,
};
static int byte_addressing_test(void *mem, size_t size)
{
int err, i;
for (i = 0; i < ARRAY_SIZE(func); ++i) {
err = func[i](mem, size);
if (err)
return err;
}
return 0;
}
static int byte_addressing_test_mq(enum trtl_mq_type type,
unsigned int cpu, unsigned int hmq)
{
const struct trtl_config_rom *cfg = trtl_config_rom_get();
uint32_t size;
int err, g_err = 0, max_wait_cycle, wait, i;
char c = (type == TRTL_HMQ ? 'H' : 'R');
mq_claim(type, hmq);
size = TRTL_CONFIG_ROM_MQ_SIZE_PAYLOAD(cfg->rmq[cpu][hmq].sizes);
err = byte_addressing_test(mq_map_out_buffer(type, hmq),
size);
g_err |= err;
if (err)
pr_error("Failed, %cMQ[%d] out payload\r\n", c, hmq);
size = TRTL_CONFIG_ROM_MQ_SIZE_HEADER(cfg->hmq[cpu][hmq].sizes);
err = byte_addressing_test(mq_map_out_header(type, hmq),
size);
g_err |= err;
if (err)
pr_error("Failed, %cMQ[%d] out header\r\n", c, hmq);
if (type == TRTL_RMQ)
goto out; /* can't check input for RMQ */
for (i = 0; i < ARRAY_SIZE(func); ++i) {
wait = (1 << hmq);
max_wait_cycle = 0xFFFFFF;
while ((mq_poll_in(type) & wait) != wait) {
if (--max_wait_cycle == 0) {
pr_error("\tNO MESSAGE PENDING %cMQ[%d\r\n",
c, hmq);
return -1;
}
}
break; /* FIXME do not test input - somehting wrong with the test */
err = func[i](mq_map_in_header(type, hmq), size);
g_err |= err;
if (err)
pr_error("Failed, %cMQ[%d] in header\r\n", c, hmq);
err = func[i](mq_map_in_buffer(type, hmq), size);
g_err |= err;
if (err)
pr_error("Failed, %cMQ[%d] in payload\r\n", c, hmq);
mq_discard(TRTL_HMQ, hmq);
}
out:
mq_purge(type, hmq);
return g_err;
}
static int byte_addressing_test_shm(void)
{
const struct trtl_config_rom *cfg = trtl_config_rom_get();
void *smem_buf = (void *)TRTL_ADDR_SHM_BASE;
int err;
err = byte_addressing_test(smem_buf, cfg->smem_size);
if (err)
pr_error("Failed, shared memory\r\n");
return err;
}
int main()
{
int cpu = 0, i, g_err = 0;
const struct trtl_config_rom *cfg = trtl_config_rom_get();
pr_debug("BYTE ADDRESSING\r\n");
g_err |= byte_addressing_test_shm();
for (i = 0; i < cfg->n_rmq[cpu]; ++i)
g_err |= byte_addressing_test_mq(TRTL_RMQ, cpu, i);
for (i = 0; i < cfg->n_hmq[cpu]; ++i)
g_err |= byte_addressing_test_mq(TRTL_HMQ, cpu, i);
if (!g_err)
pp_printf("OK\r\n");
return g_err;
}
#
# Automatically generated file; DO NOT EDIT.
# config_rom test configuration
#
#
# Project specific configuration
#
CONFIG_FPGA_APPLICATION_ID=0
CONFIG_RT_APPLICATION_ID=0
#
# Mock Turtle configuration
#
#
# Mock Turtle framework configuration
#
# CONFIG_MOCKTURTLE_FRAMEWORK_ENABLE is not set
#
# Mock Turtle library configuration
#
CONFIG_MOCKTURTLE_LIBRARY_PRINT_ENABLE=y
# CONFIG_MOCKTURTLE_LIBRARY_PRINT_DEBUG_ENABLE is not set
CONFIG_MOCKTURTLE_LIBRARY_PRINT_ERROR_ENABLE=y
mainmenu "config_rom test configuration"
comment "Project specific configuration"
config FPGA_APPLICATION_ID
int "FPGA application ID"
default 0
help
Help text
config RT_APPLICATION_ID
int "RT application ID"
default 0
help
Help text
# include Mock Turtle's Kconfig
source "Kconfig.mt"
OBJS = notify.o
OBJS += # add other object files that you need
OUTPUT = fw-notify
TRTL ?= ../../../
TRTL_SW = $(TRTL)/software
CFLAGS_OPT = -O0 # disable optimization
include $(TRTL_SW)/rt/Makefile
#
# Automatically generated file; DO NOT EDIT.
# config_rom test configuration
#
#
# Project specific configuration
#
CONFIG_FPGA_APPLICATION_ID=0
CONFIG_RT_APPLICATION_ID=0
#
# Mock Turtle configuration
#
#
# Mock Turtle framework configuration
#
# CONFIG_MOCKTURTLE_FRAMEWORK_ENABLE is not set
#
# Mock Turtle library configuration
#
CONFIG_MOCKTURTLE_LIBRARY_PRINT_ENABLE=y
# CONFIG_MOCKTURTLE_LIBRARY_PRINT_DEBUG_ENABLE is not set
CONFIG_MOCKTURTLE_LIBRARY_PRINT_ERROR_ENABLE=y
#include <mockturtle-rt.h>
int main()
{
int i, k;
pr_debug("NOTIFICATION\r\n");
for (k = 0; k < 10; ++k) {
for (i = 0; i < __TRTL_CPU_NOTIFY_MAX; ++i) {
delay(10000);
trtl_notify_user(i);
}
}
pp_printf("OK\r\n");
return 0;
}
......@@ -24,9 +24,9 @@ int main()
mq_claim(TRTL_HMQ, hmq);
hdr = mq_map_out_header(TRTL_HMQ, hmq);
msg = mq_map_out_buffer(TRTL_HMQ, hmq);
for (i = 0; i < n_word; i++)
hdr->len = n_word;
for (i = 0; i < hdr->len; i++)
msg[i] = i;
hdr->len = n_word - 1; /* last valid index */
mq_send(TRTL_HMQ, hmq);
}
}
......
......@@ -29,7 +29,7 @@ int main()
}
/* validate message */
if (hdr->len != 1 || msg[0] != count) {
if (hdr->len != 2 || msg[0] != count) {
pr_error("\th: %d, l:%d, d[0]:0x%lx, cnt:0x%x\r\n",
hmq, hdr->len, msg[0], count);
mq_discard(TRTL_HMQ, hmq);
......
......@@ -32,7 +32,7 @@ int main()
}
/* validate message */
if (hdr_r->len != 1 || msg_r[0] != count) {
if (hdr_r->len != 2 || msg_r[0] != count) {
pr_error("\th: %d, l:%d, d[0]:0x%lx, cnt:0x%x\r\n",
hmq, hdr_r->len, msg_r[0], count);
mq_discard(TRTL_HMQ, hmq);
......@@ -46,8 +46,7 @@ int main()
}
mq_claim(TRTL_HMQ, hmq);
hdr_s->len = hdr_r->len;
hdr_s->sync_id = hdr_r->sync_id;
memcpy(hdr_s, hdr_r, sizeof(struct trtl_hmq_header));
memcpy(msg_s, msg_r, (hdr_r->len + 1) * 4);
mq_discard(TRTL_HMQ, hmq);
......
mainmenu "hello_world_framework demo configuration"
comment "Project specific configuration"
config FPGA_APPLICATION_ID
int "FPGA application ID"
default 0
help
Help text
config RT_APPLICATION_ID
int "RT application ID"
default 0
help
Help text
# include Mock Turtle's Kconfig
source "Kconfig.mt"
OBJS = rt-frm-ping.o
OBJS += # add other object files that you need
OUTPUT = fw-rt-frm-ping
TRTL ?= ../../../
TRTL_SW = $(TRTL)/software
CFLAGS_OPT = -O0 # disable optimization
include $(TRTL_SW)/rt/Makefile
#
# Automatically generated file; DO NOT EDIT.
# hello_world_framework demo configuration
#
#
# Project specific configuration
#
CONFIG_FPGA_APPLICATION_ID=0
CONFIG_RT_APPLICATION_ID=0
#
# Mock Turtle configuration
#
#
# Mock Turtle framework configuration
#
CONFIG_MOCKTURTLE_FRAMEWORK_ENABLE=y
CONFIG_MOCKTURTLE_FRAMEWORK_DEBUG_ENABLE=y
# CONFIG_MOCKTURTLE_FRAMEWORK_VARIABLE_ENABLE is not set
# CONFIG_MOCKTURTLE_FRAMEWORK_BUFFER_ENABLE is not set
#
# Mock Turtle library configuration
#
CONFIG_MOCKTURTLE_LIBRARY_PRINT_ENABLE=y
CONFIG_MOCKTURTLE_LIBRARY_PRINT_DEBUG_ENABLE=y
CONFIG_MOCKTURTLE_LIBRARY_PRINT_ERROR_ENABLE=y
/*
* Copyright (C)
* Author:
* License:
*/
#include <mockturtle-framework.h>
static struct trtl_fw_application app = {
.name = "hellofrm",
.version = {
.rt_id = CONFIG_RT_APPLICATION_ID,
.rt_version = RT_VERSION(0, 1),
.git_version = GIT_VERSION
},
};
/**
* Well, the main :)
*/
int main()
{
trtl_fw_init(&app);
while (1) {
/* Handle all messages incoming from HMQ 0 as actions */
trtl_fw_mq_action_dispatch(TRTL_HMQ, 0);
}
return 0;
}
import hashlib
import os
import pytest
import serial
import time
import PyMockTurtle
@pytest.fixture
def firmware_file_loop(trtl_firmware_dir):
return os.path.join(trtl_firmware_dir, "firmware/cpu-loop/fw-loop.bin")
@pytest.fixture
def firmware_file_loop():
testdir = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
return os.path.join(testdir, "firmware/cpu-loop/fw-loop.bin")
def firmware_binary_byte_addressing(trtl_firmware_dir):
return os.path.join(trtl_firmware_dir,
"firmware/cpu-byte-addressing/fw-byte-addressing.bin")
@pytest.fixture
def firmware_binary_notification(trtl_firmware_dir):
return os.path.join(trtl_firmware_dir,
"firmware/cpu-notify/fw-notify.bin")
class TestCPU(object):
confirm = 'OK\r\n'
def test_cpu(self):
pass
......@@ -26,8 +39,8 @@ class TestCPU(object):
trtl_cpu.enable()
assert True == trtl_cpu.is_enable()
def test_load(self, trtl_cpu):
trtl_cpu.load_application_file(firmware_file_loop())
def test_load(self, trtl_cpu, firmware_file_loop):
trtl_cpu.load_application_file(firmware_file_loop)
trtl_cpu.enable()
time.sleep(1)
......@@ -35,7 +48,7 @@ class TestCPU(object):
trtl_cpu.disable()
trtl_cpu.dump_application_file("/tmp/dump.bin")
with open(firmware_file_loop(), 'rb') as f:
with open(firmware_file_loop, 'rb') as f:
data_o = f.read()
md5_o = hashlib.md5(data_o).hexdigest()
......@@ -44,3 +57,43 @@ class TestCPU(object):
md5_d = hashlib.md5(data_d).hexdigest()
assert md5_o == md5_d
def test_byte_addressing(self, trtl_cpu, firmware_binary_byte_addressing):
trtl_cpu.load_application_file(firmware_binary_byte_addressing)
for hmq in trtl_cpu.hmq:
hmq.flush()
idx_cfg = trtl_cpu.idx_cpu * PyMockTurtle.TRTL_CONFIG_ROM_MAX_CPU + hmq.idx_hmq
msg = PyMockTurtle.TrtlMessage()
msg.header.len = trtl_cpu.trtl_dev.rom.hmq[idx_cfg].payload_size
for i in range(msg.header.len): # 32bit DW
msg.payload[i] = i
hmq.send_msg(msg)
for i in range(msg.header.len): # 16bit DW
val = (i * 2)
msg.payload[i] = (((val + 1) << 16) & 0xFFFF0000) | \
(((val + 0) << 0) & 0x0000FFFF)
hmq.send_msg(msg)
for i in range(msg.header.len): # 8bit DW
val = (i * 4)
msg.payload[i] = (((val + 3) << 24) & 0xFF000000) | \
(((val + 2) << 16) & 0x00FF0000) | \
(((val + 1) << 8) & 0x0000FF00) | \
(((val + 0) << 0) & 0x000000FF)
hmq.send_msg(msg)
filename = "/dev/ttytrtl-{:04x}-{:d}".format(trtl_cpu.trtl_dev.device_id,
trtl_cpu.idx_cpu)
with serial.Serial(filename) as ser:
ser.reset_input_buffer()
trtl_cpu.enable()
time.sleep(5)
assert ser.in_waiting >= len(self.confirm)
assert self.confirm == ser.read(ser.in_waiting).decode()
def test_notification(self, trtl_cpu, firmware_binary_notification):
trtl_cpu.load_application_file(firmware_binary_notification)
trtl_cpu.enable()
time.sleep(1)
......@@ -29,9 +29,6 @@ class TestHmq(object):
confirm = 'OK\r\n'
def test_purge(self, trtl_cpu, trtl_binary_hmq_purge):
if trtl_cpu.idx_cpu != 0:
return
trtl_cpu.load_application_file(trtl_binary_hmq_purge)
# fill HMQ
......@@ -43,7 +40,9 @@ class TestHmq(object):
hmq.send_msg(msg)
# Run and check
with serial.Serial("/dev/ttyTRTL{:d}".format(trtl_cpu.idx_cpu)) as ser:
filename = "/dev/ttytrtl-{:04x}-{:d}".format(trtl_cpu.trtl_dev.device_id,
trtl_cpu.idx_cpu)
with serial.Serial(filename) as ser:
ser.reset_input_buffer()
trtl_cpu.enable()
time.sleep(1)
......@@ -51,9 +50,6 @@ class TestHmq(object):
assert self.confirm == ser.read(ser.in_waiting).decode()
def test_purge_overflow(self, trtl_cpu, trtl_binary_hmq_purge):
if trtl_cpu.idx_cpu != 0:
return
trtl_cpu.load_application_file(trtl_binary_hmq_purge)
# Fill HMQ
......@@ -67,7 +63,9 @@ class TestHmq(object):
hmq.send_msg(msg)
# Run and check
with serial.Serial("/dev/ttyTRTL{:d}".format(trtl_cpu.idx_cpu)) as ser:
filename = "/dev/ttytrtl-{:04x}-{:d}".format(trtl_cpu.trtl_dev.device_id,
trtl_cpu.idx_cpu)
with serial.Serial(filename) as ser:
ser.reset_input_buffer()
trtl_cpu.enable()
time.sleep(1)
......@@ -86,8 +84,9 @@ class TestHmq(object):
hmq.flush()
for msg in trtl_msg:
hmq.send_msg(msg)
with serial.Serial("/dev/ttyTRTL{:d}".format(trtl_cpu.idx_cpu)) as ser:
filename = "/dev/ttytrtl-{:04x}-{:d}".format(trtl_cpu.trtl_dev.device_id,
trtl_cpu.idx_cpu)
with serial.Serial(filename) as ser:
ser.reset_input_buffer()
trtl_cpu.enable()
time.sleep(1)
......@@ -138,4 +137,7 @@ class TestHmq(object):
for msg in trtl_msg:
print(msg.payload[0], msg.payload[1])
msg_r = hmq.sync_msg(msg)
# the library add automatically this flag, but for the purpose
# of this test assertiong we manually set it
msg.header.flags |= PyMockTurtle.TrtlHmqHeader.TRTL_HMQ_HEADER_FLAG_SYNC
assert msg_r == msg
import os
import pytest
import time
@pytest.fixture
def trtl_binary_frm_var(trtl_firmware_dir):
return os.path.join(trtl_firmware_dir,
"firmware/rt-frm-var/fw-rt-frm-var.bin")
@pytest.fixture
def trtl_binary_frm_ping(trtl_firmware_dir):
return os.path.join(trtl_firmware_dir,
"firmware/rt-frm-ping/fw-rt-frm-ping.bin")
@pytest.fixture
def trtl_binary_frm_version(trtl_binary_frm_ping):
return trtl_binary_frm_ping
class TestFirmwareFramework(object):
def test_var(self, trtl_cpu0, trtl_binary_frm_var):
trtl_cpu0.load_application_file(trtl_binary_frm_var)
trtl_cpu0.enable()
time.sleep(0.1)
def test_ping(self, trtl_cpu0, trtl_binary_frm_ping):
trtl_cpu0.load_application_file(trtl_binary_frm_ping)
trtl_cpu0.enable()
time.sleep(0.1)
assert trtl_cpu0.ping() == True
def test_ver(self, trtl_cpu0, trtl_binary_frm_version):
trtl_cpu0.load_application_file(trtl_binary_frm_version)
trtl_cpu0.enable()
time.sleep(0.1)
assert trtl_cpu0.ping() == True
......@@ -20,15 +20,21 @@ def firmware_output():
class TestSerial(object):
def test_exist(self, cpu_idx):
assert os.path.exists("/dev/ttyTRTL{:d}".format(cpu_idx)) == True
def test_chardevice(self, cpu_idx):
st = os.stat("/dev/ttyTRTL{:d}".format(cpu_idx))
def test_exist(self, trtl_cpu):
filename = "/dev/ttytrtl-{:04x}-{:d}".format(trtl_cpu.trtl_dev.device_id,
trtl_cpu.idx_cpu)
assert os.path.exists(filename) == True
def test_chardevice(self, trtl_cpu):
filename = "/dev/ttytrtl-{:04x}-{:d}".format(trtl_cpu.trtl_dev.device_id,
trtl_cpu.idx_cpu)
st = os.stat(filename)
assert stat.S_ISCHR(st.st_mode) == True
def test_permission(self, cpu_idx):
st = os.stat("/dev/ttyTRTL{:d}".format(cpu_idx))
def test_permission(self, trtl_cpu):
filename = "/dev/ttytrtl-{:04x}-{:d}".format(trtl_cpu.trtl_dev.device_id,
trtl_cpu.idx_cpu)
st = os.stat(filename)
assert st.st_mode & stat.S_IRUSR != 0
assert st.st_mode & stat.S_IRGRP != 0
......@@ -37,7 +43,9 @@ class TestSerial(object):
trtl_cpu.disable()
trtl_cpu.load_application_file(firmware_file_serial)
with serial.Serial("/dev/ttyTRTL{:d}".format(trtl_cpu.idx_cpu)) as ser:
filename = "/dev/ttytrtl-{:04x}-{:d}".format(trtl_cpu.trtl_dev.device_id,
trtl_cpu.idx_cpu)
with serial.Serial(filename) as ser:
trtl_cpu.enable()
time.sleep(1) # wait for all the characters
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment