Exemplo n.º 1
0
/*-------------------------------------------------------------------------
 Handle a signal (^C or similar)
-------------------------------------------------------------------------*/
void
signalHandler(
	int sigId)
{
	(void) sigId;
	abortTest(logFile, 4, "Test terminated at user request.\n", &results);
}
Exemplo n.º 2
0
/*-------------------------------------------------------------------------
 Timeout
-------------------------------------------------------------------------*/
int timer_handler(int sigtype)
{
	(void) sigtype;

	fflush(stdout);
	printf("\nNode %d: Timeout\n", results.thisHost);
	abortTest(logFile, 3, "\nTimeout\n", NULL);
	return 0;
}
Exemplo n.º 3
0
void myassert(int x, int lineno)
{
	if (!(x)) {
		char buf[256];
		sprintf(buf, "Node %d: Assertion failed, line %d\n", results.thisHost, lineno);
		printf("%s", buf);
		abortTest(logFile, 9, buf, NULL);
	}
}
Exemplo n.º 4
0
void TestFramework::timeOut()
{
	if (is_command_line_ && 
			max_run_time_ != FLT_MAX &&
			runtime_.getClockTime() > max_run_time_)
	{
		abortTest();
		getMainControl()->quit(-1);
		return;
	}

	// if MainControl is busy: send event only if MC was also busy when we recorded it
	if (getMainControl()->isBusy() && !event_busy_)
	{
		return;
	}

	if (!getMainControl()->isBusy())
	{
		getMainControl()->processEvents(1000);
	}

	if (timer_.getClockTime() < time_) return;

#ifdef BALL_PYTHON_SUPPORT		
	if (python_line_ != "")
	{
		PyWidget* pyw = 0;

		pyw = PyWidget::getInstance(0);
		if (pyw == 0) 
		{
			Log.error() << "Can not exec Python in macro since no Python support available" << std::endl;
		}

		else
		{
			if (expected_result_ == "")
			{
				pyw->runString(python_line_);
			}
			else
			{
				bool ok;
				String result = PyInterpreter::run(python_line_, ok);
				// trim newline
				if (result.size()) result.truncate(result.size()-1);
				if (!ok || result != expected_result_)
				{
					Log.error() << "------------------------------------------------" << std::endl;
					Log.error() << "Test failed in "
											<< filename_ << " " << line_nr_ << ":";
					if (!ok) Log.error() << "(call failed)";
					Log.error() << std::endl 
					            << python_line_ << std::endl 
					            << result << "!=" 
					            << expected_result_<< "!" << std::endl;
					errors_++;
				}
			}
		}

		processEvent_();
		return;
	}
#endif

	if (type_ == 0) 
	{
		test_running_ = false;
		return;
	}

	if (our_type_ != SHORTCUT && widget_ == 0)
	{
		BALLVIEW_DEBUG;
		return;
	}

	QEvent* e = 0;

	bool hide = false;

	if (our_type_ == MOUSE)
	{
		// circumvent problems with context menus:	
		if ((Qt::MouseButton) button_ == Qt::RightButton)
		{
			/*
			QWidget* w = (QWidget*)widget_->parent();
			while (w != 0)
			{
				DockWidget* dw = dynamic_cast<DockWidget*>(w);
				if (dw != 0)
				{
					QCursor::setPos(QPoint(x_,y_));
					dw->showGuestContextMenu(QPoint(x_,y_));
					processEvent_();
					return;
				}

				w = (QWidget*)w->parent();
			}
			*/
		}

		bool was_visible = widget_->isVisible();
		widget_->show();
		QPoint local = widget_->mapFromGlobal(QPoint(x_,y_));
		QPoint org_p = local;
		if (local.x() >= widget_->width())  local.setX((int)(widget_->width() * 0.9));
		if (local.y() >= widget_->height()) local.setY((int)(widget_->height() * 0.9));
		if (local.x() <= 0) local.setX((int)(widget_->width() * 0.1));
		if (local.y() <= 0) local.setY((int)(widget_->height() * 0.1));
#ifdef BALL_VIEW_DEBUG
		if (org_p != local)
		{
			Log.error() << ascii(widget_->objectName()) << " " << org_p.x() 
									<< " " << org_p.y() << std::endl;
		}
#endif
		e = new MyMouseEvent((QMouseEvent::Type)type_, 
												local,
												(Qt::MouseButton)button_, 
												(Qt::MouseButtons)buttons_, 
												(Qt::KeyboardModifier)modifiers_);
		
		if ((Qt::MouseButton) button_ == Qt::LeftButton &&
				RTTI::isKindOf<QMenu>(*widget_) && 
				!was_visible)
		{
			hide = true;
		}
		
    QCursor::setPos(QPoint(x_,y_));
	}
	else if (our_type_ == KEY)
	{
		// workaround for capitalized keys:
		if (modifiers_ == Qt::ShiftModifier)
		{
			if (button_ != Qt::Key_Shift)
			{
				QKeySequence seq(button_);
				QTest::keyClicks(widget_, seq.toString());
			}
		}
		else
		{
			QTest::keyClick(widget_, (Qt::Key)button_, (Qt::KeyboardModifiers)modifiers_);
		}
	}
	else if (our_type_ == SHORTCUT)
	{
		if (action_ != 0)
		{
			action_->trigger();
		}
	}


	if (e != 0)
	{
		reinterpret_cast<QSpontaneKeyEvent*>(e)->setSpontaneous();
    if (!qApp->notify(widget_, e))
		{
 			BALLVIEW_DEBUG
		}
		delete e;
	}
Exemplo n.º 5
0
bool TestFramework::eventFilter(QObject* obj, QEvent* e) 
{
	if (test_running_)
	{
//   		if (e == last_event_) return false;
//   		last_event_ = e;

		bool stop = false;
		if (e->type() == QEvent::KeyPress)
		{
			QKeyEvent* ke = dynamic_cast<QKeyEvent*>(e);
			// pause macro if pause key is pressed
			if (ke->key() == Qt::Key_Pause) stop = true;
			else if (ke->key() == Qt::Key_X && ke->modifiers() == Qt::AltModifier)
			{
				// if a user presses Alt-X: quit immediately
				abortTest();
				getMainControl()->quit(0);
				return true;
			}
		}
		else if (e->type() == QEvent::MouseButtonPress ||
						 e->type() == QEvent::MouseButtonRelease)
		{
			// abort macro if user presses mouse button:
			if (!RTTI::isKindOf<MyMouseEvent>(*e) && e->spontaneous())
			{
 				stop = true;
			}
		}
		else
		{
			return false;
		}

		if (stop)
		{
			abortTest();
			qApp->installEventFilter(this);
			return true;
		}

		return false;
	}
	
	// if test is paused and pause key is pressed->resume macro
	if (!recording_ && e->type() == QEvent::KeyPress && lines_.size() > 0)
	{
		QKeyEvent* ke = dynamic_cast<QKeyEvent*>(e);
		if (ke->key() == Qt::Key_Pause)
		{
			processEvent_();
			timer_.reset();
			timer_.start();
			test_running_ = true;
			thread_.start();
			return true;
		}

		return false;
	}

	if (!recording_) return false;

	if (!RTTI::isKindOf<QKeyEvent>(*e) &&
			!RTTI::isKindOf<QMouseEvent>(*e) &&
			!RTTI::isKindOf<QShortcutEvent>(*e))
	{
		return false;
	}

	if (e->type() == QEvent::ShortcutOverride) return false;
 	if (e->type() == QEvent::KeyRelease) return false;
	QMouseEvent* 		me = dynamic_cast<QMouseEvent*>(e);
	QKeyEvent* 			ke = dynamic_cast<QKeyEvent*>(e);
	QShortcutEvent* se = dynamic_cast<QShortcutEvent*>(e);

	if (ke != 0 && 
			ke->type() == QEvent::KeyPress &&
			ke->key() == Qt::Key_Pause)
	{
		stopTest();
		return false;
	}

	///////////////////////////////////////////////////////
	// uniquely identify the active widget:
	// walk up the QObject tree and collect all names of QWidgets
	///////////////////////////////////////////////////////
	
	// take the sending object
 	QObject* o = obj;
	QObject* parent = 0;
	x_ = y_ = 0;

	// for mouse events: take widget under the mouse cursor
	if (me != 0) 
	{
		widget_ = qApp->widgetAt(me->globalPos());
		if (widget_ == 0) return false;
		if (widget_->objectName() == "" &&
				widget_->actions().size() == 0)
		{
			widget_ = dynamic_cast<QWidget*>(widget_->parent());
			if (widget_ == 0 || widget_->objectName() == "") return false;
		}
		o = widget_;

		QPoint global = me->globalPos();
		// if we can not get local coordinates: abort
 		QPoint local = widget_->mapFromGlobal(global);
		if (local.x() < 0 || local.y() < 0 ||
				local.x() >= widget_->width() || local.y() >= widget_->height()) 
		{
			return false;
		}

		// for menus: take the position of the action under the cursor
		QMenu* menu = dynamic_cast<QMenu*>(o);
		if (menu)
		{
			QAction* action = menu->actionAt(local);
			if (action != 0)
			{
				o = action;
				parent = menu;
				QRect rect = menu->actionGeometry(action);
				local.rx() -= rect.x();
				local.ry() -= rect.y();

				if (rect.width() == 0 || rect.height() == 0) return false;
				x_ = local.x();
				y_ = local.y();
			}
		}

		if (x_ == 0 && y_ == 0)
		{
			// take the position as percent of the widget's actual size
			if (widget_->width() == 0 || widget_->height() == 0) return false;
			x_ = local.x();
			y_ = local.y();
		}
	}

	String names;
	while (o != 0)
	{
		String name = ascii(o->objectName());
		if (name == "")
		{
			QWidget* widget = dynamic_cast<QWidget*>(o);
			if (widget != 0)
			{
				QList<QAction*> actions = widget->actions();
				if (actions.size() == 1)
				{
					name = ascii((**actions.begin()).objectName());
				}
			}
		}
		else
		{
			// if a parent has more childs with the same name: add a suffix with the number
			if (!parent) parent = o->parent();
			if (parent != 0)
			{
				QList<QWidget*> childs = parent->findChildren<QWidget*>(name.c_str());
				if (childs.size() > 1)
				{
					Position pos = 0;
					QList<QWidget*>::iterator wit = childs.begin();
					for (; wit != childs.end(); wit++)
					{
						if (*wit == o)
						{
							name += "#";
							name += String(pos);
							break;
						}

						pos++;
					}
				}
			}
		}

		if (name != "") names = name + "|" + names;
		o = o->parent();
	}


	String event_string;
	event_string += String((int)e->type()) + "|";
	event_string += String(getMainControl()->isBusy()) + "|";

	if (me != 0)
	{
		if (me->button() == Qt::NoButton &&
				!switch_move->isChecked() && 
				me->type() == QEvent::MouseMove &&	
				widget_ == last_widget_)
		{
			return false;
		}

 		last_widget_ = widget_;

		event_string += String((int)MOUSE) + "|";
		event_string += String((int) me->modifiers()) + "|";
		event_string += String((int) me->button()) + "|";
		event_string += String((int) me->buttons()) + "|";
		event_string += String(x_) + "|";
		event_string += String(y_) + "|";

		// prevent mouse move events with same position
		if (event_string == last_event_string_ &&
				names 			 == last_names_)
		{
			return false;
		}
	}
	else if (ke != 0)
	{
		// prevent accepting key events that are resend further up in the widget tree
		if (timer_.getClockTime() < 0.01) return false;

		int m = (int) ke->modifiers();
		// sometimes Qt sends nonsense Key messages
		if (m > (int)(Qt::AltModifier | Qt::ControlModifier | Qt::ShiftModifier)) return false;

		event_string += String((int)KEY) + "|";
		event_string += String(m);
		event_string += "|";
		event_string += String(ke->key()) + "|";
	}
	else if (se != 0)
	{
		event_string += String((int)SHORTCUT) + "|";
		event_string += String(se->shortcutId()) + "|";
		event_string += ascii(se->key().toString()) + "|";
	}

	float time = timer_.getClockTime();
	timer_.reset();

	outfile_ << "I°"
					 << time << "°"
					 << names << "°"
					 << event_string << std::endl;

	last_event_string_ = event_string;
	last_names_  			 = names;

	return false;
}
Exemplo n.º 6
0
void RzTest::onTestTimeout() {
	EXPECT_TRUE(false) << "Test timeout, closing all connections";
	abortTest();
}
Exemplo n.º 7
0
/*-------------------------------------------------------------------------
 Entry point
-------------------------------------------------------------------------*/
int						/* Success (0) or failure (nonzero) */
main(
	int argc,			/* number of arguments */
	char *argv[] )		/* value of arguments */
{
	logFile = stdout;
	sprintf(usage, "Usage: %s driver nhosts nloops\n\
or: %s driver nhosts nloops hostnum nextadr \n\
or: %s hostnum filename \n\
First form launches n copies of second form;\n\
second form is the part of the test that runs on each computer;\n\
third form is a second form restoring from disk.\n\
Hostnum is 0..nhosts-1\n",
		argv[0], argv[0], argv[0]);

	/* Initialize results to no-values-found */
	results.sentSingleSmallTime = -1;
	results.sentSingleLargeTime = -1;
	results.sentMultipleSmallTime = -1;
	results.sentDeleteTime = -1;
	results.gotSingleSmallTime = -1;
	results.gotSingleLargeTime = -1;
	results.gotMultipleSmallTime = -1;
	results.gotDeleteTime = -1;

	results.singleSmallTime = -1.0f;
	results.deleteTime = -1.0f;

	results.thisHost = -1;
	results.n_hosts = -1;
	results.packetLoss = -100;
	results.exe = argv[0];

	/* Handle arguments */
	if ((argc != 3) && (argc != 4) && (argc != 6)) {
		sprintf(buf, "Invalid number of arguments (%d)\n%s", argc, usage);
		abortTest(logFile, 3, buf, NULL);
		return 1;
	}

	if(argc != 3) {
		results.driver = argv[1];

		results.n_hosts = atoi(argv[2]);
		if (results.n_hosts < 2 || results.n_hosts > 200) {
			sprintf(buf, "Invalid number of hosts (%s)\n%s", argv[2], usage);
			abortTest(logFile, 3, buf, NULL);
		}

		results.loops = atoi(argv[3]);
		if (results.loops < 1 || results.loops > 127) {
			sprintf(buf, "Invalid number of hosts (%s)\n%s", argv[3], usage);
			abortTest(logFile, 3, buf, NULL);
		}
	}

	if (argc == 3) {
		results.thisHost = atoi(argv[1]);
		if (results.thisHost < 0 || results.thisHost > 200) {
			sprintf(buf, "Invalid childnum (%s)\n%s", argv[1], usage);
			abortTest(logFile, 3, buf, NULL);
		}
		return run_one_node(results.thisHost, argv[2], -1, 1000);
	} else if (argc == 4) {
		printf("Deleting old log files:\n");
		fflush(stdout);
		system("del dptab*.log");
		printf("Done deleting old log files:\n");
		fflush(stdout);

		return run_n_nodes(argv[0], results.loops);
	} else {
		int stop = 0;
		results.thisHost = atoi(argv[4]);
		if (results.thisHost < 0 || results.thisHost > 200) {
			sprintf(buf, "Invalid childnum (%s)\n%s", argv[4], usage);
			abortTest(logFile, 3, buf, NULL);
		}
		stop = 2 + 2*results.thisHost;
		return run_one_node(results.thisHost, argv[5], results.loops, stop);
	}
}
Exemplo n.º 8
0
/*-------------------------------------------------------------------------
 Run n copies of the test.
 Return value is 0 on success.
-------------------------------------------------------------------------*/
int					/* */
run_n_nodes(
	char *exe,		/* */
	int loops)		/* */
{
	char *childArgs[7] = {NULL, NULL, "nhosts", "nloops", "childnum", "nextadr.possibly.internet.address:maybeWithPortNumber", NULL};
	int* procs = NULL;
	int* result = NULL;
	int i;

	childArgs[0] = exe;
	childArgs[1] = results.driver;

	if ((procs = (int *) malloc(results.n_hosts * sizeof(int))) == NULL)
		abortTest(logFile, 3, "Unable to allocate process handle storage.\n", NULL);
	if((result = (int *) malloc(results.n_hosts * sizeof(int))) == NULL)
		abortTest(logFile, 3, "Unable to allocate result storage.\n", NULL);

	/* Start tests */
	for (i=0; i < results.n_hosts; i++) {
		sprintf(childArgs[2], "%d", results.n_hosts);
		sprintf(childArgs[3], "%d", loops);
		sprintf(childArgs[4], "%d", i);
		#if LOOPBACK_ADDRESS
			sprintf(childArgs[5], "%d.0.0.0", ((i+1) % results.n_hosts) + 1);
		#elif INTERNET_ADDRESS
			sprintf(childArgs[5], "207.82.188.88:%d", ((i+1) % results.n_hosts) + PORT_OFFSET);
		#else
			Warning: Must choose one of the above defines.
		#endif
		printf("Launching %s %s %s %s %s %s\n",
				childArgs[0],
				childArgs[1],
				childArgs[2],
				childArgs[3],
				childArgs[4],
				childArgs[5]);
		procs[i] = _spawnv(_P_NOWAIT, exe, childArgs);
		if(procs[i] == -1) {
			sprintf(buf, "Unable to start process %d: %s\n", i, strerror(errno));
			abortTest(logFile, 4, buf, NULL);
		}
	}

	/* Wait for tests to finish */
	for (i=0; i < results.n_hosts; i++) {
		_cwait(&(result[i]), procs[i], 0);
		printf("Node %d returned %d\n", i, result[i]);
	}

	/* Get test results */
	{
		FILE* fp;
		char fname[256];

		sprintf(fname, LOGNAME, 0);
		if ((fp = fopen(fname, "r")) != NULL) {
			readReport(fp, &results);
		} else
			fprintf(logFile, "Can't read client %d's logfile %s\n", 0, fname);
	}
	writeReport(logFile, &results);
	return 0;
}