Skip to content

Commit

Permalink
Added test case for MDD serial packager
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhard-thiele authored and OpenModelica-Hudson committed May 5, 2017
1 parent 582c559 commit 771ca55
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitvalidfiles
Expand Up @@ -183,6 +183,7 @@
./simulation/libraries/3rdParty/MathematicalAspects/ReferenceFiles/TestSwitch1.mat
./simulation/libraries/3rdParty/MathematicalAspects/ReferenceFiles/TestSwitch2.mat
./simulation/libraries/3rdParty/Modelica_Synchronous/simulateAll.sh
./simulation/libraries/3rdParty/Modelica_DeviceDrivers/simulateAll.sh
./simulation/libraries/3rdParty/PNlib/ReferenceFiles/PNlib.Examples.Test10.mat
./simulation/libraries/3rdParty/PNlib/ReferenceFiles/PNlib.Examples.Test11.mat
./simulation/libraries/3rdParty/PNlib/ReferenceFiles/PNlib.Examples.Test12.mat
Expand Down
Binary file not shown.
61 changes: 61 additions & 0 deletions simulation/libraries/3rdParty/Modelica_DeviceDrivers/Makefile
@@ -0,0 +1,61 @@
# A collection of libraries that can be tested, but are not enabled by default (since they are usually not installed by developers)

TEST = ../../../../rtest -v

TESTFILES = \
Modelica_DeviceDrivers.Blocks.Examples.TestSerialPackager.mos \


# test that currently fail. Move up when fixed.
# Run make testfailing
FAILINGTESTFILES= \
Modelica_DeviceDrivers.Blocks.Examples.TestSerialPackager_UDP.mos \


# Dependency files that are not .mo .mos or Makefile
# Add them here or they will be cleaned.
DEPENDENCIES = \
*.mo \
*.mos \
*.mat \
Makefile \
ReferenceFiles \
simulateAll.sh \
simulateAll.cmd \
sortResults.py


CLEAN = `ls | grep -w -v -f deps.tmp`

.PHONY : test clean getdeps failingtest

test :
@echo
@echo Running tests...
@echo
@echo OPENMODELICAHOME=" $(OPENMODELICAHOME) "
@$(TEST) $(TESTFILES)

# Cleans all files that are not listed as dependencies
clean :
@echo $(DEPENDENCIES) | sed 's/ /\\|/g' > deps.tmp
@rm -f *.mos.txt
@rm -rf $(CLEAN)

# Run this if you want to list out the files (dependencies).
# do it after cleaning and updating the folder
# then you can get a list of file names (which must be dependencies
# since you got them from repository + your own new files)
# then add them to the DEPENDENCIES. You can find the
# list in deps.txt
getdeps:
@echo $(DEPENDENCIES) | sed 's/ /\\|/g' > deps.tmp
@echo $(CLEAN) | sed -r 's/deps.txt|deps.tmp//g' | sed 's/ / \\\n/g' > deps.txt
@echo Dependency list saved in deps.txt.
@echo Copy the list from deps.txt and add it to the Makefile @DEPENDENCIES

failingtest :
@echo
@echo Running failing tests...
@echo
@$(TEST) $(FAILINGTESTFILES) \
@@ -0,0 +1,50 @@
// name: Modelica_DeviceDrivers.Blocks.Examples.TestSerialPackager
// keywords: simulation Modelica_Synchronous examples
// status: correct
//
// Simulation Results
// Modelica_Synchronous
//

runScript("../../common/ModelTestingDefaults.mos"); getErrorString();

echo(false);
modelTestingType := OpenModelicaModelTesting.Kind.VerifiedSimulation;
modelName := $TypeName(Modelica_DeviceDrivers.Blocks.Examples.TestSerialPackager);
compareVars :=
{"unpackInt.y", "getInteger.y[1]", "unpackInt1.y"};

runScript("common.mos");getErrorString();

runScript(modelTesting);getErrorString();

