Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test case for MDD serial packager
- Loading branch information
1 parent
582c559
commit 771ca55
Showing
8 changed files
with
353 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+1.36 KB
...s/Modelica_DeviceDrivers/Modelica_DeviceDrivers.Blocks.Examples.TestSerialPackager.mat.xz
Binary file not shown.
61 changes: 61 additions & 0 deletions
61
simulation/libraries/3rdParty/Modelica_DeviceDrivers/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) \ |
50 changes: 50 additions & 0 deletions
50
...arty/Modelica_DeviceDrivers/Modelica_DeviceDrivers.Blocks.Examples.TestSerialPackager.mos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
8 changes: 8 additions & 0 deletions
8
simulation/libraries/3rdParty/Modelica_DeviceDrivers/common.mos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
38 changes: 38 additions & 0 deletions
38
simulation/libraries/3rdParty/Modelica_DeviceDrivers/simulateAll.cmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
26 changes: 26 additions & 0 deletions
26
simulation/libraries/3rdParty/Modelica_DeviceDrivers/simulateAll.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
169
simulation/libraries/3rdParty/Modelica_DeviceDrivers/sortResults.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |