/**
 * Worker thread to handle read/write events
 */
static void worker(struct work_struct *work)
{
	switch (test_ctx->testcase) {
	case 1:
		loopback_test();
		break;
	case 2:
		sender_test();
		break;
	case 3:
		a2_performance_test();
		break;
	default:
		pr_info(TEST_MODULE_NAME "Bad Test number = %d.\n",
			(int) test_ctx->testcase);
	}
}
Example #2
0
int 
main(int argc, char** argv)
{
  if (argc != 5) {
    fprintf(stderr, "usage: ./test-nadk <name> <pipeline>\n\n");
    fprintf(stderr, " Arguments:\n");
    fprintf(stderr, "    name       the symbolic name of the dataplane\n");
    fprintf(stderr, "    pipeline   the absolute path to a pipeline module\n");
    fprintf(stderr, "    dprc       the name of the NADK resource container\n");
    fprintf(stderr, "    test_type  0: Reflect; 1: XRefelct; "
                    "2:Loopback, 3:XLoopback, 4: Dataplane\n");
    return -1;
  }

  char const* name = argv[1];
  char const* path = argv[2];
  char const* dprc = argv[3];
  const test_type_t test = atoi(argv[4]);

  /* Asynchronous signals that result in attempted graceful exit */
  install_signal_handler();

  fp_error_t err;
  struct fp_dataplane* dp = fp_dataplane_create(name, path, &err);
  if (fp_error(err)) {
    fprintf(stderr, "error: %s\n", fp_strerror(err));
    return -1;
  }

  /* Hack to initialize NADK framework with passed-in DPRC */
  fp_nadk_init(dprc);

  /* Add ports to the dataplane. */
  struct fp_port* port1 = add_port(dp, 0);
  if (!port1)
    return -1;
  struct fp_port* port2 = add_port(dp, 1);
  if (!port2)
    return -1;

  /* Start the data plane. */
  bool ok = true;
  err = fp_dataplane_start(dp);
  if (fp_error(err)) {
    fprintf(stderr, "error: %s\n", fp_strerror(err));
    ok = false;
  }

  /* Enter test loop until Ctrl-C (SIGINT) is received */
  printf("Entering packet I/O loop until Ctrl-C (SIGINT) is received\n");
  int i = 0;
  while(!received_sigint) {
    // choose which test to run by run-time parameter:
    switch(test) {
    case TEST_REFLECT:
      reflect_test(port1, port2);
      break;
    case TEST_XREFLECT:
      xreflect_test(port1, port2);
      break;
    case TEST_LOOPBACK:
      loopback_test(port1, port2);
      break;
    case TEST_XLOOPBACK:
      xloopback_test(port1, port2);
      break;
    case TEST_DATAPLANE:
      dataplane_test(dp, port1, port2);
      break;
    default:
      printf("Invalid test_type: %d...\n", test);
      received_sigint = 1;
      break;
    }
  }
  printf("Broke out of processing loop\n");
  
  /* Stop the data plane. */
  err = fp_dataplane_stop(dp);
  if (fp_error(err)) {
    fprintf(stderr, "error: %s\n", fp_strerror(err));
    ok = false;
  }

  /* Clean up the data plane. */
  fp_dataplane_delete(dp, &err);

  return ok ? 0 : -1;
}