/*
 *------------------------------------------------------------------
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *------------------------------------------------------------------
 */
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include <main_test.h>

#include <memif_private.h>

#define SOCKET_FILENAME "/run/vpp/memif.sock"

uint8_t ready_called;
#define read_call  (1 << 0)
#define write_call (1 << 1)
#define error_call (1 << 2)

int
read_fn (memif_connection_t * c)
{
  ready_called |= read_call;
  return 0;
}

int
write_fn (memif_connection_t * c)
{
  ready_called |= write_call;
  return 0;
}

int
error_fn (memif_connection_t * c)
{
  ready_called |= error_call;
  return 0;
}

static void
register_fd_ready_fn (memif_connection_t * c,
		      memif_fn * read_fn, memif_fn * write_fn,
		      memif_fn * error_fn)
{
  c->read_fn = read_fn;
  c->write_fn = write_fn;
  c->error_fn = error_fn;
}

START_TEST (test_init)
{
  int err;

  if ((err =
       memif_init (control_fd_update, TEST_APP_NAME, NULL,
		   NULL, NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  libmemif_main_t *lm = &libmemif_main;

  ck_assert_ptr_ne (lm, NULL);
  ck_assert_ptr_ne (lm->control_fd_update, NULL);
  ck_assert_int_gt (lm->timerfd, 2);

  if (lm->timerfd > 0)
    close (lm->timerfd);
  lm->timerfd = -1;
}

END_TEST
START_TEST (test_init_epoll)
{
  int err;

  if ((err =
       memif_init (NULL, TEST_APP_NAME, NULL, NULL, NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  libmemif_main_t *lm = &libmemif_main;

  ck_assert_ptr_ne (lm, NULL);
  ck_assert_ptr_ne (lm->control_fd_update, NULL);
  ck_assert_int_gt (lm->timerfd, 2);
  ck_assert_int_gt (lm->epfd, -1);

  if (lm->timerfd > 0)
    close (lm->timerfd);
  lm->timerfd = -1;
}

END_TEST
START_TEST (test_create)
{
  int err;
  memif_conn_handle_t conn = NULL;
  memif_conn_args_t args;
  memset (&args, 0, sizeof (args));

  libmemif_main_t *lm = &libmemif_main;

  if ((err =
       memif_init (control_fd_update, TEST_APP_NAME, NULL,
		   NULL, NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));

  if ((err = memif_create (&conn, &args, on_connect,
			   on_disconnect, on_interrupt,
			   NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  memif_connection_t *c = (memif_connection_t *) conn;

  ck_assert_ptr_ne (c, NULL);

  ck_assert_uint_eq (c->args.interface_id, args.interface_id);
  ck_assert_uint_eq (c->args.is_master, args.is_master);
  ck_assert_uint_eq (c->args.mode, args.mode);

  ck_assert_uint_eq (c->args.num_s2m_rings, MEMIF_DEFAULT_TX_QUEUES);
  ck_assert_uint_eq (c->args.num_m2s_rings, MEMIF_DEFAULT_RX_QUEUES);
  ck_assert_uint_eq (c->args.buffer_size, MEMIF_DEFAULT_BUFFER_SIZE);
  ck_assert_uint_eq (c->args.log2_ring_size, MEMIF_DEFAULT_LOG2_RING_SIZE);

  ck_assert_ptr_eq (c->msg_queue, NULL);
  ck_assert_ptr_eq (c->regions, NULL);
  ck_assert_ptr_eq (c->tx_queues, NULL);
  ck_assert_ptr_eq (c->rx_queues, NULL);

  ck_assert_int_eq (c->fd, -1);

  ck_assert_ptr_ne (c->on_connect, NULL);
  ck_assert_ptr_ne (c->on_disconnect, NULL);
  ck_assert_ptr_ne (c->on_interrupt, NULL);

  ck_assert_str_eq ((char *)c->args.interface_name, (char *)args.interface_name);

  struct itimerspec timer;
  timerfd_gettime (lm->timerfd, &timer);

  ck_assert_msg (timer.it_interval.tv_sec == lm->arm.it_interval.tv_sec,
		 "timerfd not armed!");

  if (lm->timerfd > 0)
    close (lm->timerfd);
  lm->timerfd = -1;

  memif_delete (&conn);
  ck_assert_ptr_eq (conn, NULL);
}

END_TEST
START_TEST (test_create_master)
{
  int err, rv;
  memif_conn_handle_t conn = NULL;
  memif_conn_args_t args;
  memset (&args, 0, sizeof (args));
  args.is_master = 1;

  if ((err =
       memif_init (control_fd_update, TEST_APP_NAME, NULL,
		   NULL, NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));

  if ((err = memif_create (&conn, &args, on_connect,
			   on_disconnect, on_interrupt,
			   NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  memif_connection_t *c = (memif_connection_t *) conn;

  ck_assert_ptr_ne (c, NULL);

  ck_assert_uint_eq (c->args.interface_id, args.interface_id);
  ck_assert_uint_eq (c->args.is_master, args.is_master);
  ck_assert_uint_eq (c->args.mode, args.mode);

  ck_assert_uint_eq (c->args.num_s2m_rings, MEMIF_DEFAULT_TX_QUEUES);
  ck_assert_uint_eq (c->args.num_m2s_rings, MEMIF_DEFAULT_RX_QUEUES);
  ck_assert_uint_eq (c->args.buffer_size, MEMIF_DEFAULT_BUFFER_SIZE);
  ck_assert_uint_eq (c->args.log2_ring_size, MEMIF_DEFAULT_LOG2_RING_SIZE);

  ck_assert_ptr_eq (c->msg_queue, NULL);
  ck_assert_ptr_eq (c->regions, NULL);
  ck_assert_ptr_eq (c->tx_queues, NULL);
  ck_assert_ptr_eq (c->rx_queues, NULL);

  ck_assert_int_eq (c->fd, -1);

  ck_assert_ptr_ne (c->on_connect, NULL);
  ck_assert_ptr_ne (c->on_disconnect, NULL);
  ck_assert_ptr_ne (c->on_interrupt, NULL);

  ck_assert_str_eq ((char *)c->args.interface_name, (char *)args.interface_name);

  struct stat file_stat;

  rv = stat (SOCKET_FILENAME, &file_stat);
  ck_assert_int_eq (rv, 0);

  ck_assert (S_ISSOCK (file_stat.st_mode));

  memif_delete (&conn);
  ck_assert_ptr_eq (conn, NULL);
}

END_TEST
START_TEST (test_create_mult)
{
  int err;
  memif_conn_handle_t conn = NULL;
  memif_conn_handle_t conn1 = NULL;
  memif_conn_args_t args;
  memset (&args, 0, sizeof (args));

  libmemif_main_t *lm = &libmemif_main;

  if ((err =
       memif_init (control_fd_update, TEST_APP_NAME, NULL,
		   NULL, NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));

  if ((err = memif_create (&conn, &args, on_connect,
			   on_disconnect, on_interrupt,
			   NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  args.interface_id = 1;

  if ((err = memif_create (&conn1, &args, on_connect,
			   on_disconnect, on_interrupt,
			   NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  memif_connection_t *c = (memif_connection_t *) conn;
  memif_connection_t *c1 = (memif_connection_t *) conn1;

  ck_assert_ptr_ne (c, NULL);
  ck_assert_ptr_ne (c1, NULL);

  ck_assert_uint_eq (c->args.interface_id, 0);
  ck_assert_uint_eq (c->args.is_master, args.is_master);
  ck_assert_uint_eq (c->args.mode, args.mode);
  ck_assert_uint_eq (c1->args.interface_id, 1);
  ck_assert_uint_eq (c1->args.is_master, args.is_master);
  ck_assert_uint_eq (c1->args.mode, args.mode);

  ck_assert_uint_eq (c->args.num_s2m_rings, MEMIF_DEFAULT_TX_QUEUES);
  ck_assert_uint_eq (c->args.num_m2s_rings, MEMIF_DEFAULT_RX_QUEUES);
  ck_assert_uint_eq (c->args.buffer_size, MEMIF_DEFAULT_BUFFER_SIZE);
  ck_assert_uint_eq (c->args.log2_ring_size, MEMIF_DEFAULT_LOG2_RING_SIZE);
  ck_assert_uint_eq (c1->args.num_s2m_rings, MEMIF_DEFAULT_TX_QUEUES);
  ck_assert_uint_eq (c1->args.num_m2s_rings, MEMIF_DEFAULT_RX_QUEUES);
  ck_assert_uint_eq (c1->args.buffer_size, MEMIF_DEFAULT_BUFFER_SIZE);
  ck_assert_uint_eq (c1->args.log2_ring_size, MEMIF_DEFAULT_LOG2_RING_SIZE);

  ck_assert_ptr_eq (c->msg_queue, NULL);
  ck_assert_ptr_eq (c->regions, NULL);
  ck_assert_ptr_eq (c->tx_queues, NULL);
  ck_assert_ptr_eq (c->rx_queues, NULL);
  ck_assert_ptr_eq (c1->msg_queue, NULL);
  ck_assert_ptr_eq (c1->regions, NULL);
  ck_assert_ptr_eq (c1->tx_queues, NULL);
  ck_assert_ptr_eq (c1->rx_queues, NULL);

  ck_assert_int_eq (c->fd, -1);
  ck_assert_int_eq (c1->fd, -1);

  ck_assert_ptr_ne (c->on_connect, NULL);
  ck_assert_ptr_ne (c->on_disconnect, NULL);
  ck_assert_ptr_ne (c->on_interrupt, NULL);
  ck_assert_ptr_ne (c1->on_connect, NULL);
  ck_assert_ptr_ne (c1->on_disconnect, NULL);
  ck_assert_ptr_ne (c1->on_interrupt, NULL);

  ck_assert_str_eq ((char *)c->args.interface_name, (char *)args.interface_name);
  ck_assert_str_eq ((char *)c1->args.interface_name, (char *)args.interface_name);

  struct itimerspec timer;
  timerfd_gettime (lm->timerfd, &timer);

  ck_assert_msg (timer.it_interval.tv_sec == lm->arm.it_interval.tv_sec,
		 "timerfd not armed!");

  if (lm->timerfd > 0)
    close (lm->timerfd);
  lm->timerfd = -1;

  memif_delete (&conn);
  ck_assert_ptr_eq (conn, NULL);
}

END_TEST
START_TEST (test_control_fd_handler)
{
  int err;
  ready_called = 0;
  memif_conn_handle_t conn = NULL;
  memif_conn_args_t args;
  memset (&args, 0, sizeof (args));
  args.num_s2m_rings = 2;
  args.num_m2s_rings = 2;

  libmemif_main_t *lm = &libmemif_main;

  if ((err =
       memif_init (control_fd_update, TEST_APP_NAME, NULL,
		   NULL, NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));

  if ((err = memif_create (&conn, &args, on_connect,
			   on_disconnect, on_interrupt,
			   NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  memif_connection_t *c = (memif_connection_t *) conn;

  if ((err =
       memif_control_fd_handler (lm->timerfd,
				 MEMIF_FD_EVENT_READ)) != MEMIF_ERR_SUCCESS)
    ck_assert_msg (err == MEMIF_ERR_NO_FILE, "err code: %u, err msg: %s", err,
		   memif_strerror (err));

  register_fd_ready_fn (c, read_fn, write_fn, error_fn);
  c->fd = 69;
  lm->control_list[0].key = c->fd;
  lm->control_list[0].data_struct = c;

  if ((err =
       memif_control_fd_handler (c->fd,
				 MEMIF_FD_EVENT_READ)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  ck_assert (ready_called & read_call);

  if ((err =
       memif_control_fd_handler (c->fd,
				 MEMIF_FD_EVENT_WRITE)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  ck_assert (ready_called & write_call);

  if ((err =
       memif_control_fd_handler (c->fd,
				 MEMIF_FD_EVENT_ERROR)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  ck_assert (ready_called & error_call);

  if (lm->timerfd > 0)
    close (lm->timerfd);
  lm->timerfd = -1;

  memif_delete (&conn);
  ck_assert_ptr_eq (conn, NULL);
}

END_TEST
START_TEST (test_buffer_alloc)
{
  int err, i;
  uint8_t qid;
  uint16_t buf;
  memif_buffer_t *bufs;
  uint16_t max_buf = 10;
  ready_called = 0;
  memif_conn_handle_t conn = NULL;
  memif_conn_args_t args;
  memset (&args, 0, sizeof (args));
  args.num_s2m_rings = 2;
  args.num_m2s_rings = 2;

  libmemif_main_t *lm = &libmemif_main;

  if ((err =
       memif_init (control_fd_update, TEST_APP_NAME, NULL,
		   NULL, NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));

  if ((err = memif_create (&conn, &args, on_connect,
			   on_disconnect, on_interrupt,
			   NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  memif_connection_t *c = (memif_connection_t *) conn;

  c->run_args.num_s2m_rings = 2;
  c->run_args.num_m2s_rings = 2;
  c->run_args.log2_ring_size = 10;
  c->run_args.buffer_size = 2048;

  if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  c->fd = 69;

  /* test buffer allocation qid 0 (positive) */

  bufs = malloc (sizeof (memif_buffer_t) * max_buf);

  qid = 0;
  if ((err =
       memif_buffer_alloc (conn, qid, bufs, max_buf,
			   &buf,
			   MEMIF_DEFAULT_BUFFER_SIZE)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  ck_assert_uint_eq (buf, max_buf);
  for (i = 0; i < max_buf; i++)
    ck_assert_uint_eq (bufs[i].len, MEMIF_DEFAULT_BUFFER_SIZE);

  /* test buffer allocation qid 1 (positive) */
  free (bufs);
  bufs = malloc (sizeof (memif_buffer_t) * max_buf);

  qid = 1;
  if ((err =
       memif_buffer_alloc (conn, qid, bufs, max_buf,
			   &buf,
			   MEMIF_DEFAULT_BUFFER_SIZE)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  ck_assert_uint_eq (buf, max_buf);
  for (i = 0; i < max_buf; i++)
    ck_assert_uint_eq (bufs[i].len, MEMIF_DEFAULT_BUFFER_SIZE);

  /* test buffer allocation qid 2 (negative) */

  free (bufs);
  bufs = malloc (sizeof (memif_buffer_t) * max_buf);

  qid = 2;
  if ((err =
       memif_buffer_alloc (conn, qid, bufs, max_buf,
			   &buf,
			   MEMIF_DEFAULT_BUFFER_SIZE)) != MEMIF_ERR_SUCCESS)
    ck_assert_msg (err == MEMIF_ERR_QID, "err code: %u, err msg: %s", err,
		   memif_strerror (err));

  if (lm->timerfd > 0)
    close (lm->timerfd);
  lm->timerfd = -1;

  free (bufs);
  bufs = NULL;

  memif_delete (&conn);
  ck_assert_ptr_eq (conn, NULL);
}

END_TEST
START_TEST (test_tx_burst)
{
  int err, i;
  uint16_t max_buf = 10, buf, tx;
  uint8_t qid;
  memif_buffer_t *bufs;
  ready_called = 0;
  memif_conn_handle_t conn = NULL;
  memif_conn_args_t args;
  memset (&args, 0, sizeof (args));
  args.num_s2m_rings = 2;
  args.num_m2s_rings = 2;

  libmemif_main_t *lm = &libmemif_main;

  if ((err =
       memif_init (control_fd_update, TEST_APP_NAME, NULL,
		   NULL, NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));

  if ((err = memif_create (&conn, &args, on_connect,
			   on_disconnect, on_interrupt,
			   NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  memif_connection_t *c = (memif_connection_t *) conn;

  c->run_args.num_s2m_rings = 2;
  c->run_args.num_m2s_rings = 2;
  c->run_args.log2_ring_size = 10;
  c->run_args.buffer_size = 2048;

  if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  c->fd = 69;

  /* test transmit qid 0 (positive) */

  bufs = malloc (sizeof (memif_buffer_t) * max_buf);
  qid = 0;
  if ((err =
       memif_buffer_alloc (conn, qid, bufs, max_buf,
			   &buf,
			   MEMIF_DEFAULT_BUFFER_SIZE)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  ck_assert_uint_eq (buf, max_buf);
  for (i = 0; i < max_buf; i++)
    ck_assert_uint_eq (bufs[i].len, MEMIF_DEFAULT_BUFFER_SIZE);

  if ((err =
       memif_tx_burst (conn, qid, bufs, max_buf, &tx)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  ck_assert_uint_eq (tx, max_buf);
  for (i = 0; i < max_buf; i++)
    ck_assert_ptr_eq (bufs[i].data, NULL);

  /* test transmit qid 1 (positive) */
  free (bufs);
  bufs = malloc (sizeof (memif_buffer_t) * max_buf);
  qid = 1;
  if ((err =
       memif_buffer_alloc (conn, qid, bufs, max_buf,
			   &buf,
			   MEMIF_DEFAULT_BUFFER_SIZE)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  ck_assert_uint_eq (buf, max_buf);
  for (i = 0; i < max_buf; i++)
    ck_assert_uint_eq (bufs[i].len, MEMIF_DEFAULT_BUFFER_SIZE);

  if ((err =
       memif_tx_burst (conn, qid, bufs, max_buf, &tx)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  ck_assert_uint_eq (tx, max_buf);
  for (i = 0; i < max_buf; i++)
    ck_assert_ptr_eq (bufs[i].data, NULL);

  /* test transmit qid 2 (negative) */
  free (bufs);
  bufs = malloc (sizeof (memif_buffer_t) * max_buf);
  qid = 2;
  if ((err =
       memif_tx_burst (conn, qid, bufs, max_buf, &tx)) != MEMIF_ERR_SUCCESS)
    ck_assert_msg (err == MEMIF_ERR_QID, "err code: %u, err msg: %s", err,
		   memif_strerror (err));

  if (lm->timerfd > 0)
    close (lm->timerfd);
  lm->timerfd = -1;
  free (bufs);
  bufs = NULL;

  memif_delete (&conn);
  ck_assert_ptr_eq (conn, NULL);
}

END_TEST
START_TEST (test_rx_burst)
{
  int err, i;
  uint16_t max_buf = 10, rx;
  uint8_t qid;
  memif_buffer_t *bufs;
  memif_queue_t *mq;
  memif_ring_t *ring;
  ready_called = 0;
  memif_conn_handle_t conn = NULL;
  memif_conn_args_t args;
  memset (&args, 0, sizeof (args));
  args.num_s2m_rings = 2;
  args.num_m2s_rings = 2;

  libmemif_main_t *lm = &libmemif_main;

  if ((err =
       memif_init (control_fd_update, TEST_APP_NAME, NULL,
		   NULL, NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));

  if ((err = memif_create (&conn, &args, on_connect,
			   on_disconnect, on_interrupt,
			   NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  memif_connection_t *c = (memif_connection_t *) conn;

  c->run_args.num_s2m_rings = 2;
  c->run_args.num_m2s_rings = 2;
  c->run_args.log2_ring_size = 10;
  c->run_args.buffer_size = 2048;

  if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  c->fd = 69;

  /* test receive qid 0 (positive) */
  qid = 0;
  mq = &c->rx_queues[qid];
  ring = mq->ring;
  ring->tail += max_buf;

  bufs = malloc (sizeof (memif_buffer_t) * max_buf);

  if ((err =
       memif_rx_burst (conn, qid, bufs, max_buf, &rx)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  ck_assert_uint_eq (rx, max_buf);
  for (i = 0; i < max_buf; i++)
    ck_assert_ptr_ne (bufs[i].data, NULL);

  /* test receive qid 1 (positive) */
  qid = 1;
  mq = &c->rx_queues[qid];
  ring = mq->ring;
  ring->tail += max_buf;

  free (bufs);
  bufs = malloc (sizeof (memif_buffer_t) * max_buf);

  if ((err =
       memif_rx_burst (conn, qid, bufs, max_buf, &rx)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  ck_assert_uint_eq (rx, max_buf);
  for (i = 0; i < max_buf; i++)
    ck_assert_ptr_ne (bufs[i].data, NULL);

  /* test receive qid 2 (negative) */
  free (bufs);
  bufs = malloc (sizeof (memif_buffer_t) * max_buf);

  if ((err =
       memif_rx_burst (conn, qid, bufs, max_buf, &rx)) != MEMIF_ERR_SUCCESS)
    ck_assert_msg (err == MEMIF_ERR_QID, "err code: %u, err msg: %s", err,
		   memif_strerror (err));

  if (lm->timerfd > 0)
    close (lm->timerfd);
  lm->timerfd = -1;
  free (bufs);
  bufs = NULL;

  memif_delete (&conn);
  ck_assert_ptr_eq (conn, NULL);
}

END_TEST
START_TEST (test_get_details)
{
  int err, i;
  ready_called = 0;
  memif_conn_handle_t conn = NULL;
  memif_conn_args_t args;
  memset (&args, 0, sizeof (args));
  args.num_s2m_rings = 2;
  args.num_m2s_rings = 2;

  libmemif_main_t *lm = &libmemif_main;

  if ((err =
       memif_init (control_fd_update, TEST_APP_NAME, NULL,
		   NULL, NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));

  if ((err = memif_create (&conn, &args, on_connect,
			   on_disconnect, on_interrupt,
			   NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  memif_connection_t *c = (memif_connection_t *) conn;

  c->run_args.num_s2m_rings = 2;
  c->run_args.num_m2s_rings = 2;
  c->run_args.log2_ring_size = 10;
  c->run_args.buffer_size = 2048;

  if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  memif_details_t md;
  memset (&md, 0, sizeof (md));
  ssize_t buflen = 2048;
  char *buf = malloc (buflen);
  memset (buf, 0, buflen);

  if ((err = memif_get_details (conn, &md, buf, buflen)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  ck_assert_str_eq ((char *)md.if_name, (char *)c->args.interface_name);
  ck_assert_str_eq ((char *)md.remote_if_name, (char *)c->remote_if_name);
  ck_assert_str_eq ((char *)md.remote_inst_name, (char *)c->remote_name);
  ck_assert_str_eq ((char *)md.secret, (char *)c->args.secret);

  ck_assert_uint_eq (md.id, c->args.interface_id);
  ck_assert_uint_ne (md.role, c->args.is_master);
  ck_assert_uint_eq (md.mode, c->args.mode);
  for (i = 0; i < md.rx_queues_num; i++)
    {
      ck_assert_uint_eq (md.rx_queues[i].qid, i);
      ck_assert_uint_eq (md.rx_queues[i].ring_size,
			 (1 << c->args.log2_ring_size));
      ck_assert_uint_eq (md.rx_queues[i].buffer_size, c->args.buffer_size);
    }
  for (i = 0; i < md.tx_queues_num; i++)
    {
      ck_assert_uint_eq (md.tx_queues[i].qid, i);
      ck_assert_uint_eq (md.tx_queues[i].ring_size,
			 (1 << c->args.log2_ring_size));
      ck_assert_uint_eq (md.tx_queues[i].buffer_size, c->args.buffer_size);
    }
  ck_assert_uint_eq (md.link_up_down, 0);

  if (lm->timerfd > 0)
    close (lm->timerfd);
  lm->timerfd = -1;

  memif_delete (&conn);
  ck_assert_ptr_eq (conn, NULL);
}

END_TEST
START_TEST (test_init_regions_and_queues)
{
  int err;
  ready_called = 0;
  memif_conn_handle_t conn = NULL;
  memif_conn_args_t args;
  memset (&args, 0, sizeof (args));
  args.num_s2m_rings = 2;
  args.num_m2s_rings = 2;

  libmemif_main_t *lm = &libmemif_main;

  if ((err =
       memif_init (control_fd_update, TEST_APP_NAME, NULL,
		   NULL, NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));

  if ((err = memif_create (&conn, &args, on_connect,
			   on_disconnect, on_interrupt,
			   NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  memif_connection_t *c = (memif_connection_t *) conn;

  c->run_args.num_s2m_rings = 2;
  c->run_args.num_m2s_rings = 2;
  c->run_args.log2_ring_size = 10;
  c->run_args.buffer_size = 2048;

  if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  ck_assert_ptr_ne (c->regions, NULL);
  ck_assert_ptr_ne (c->tx_queues, NULL);
  ck_assert_ptr_ne (c->rx_queues, NULL);

  ck_assert_ptr_ne (c->regions->addr, NULL);
  ck_assert_ptr_ne (c->tx_queues->ring, NULL);
  ck_assert_ptr_ne (c->rx_queues->ring, NULL);

  ck_assert_int_ne (c->regions->fd, -1);
  ck_assert_uint_eq (c->tx_queues->ring->cookie, MEMIF_COOKIE);
  ck_assert_uint_eq (c->rx_queues->ring->cookie, MEMIF_COOKIE);

  if (lm->timerfd > 0)
    close (lm->timerfd);
  lm->timerfd = -1;

  memif_delete (&conn);
  ck_assert_ptr_eq (conn, NULL);
}

END_TEST
START_TEST (test_connect1)
{
  int err;
  ready_called = 0;
  memif_conn_handle_t conn = NULL;
  memif_conn_args_t args;
  memset (&args, 0, sizeof (args));
  args.num_s2m_rings = 2;
  args.num_m2s_rings = 2;

  libmemif_main_t *lm = &libmemif_main;

  if ((err =
       memif_init (control_fd_update, TEST_APP_NAME, NULL,
		   NULL, NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));

  if ((err = memif_create (&conn, &args, on_connect,
			   on_disconnect, on_interrupt,
			   NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  memif_connection_t *c = (memif_connection_t *) conn;

  c->run_args.num_s2m_rings = 2;
  c->run_args.num_m2s_rings = 2;
  c->run_args.log2_ring_size = 10;
  c->run_args.buffer_size = 2048;

  if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  if ((err = memif_connect1 (c)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  if (lm->timerfd > 0)
    close (lm->timerfd);
  lm->timerfd = -1;

  memif_delete (&conn);
  ck_assert_ptr_eq (conn, NULL);
}

END_TEST
START_TEST (test_disconnect_internal)
{
  int err;
  ready_called = 0;
  memif_conn_handle_t conn = NULL;
  memif_conn_args_t args;
  memset (&args, 0, sizeof (args));
  args.num_s2m_rings = 2;
  args.num_m2s_rings = 2;

  libmemif_main_t *lm = &libmemif_main;

  if ((err =
       memif_init (control_fd_update, TEST_APP_NAME, NULL,
		   NULL, NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));

  if ((err = memif_create (&conn, &args, on_connect,
			   on_disconnect, on_interrupt,
			   NULL)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  memif_connection_t *c = (memif_connection_t *) conn;

  c->run_args.num_s2m_rings = 2;
  c->run_args.num_m2s_rings = 2;
  c->run_args.log2_ring_size = 10;
  c->run_args.buffer_size = 2048;

  if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  if ((err = memif_disconnect_internal (c)) != MEMIF_ERR_SUCCESS)
    ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));

  ck_assert_int_eq (c->fd, -1);

  ck_assert_ptr_eq (c->tx_queues, NULL);
  ck_assert_ptr_eq (c->rx_queues, NULL);
  ck_assert_ptr_eq (c->regions, NULL);
  ck_assert_ptr_eq (c->msg_queue, NULL);

  struct itimerspec timer;
  timerfd_gettime (lm->timerfd, &timer);

  ck_assert_msg (timer.it_interval.tv_sec == lm->arm.it_interval.tv_sec,
		 "timerfd not armed!");

  if (lm->timerfd > 0)
    close (lm->timerfd);
  lm->timerfd = -1;

  memif_delete (&conn);
  ck_assert_ptr_eq (conn, NULL);
}

END_TEST Suite *
main_suite ()
{
  Suite *s;

  TCase *tc_api;
  TCase *tc_internal;

  /* create main test suite */
  s = suite_create ("Libmemif main");

  /* create api test case */
  tc_api = tcase_create ("Api calls");
  /* add tests to test case */
  tcase_add_test (tc_api, test_init);
  tcase_add_test (tc_api, test_init_epoll);
  tcase_add_test (tc_api, test_create);
  tcase_add_test (tc_api, test_create_master);
  tcase_add_test (tc_api, test_create_mult);
  tcase_add_test (tc_api, test_control_fd_handler);
  tcase_add_test (tc_api, test_buffer_alloc);
  tcase_add_test (tc_api, test_tx_burst);
  tcase_add_test (tc_api, test_rx_burst);
  tcase_add_test (tc_api, test_get_details);

  /* create internal test case */
  tc_internal = tcase_create ("Internal");
  /* add tests to test case */
  tcase_add_test (tc_internal, test_init_regions_and_queues);
  tcase_add_test (tc_internal, test_connect1);
  tcase_add_test (tc_internal, test_disconnect_internal);

  /* add test cases to test suite */
  suite_add_tcase (s, tc_api);
  suite_add_tcase (s, tc_internal);

  /* return main test suite to test runner */
  return s;
}
