Beispiel #1
0
/****
 * Main function
 */
int main(int argc, char * argv[])
{
	long opt_TMR, opt_CS;
	int ret=0;

	output_init();
	
	#if VERBOSE > 1
	output("Test starting...\n");
	#endif

	opt_TMR=sysconf(_SC_TIMERS);
	opt_CS =sysconf(_SC_CLOCK_SELECTION);
	
	#if VERBOSE > 1
	output("Timers option : %li\n", opt_TMR);
	output("Clock Selection option : %li\n", opt_CS);
	#endif
	
	if ((opt_TMR != -1L) && (opt_CS != -1L))
	{
		#if VERBOSE > 0
		output("Starting clock test\n");
		#endif
		ret = do_cs_test();
	}
	else
	{
		UNTESTED("This test requires unsupported features");
	}		
	if (ret != 0)
	{  FAILED("The cond vars use different clocks.");  }
	
	PASSED;
}
Beispiel #2
0
/* main function */
int main()
{
	int ret;
	long rts;

	struct sigaction sa;

	/* Initialize output */
	output_init();

	/* Test the RTS extension */
	rts = sysconf(_SC_REALTIME_SIGNALS);

	if (rts < 0L) {
		UNTESTED("This test needs the RTS extension");
	}

	/* Set the signal handler */
	sa.sa_flags = SA_SIGINFO;

	sa.sa_sigaction = handler;

	ret = sigemptyset(&sa.sa_mask);

	if (ret != 0) {
		UNRESOLVED(ret, "Failed to empty signal set");
	}

	/* Install the signal handler for SIGTERM */
	ret = sigaction(SIGNAL, &sa, 0);

	if (ret != 0) {
		UNRESOLVED(ret, "Failed to set signal handler");
	}

	if (called) {
		FAILED
		    ("The signal handler has been called when no signal was raised");
	}

	ret = raise(SIGNAL);

	if (ret != 0) {
		UNRESOLVED(ret, "Failed to raise SIGTERM");
	}

	if (!called) {
		FAILED
		    ("the sa_handler was not called whereas SA_SIGINFO was not set");
	}

	/* Test passed */
#if VERBOSE > 0

	output("Test passed\n");

#endif

	PASSED;
}
Beispiel #3
0
Datei: 1-2.c Projekt: 1587/ltp
/* thread function 2 */
void *changer(void *arg)
{
	int ret = 0;

	struct sched_param sp;
	sp.sched_priority = sched_get_priority_min(SCHED_RR);

	if (sp.sched_priority < 0) {
		UNTESTED("Failed to get min SCHED_RR range");
	}

	/* set the other thread's policy */
	ret = pthread_setschedparam(*(pthread_t *) arg, SCHED_RR, &sp);

	if (ret != 0) {
		UNRESOLVED(ret, "Failed to set other's thread policy");
	}

	return NULL;
}
Beispiel #4
0
		/* Destroy data */
		ret = pthread_cond_destroy(&(data.cnd));
		if (ret != 0)
			UNRESOLVED(ret, "Cond destroy failed");

		ret = pthread_mutex_destroy(&(data.mtx1));
		if (ret != 0)
			UNRESOLVED(ret, "Mutex 1 destroy failed");

		ret = pthread_mutex_destroy(&(data.mtx2));
		if (ret != 0)
			UNRESOLVED(ret, "Mutex 2 destroy failed");

		ret = pthread_condattr_destroy(&ca);
		if (ret != 0)
			UNRESOLVED(ret, "Cond attribute destroy failed");

		ret = pthread_mutexattr_destroy(&ma);
		if (ret != 0)
			UNRESOLVED(ret, "Mutex attr destroy failed");
	}			/* Proceed to next case */

	PASSED;
}

