TEST_F(PermissionsTests, test_multi_thread_poll) {
  if (getuid() != 0) {
    LOG(WARNING) << "Not root, skipping multi-thread deprivilege testing";
    return;
  }

  ASSERT_EQ(0U, geteuid());

  // Set the multi-thread path, which both threads will write into.
  auto multi_thread_path = fs::path(kTestWorkingDirectory) / "threadperms.txt";
  kMultiThreadPermissionPath = multi_thread_path.string();

  // Start our permissions thread.
  auto pool_thread = std::make_shared<PermissionsPollRunnable>();
  Dispatcher::addService(pool_thread);

  // Wait for the permissions thread to write once.
  EXPECT_TRUE(waitForTick(pool_thread));

  auto nobody = getpwnam("nobody");
  EXPECT_NE(nobody, nullptr);
  {
    auto dropper = DropPrivileges::get();
    EXPECT_TRUE(dropper->dropTo(nobody->pw_uid, nobody->pw_gid));
    EXPECT_EQ(geteuid(), nobody->pw_uid);

    EXPECT_TRUE(waitForTick(pool_thread));
  }

  Dispatcher::stopServices();
  Dispatcher::joinServices();
}
Exemple #2
0
int main(void)
{
    Grace_init();                   // Activate Grace-generated configuration
    
    // >>>>> Fill-in user code here <<<<<
    int j = 0;
    while(1)
    {
    	int i;

    	for (i=0; i< 3; i++)
    	{
    		waitForTick();
    	}
    	if (!(P2IN & BIT6))
    	{
			printf("%i) Test output from SPI adaptor\r\n", j);
//    		putc(1);
			j++;
    	}

    }
    
    return (0);
}
Exemple #3
0
///////////////////////////////////////////////////////////////////////////////
// calibrate:  Determine overhead of measurement, initialization routine,
//	and finalization routine
///////////////////////////////////////////////////////////////////////////////
void
Timer::calibrate() {
	double runTime = chooseRunTime();

	preop();

	long reps = 0;
	double current;
	double start = waitForTick();
	do {
		postop();
		++reps;
	} while ((current = getClock()) < start + runTime);

	overhead   = (current - start) / (double) reps;
	calibrated = true;
} // Timer::calibrate
Exemple #4
0
void Server::start() {
	connectToUnifier("localhost", 30000);
	registerService("FE");

	int fd = 0;
	unsigned long ticks = 0;

	LOG_INFO(logger, "Starting the server");
	while (true) {
		waitForTick();
		while((fd = accept(m_sock, NULL, NULL)) > 0) {
			handleAccept(fd);
		}

		m_sessionManager.tick();

		sendTock();
		ticks++;
	}
}
Exemple #5
0
///////////////////////////////////////////////////////////////////////////////
// time:  measure time (in seconds) to perform caller's operation
///////////////////////////////////////////////////////////////////////////////
double
Timer::time() {
	// Select a run time that's appropriate for our timer resolution:
	double runTime = chooseRunTime();

	// Measure successively larger batches of operations until we find
	// one that's long enough to meet our runtime target:
	long reps = 1;
	double start;
	double current;
	for (;;) {
		preop();

		start = waitForTick();

		for (long i = reps; i > 0; --i) op();


		postop();

		current = getClock();
		if (current >= start + runTime + overhead)
			break;

		// Try to reach runtime target in one fell swoop:
		long newReps;
		if (current > start + overhead)
			newReps = static_cast<long> (reps *
			       (0.5 + runTime / (current - start - overhead)));
		else
			newReps = reps * 2;
		if (newReps == reps)
			reps += 1;
		else
			reps = newReps;
		}

	// Subtract overhead to determine the final operation rate:
	return (current - start - overhead) / reps;
} // Timer::time