Пример #1
0
int main(int argc, char* argv[]) {
  int num = TEST_NUM;
  struct NaClThread thr;

  UNREFERENCED_PARAMETER(argc);
  UNREFERENCED_PARAMETER(argv);

  if (!NaClThreadCreateJoinable(&thr, myThread, &num, 128*1024)) {
    failWithErrno("NaClThreadCreateJoinable");
  }

  /* This test check that the thread actually starts. It checks that this does
   * not hang. */
  NaClThreadJoin(&thr);

  return 0;
}
Пример #2
0
int main(int argc, char* argv[]) {
  int result;
  NaClHandle pair[2];
#ifdef __native_client__
  int imc_desc[2];
#else
  struct NaClDescImcDesc* imc_desc[2];
#endif
  struct NaClThread thr;
  NaClSrpcChannel channel;
  NaClSrpcError error;
  struct ServiceThreadArgs* threadArg;

  UNREFERENCED_PARAMETER(argc);
  UNREFERENCED_PARAMETER(argv);

  NaClSrpcModuleInit();

  if (0 != NaClSocketPair(pair)) {
    failWithErrno("SocketPair");
  }

#ifdef __native_client__
  imc_desc[0] = pair[0];
  imc_desc[1] = pair[1];
#else
  NaClNrdAllModulesInit();

  imc_desc[0] = (struct NaClDescImcDesc*) calloc(1, sizeof(*imc_desc[0]));
  if (0 == imc_desc[0]) {
    failWithErrno("calloc");
  }
  imc_desc[1] = (struct NaClDescImcDesc*) calloc(1, sizeof(*imc_desc[1]));
  if (0 == imc_desc[1]) {
    failWithErrno("calloc");
  }

  if (!NaClDescImcDescCtor(imc_desc[0], pair[0])) {
    failWithErrno("NaClDescImcDescCtor");
  }

  if (!NaClDescImcDescCtor(imc_desc[1], pair[1])) {
    failWithErrno("NaClDescImcDescCtor");
  }
#endif

  threadArg = (struct ServiceThreadArgs*) calloc(1, sizeof(*threadArg));
  if (NULL == threadArg) {
    failWithErrno("calloc for threadArg");
  }
  threadArg->desc = (NaClSrpcImcDescType)imc_desc[0];

  if (!NaClThreadCreateJoinable(&thr, serviceThread, threadArg, 128*1024)) {
    failWithErrno("NaClThreadCtor");
  }

  if (!NaClSrpcClientCtor(&channel, (NaClSrpcImcDescType) imc_desc[1])) {
    failWithErrno("NaClSrpcClientCtor");
  }

  error = NaClSrpcInvokeBySignature(&channel, "getNum::i", &result);
  if (NACL_SRPC_RESULT_OK != error) {
    fprintf(stderr,
            "SRPC call to getNum::i failed: %s\n",
            NaClSrpcErrorString(error));
    exit(EXIT_FAILURE);
  }

  if (TEST_NUM != result) {
    fprintf(stderr, "expected: %d, got: %d\n", TEST_NUM, result);
    exit(EXIT_FAILURE);
  }

  NaClSrpcDtor(&channel);
#ifdef __native_client__
  close(imc_desc[1]);
#else
  NaClDescUnref((NaClSrpcImcDescType)imc_desc[1]);
#endif

  NaClThreadJoin(&thr);

  NaClSrpcModuleFini();
  return 0;
}
Пример #3
0
int main(int argc, char* argv[]) {
    nacl_abi_size_t char_array_count;
    char* char_array_carr;
    NaClHandle pair[2];
#ifdef __native_client__
    int imc_desc[2];
#else
    struct NaClDescImcDesc* imc_desc[2];
#endif
    struct NaClThread thr;
    NaClSrpcChannel channel;
    NaClSrpcError error;
    struct ServiceThreadArgs* threadArg;

    UNREFERENCED_PARAMETER(argc);
    UNREFERENCED_PARAMETER(argv);

    NaClSrpcModuleInit();

    if (0 != NaClSocketPair(pair)) {
        failWithErrno("SocketPair");
    }

#ifdef __native_client__
    imc_desc[0] = pair[0];
    imc_desc[1] = pair[1];
#else
    NaClNrdAllModulesInit();

    imc_desc[0] = (struct NaClDescImcDesc*) calloc(1, sizeof(*imc_desc[0]));
    if (0 == imc_desc[0]) {
        failWithErrno("calloc");
    }
    imc_desc[1] = (struct NaClDescImcDesc*) calloc(1, sizeof(*imc_desc[1]));
    if (0 == imc_desc[1]) {
        failWithErrno("calloc");
    }

    if (!NaClDescImcDescCtor(imc_desc[0], pair[0])) {
        failWithErrno("NaClDescImcDescCtor");
    }

    if (!NaClDescImcDescCtor(imc_desc[1], pair[1])) {
        failWithErrno("NaClDescImcDescCtor");
    }
#endif

    threadArg = (struct ServiceThreadArgs*) calloc(1, sizeof(*threadArg));
    if (NULL == threadArg) {
        failWithErrno("calloc for threadArg");
    }
    threadArg->desc = (NaClSrpcImcDescType)imc_desc[0];

    if (!NaClThreadCreateJoinable(&thr, serviceThread, threadArg, 128*1024)) {
        failWithErrno("NaClThreadCtor");
    }

    if (!NaClSrpcClientCtor(&channel, (NaClSrpcImcDescType) imc_desc[1])) {
        failWithErrno("NaClSrpcClientCtor");
    }

    char_array_count = TEST_ARRAY_LENGTH;
    char_array_carr = (char*) calloc(TEST_ARRAY_LENGTH, sizeof(char));
    if (!char_array_carr) {
        failWithErrno("calloc for char_array");
    }
    memset(char_array_carr, TEST_NUM, TEST_ARRAY_LENGTH);

    error = NaClSrpcInvokeBySignature(&channel,
                                      "putArr:C:",
                                      char_array_count,
                                      char_array_carr);

    if (NACL_SRPC_RESULT_OK != error) {
        fprintf(stderr,
                "SRPC call to putArr:C: failed: %s\n",
                NaClSrpcErrorString(error));
        exit(EXIT_FAILURE);
    }
    free(char_array_carr);

    NaClSrpcDtor(&channel);
#ifdef __native_client__
    close(imc_desc[1]);
#else
    NaClDescUnref((NaClSrpcImcDescType)imc_desc[1]);
#endif

    NaClThreadJoin(&thr);

    NaClSrpcModuleFini();
    return 0;
}