/*
 *------------------------------------------------------------------
 * 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 (memif_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;
}