#else /* WITHOUT_XOPEN */
int main(int argc, char *argv[])
{
	output_init();
	UNTESTED("This test requires XSI features");
}
Beispiel #5
0
static inline HRESULT
present( struct NineSwapChain9 *This,
         const RECT *pSourceRect,
         const RECT *pDestRect,
         HWND hDestWindowOverride,
         const RGNDATA *pDirtyRegion,
         DWORD dwFlags )
{
    struct pipe_context *pipe;
    struct pipe_resource *resource;
    struct pipe_fence_handle *fence;
    HRESULT hr;
    struct pipe_blit_info blit;

    DBG("present: This=%p pSourceRect=%p pDestRect=%p "
        "pDirtyRegion=%p hDestWindowOverride=%p"
        "dwFlags=%d resource=%p\n",
        This, pSourceRect, pDestRect, pDirtyRegion,
        hDestWindowOverride, (int)dwFlags, This->buffers[0]->base.resource);

    if (pSourceRect)
        DBG("pSourceRect = (%u..%u)x(%u..%u)\n",
            pSourceRect->left, pSourceRect->right,
            pSourceRect->top, pSourceRect->bottom);
    if (pDestRect)
        DBG("pDestRect = (%u..%u)x(%u..%u)\n",
            pDestRect->left, pDestRect->right,
            pDestRect->top, pDestRect->bottom);

    /* TODO: in the case the source and destination rect have different size:
     * We need to allocate a new buffer, and do a blit to it to resize.
     * We can't use the present_buffer for that since when we created it,
     * we couldn't guess which size would have been needed.
     * If pDestRect or pSourceRect is null, we have to check the sizes
     * from the source size, and the destination window size.
     * In this case, either resize rngdata, or pass NULL instead
     */
    /* Note: This->buffers[0]->level should always be 0 */

    if (This->rendering_done)
        goto bypass_rendering;

    resource = This->buffers[0]->base.resource;

    if (This->params.SwapEffect == D3DSWAPEFFECT_DISCARD)
        handle_draw_cursor_and_hud(This, resource);

    pipe = NineDevice9_GetPipe(This->base.device);

    if (This->present_buffers[0]) {
        memset(&blit, 0, sizeof(blit));
        blit.src.resource = resource;
        blit.src.level = 0;
        blit.src.format = resource->format;
        blit.src.box.z = 0;
        blit.src.box.depth = 1;
        blit.src.box.x = 0;
        blit.src.box.y = 0;
        blit.src.box.width = resource->width0;
        blit.src.box.height = resource->height0;

        resource = This->present_buffers[0];

        blit.dst.resource = resource;
        blit.dst.level = 0;
        blit.dst.format = resource->format;
        blit.dst.box.z = 0;
        blit.dst.box.depth = 1;
        blit.dst.box.x = 0;
        blit.dst.box.y = 0;
        blit.dst.box.width = resource->width0;
        blit.dst.box.height = resource->height0;

        blit.mask = PIPE_MASK_RGBA;
        blit.filter = PIPE_TEX_FILTER_NEAREST;
        blit.scissor_enable = FALSE;
        blit.alpha_blend = FALSE;

        pipe->blit(pipe, &blit);
    }

    /* The resource we present has to resolve fast clears
     * if needed (and other things) */
    pipe->flush_resource(pipe, resource);

    if (This->params.SwapEffect != D3DSWAPEFFECT_DISCARD)
        handle_draw_cursor_and_hud(This, resource);

    fence = NULL;
    pipe->flush(pipe, &fence, PIPE_FLUSH_END_OF_FRAME);
    if (fence) {
        swap_fences_push_back(This, fence);
        This->screen->fence_reference(This->screen, &fence, NULL);
    }

    This->rendering_done = TRUE;
bypass_rendering:

    if (dwFlags & D3DPRESENT_DONOTWAIT) {
        UNTESTED(2);
        BOOL still_draw = FALSE;
        fence = swap_fences_see_front(This);
        if (fence) {
            still_draw = !This->screen->fence_finish(This->screen, NULL, fence, 0);
            This->screen->fence_reference(This->screen, &fence, NULL);
        }
        if (still_draw)
            return D3DERR_WASSTILLDRAWING;
    }

    if (!This->enable_threadpool) {
        This->tasks[0]=NULL;
        fence = swap_fences_pop_front(This);
        if (fence) {
            (void) This->screen->fence_finish(This->screen, NULL, fence, PIPE_TIMEOUT_INFINITE);
            This->screen->fence_reference(This->screen, &fence, NULL);
        }

        hr = ID3DPresent_PresentBuffer(This->present, This->present_handles[0], hDestWindowOverride, pSourceRect, pDestRect, pDirtyRegion, dwFlags);

        if (FAILED(hr)) { UNTESTED(3);return hr; }
    } else {
        pend_present(This, hDestWindowOverride);
    }
    This->rendering_done = FALSE;

    return D3D_OK;
}
Beispiel #6
0
int do_cs_test(void)
{
	int ret;
	int result=0;
	
	pthread_mutex_t mtxN, mtxI;
	pthread_cond_t cndN;
	
	pthread_condattr_t ca;
	
	pthread_t thN, thD;
	
	struct timespec ts, timeout;
	
	clockid_t  cid;

	/* The 3 next data aim to minimize the impact on the
	 *  system time, when the monotonic clock is supported
	 */
	long monotonic_clk;
	struct timespec diff;
	char sens=0;
	
	/* We are going to initialize the cond vars and the mutexes */
	dtN.pmtx = &mtxN;
	dtI.pmtx = &mtxI;
	dtN.pcnd = &cndN;
	dtI.pcnd = &cndI;
	ret = pthread_mutex_init(&mtxI, NULL);
	if (ret != 0)
	{  UNRESOLVED(ret, "Unable to initialize a default mutex");  }
	ret = pthread_mutex_init(&mtxN, NULL);
	if (ret != 0)
	{  UNRESOLVED(ret, "Unable to initialize a default mutex");  }
	ret = pthread_condattr_init(&ca);
	if (ret != 0)
	{  UNRESOLVED(ret, "Unable to initialize cond attribute object");  }

#if 0	/*  Test if the testcase is valid: change the clock from the "NULL" cond var */
	pthread_condattr_setclock(&ca, CLOCK_MONOTONIC);
	ret = pthread_cond_init(&cndN, &ca);
	pthread_condattr_setclock(&ca, CLOCK_REALTIME);
#else
	ret = pthread_cond_init(&cndN, NULL);
#endif
	if (ret != 0)
	{  UNRESOLVED(ret, "Unable to initialize the NULL attribute conditional variable.");  }
	
	dtI.ctrl = 0;
	dtN.ctrl = 0;
	dtI.rc   = 0;
	dtN.rc   = 0;
	
	#if VERBOSE > 1
	output("Data initialized successfully for CS test.\n");
	#endif
	
	monotonic_clk = sysconf(_SC_MONOTONIC_CLOCK);
	#if VERBOSE > 1
	output("Sysconf for monotonix clock: %li\n", monotonic_clk);
	#endif
	
	/* Get the default clock ID */
	ret = pthread_condattr_getclock(&ca, &cid);
	if (ret != 0)
	{  UNRESOLVED(ret, "Unable to get clockid from the default cond attribute object");  }
	
	/* Check whether we can set the system clock */
	
	/* Backup the current monotonic time if available */
	if (monotonic_clk != -1L)
	{
		ret = clock_gettime(CLOCK_MONOTONIC, &diff);
		if (ret != 0)
		{
			output("Clock_gettime(CLOCK_MONOTONIC) failed when the system claims to support this option\n");
			monotonic_clk = -1L;
		}
	}
	ret = clock_gettime(cid, &ts);
	if (ret != 0)
	{  UNRESOLVED(errno, "Unable to get clock time");  }
	
	
	ret = clock_settime(cid, &ts);
	if (ret != 0)
	{
		#if VERBOSE > 1
		output("clock_settime failed (%s)\n", strerror(errno));
		output("We cannot test if both cond uses the same clock then...\n");
		#endif
		UNTESTED("Was unable to set the default clock time. Need more privileges?");
	}
	else /* We can do the test */
	{
		#if VERBOSE > 1
		output("clock_settime succeeded\n");
		#endif
		
		if (monotonic_clk != -1L)
		{
			#if VERBOSE > 2
			output("Monotonic clock : %10i.%09li\n", diff.tv_sec, diff.tv_nsec);
			output("Default clock   : %10i.%09li\n", ts.tv_sec, ts.tv_nsec);
			#endif
			/* Save the decay between default clock and clock MONOTONIC */
			if (diff.tv_sec > ts.tv_sec)
			{
				sens = -1; /* monotonic was bigger than system */
				if (diff.tv_nsec < ts.tv_nsec)
				{
					diff.tv_nsec += 1000000000 - ts.tv_nsec;
					diff.tv_sec  -= 1 + ts.tv_sec;
				}
				else
				{
					diff.tv_nsec -= ts.tv_nsec;
					diff.tv_sec -= ts.tv_sec;
				}
			}
			else
			{
				if (diff.tv_sec == ts.tv_sec)
				{
					diff.tv_sec = 0;
					if (diff.tv_nsec > ts.tv_nsec)
					{
						sens = -1;
						diff.tv_nsec -= ts.tv_nsec;
					}
					else
					{
						sens = 1; /* Default clock was bigger than monotonic */
						diff.tv_nsec = ts.tv_nsec - diff.tv_nsec;
					}
				}
				else /* ts.tv_sec > diff.tv_sec */
				{
					sens = 1;
					if (ts.tv_nsec < diff.tv_nsec)
					{
						diff.tv_nsec = 1000000000 + ts.tv_nsec - diff.tv_nsec;
						diff.tv_sec = ts.tv_sec - (1 + diff.tv_sec);
					}
					else
					{
						diff.tv_nsec = ts.tv_nsec - diff.tv_nsec;
						diff.tv_sec = ts.tv_sec - diff.tv_sec;
					}
				}
			}
						
			#if VERBOSE > 2
			output("Computed diff   : %10i.%09li\n", diff.tv_sec, diff.tv_nsec);
			output("With monotonic %s than default\n", sens>0?"smaller":"bigger");
			#endif
		}
		
		/* Prepare the timeout parameters */
		timeout.tv_nsec = 0;
		timeout.tv_sec = ts.tv_sec + 260000; /* About 3 days later */
		dtN.timeout = &timeout;
		dtI.timeout = &timeout;
		
		/* create the threads */
		ret = pthread_create(&thD, NULL, test_timeout, &dtI);
		if (ret != 0)
		{  UNRESOLVED(ret, "Unable to create a thread");  }
		ret = pthread_create(&thN, NULL, test_timeout, &dtN);
		if (ret != 0)
		{  UNRESOLVED(ret, "Unable to create a thread");  }
		
		/* Lock the two mutex and make sure the threads are in wait */
		ret = pthread_mutex_lock(&mtxN);
		if (ret != 0)  {  UNRESOLVED(ret, "Unable to lock a mutex");  }
		while ((dtN.ctrl & FLAG_INWAIT) == 0)
		{
			ret = pthread_mutex_unlock(&mtxN);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to unlock a mutex");  }
			sched_yield();
			ret = pthread_mutex_lock(&mtxN);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to lock a mutex");  }
		}
		ret = pthread_mutex_lock(&mtxI);
		if (ret != 0)  {  UNRESOLVED(ret, "Unable to lock a mutex");  }
		while ((dtI.ctrl & FLAG_INWAIT) == 0)
		{
			ret = pthread_mutex_unlock(&mtxI);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to unlock a mutex");  }
			sched_yield();
			ret = pthread_mutex_lock(&mtxI);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to lock a mutex");  }
		}
		
		/* Now both threads are in the timed wait */
		#if VERBOSE > 1
		output("Two threads are created and waiting.\n");
		output("About to change the default clock value.\n");
		#endif
		
		/* We re-read the default clock time, to introduce minimal error on the clock */
		ret = clock_gettime(cid, &ts);
		if (ret != 0)  {  UNRESOLVED(errno, "Unable to get clock time");  }
		
		ts.tv_sec += 604800;  /* Exactly 1 week forth */
		
		/* We set the clock to a date after the timeout parameter */
		ret = clock_settime(cid, &ts);
		if (ret != 0)  {  UNRESOLVED(errno, "Unable to set clock time (again)");  }
		
		/* unlock the two mutex */
		ret = pthread_mutex_unlock(&mtxI);
		if (ret != 0)  {  UNRESOLVED(ret, "Unable to unlock a mutex");  }
		ret = pthread_mutex_unlock(&mtxN);
		if (ret != 0)  {  UNRESOLVED(ret, "Unable to unlock a mutex");  }
		
		/* Let the others threads run */
		sched_yield();
		
		#if VERBOSE > 1
		output("Checking that both threads have timedout...\n");
		#endif
		
		/* Relock the mutexs */
		ret = pthread_mutex_lock(&mtxN);
		if (ret != 0)  {  UNRESOLVED(ret, "Unable to lock a mutex");  }
		ret = pthread_mutex_lock(&mtxI);
		if (ret != 0)  {  UNRESOLVED(ret, "Unable to lock a mutex");  }
		
		/* Check whether the thread has timedout */
		if (dtI.rc == 0)
		{
			#if VERBOSE > 0
			output("The thread was not woken when the clock was changed so as the timeout expired\n");
			output("Going to simulate this POSIX behavior...\n");
			#endif
			ret = pthread_cond_signal(&cndN);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to signal the Null attribute condition");  }
			ret = pthread_cond_signal(&cndI);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to signal the Default attribute condition");  }
			
			/* The threads will now report a spurious wake up ... */
			
			/* We give the threads another chance to timeout */
			/* unlock the two mutex */
			ret = pthread_mutex_unlock(&mtxI);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to unlock a mutex");  }
			ret = pthread_mutex_unlock(&mtxN);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to unlock a mutex");  }
			
			/* Let the others threads run */
			sched_yield();
			
			#if VERBOSE > 1
			output("Rechecking that both threads have timedout...\n");
			#endif
			
			/* Relock the mutexs */
			ret = pthread_mutex_lock(&mtxN);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to lock a mutex");  }
			ret = pthread_mutex_lock(&mtxI);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to lock a mutex");  }
		}
			
		
		/* Process the Null condvar */
		if ((dtN.ctrl & FLAG_TIMEDOUT) != 0)
		{
			#if VERBOSE > 1
			output("Null attribute cond var timed out\n");
			#endif
			/* Join the thread */
			ret = pthread_join(thN, NULL);
			if (ret != 0)  {  UNRESOLVED(ret, "Join thread failed");  }
			/* Unlock the mutex */
			ret = pthread_mutex_unlock(&mtxN);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to unlock a mutex");  }
		}
		else
		{
			#if VERBOSE > 1
			output("Null attribute cond var did not time out\n");
			#endif
			/* Signal the condition */
			dtN.ctrl |= FLAG_CONDWAKE;
			ret = pthread_cond_signal(&cndN);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to signal the Null attribute condition");  }
			/* Unlock the mutex and join the thread */
			ret = pthread_mutex_unlock(&mtxN);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to unlock a mutex");  }
			/* Join the thread */
			ret = pthread_join(thN, NULL);
			if (ret != 0)  {  UNRESOLVED(ret, "Join thread failed");  }
		}
		
		/* Process the Default condvar */
		if ((dtI.ctrl & FLAG_TIMEDOUT) != 0)
		{
			#if VERBOSE > 1
			output("Default attribute cond var timed out\n");
			#endif
			/* Join the thread */
			ret = pthread_join(thD, NULL);
			if (ret != 0)  {  UNRESOLVED(ret, "Join thread failed");  }
			/* Unlock the mutex */
			ret = pthread_mutex_unlock(&mtxI);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to unlock a mutex");  }
		}
		else
		{
			#if VERBOSE > 1
			output("Default attribute cond var did not time out\n");
			#endif
			/* Signal the condition */
			dtI.ctrl |= FLAG_CONDWAKE;
			ret = pthread_cond_signal(&cndI);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to signal the Default attribute condition");  }
			/* Unlock the mutex and join the thread */
			ret = pthread_mutex_unlock(&mtxI);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to unlock a mutex");  }
			/* Join the thread */
			ret = pthread_join(thD, NULL);
			if (ret != 0)  {  UNRESOLVED(ret, "Join thread failed");  }
		}
		
		/* Set the system time back to its value */
		if (monotonic_clk == -1L) /* Monotonic is not supported */
		{
			ret = clock_gettime(cid, &ts);
			if (ret != 0)  {  UNRESOLVED(errno, "Unable to get clock time");  }
			
			ts.tv_sec -= 604800;  /* Exactly 1 week back */ 
			
			/* We set the clock to a date after the timeout parameter */
			ret = clock_settime(cid, &ts);
			if (ret != 0)  {  UNRESOLVED(errno, "Unable to set clock time (3rd time)");  }
			#if VERBOSE > 1
			output("Default clock was set back\n");
			#endif
		}
		else
		{
			/* Read the monotonic time */
			ret = clock_gettime(CLOCK_MONOTONIC, &ts);
			if (ret != 0)  {  UNRESOLVED(errno, "Unable to get monotonic clock time");  }
			
			/* Apply the difference back */
			if (sens > 0) /* monotonic was smaller than system => we must add the diff value */
			{
				ts.tv_sec += diff.tv_sec;
				ts.tv_nsec += diff.tv_nsec;
				if (ts.tv_nsec >= 1000000000)
				{
					ts.tv_nsec -= 1000000000;
					ts.tv_sec += 1;
				}
			}
			else /* monotonic was bigger than system => we must remove the diff value */
			{
				ts.tv_sec -= diff.tv_sec;
				if (ts.tv_nsec < diff.tv_nsec)
				{
					ts.tv_sec -= 1;
					ts.tv_nsec += 1000000000 - diff.tv_nsec;
				}
				else
				{
					ts.tv_nsec -= diff.tv_nsec;
				}
			}
			
			/* We set the clock to a date after the timeout parameter */
			ret = clock_settime(cid, &ts);
			if (ret != 0)  {  UNRESOLVED(errno, "Unable to set clock time (3rd time)");  }
			
			#if VERBOSE > 1
			output("Default clock was set back using monotonic clock as a reference\n");
			#endif
		}
		
		/* Compare the two cond vars */
		#if VERBOSE > 2
		output("Default attribute cond var timedwait return value: %d\n", dtI.rc);
		output("Default attribute cond var exited with a timeout : %s\n", (dtI.ctrl & FLAG_TIMEDOUT)?"yes":"no");
		output("Default attribute cond var had to be signaled    : %s\n", (dtI.ctrl & FLAG_CONDWAKE)?"yes":"no");
		output("Default attribute cond var exited as signaled    : %s\n", (dtI.ctrl & FLAG_AWAKEN)?"yes":"no");
		output("Default attribute cond var spurious wakeups      : %d\n", (dtI.ctrl & MASK_COUNTER) - 1);
		output(" Null   attribute cond var timedwait return value: %d\n", dtN.rc);
		output(" Null   attribute cond var exited with a timeout : %s\n", (dtN.ctrl & FLAG_TIMEDOUT)?"yes":"no");
		output(" Null   attribute cond var had to be signaled    : %s\n", (dtN.ctrl & FLAG_CONDWAKE)?"yes":"no");
		output(" Null   attribute cond var exited as signaled    : %s\n", (dtN.ctrl & FLAG_AWAKEN)?"yes":"no");
		output(" Null   attribute cond var spurious wakeups      : %d\n", (dtN.ctrl & MASK_COUNTER) - 1);
		#endif
		if ((dtN.ctrl == dtI.ctrl) && (dtN.rc == dtI.rc))
		{
			result = 0;
			#if VERBOSE > 1
			output("The two cond vars behaved exactly in the same maneer\n");
			#endif
		}
		else
		{
			if ((dtN.ctrl & FLAG_TIMEDOUT) != (dtI.ctrl & FLAG_TIMEDOUT))
			{
				result += 1; /* The test has failed */
			}
			else
			{
				if (dtN.rc != dtI.rc)
				{
					output("Error codes were different: N:%d D:%d\n",dtN.rc, dtI.rc);
					UNRESOLVED(dtN.rc>dtI.rc?dtN.rc:dtI.rc, "Different error codes?");
				}
				if ((dtN.ctrl & FLAG_AWAKEN) == (dtI.ctrl & FLAG_AWAKEN))
				{
					/* The number of spurious wakeups is different */
					output("Different spurious wakeups: N:%d D:%d\n", 
						(dtN.ctrl & MASK_COUNTER) - 1, 
						(dtI.ctrl & MASK_COUNTER) - 1);
					
					result = 0; /* We don't consider this as a fail case */
				}
			}
		}
	}
	
	/* We can cleanup things now */
	ret = pthread_cond_destroy(&cndN);
	if (ret != 0)
	{  UNRESOLVED(ret, "Cond destroy failed");  }
	ret = pthread_condattr_destroy(&ca);
	if (ret != 0)
	{  UNRESOLVED(ret, "Cond attr destroy failed");  }
	ret = pthread_mutex_destroy(&mtxN);
	if (ret != 0)
	{  UNRESOLVED(ret, "Mutex destroy failed");  }
	ret = pthread_mutex_destroy(&mtxI);
	if (ret != 0)
	{  UNRESOLVED(ret, "Mutex destroy failed");  }
	
	return result;
}
Beispiel #7
0
Datei: 22-1.c Projekt: 1587/ltp
int main(void)
{
	int ret, status;
	pid_t child, ctl;

	long ctp, ctt;
	clockid_t clp, clt;

	struct timespec tp;

	output_init();

	ctp = sysconf(_SC_CPUTIME);
	ctt = sysconf(_SC_THREAD_CPUTIME);

	if ((ctp == -1) && (ctt == -1)) {
		UNTESTED
		    ("The testcase needs CPUTIME or THREAD_CPUTIME support");
	}
#if VERBOSE > 0
	output("System abilities:\n");

	output("  _POSIX_CPUTIME        : %ld\n", ctp);

	output("  _POSIX_THREAD_CPUTIME : %ld\n", ctt);

#endif
	if (ctp > 0) {
		ret = clock_getcpuclockid(0, &clp);

		if (ret != 0) {
			UNRESOLVED(ret,
				   "Unable to get cpu-time clock id of the process");
		}

		do {
			ret = clock_gettime(clp, &tp);

			if (ret != 0) {
				UNRESOLVED(errno,
					   "Failed to read CPU time clock");
			}
		}
		while (tp.tv_sec < 1);
	}

	if (ctt > 0) {
		ret = pthread_getcpuclockid(pthread_self(), &clt);

		if (ret != 0) {
			UNRESOLVED(ret,
				   "Unable to get cpu-time clock id of the thread");
		}

		do {
			ret = clock_gettime(clt, &tp);

			if (ret != 0) {
				UNRESOLVED(errno,
					   "Failed to read thread CPU time clock");
			}
		}
		while (tp.tv_sec < 1);
	}

	/* Create the child */
	child = fork();

	if (child == -1) {
		UNRESOLVED(errno, "Failed to fork");
	}

	/* child */
	if (child == 0) {
		if (ctp > 0) {
			ret = clock_getcpuclockid(0, &clp);

			if (ret != 0) {
				UNRESOLVED(ret,
					   "Unable to get cpu-time clock id of the process");
			}

			ret = clock_gettime(clp, &tp);

			if (ret != 0) {
				UNRESOLVED(errno,
					   "Failed to read CPU time clock");
			}

			if (tp.tv_sec > 0) {
				FAILED
				    ("The process CPU-time clock was not reset in child\n");
			}
		}

		if (ctt > 0) {
			ret = pthread_getcpuclockid(pthread_self(), &clt);

			if (ret != 0) {
				UNRESOLVED(ret,
					   "Unable to get cpu-time clock id of the thread");
			}

			ret = clock_gettime(clt, &tp);

			if (ret != 0) {
				UNRESOLVED(errno,
					   "Failed to read thread CPU time clock");
			}

			if (tp.tv_sec > 0) {
				FAILED
				    ("The thread CPU-time clock was not reset in child\n");
			}
		}

		exit(PTS_PASS);
	}

	/* Parent joins the child */
	ctl = waitpid(child, &status, 0);

	if (ctl != child) {
		UNRESOLVED(errno, "Waitpid returned the wrong PID");
	}

	if (!WIFEXITED(status) || (WEXITSTATUS(status) != PTS_PASS)) {
		FAILED("Child exited abnormally");
	}

#if VERBOSE > 0
	output("Test passed\n");
#endif
	PASSED;
}
Beispiel #8
0
Datei: 2-5.c Projekt: Nan619/ltp
        /* Destroy data */
        ret = pthread_cond_destroy(&(data.cnd));
        if (ret != 0)
            UNRESOLVED(ret, "Cond destroy failed");

        ret = pthread_mutex_destroy(&(data.mtx1));
        if (ret != 0)
            UNRESOLVED(ret, "Mutex 1 destroy failed");

        ret = pthread_mutex_destroy(&(data.mtx2));
        if (ret != 0)
            UNRESOLVED(ret, "Mutex 2 destroy failed");

        ret = pthread_condattr_destroy(&ca);
        if (ret != 0)
            UNRESOLVED(ret, "Cond attribute destroy failed");

        ret = pthread_mutexattr_destroy(&ma);
        if (ret != 0)
            UNRESOLVED(ret, "Mutex attr destroy failed");
    }			/* Proceed to next case */

    PASSED;
}

