Skip to content

Commit

Permalink
Added simulation test with homotopy (#968)
Browse files Browse the repository at this point in the history
Added simulation test for Modelica code with homotopy operator

Tests simulation flags `lv="LOG_NLS_V,LOG_INIT_HOMOTOPY"`
Use QSignalSpy with timeout for the simulation instead of QEventLoop
Call exit to make sure the simulation thread is finished properly
  • Loading branch information
adeas31 committed Dec 11, 2020
1 parent 6d0af09 commit c867ad1
Show file tree
Hide file tree
Showing 16 changed files with 351 additions and 38 deletions.
37 changes: 21 additions & 16 deletions OMEdit/OMEditLIB/Simulation/SimulationOutputHandler.cpp
Expand Up @@ -338,8 +338,7 @@ bool SimulationOutputHandler::isMaximumDisplayLimitReached() const
* \param atts
* \return
*/
bool SimulationOutputHandler::startElement(const QString &namespaceURI, const QString &localName, const QString &qName,
const QXmlAttributes &atts)
bool SimulationOutputHandler::startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
{
Q_UNUSED(namespaceURI);
Q_UNUSED(localName);
Expand All @@ -353,23 +352,29 @@ bool SimulationOutputHandler::startElement(const QString &namespaceURI, const QS
/* if display limit is reached then close and display the so far text
* and display a message showing that the limit is reached.
*/
static int init = 0;
if (isMaximumDisplayLimitReached()) {
while (mLevel > 0) {
endElement("", "", "message");
}
// Only generate the reached display limit message once.
if (!init) {
init = 1;

if (mpSimulationOutputWidget->isOutputStructured()) {
mpSimulationMessage = new SimulationMessage(mpSimulationMessageModel->getRootSimulationMessage());
} else {
mpSimulationMessage = new SimulationMessage;
while (mLevel > 0) {
endElement("", "", "message");
}

if (mpSimulationOutputWidget->isOutputStructured()) {
mpSimulationMessage = new SimulationMessage(mpSimulationMessageModel->getRootSimulationMessage());
} else {
mpSimulationMessage = new SimulationMessage;
}
mpSimulationMessage->mStream = "stdout";
mpSimulationMessage->mType = StringHandler::OMEditInfo;
mpSimulationMessage->mText = QString("Reached display limit");
mpSimulationMessage->mLevel = mLevel;
mSimulationMessagesLevelMap.insert(mLevel, mpSimulationMessage);
mLevel++;
endElement("", "", "message");
}
mpSimulationMessage->mStream = "stdout";
mpSimulationMessage->mType = StringHandler::OMEditInfo;
mpSimulationMessage->mText = QString("Reached display limit");
mpSimulationMessage->mLevel = mLevel;
mSimulationMessagesLevelMap.insert(mLevel, mpSimulationMessage);
mLevel++;
endElement("", "", "message");
return true;
}

Expand Down
7 changes: 3 additions & 4 deletions OMEdit/OMEditLIB/Simulation/SimulationOutputWidget.cpp
Expand Up @@ -675,8 +675,6 @@ void SimulationOutputWidget::simulationProcessStarted()
*/
void SimulationOutputWidget::writeSimulationOutput(QString output, StringHandler::SimulationMessageType type, bool textFormat)
{
mpGeneratedFilesTabWidget->setTabEnabled(0, true);

if (textFormat) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QString escaped = QString(output).toHtmlEscaped();
Expand All @@ -696,8 +694,6 @@ void SimulationOutputWidget::writeSimulationOutput(QString output, StringHandler
} else {
mpSimulationOutputHandler->parseSimulationOutput(output);
}
/* make the compilation tab the current one */
mpGeneratedFilesTabWidget->setCurrentIndex(0);
}

/*!
Expand All @@ -711,6 +707,9 @@ void SimulationOutputWidget::simulationProcessFinished(int exitCode, QProcess::E
{
Q_UNUSED(exitCode);
Q_UNUSED(exitStatus);
mpGeneratedFilesTabWidget->setTabEnabled(0, true);
/* make the output tab the current one */
mpGeneratedFilesTabWidget->setCurrentIndex(0);
mpProgressLabel->setText(tr("Simulation of %1 is finished.").arg(mSimulationOptions.getClassName()));
mpProgressBar->setValue(mpProgressBar->maximum());
mpCancelButton->setEnabled(false);
Expand Down
13 changes: 10 additions & 3 deletions OMEdit/OMEditLIB/Simulation/SimulationProcessThread.cpp
Expand Up @@ -58,7 +58,7 @@ void SimulationProcessThread::run()
} else {
runSimulationExecutable();
}
exec();
QThread::run();
}

/*!
Expand Down Expand Up @@ -186,7 +186,7 @@ void SimulationProcessThread::readCompilationStandardError()
/*!
* \brief SimulationProcessThread::compilationProcessError
* Slot activated when mpCompilationProcess errorOccurred signal is raised.\n
* Notifies the SimulationOutputWidget about the erro by emitting the sendCompilationOutput signal.
* Notifies the SimulationOutputWidget about the error by emitting the sendCompilationOutput signal.
* \param error
*/
void SimulationProcessThread::compilationProcessError(QProcess::ProcessError error)
Expand All @@ -195,9 +195,11 @@ void SimulationProcessThread::compilationProcessError(QProcess::ProcessError err
mIsCompilationProcessRunning = false;
/* this signal is raised when we kill the compilation process forcefully. */
if (isCompilationProcessKilled()) {
exit();
return;
}
emit sendCompilationOutput(mpCompilationProcess->errorString(), Qt::red);
exit();
}

/*!
Expand All @@ -223,9 +225,11 @@ void SimulationProcessThread::compilationProcessFinished(int exitCode, QProcess:
} else if (mpCompilationProcess->error() == QProcess::UnknownError) {
emit sendCompilationOutput(exitCodeStr, Qt::red);
emit sendCompilationFinished(exitCode, exitStatus);
exit();
} else {
emit sendCompilationOutput(mpCompilationProcess->errorString() + "\n" + exitCodeStr, Qt::red);
emit sendCompilationFinished(exitCode, exitStatus);
exit();
}
}

Expand Down Expand Up @@ -270,7 +274,7 @@ void SimulationProcessThread::readSimulationStandardError()
/*!
* \brief SimulationProcessThread::simulationProcessError
* Slot activated when mpSimulationProcess errorOccurred signal is raised.\n
* Notifies the SimulationOutputWidget about the erro by emitting the sendSimulationOutput signal.
* Notifies the SimulationOutputWidget about the error by emitting the sendSimulationOutput signal.
* \param error
*/
void SimulationProcessThread::simulationProcessError(QProcess::ProcessError error)
Expand All @@ -279,9 +283,11 @@ void SimulationProcessThread::simulationProcessError(QProcess::ProcessError erro
mIsSimulationProcessRunning = false;
/* this signal is raised when we kill the simulation process forcefully. */
if (isSimulationProcessKilled()) {
exit();
return;
}
emit sendSimulationOutput(mpSimulationProcess->errorString(), StringHandler::Error, true);
exit();
}

/*!
Expand Down Expand Up @@ -309,4 +315,5 @@ void SimulationProcessThread::simulationProcessFinished(int exitCode, QProcess::
emit sendSimulationOutput(mpSimulationProcess->errorString() + "\n" + exitCodeStr, StringHandler::Error, true);
}
emit sendSimulationFinished(exitCode, exitStatus);
exit();
}
13 changes: 4 additions & 9 deletions OMEdit/Testsuite/BrowseMSL/BrowseMSL.cpp
Expand Up @@ -45,27 +45,22 @@ extern "C" {

OMEDITTEST_MAIN(BrowseMSL)

/*!
* \brief Test::electricalAnalogBasic
* Browses the Modelica.Electrical.Analog.Basic
*/
void BrowseMSL::electricalAnalogBasic()
{
if (!Util::expandLibraryTreeItemParentHierarchy(MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem("Modelica.Electrical.Analog.Basic"))) {
QFAIL("Expanding to Modelica.Electrical.Analog.Basic failed.");
}
MainWindow::instance()->close();
}

/*!
* \brief Test::mediaAir
* Browses the Modelica.Media.Air
*/
void BrowseMSL::mediaAir()
{
OMEDITTEST_SKIP("Enable this testcase by removing this line once the ticket#5669 (https://trac.openmodelica.org/OpenModelica/ticket/5669) is fixed.");
if (!Util::expandLibraryTreeItemParentHierarchy(MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem("Modelica.Media.Air"))) {
QFAIL("Expanding to Modelica.Media.Air failed.");
}
}

void BrowseMSL::cleanupTestCase()
{
MainWindow::instance()->close();
}
13 changes: 13 additions & 0 deletions OMEdit/Testsuite/BrowseMSL/BrowseMSL.h
Expand Up @@ -37,13 +37,26 @@

#include <QObject>

/*!
* \brief The BrowseMSL class
* Browses the items in the Libraries tree.
*/
class BrowseMSL: public QObject
{
Q_OBJECT

private slots:
/*!
* \brief electricalAnalogBasic
* Browses the Modelica.Electrical.Analog.Basic
*/
void electricalAnalogBasic();
/*!
* \brief mediaAir
* Browses the Modelica.Media.Air
*/
void mediaAir();
void cleanupTestCase();
};

#endif // BROWSEMSL_H
2 changes: 2 additions & 0 deletions OMEdit/Testsuite/Common/Testsuite.pri
Expand Up @@ -50,6 +50,8 @@ INCLUDEPATH += ../../ \
../../OMEditLIB \
../Common \
$$OPENMODELICAHOME/include \
$$OPENMODELICAHOME/include/omplot \
$$OPENMODELICAHOME/include/omplot/qwt \
$$OPENMODELICAHOME/include/omc/c \
$$OPENMODELICAHOME/include/omc/scripting-API

Expand Down
7 changes: 3 additions & 4 deletions OMEdit/Testsuite/Diagram/Diagram.cpp
Expand Up @@ -45,10 +45,6 @@ extern "C" {

OMEDITTEST_MAIN(Diagram)

/*!
* \brief Test::chuaCircuit
* Browses to Modelica.Electrical.Analog.Examples.ChuaCircuit and loads it diagram view.
*/
void Diagram::chuaCircuit()
{
LibraryTreeItem *pLibraryTreeItem = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem("Modelica.Electrical.Analog.Examples.ChuaCircuit");
Expand All @@ -63,6 +59,9 @@ void Diagram::chuaCircuit()
QModelIndex modelIndex = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->libraryTreeItemIndex(pLibraryTreeItem);
QModelIndex proxyIndex = MainWindow::instance()->getLibraryWidget()->getLibraryTreeProxyModel()->mapFromSource(modelIndex);
MainWindow::instance()->getLibraryWidget()->getLibraryTreeView()->libraryTreeItemDoubleClicked(proxyIndex);
}

void Diagram::cleanupTestCase()
{
MainWindow::instance()->close();
}
9 changes: 9 additions & 0 deletions OMEdit/Testsuite/Diagram/Diagram.h
Expand Up @@ -37,12 +37,21 @@

#include <QObject>

/*!
* \brief The Diagram class
* Browses the items in the Libraries tree and opens then in the diagram view.
*/
class Diagram: public QObject
{
Q_OBJECT

private slots:
/*!
* \brief chuaCircuit
* Browses to Modelica.Electrical.Analog.Examples.ChuaCircuit and loads its diagram view.
*/
void chuaCircuit();
void cleanupTestCase();
};

#endif // DIAGRAM_H
39 changes: 39 additions & 0 deletions OMEdit/Testsuite/Homotopy/Homotopy.pro
@@ -0,0 +1,39 @@
#
# This file is part of OpenModelica.
#
# Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
# c/o Linköpings universitet, Department of Computer and Information Science,
# SE-58183 Linköping, Sweden.
#
# All rights reserved.
#
# THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
# THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
# ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE
# OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
#
# The OpenModelica software and the Open Source Modelica
# Consortium (OSMC) Public License (OSMC-PL) are obtained
# from OSMC, either from the above address,
# from the URLs: http://www.ida.liu.se/projects/OpenModelica or
# http://www.openmodelica.org, and in the OpenModelica distribution.
# GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
#
# This program is distributed WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
# IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
#
# See the full OSMC Public License conditions for more details.
#
#/

include(../Common/Testsuite.pri)

TARGET = Homotopy

SOURCES += ../Common/Util.cpp \
HomotopyTest.cpp

HEADERS += ../Common/Util.h \
HomotopyTest.h

0 comments on commit c867ad1

Please sign in to comment.