// Result:
// "true
// "
// ""
// Simulation options: startTime = 0.0, stopTime = 5.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'Modelica_DeviceDrivers.Blocks.Examples.TestSerialPackager', options = '', outputFormat = 'mat', variableFilter = 'time|unpackInt.y|getInteger.y.1.|unpackInt1.y', cflags = '', simflags = ' -abortSlowSimulation -alarm=360 -emit_protected'
// Result file: Modelica_DeviceDrivers.Blocks.Examples.TestSerialPackager_res.mat
// Files Equal!
// Warning: Alias equations of external objects are not Modelica compliant as in:
// addBoolean.pkgOut[1].pkg = resetPointer.pkgIn.pkg
// getBoolean.pkgIn.pkg = getInteger.pkgOut[1].pkg
// addBoolean.pkgIn.pkg = addInteger.pkgOut[1].pkg
// getInteger.pkgIn.pkg = unpackInt1.pkgOut[1].pkg
// unpackInt.pkgOut[1].pkg = unpackInt1.pkgIn.pkg
// resetPointer.pkgOut[1].pkg = unpackInt.pkgIn.pkg
// addInteger.pkgIn.pkg = packInt1.pkgOut[1].pkg
// packInt.pkgOut[1].pkg = packInt1.pkgIn.pkg
// packInt.pkgIn.pkg = packager.pkgOut.pkg
// addBoolean.pkgOut[1].pkg = addBoolean.pkgIn.pkg
// unpackInt1.pkgOut[1].pkg = unpackInt1.pkgIn.pkg
// getInteger.pkgOut[1].pkg = getInteger.pkgIn.pkg
// unpackInt.pkgOut[1].pkg = unpackInt.pkgIn.pkg
// resetPointer.pkgOut[1].pkg = resetPointer.pkgIn.pkg
// packInt1.pkgOut[1].pkg = packInt1.pkgIn.pkg
// addInteger.pkgOut[1].pkg = addInteger.pkgIn.pkg
// packInt.pkgOut[1].pkg = packInt.pkgIn.pkg
//
// "true
// "
// ""
// endResult
@@ -0,0 +1,8 @@
//
// These commands are common to all Modelica_DeviceDrivers examples
//

packageName := $TypeName(Modelica_DeviceDrivers);
packageVersion := "";
setCommandLineOptions("+d=nogen +std=3.3 +d=initialization");
referenceFileDir := "Modelica_DeviceDrivers"; // Default directory of reference files
@@ -0,0 +1,38 @@
@echo off
cls

rem get path to omc
SET OMC=%OPENMODELICAHOME%\bin\omc.exe +simCodeTarget=Cpp +locale=C +running-testsuite=dummy.out

rem try to simulate all *.mos files in current folder
for %%f in (*.mos) do (

time /t
echo %%f
%OMC% %%f > %%f.txt 2>&1
rem check the output
if %ERRORLEVEL% NEQ 0 (
echo - translation failed
) else (
if not exist %%~nf_res.mat (
echo - simulation failed
) else (
echo - OK
)
)

rem cleanup the mess
del dummy.out
del *.exe 2>nul 1>&2
del *.c 2>nul 1>&2
del *.h 2>nul 1>&2
del *.libs 2>nul 1>&2
del *.makefile 2>nul 1>&2
del *.mat 2>nul 1>&2
del *.o 2>nul 1>&2
del *.log 2>nul 1>&2
del *.xml 2>nul 1>&2
)

rem sortresults
python sortResults.py > results.txt
@@ -0,0 +1,26 @@
#!/bin/bash
OMC="${OPENMODELICAHOME}/bin/omc +locale=C +running-testsuite=dummy.out +d=hpcom +n=2"
#OMC="${OPENMODELICAHOME}/bin/omc +locale=C +running-testsuite=dummy.out"
echo $OMC
COUNTER=0
for f in *.mos; do
echo $f
$OMC $f > $f.txt 2>&1
ERRORLEVEL=$?

if [ $ERRORLEVEL -ne 0 ]; then
echo "- translation failed"
else
if [ -f ${f}_res.mat ]; then
echo "- simulation failed"
else
echo "- OK"
fi
fi
#COUNTER=$((COUNTER+1))
#if [ $COUNTER -gt 5 ]; then
# break
#fi
done

python sortResults.py > results.txt
169 changes: 169 additions & 0 deletions simulation/libraries/3rdParty/Modelica_DeviceDrivers/sortResults.py
@@ -0,0 +1,169 @@
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: Schubert
#
# Created: 12.11.2012
# Copyright: (c) Schubert 2012
# Licence: <your licence>
#-------------------------------------------------------------------------------

import os
import glob
import shutil

NOGROUP = '_NoGroup'