#else /* WITHOUT_XOPEN */
int main(void)
{
    output_init();
    UNTESTED("This test requires XSI features");
}
Beispiel #9
0
Datei: 7-1.c Projekt: 1587/ltp
/* The main test function. */
int main(void)
{
	int ret, i;
	sem_t *sems;
	sem_t sem_last;

	long max;

	/* Initialize output */
	output_init();

	max = sysconf(_SC_SEM_NSEMS_MAX);

	if (max <= 0) {
		output("sysconf(_SC_SEM_NSEMS_MAX) = %ld\n", max);
		UNTESTED("There is no constraint on SEM_NSEMS_MAX");
	}

	sems = (sem_t *) calloc(max, sizeof(sem_t));

	if (sems == NULL) {
		UNRESOLVED(errno, "Failed to alloc space");
	}

	for (i = 0; i < max; i++) {
		ret = sem_init(&sems[i], 0, 0);

		if (ret != 0) {
			output
			    ("sem_init failed to initialize the %d nth semaphore.\n",
			     i);
			output("Tryed to initialize %ld.\n", max);
			output("Error is %d: %s\n", errno, strerror(errno));

			for (; i > 0; i--)
				sem_destroy(&sems[i - 1]);

			free(sems);

			PASSED;
		}
	}

	ret = sem_init(&sem_last, 0, 1);

	if (ret == 0) {
		FAILED
		    ("We were able to sem_init more than SEM_NSEMS_MAX semaphores");
	}

	if (errno != ENOSPC) {
		output("Error is %d: %s\n", errno, strerror(errno));
	}

	for (i = 0; i < max; i++)
		sem_destroy(&sems[i]);

	free(sems);

	/* Test passed */
#if VERBOSE > 0

	output("Test passed\n");

#endif

	PASSED;
}
/* This function will initialize every pthread_attr_t object in the scenarii array */
void scenar_init()
{
	int ret=0;
	int i;
	int old;
	long pagesize, minstacksize;
	long tsa, tss, tps;
	
	pagesize	=sysconf(_SC_PAGESIZE);
	minstacksize 	=sysconf(_SC_THREAD_STACK_MIN);
	tsa		=sysconf(_SC_THREAD_ATTR_STACKADDR);
	tss		=sysconf(_SC_THREAD_ATTR_STACKSIZE);
	tps		=sysconf(_SC_THREAD_PRIORITY_SCHEDULING);
	
	#if VERBOSE > 0
	output("System abilities:\n");
	output(" TSA: %li\n", tsa);
	output(" TSS: %li\n", tss);
	output(" TPS: %li\n", tps);
	output(" pagesize: %li\n", pagesize);
	output(" min stack size: %li\n", minstacksize);
	#endif
	
	
	if (minstacksize % pagesize)
	{
		UNTESTED("The min stack size is not a multiple of the page size");
	}
	
	for (i=0; i<NSCENAR; i++)
	{
		#if VERBOSE > 2
		output("Initializing attribute for scenario %i: %s\n", i, scenarii[i].descr);
		#endif
		
		ret = pthread_attr_init(&scenarii[i].ta);
		if (ret != 0)  {  UNRESOLVED(ret, "Failed to initialize a thread attribute object");  }
		
		/* Set the attributes according to the scenario */
		if (scenarii[i].detached == 1)
		{
			ret = pthread_attr_setdetachstate(&scenarii[i].ta, PTHREAD_CREATE_DETACHED);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to set detachstate");  }
		}
		else
		{
			ret = pthread_attr_getdetachstate(&scenarii[i].ta, &old);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to get detachstate from initialized attribute");  }
			if (old != PTHREAD_CREATE_JOINABLE)  {  FAILED("The default attribute is not PTHREAD_CREATE_JOINABLE");  }
		}
		#if VERBOSE > 4
		output("Detach state was set sucessfully\n");
		#endif
		
		/* Sched related attributes */
		if (tps>0) /* This routine is dependent on the Thread Execution Scheduling option */
		{
			if (scenarii[i].explicitsched == 1)
				ret = pthread_attr_setinheritsched(&scenarii[i].ta, PTHREAD_EXPLICIT_SCHED);
			else
				ret = pthread_attr_setinheritsched(&scenarii[i].ta, PTHREAD_INHERIT_SCHED);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to set inheritsched attribute");  }
			#if VERBOSE > 4
			output("inheritsched state was set sucessfully\n");
			#endif
		}
		#if VERBOSE > 4
		else
			output("TPS unsupported => inheritsched parameter untouched\n");
		#endif
		
		if (tps>0) /* This routine is dependent on the Thread Execution Scheduling option */
		{
			if (scenarii[i].schedpolicy == 1)
			{
				ret = pthread_attr_setschedpolicy(&scenarii[i].ta, SCHED_FIFO);
			}
			if (scenarii[i].schedpolicy == 2)
			{
				ret = pthread_attr_setschedpolicy(&scenarii[i].ta, SCHED_RR);
			}
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to set the sched policy");  }
			#if VERBOSE > 4
			if (scenarii[i].schedpolicy)
				output("Sched policy was set sucessfully\n");
			else
				output("Sched policy untouched\n");
			#endif
		}
		#if VERBOSE > 4
		else
			output("TPS unsupported => sched policy parameter untouched\n");
		#endif
		
		if (scenarii[i].schedparam != 0)
		{
			struct sched_param sp;
			
			ret = pthread_attr_getschedpolicy(&scenarii[i].ta, &old);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to get sched policy from attribute"); }
			
			if (scenarii[i].schedparam == 1)
				sp.sched_priority = sched_get_priority_max(old);
			if (scenarii[i].schedparam == -1)
				sp.sched_priority = sched_get_priority_min(old);
			
			ret = pthread_attr_setschedparam(&scenarii[i].ta, &sp);
			if (ret != 0)  {  UNRESOLVED(ret, "Failed to set the sched param");  }
			
		#if VERBOSE > 4
			output("Sched param was set sucessfully to %i\n", sp.sched_priority);
		}
		else
		{
			output("Sched param untouched\n");
		#endif
		}
		
		if (tps>0) /* This routine is dependent on the Thread Execution Scheduling option */
		{
			ret = pthread_attr_getscope(&scenarii[i].ta, &old);
			if (ret != 0)  {  UNRESOLVED(ret, "Failed to get contension scope from thread attribute");  }
			
			if (scenarii[i].altscope != 0)
			{
				if (old == PTHREAD_SCOPE_PROCESS)
					old = PTHREAD_SCOPE_SYSTEM;
				else
					old = PTHREAD_SCOPE_PROCESS;
				
				ret = pthread_attr_setscope(&scenarii[i].ta, old);
				//if (ret != 0)  {  UNRESOLVED(ret, "Failed to set contension scope");  }
				#if VERBOSE > 0
				if (ret != 0)  {  output("WARNING: The TPS option is claimed to be supported but setscope fails\n");  }
				#endif
				
			#if VERBOSE > 4
				output("Contension scope set to %s\n", old==PTHREAD_SCOPE_PROCESS?"PTHREAD_SCOPE_PROCESS":"PTHREAD_SCOPE_SYSTEM");
			}
			else
			{
				output("Contension scope untouched (%s)\n", old==PTHREAD_SCOPE_PROCESS?"PTHREAD_SCOPE_PROCESS":"PTHREAD_SCOPE_SYSTEM");
			#endif
			}
		}
		#if VERBOSE > 4
		else
			output("TPS unsupported => sched contension scope parameter untouched\n");
		#endif
		
		/* Stack related attributes */
		if ((tss>0) && (tsa>0)) /* This routine is dependent on the Thread Stack Address Attribute 
			                   and Thread Stack Size Attribute options */
		{
			if (scenarii[i].altstack != 0)
			{
				/* This is slightly more complicated. We need to alloc a new stack
				and free it upon test termination */
				/* We will alloc with a simulated guardsize of 1 pagesize */
				scenarii[i].bottom = malloc(minstacksize + pagesize);
				if (scenarii[i].bottom == NULL)  {  UNRESOLVED(errno,"Unable to alloc enough memory for alternative stack"); }
				
				ret = pthread_attr_setstack(&scenarii[i].ta, scenarii[i].bottom, minstacksize);
				if (ret != 0)  {  UNRESOLVED(ret, "Failed to specify alternate stack");  }
			
				#if VERBOSE > 1
				output("Alternate stack created successfully. Bottom=%p, Size=%i\n", scenarii[i].bottom, minstacksize);
				#endif
			}
		}
		#if VERBOSE > 4
		else
			output("TSA or TSS unsupported => No alternative stack\n");
		#endif
		
		#ifndef WITHOUT_XOPEN
		if (scenarii[i].guard != 0)
		{
			if (scenarii[i].guard == 1)
				ret = pthread_attr_setguardsize(&scenarii[i].ta, 0);
			if (scenarii[i].guard == 2)
				ret = pthread_attr_setguardsize(&scenarii[i].ta, pagesize);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to set guard area size in thread stack");  }
			#if VERBOSE > 4
			output("Guard size set to %i\n", (scenarii[i].guard==1)?1:pagesize);
			#endif
		}
		#endif
		
		if (tss>0) /* This routine is dependent on the Thread Stack Size Attribute option */
		{
			if (scenarii[i].altsize != 0)
			{
				ret = pthread_attr_setstacksize(&scenarii[i].ta, minstacksize);
				if (ret != 0)  {  UNRESOLVED(ret, "Unable to change stack size");  }
				#if VERBOSE > 4
				output("Stack size set to %i (this is the min)\n", minstacksize);
				#endif
			}
		}
		#if VERBOSE > 4
		else
			output("TSS unsupported => stack size unchanged\n");
		#endif

		ret = sem_init(&scenarii[i].sem, 0,0);
		if (ret == -1) {  UNRESOLVED(errno, "Unable to init a semaphore");  }
		
	}
	#if VERBOSE > 0
	output("All %i thread attribute objects were initialized\n\n", NSCENAR);
	#endif
}
Beispiel #11
0
/* main function */
int main()
{
	int ret;
	long rts;

	struct sigaction sa;
	union sigval sv;
	sigset_t mask;

	/* Initialize output */
	output_init();

	/* Test the RTS extension */
	rts = sysconf(_SC_REALTIME_SIGNALS);

	if (rts < 0L)
	{
		UNTESTED("This test needs the RTS extension");
	}

	/* Set the signal handler */
	sa.sa_flags = SA_SIGINFO;

	sa.sa_sigaction = handler;

	ret = sigemptyset(&sa.sa_mask);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to empty signal set");
	}

	/* Install the signal handler for SIGRTMAX */
	ret = sigaction(SIGRTMAX, &sa, 0);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to set signal handler");
	}

	/* Mask this signal */
	ret = sigemptyset(&mask);

	if (ret != 0)
	{
		UNRESOLVED(ret, "An error occured while initializing mask");
	}

	ret = sigaddset(&mask, SIGRTMAX);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to add SIGRTMAX to signal set");
	}

	ret = sigprocmask(SIG_BLOCK, &mask, NULL);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to set process signal mask");
	}

	/* Now queue the signal to be pending */

	for (sv.sival_int = 1; sv.sival_int <= QUEUELENGTH; sv.sival_int++)
	{
		ret = sigqueue(getpid(), SIGRTMAX, sv);

		if (ret != 0)
		{
			UNRESOLVED(ret, "Failed to queue the signal");
		}
	}

	if (latest != 0)
	{
		FAILED("Signal was delivered while masked??");
	}

	/* And finally unmask the signal so it is delivered */
	ret = sigprocmask(SIG_UNBLOCK, &mask, NULL);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to set process signal mask");
	}

	sched_yield();

	/* Check the signal has been delivered as expected */

	if (latest != QUEUELENGTH)
	{
		output("Only %d signal delivered instead of %d\n", latest, QUEUELENGTH);

		if (latest == 1)
		{
			UNTESTED("It seems like SIGRTMAX is not a queuable signal here?");
		}
	}

	/* Test passed */
