예제 #1
0
파일: rain_context.c 프로젝트: wodconf/rain
int
rain_handle_kill(rain_routine_t rid,int code)
{
	struct rain_handle* h = H;
	int hash = hash_func(LOCAL_ID(rid));
	if( hash >= CTX_SET){
		return RAIN_ERROR;
	}
	rain_mutex_lock(&h->mtx);
	struct rain_ctx *ctx =  h->ppctx[hash];
	if( !ctx ||  ctx->rid != rid ){
		RAIN_LOG(0,"rain_ctx_handle_kill:,invailed rid:%x",rid);
		rain_mutex_unlock(&h->mtx);
		return RAIN_ERROR;
	}
	bool bexit = false;
	if(__sync_bool_compare_and_swap(&ctx->bexit,false,true)){
		ctx->exit_code = code;
		if(__sync_sub_and_fetch(&ctx->ref,1) == 0){
			bexit = true;
			_unregist_handle(hash);
		}
	}
	rain_mutex_unlock(&h->mtx);
	if(bexit){
		_ctx_destroy(ctx);
	}
	return RAIN_OK;
}
예제 #2
0
파일: rain_context.c 프로젝트: wodconf/rain
void
rain_ctx_unref(struct rain_ctx *ctx)
{
	if(__sync_sub_and_fetch(&ctx->ref,1) == 0){
		int hash = hash_func(LOCAL_ID(ctx->rid));
		struct rain_handle* h = H;
		rain_mutex_lock(&h->mtx);
		_unregist_handle(hash);
		rain_mutex_unlock(&h->mtx);
		_ctx_destroy(ctx);
	}
}
예제 #3
0
END_TEST
START_TEST (test_proxy_resource_preemption)
{
  tizrm_error_t error = TIZRM_SUCCESS;
  OMX_ERRORTYPE omx_error = OMX_ErrorNone;
  int rc, daemon_existed = 1;
  tizrm_t p_rm1, p_rm2;
  pid_t pid;
  OMX_UUIDTYPE uuid_omx1, uuid_omx2;
  OMX_PRIORITYMGMTTYPE primgmt;
  tizrm_proxy_callbacks_t cbacks1, cbacks2;
  cc_ctx_t ctx1, ctx2;
  check_common_context_t *p_ctx1 = NULL, *p_ctx2 = NULL;
  OMX_BOOL timedout1 = OMX_FALSE, timedout2 = OMX_FALSE;;

  /* Init the RM database */
  rc = system ("./updatedb.sh db_resource_preemption.before.sql3");

  /* Dump its initial contents */
  fail_if (!dump_rmdb ("test_proxy_resource_preemption.before.dump"));

  /* Check if an RM daemon is running already */
  if ((pid = check_tizrmproxy_find_proc ("tizrmd"))
      || (pid = check_tizrmproxy_find_proc ("lt-tizrmd")))
    {
      TIZ_LOG (TIZ_TRACE, "RM Process [PID %d] FOUND -- > SKIPPING THIS TEST", pid);
    }
  else
    {
      if (-1 == pid)
        {
          /* Start the rm daemon */
          pid = fork ();
          fail_if (pid == -1);
          daemon_existed = 0;
        }

      if (pid)
        {

          sleep (1);

          omx_error = _ctx_init (&ctx1);
          fail_if (OMX_ErrorNone != omx_error);
          p_ctx1 = (check_common_context_t *) (ctx1);
          p_ctx1->pp_rm = &p_rm1;

          omx_error = _ctx_init (&ctx2);
          fail_if (OMX_ErrorNone != omx_error);
          p_ctx2 = (check_common_context_t *) (ctx2);
          p_ctx2->pp_rm = &p_rm2;

          /* Generate the uuids */
          tiz_uuid_generate (&uuid_omx1);
          tiz_uuid_generate (&uuid_omx2);

          /* Init the rm hdls */
          primgmt.nSize = sizeof (OMX_PRIORITYMGMTTYPE);
          primgmt.nVersion.nVersion = OMX_VERSION;
          primgmt.nGroupPriority = COMPONENT1_PRIORITY;
          primgmt.nGroupID = COMPONENT1_GROUP_ID;

          cbacks1.pf_waitend = &check_tizrmproxy_comp1_wait_complete;
          cbacks1.pf_preempt = &check_tizrmproxy_comp1_preemption_req;
          cbacks1.pf_preempt_end = &check_tizrmproxy_comp1_preemption_complete;

          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_init : [%s]", COMPONENT1_NAME);
          error =
            tizrm_proxy_init (&p_rm1, COMPONENT1_NAME,
                              (const OMX_UUIDTYPE *) &uuid_omx1, &primgmt,
                              &cbacks1, (OMX_PTR *) (&ctx1));
          fail_if (error != TIZRM_SUCCESS);

          primgmt.nGroupPriority = COMPONENT2_PRIORITY;
          primgmt.nGroupID = COMPONENT2_GROUP_ID;

          cbacks2.pf_waitend = &check_tizrmproxy_comp2_wait_complete;
          cbacks2.pf_preempt = &check_tizrmproxy_comp2_preemption_req;
          cbacks2.pf_preempt_end = &check_tizrmproxy_comp2_preemption_complete;

          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_init : [%s]", COMPONENT2_NAME);
          error =
            tizrm_proxy_init (&p_rm2, COMPONENT2_NAME,
                              (const OMX_UUIDTYPE *) &uuid_omx2, &primgmt,
                              &cbacks2, (OMX_PTR *) (&ctx2));
          fail_if (error != TIZRM_SUCCESS);

          /* Component1 acquires all the available units (1) of resource TIZRM_RESOURCE_DUMMY */
          error = tizrm_proxy_acquire (&p_rm1, TIZRM_RESOURCE_DUMMY, 1);
          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_acquire returned (rm1) [%d]",
                     error);
          fail_if (error != TIZRM_SUCCESS);

          /* Component2 requests the same resource. It belongs to a higher priority
           * group and causes the preemption of the resource from Component1 */
          error = tizrm_proxy_acquire (&p_rm2, TIZRM_RESOURCE_DUMMY, 1);
          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_acquire returned (rm2) [%d]",
                     error);
          fail_if (error != TIZRM_PREEMPTION_IN_PROGRESS);

          TIZ_LOG (TIZ_TRACE, "Preemption is in progress (rm1) [%d]",
                     error);

          /* Verify preemption req for Component1's resource */
          omx_error = _ctx_wait (&ctx1, TIMEOUT_EXPECTING_SUCCESS, &timedout1);
          fail_if (OMX_ErrorNone != omx_error);
          fail_if (OMX_TRUE == timedout1);
          fail_if (TIZRM_RESOURCE_DUMMY != p_ctx1->rid);

          TIZ_LOG (TIZ_TRACE, "Preemption request verified (rm1) [%d]",
                     error);

          /* Now Component1 releases the resource */
          error = tizrm_proxy_preemption_conf (&p_rm1, TIZRM_RESOURCE_DUMMY, 1);
          TIZ_LOG (TIZ_TRACE,
                     "tizrm_proxy_preemption_conf returned (rm1) [%d]", error);
          fail_if (error != TIZRM_SUCCESS);

          /* Verify preemption completion and Component2's resource ownership */
          omx_error = _ctx_wait (&ctx2, TIMEOUT_EXPECTING_SUCCESS, &timedout2);
          fail_if (OMX_ErrorNone != omx_error);
          fail_if (OMX_TRUE == timedout2);
          fail_if (TIZRM_RESOURCE_DUMMY != p_ctx2->rid);

          TIZ_LOG (TIZ_TRACE, "Preemption completion verified (rm2) [%d]",
                     error);

          /* Now Component2 releases the resource */
          error = tizrm_proxy_release (&p_rm2, TIZRM_RESOURCE_DUMMY, 1);
          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_release returned (rm2) [%d]",
                     error);
          fail_if (error != TIZRM_SUCCESS);

          /* Destroy the rm hdls */
          TIZ_LOG (TIZ_TRACE, "Destroying rm hdls");
          error = tizrm_proxy_destroy (&p_rm1);
          fail_if (error != TIZRM_SUCCESS);
          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_destroy returned (rm1) [%d]",
                     error);

          error = tizrm_proxy_destroy (&p_rm2);
          fail_if (error != TIZRM_SUCCESS);
          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_destroy returned (rm2) [%d]",
                     error);

          _ctx_reset(&ctx1);
          _ctx_destroy(&ctx1);

          _ctx_reset(&ctx2);
          _ctx_destroy(&ctx2);

          if (!daemon_existed)
            {
              error = kill (pid, SIGTERM);
              fail_if (error == -1);
            }

          /* Check db */
          fail_if (!dump_rmdb ("test_proxy_resource_preemption.after.dump"));

          rc =
            system
            ("cmp -s /tmp/test_proxy_resource_preemption.before.dump /tmp/test_proxy_resource_preemption.after.dump");

          TIZ_LOG (TIZ_TRACE, "DB comparison check [%s]",
                     (rc == 0 ? "SUCCESS" : "FAILED"));
          fail_if (rc != 0);

          /* Restore the RM database */
          rc = system ("./updatedb.sh db_resource_preemption.after.sql3");

        }
      else
        {
          TIZ_LOG (TIZ_TRACE, "Starting the RM Daemon");
          const char *arg0 = "";
          error = execlp (pg_rmd_path, arg0, (char *) NULL);
          fail_if (error == -1);
        }

    }
}
예제 #4
0
END_TEST
START_TEST (test_proxy_busy_resource_management)
{
  tizrm_error_t error = TIZRM_SUCCESS;
  OMX_ERRORTYPE omx_error = OMX_ErrorNone;
  int rc, daemon_existed = 1;
  tizrm_t p_rm1, p_rm2;
  pid_t pid;
  OMX_UUIDTYPE uuid_omx1, uuid_omx2;
  OMX_PRIORITYMGMTTYPE primgmt;
  tizrm_proxy_callbacks_t cbacks1, cbacks2;
  cc_ctx_t ctx;
  check_common_context_t *p_ctx = NULL;
  OMX_BOOL timedout = OMX_FALSE;

  /* Init the RM database */
  rc = system ("./updatedb.sh db_busy_resource_management.before.sql3");

  /* Dump its initial contents */
  fail_if (!dump_rmdb ("test_proxy_busy_resource_management.before.dump"));

  /* Check if an RM daemon is running already */
  if ((pid = check_tizrmproxy_find_proc ("tizrmd"))
      || (pid = check_tizrmproxy_find_proc ("lt-tizrmd")))
    {
      TIZ_LOG (TIZ_TRACE, "RM Process [PID %d] FOUND -- > SKIPPING THIS TEST", pid);
    }
  else
    {
      if (-1 == pid)
        {
          /* Start the rm daemon */
          pid = fork ();
          fail_if (pid == -1);
          daemon_existed = 0;
        }

      if (pid)
        {

          sleep (1);

          omx_error = _ctx_init (&ctx);
          fail_if (OMX_ErrorNone != omx_error);
          p_ctx = (check_common_context_t *) (ctx);

          /* Generate the uuids */
          tiz_uuid_generate (&uuid_omx1);
          tiz_uuid_generate (&uuid_omx2);

          /* Init the rm hdls */
          primgmt.nSize = sizeof (OMX_PRIORITYMGMTTYPE);
          primgmt.nVersion.nVersion = OMX_VERSION;
          primgmt.nGroupPriority = COMPONENT1_PRIORITY;
          primgmt.nGroupID = COMPONENT1_GROUP_ID;

          cbacks1.pf_waitend = &check_tizrmproxy_comp1_wait_complete;
          cbacks1.pf_preempt = &check_tizrmproxy_comp1_preemption_req;
          cbacks1.pf_preempt_end = &check_tizrmproxy_comp1_preemption_complete;

          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_init : [%s]", COMPONENT1_NAME);
          error =
            tizrm_proxy_init (&p_rm1, COMPONENT1_NAME,
                              (const OMX_UUIDTYPE *) &uuid_omx1, &primgmt,
                              &cbacks1, (OMX_PTR *) (&ctx));
          fail_if (error != TIZRM_SUCCESS);

          cbacks2.pf_waitend = &check_tizrmproxy_comp2_wait_complete;
          cbacks2.pf_preempt = &check_tizrmproxy_comp2_preemption_req;
          cbacks2.pf_preempt_end = &check_tizrmproxy_comp2_preemption_complete;

          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_init : [%s]", COMPONENT2_NAME);
          error =
            tizrm_proxy_init (&p_rm2, COMPONENT2_NAME,
                              (const OMX_UUIDTYPE *) &uuid_omx2, &primgmt,
                              &cbacks2, (OMX_PTR *) (&ctx));
          fail_if (error != TIZRM_SUCCESS);

          /* Component1 acquires all the available units (1) of resource TIZRM_RESOURCE_DUMMY */
          error = tizrm_proxy_acquire (&p_rm1, TIZRM_RESOURCE_DUMMY, 1);
          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_acquire returned (rm1) [%d]",
                     error);
          fail_if (error != TIZRM_SUCCESS);

          /* Component2 cannot acquire the resource, because there are not enough
           * units available */
          error = tizrm_proxy_acquire (&p_rm2, TIZRM_RESOURCE_DUMMY, 1);
          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_acquire returned (rm2) [%d]",
                     error);
          fail_if (error != TIZRM_NOT_ENOUGH_RESOURCE_AVAILABLE);

          /* Component2 signals its intent to wait for the resource */
          error = tizrm_proxy_wait (&p_rm2, TIZRM_RESOURCE_DUMMY, 1);
          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_wait returned (rm2) [%d]",
                     error);
          fail_if (error != TIZRM_SUCCESS);

          /* Now Component1 releases the resource */
          error = tizrm_proxy_release (&p_rm1, TIZRM_RESOURCE_DUMMY, 1);
          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_release returned (rm1) [%d]",
                     error);
          fail_if (error != TIZRM_SUCCESS);

          /* and now Component2 receives the resource  */
          /* Check wait complete */
          omx_error = _ctx_wait (&ctx, TIMEOUT_EXPECTING_SUCCESS, &timedout);
          fail_if (OMX_ErrorNone != omx_error);
          fail_if (OMX_TRUE == timedout);
          fail_if (TIZRM_RESOURCE_DUMMY != p_ctx->rid);

          TIZ_LOG (TIZ_TRACE, "Wait complete (rm2)");

          /* Component2 releases the resource  */
          error = tizrm_proxy_release (&p_rm2, TIZRM_RESOURCE_DUMMY, 1);
          fail_if (error != TIZRM_SUCCESS);
          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_release returned (rm2) [%d]",
                     error);

          /* Destroy the rm hdls */
          TIZ_LOG (TIZ_TRACE, "Destroying rm hdls");
          error = tizrm_proxy_destroy (&p_rm1);
          fail_if (error != TIZRM_SUCCESS);
          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_destroy returned (rm1) [%d]",
                     error);

          error = tizrm_proxy_destroy (&p_rm2);
          fail_if (error != TIZRM_SUCCESS);
          TIZ_LOG (TIZ_TRACE, "tizrm_proxy_destroy returned (rm2) [%d]",
                     error);

          _ctx_reset(&ctx);
          _ctx_destroy(&ctx);

          if (!daemon_existed)
            {
              error = kill (pid, SIGTERM);
              fail_if (error == -1);
            }

          /* Check db */
          fail_if (!dump_rmdb ("test_proxy_busy_resource_management.after.dump"));

          rc =
            system
            ("cmp -s /tmp/test_proxy_busy_resource_management.before.dump /tmp/test_proxy_busy_resource_management.after.dump");

          TIZ_LOG (TIZ_TRACE, "DB comparison check [%s]",
                     (rc == 0 ? "SUCCESS" : "FAILED"));
          fail_if (rc != 0);

          /* Restore the RM database */
          rc = system ("./updatedb.sh db_busy_resource_management.before.sql3");

        }
      else
        {
          TIZ_LOG (TIZ_TRACE, "Starting the RM Daemon");
          const char *arg0 = "";
          error = execlp (pg_rmd_path, arg0, (char *) NULL);
          fail_if (error == -1);
        }
    }
}