Commit 52dce501 authored by Federico Vaga's avatar Federico Vaga

ut: add some operational tests

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent ab3cba4a
......@@ -4,9 +4,12 @@
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include <errno.h>
#include <getopt.h>
#include <libgen.h>
#include <poll.h>
#include <stdlib.h>
#include <string.h>
#include <mamma.h>
#include <fmctdc-lib.h>
......@@ -16,6 +19,23 @@ struct fmctdc_test_desc {
};
static int fmctdc_dev_id;
static int fmcfd_dev_id;
#define CMD_LEN 1024
static int fmctdc_execute_fmc_fdelay_pulse(unsigned int devid,
unsigned int channel,
unsigned int period_us,
unsigned int delay_us,
unsigned int count)
{
char cmd[CMD_LEN];
snprintf(cmd, CMD_LEN,
"fmc-fdelay-pulse -d 0x%x -o %d -m pulse -T %du -w 150n -r %du -c %d > /dev/null",
devid, channel + 1, period_us, delay_us, count);
return system(cmd);
}
/**
......@@ -24,10 +44,12 @@ static int fmctdc_dev_id;
*/
static void fmctdc_ut_help(char *name)
{
fprintf(stderr, "%s -D 0x<dev_id>\n", basename(name));
fprintf(stderr, "%s -T 0x<dev_id> -F 0x<dev_id>\n", basename(name));
fprintf(stderr, "\t-T 0x<dev_id> : FMC TDC device ID\n");
fprintf(stderr, "\t-F 0x<dev_id> : FMC FineDelay device ID\n");
}
static void fmctdc_param_set_up(struct m_suite *m_suite)
static void fmctdc_set_up(struct m_suite *m_suite)
{
struct fmctdc_test_desc *d;
int ret;
......@@ -44,7 +66,7 @@ static void fmctdc_param_set_up(struct m_suite *m_suite)
m_suite->private = d;
}
static void fmctdc_param_tear_down(struct m_suite *m_suite)
static void fmctdc_tear_down(struct m_suite *m_suite)
{
struct fmctdc_test_desc *d = m_suite->private;
struct fmctdc_board *tdc = d->tdc;
......@@ -188,6 +210,153 @@ static const char *fmctdc_param_test6_desc =
"Being able to change the software buffer len";
static void fmctdc_param_test7(struct m_test *m_test)
{
struct fmctdc_test_desc *d = m_test->suite->private;
struct fmctdc_board *tdc = d->tdc;
int ret;
ret = fmctdc_wr_mode(tdc, 1);
m_assert_int_eq(0, ret);
ret = fmctdc_check_wr_mode(tdc);
m_assert_int_eq(0, ret);
ret = fmctdc_wr_mode(tdc, 0);
m_assert_int_eq(ENOLINK, ret);
ret = fmctdc_check_wr_mode(tdc);
m_assert_int_eq(ENODEV, ret);
}
static const char *fmctdc_param_test7_desc =
"Being able to change the White-Rabbit mode";
static void fmctdc_op_test_setup(struct m_test *m_test)
{
struct fmctdc_test_desc *d = m_test->suite->private;
struct fmctdc_board *tdc = d->tdc;
int i, err, ret;
for (i = 0; i < FMCTDC_NUM_CHANNELS; ++i) {
err = fmctdc_channel_status_set(tdc, i, FMCTDC_STATUS_DISABLE);
m_assert_int_eq(0, err);
ret = fmctdc_channel_status_get(tdc, i);
m_assert_int_eq(FMCTDC_STATUS_DISABLE, ret);
err = fmctdc_set_buffer_len(tdc, i, 16);
m_assert_int_eq(0, err);
err = fmctdc_ts_mode_set(tdc, i, FMCTDC_TS_MODE_POST);
m_assert_int_eq(0, err);
err = fmctdc_coalescing_timeout_set(tdc, i, 10);
m_assert_int_eq(0, err);
err = fmctdc_set_buffer_mode(tdc, i, FMCTDC_BUFFER_FIFO);
m_assert_int_eq(0, err);
err = fmctdc_flush(tdc, i);
m_assert_int_eq(0, err);
}
}
static void fmctdc_op_test_tear_down(struct m_test *m_test)
{
struct fmctdc_test_desc *d = m_test->suite->private;
struct fmctdc_board *tdc = d->tdc;
int i, err, ret;
for (i = 0; i < FMCTDC_NUM_CHANNELS; ++i) {
err = fmctdc_channel_status_set(tdc, i, FMCTDC_STATUS_DISABLE);
m_assert_int_eq(0, err);
ret = fmctdc_channel_status_get(tdc, i);
m_assert_int_eq(FMCTDC_STATUS_DISABLE, ret);
}
}
static void fmctdc_op_test_parameters(struct m_test *m_test,
unsigned int count,
unsigned int period)
{
struct fmctdc_test_desc *d = m_test->suite->private;
struct fmctdc_board *tdc = d->tdc;
struct fmctdc_time t[FMCTDC_NUM_CHANNELS], tmp;
struct pollfd p;
int i, k, err, ret;
for (i = 0; i < FMCTDC_NUM_CHANNELS; ++i) {
err = fmctdc_channel_enable(tdc, i);
m_assert_int_eq(0, err);
}
for (i = 0; i < FMCTDC_NUM_CHANNELS - 1; ++i) {
err = fmctdc_execute_fmc_fdelay_pulse(fmcfd_dev_id,
i, period, 0, count);
m_assert_int_eq(0, err);
}
for (k = 0; k < count; ++k) {
for (i = 0; i < FMCTDC_NUM_CHANNELS; ++i) {
p.fd = fmctdc_fileno_channel(tdc, i);
p.events = POLLIN | POLLERR;
ret = poll(&p, 1, 1000);
m_assert_int_neq(0, ret); /* detect time out */
m_assert_int_neq(0, p.revents & POLLIN);
m_assert_int_lt(0, ret);
ret = fmctdc_read(tdc, i, &t[i], 1, 0);
m_assert_int_eq(1, ret);
}
for (i = 1; i < FMCTDC_NUM_CHANNELS; ++i) {
memcpy(&tmp, &t[0], sizeof(t));
fmctdc_ts_sub(&tmp, &t[i]);
/*
* We know that from time to time ACAM TDC-GPX
* produces wrong timestamps (-8ns +8ns)
*/
m_assert_int_range(0, 8000, fmctdc_ts_ps(&tmp));
}
}
}
static void fmctdc_op_test1(struct m_test *m_test)
{
fmctdc_op_test_parameters(m_test, 1, 1);
}
static const char *fmctdc_op_test1_desc =
"FineDelay generates, simultaneously, one pulse for each channel. We check that they all arrives and the timestamp is the same (ignore fine field)";
static void fmctdc_op_test2(struct m_test *m_test)
{
fmctdc_op_test_parameters(m_test, 1000, 1000);
}
static const char *fmctdc_op_test2_desc =
"FineDelay generates, simultaneously, 1000 pulse for each channel (1kHz). We check that they all arrives and the timestamp is the same (ignore fine field)";
static void fmctdc_op_test3(struct m_test *m_test)
{
fmctdc_op_test_parameters(m_test, 10000, 100);
}
static const char *fmctdc_op_test3_desc =
"FineDelay generates, simultaneously, 10000 pulse for each channel (10kHz). We check that they all arrives and the timestamp is the same (ignore fine field)";
static void fmctdc_op_test4(struct m_test *m_test)
{
fmctdc_op_test_parameters(m_test, 100000, 10);
}
static const char *fmctdc_op_test4_desc =
"FineDelay generates, simultaneously, 100000 pulse for each channel (100kHz). We check that they all arrives and the timestamp is the same (ignore fine field)";
static void fmctdc_op_test5(struct m_test *m_test)
{
fmctdc_op_test_parameters(m_test, 1000000, 100);
}
static const char *fmctdc_op_test5_desc =
"FineDelay generates, simultaneously, 1000000 pulse for each channel (1MHz). We check that they all arrives and the timestamp is the same (ignore fine field)";
int main(int argc, char *argv[])
{
struct m_test fmctdc_param_tests[] = {
......@@ -203,24 +372,61 @@ int main(int argc, char *argv[])
fmctdc_param_test5_desc),
m_test_desc(NULL, fmctdc_param_test6, NULL,
fmctdc_param_test6_desc),
m_test_desc(NULL, fmctdc_param_test7, NULL,
fmctdc_param_test7_desc),
};
struct m_suite fmctdc_suite_param = m_suite("FMC TDC test: parameters",
M_VERBOSE,
fmctdc_param_tests,
fmctdc_set_up,
fmctdc_tear_down);
struct m_test fmctdc_op_tests[] = {
m_test_desc(fmctdc_op_test_setup,
fmctdc_op_test1,
fmctdc_op_test_tear_down,
fmctdc_op_test1_desc),
m_test_desc(fmctdc_op_test_setup,
fmctdc_op_test2,
fmctdc_op_test_tear_down,
fmctdc_op_test2_desc),
m_test_desc(fmctdc_op_test_setup,
fmctdc_op_test3,
fmctdc_op_test_tear_down,
fmctdc_op_test3_desc),
m_test_desc(fmctdc_op_test_setup,
fmctdc_op_test4,
fmctdc_op_test_tear_down,
fmctdc_op_test4_desc),
m_test_desc(fmctdc_op_test_setup,
fmctdc_op_test5,
fmctdc_op_test_tear_down,
fmctdc_op_test5_desc),
};
struct m_suite fmctdc_suite = m_suite("FMC TDC test: parameters",
M_VERBOSE,
fmctdc_param_tests,
fmctdc_param_set_up,
fmctdc_param_tear_down);
struct m_suite fmctdc_suite_op = m_suite("FMC TDC test: operation",
M_VERBOSE,
fmctdc_op_tests,
fmctdc_set_up,
fmctdc_tear_down);
char opt;
int ret;
while ((opt = getopt(argc, argv, "D:h")) != -1) {
while ((opt = getopt(argc, argv, "T:F:h")) != -1) {
switch (opt) {
case 'D':
case 'T':
ret = sscanf(optarg, "0x%04x", &fmctdc_dev_id);
if (ret != 1) {
fmctdc_ut_help(argv[0]);
exit(EXIT_FAILURE);
}
break;
case 'F':
ret = sscanf(optarg, "0x%04x", &fmcfd_dev_id);
if (ret != 1) {
fmctdc_ut_help(argv[0]);
exit(EXIT_FAILURE);
}
break;
case 'h':
case '?':
fmctdc_ut_help(argv[0]);
......@@ -230,12 +436,18 @@ int main(int argc, char *argv[])
}
if (!fmctdc_dev_id) {
fprintf(stderr, "Missing device ID options\n");
fprintf(stderr, "Missing TDC device ID options\n");
fmctdc_ut_help(argv[0]);
exit(EXIT_FAILURE);
}
m_suite_run(&fmctdc_suite_param);
m_suite_run(&fmctdc_suite);
if (!fmcfd_dev_id) {
fprintf(stderr, "Missing FineDelay device ID options\n");
fmctdc_ut_help(argv[0]);
exit(EXIT_FAILURE);
}
m_suite_run(&fmctdc_suite_op);
exit(EXIT_SUCCESS);
}
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