#if VERBOSE > 0

	output("Test passed\n");

#endif

	PASSED;
}
Beispiel #12
0
/* The main test function. */
int main( int argc, char * argv[] )
{
#if __APPLE__
    return 0;
#else /* !__APPLE__ */
	int ret, i;
	sem_t *sems;
	sem_t sem_last;

	long max;

	/* Initialize output */
	output_init();

	max = sysconf( _SC_SEM_NSEMS_MAX );

	if ( max <= 0 )
	{
#if !__ANDROID__
        PASSED;
#else
		output( "sysconf( _SC_SEM_NSEMS_MAX ) = %ld\n", max );
		UNTESTED( "There is no constraint on SEM_NSEMS_MAX" );
#endif
	}

	sems = ( sem_t * ) calloc( max, sizeof( sem_t ) );

	if ( sems == NULL )
	{
		UNRESOLVED( errno, "Failed to alloc space" );
	}


	for ( i = 0; i < max; i++ )
	{
		ret = sem_init( &sems[ i ], 0, 0 );

		if ( ret != 0 )
		{
			output( "sem_init failed to initialize the %d nth semaphore.\n", i );
			output( "Tryed to initialize %ld.\n", max );
			output( "Error is %d: %s\n", errno, strerror( errno ) );

			for ( ; i > 0; i-- )
				sem_destroy( &sems[ i - 1 ] );

			free( sems );

			PASSED;
		}
	}

	ret = sem_init( &sem_last, 0, 1 );

#if !__ANDROID__
    /* Temporarily disable it for Android until https://tracker.crystax.net/issues/1138 is fixed */
	if ( ret == 0 )
	{
		FAILED( "We were able to sem_init more than SEM_NSEMS_MAX semaphores" );
	}

	if ( errno != ENOSPC )
	{
		output( "Error is %d: %s\n", errno, strerror( errno ) );
	}
#endif /* !__ANDROID__ */

	for ( i = 0; i < max; i++ )
		sem_destroy( &sems[ i ] );

	free( sems );



	/* Test passed */
#if VERBOSE > 0

	output( "Test passed\n" );

#endif

	PASSED;
#endif /* !__APPLE__ */
}
Beispiel #13
0
/* The main test function. */
int main(int argc, char * argv[])
{
	int ret, i, sig;
	long rts;
	sigset_t set;

	/* Initialize output */
	output_init();

	/* Test the RTS extension */
	rts = sysconf(_SC_REALTIME_SIGNALS);

	if (rts < 0L)
	{
		UNTESTED("This test needs the RTS extension");
	}

	/* Set the signal mask */
	ret = sigemptyset(&set);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to empty signal set");
	}

	/* Add all SIGRT signals */
	for (i = SIGRTMIN; i <= SIGRTMAX; i++)
	{

		ret = sigaddset(&set, i);

		if (ret != 0)
		{
			UNRESOLVED(ret, "failed to add signal to signal set");
		}
	}

	/* Block all RT signals */
	ret = pthread_sigmask(SIG_BLOCK, &set, NULL);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to block RT signals");
	}

	/* raise the signals in no particular order */
	for (i = SIGRTMIN + 1; i <= SIGRTMAX; i += 3)
	{
		ret = raise(i);

		if (ret != 0)
		{
			UNRESOLVED(ret, "Failed to raise the signal");
		}
	}

	for (i = SIGRTMIN; i <= SIGRTMAX; i += 3)
	{
		ret = raise(i);

		if (ret != 0)
		{
			UNRESOLVED(ret, "Failed to raise the signal");
		}
	}

	for (i = SIGRTMIN + 2; i <= SIGRTMAX; i += 3)
	{
		ret = raise(i);

		if (ret != 0)
		{
			UNRESOLVED(ret, "Failed to raise the signal");
		}
	}

	/* All RT signals are pending */

	/* Check the signals are delivered in order */
	for (i = SIGRTMIN; i <= SIGRTMAX; i++)
	{
		ret = sigwait(&set, &sig);

		if (ret != 0)
		{
			UNRESOLVED(ret , "Failed to sigwait for RT signal");
		}

		if (sig != i)
		{
			output("SIGRTMIN: %d, SIGRTMAX: %d, i: %d, sig:%d\n",
			        SIGRTMIN, SIGRTMAX, i, sig);
			FAILED("Got wrong signal");
		}
	}

	/* Test passed */
#if VERBOSE > 0
	output("Test passed\n");

#endif
	PASSED;
}