Esempio n. 1
0
	virtual void tick() {
		switch( style ) {
			case 0: {	// divizion by zero
				int a = 10;
				int b = 3;
				b-=3;
				a /= b;
				break;
					}
			case 1: {	// throw (int) exception
				throw 0;
				break;
					}

			case 2: {	// NULL pointer with vtable
				IThread *thread = NULL;
				thread->isActive();
				break;
					}

			case 3: {	// invalid pointer with vtable
				IThread *thread = (IThread *)0x335337L;
				thread->isActive();
				break;
					}

			case 4: {
				mykillingstackmachine(1, 2, 3, 4, 5, 6);
				break;
					}
		}
	}
Esempio n. 2
0
void testThreadsRunningAndTerminating() {
	// ONE stopped, TWO stopped
	IThread *one = new ThreadSimple();
	IThread *two = new ThreadSimple();

	assert(one->getId() == 0);
	assert(!one->isActive());
	assert(two->getId() == 0);
	assert(!two->isActive());
	assert(ThreadHolder::getActiveThreads() == 0);

	// ONE started, TWO started
	one->start();
	two->start();

	assert(one->getId() != 0);
	assert(one->isActive());
	assert(two->getId() != 0);
	assert(two->isActive());
	assert(ThreadHolder::getActiveThreads() == 2);

	Sleep(USUAL_DELAY);

	// ONE stopped, TWO started
	one->terminate();

	assert(one->getId() == 0);
	assert(!one->isActive());
	assert(two->getId() != 0);
	assert(two->isActive());
	assert(ThreadHolder::getActiveThreads() == 1);

	Sleep(USUAL_DELAY);

	// ONE started, TWO started
	one->start();

	assert(one->getId() != 0);
	assert(one->isActive());
	assert(two->getId() != 0);
	assert(two->isActive());
	assert(ThreadHolder::getActiveThreads() == 2);

	Sleep(USUAL_DELAY);

	// ONE stopped, TWO stopped
	one->terminate();
	two->terminate();

	assert(one->getId() == 0);
	assert(!one->isActive());
	assert(two->getId() == 0);
	assert(!two->isActive());
	assert(ThreadHolder::getActiveThreads() == 0);

	delete one;
	delete two;
}