# GroupName, Words that must occur, Words that must not occur
Groups = [('_Flattening', 'Error occurred while flattening model', None), \
('_Expression', 'Failed to elaborate expression', None), \
('_Nonlinear', 'Error solving nonlinear system', None), \
('_Mixed', 'Your model contains a mixed system involving algorithms', None), \
('_Initialization_convert', 'convertInitialResidualsIntoInitial', None), \
('_Initial_Under', 'It was not possible to solve the under-determined initial system', None), \
('_Initial_Over', 'It was not possible to solve the over-determined initial system', None), \
('_Initial_NotUnique', 'Internal error It is not possible to determine unique', None), \
('_Initialization', 'Error in initialization', None), \
('_Initialization', 'The number of initial equations are not consistent with the number of unfixed variables', None), \
('_Backend', 'Internal error Transformation Module', None), \
('_Backend', 'Internal error IndexReduction.', None), \
('_DivByZero', 'division by zero', None), \
('_CodeGen', 'Error building simulator', None), \
('_Unbalanced', 'Too many equations, overdetermined system', None), \
('_Unbalanced', 'Too few equations, underdetermined system', None), \
('_SimFailed', 'Simulation failed for model', None), \
('_IntegratorFailed', 'Integrator failed', None), \
('_TableBug', ['n Table: NoName from File: NoName with Size', 'try to get', 'out of range!'], None), \
('_SimExecFailed', 'Simulation execution failed for model', None), \
('_UnknownVar', ['Get Data of Var', 'from file', 'failed'], None), \
('_NotEqual', 'Files not Equal', None), \
('_OK', 'Files Equal!', 'failed')]

def checkFile(fileName, groups):

# Check File Size first (ignore > 128Kb)
if (os.path.getsize(fileName) > 128*1024):
print "Skipping %s. Because file is too large!"%fileName
return NOGROUP

# Open, Read and Close file
f = open(fileName, 'r')
content = f.read()
f.close()

# run through all groups
for g in groups:
groupName = g[0]
include = g[1]
exclude = g[2]
if (include is None): include = list()
if (not isinstance(include, (list,tuple))): include = [include]
if (exclude is None): exclude = list()
if (not isinstance(exclude, (list,tuple))): exclude = [exclude]

# test for include
found = True
for i in include:
if (content.find(i) < 0):
found = False
break
if (found == False): continue

# test for exclude
found = False
for e in exclude:
if (content.find(e) >= 0):
found = True
break
if (found == True): continue

# we found the group
return groupName

# we did not find a matching group
return None

def main():

stat = dict()
models = dict()

# set up folders
if (os.path.exists(NOGROUP)):
shutil.rmtree(NOGROUP)
os.mkdir(NOGROUP)

for g in Groups:
groupName = g[0]
pathName = os.path.join(os.curdir, groupName)
if (os.path.exists(pathName)):
shutil.rmtree( pathName )
os.mkdir( pathName )

# get all ".mos.txt" files in folder
files = glob.glob( os.path.join(os.curdir, '*.mos.txt') )
for fileName in files:

# get group for file
groupName = checkFile(fileName, Groups)

# no group found
if groupName is None: groupName = NOGROUP

# copy file to group
splitName = os.path.split(fileName)
path = os.path.join(os.curdir, groupName)
newFileName = os.path.join(path,splitName[1])
shutil.copyfile(fileName, newFileName)

# count
try:
stat[groupName] = stat[groupName] + 1
except:
stat[groupName] = 1

# log
try:
models[groupName].append(splitName[1])
except:
models[groupName] = [splitName[1]]

# delete folders if empty
for g in Groups:
groupName = g[0]
pathName = os.path.join(os.curdir, groupName)
if (not (groupName in stat.keys())) and (os.path.exists(pathName)):
os.rmdir( pathName )


# Finished
print "**** Statistics ****"
print "%i models in total"%len(files)
for k,v in sorted(stat.items()):
groupName = k.replace('_', '')
print "%s:\t%i"%(groupName,v)


print "\n**** Details - groupwise ****"
for k,v in sorted(models.items()):
groupName = k.replace('_', '')
print "%s (%i):"%(groupName, len(v))
for m in sorted(v):
modelName = m.replace('.mos.txt', '')
print "\t%s"%modelName

# Inverse Mapping
inv_map = {}
for k, v in models.iteritems():
groupName = k.replace('_', '')
for m in v:
modelName = m.replace('.mos.txt', '')
inv_map[modelName] = groupName

print "\n**** Details - modelwise ****"
for k,v in sorted(inv_map.items()):
print "%s -> %s"%(k, v)

if __name__ == '__main__':
main()

0 comments on commit 771ca55

Please sign in to comment.