Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2Cpp
Commits
81d591c9
Commit
81d591c9
authored
Jul 26, 2018
by
Christoph Richter
Browse files
Added CMake generation for Stream Tests
parent
0a379e7e
Pipeline
#65310
failed with stage
in 16 seconds
Changes
10
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/generator/cpp/TestsGeneratorCPP.java
View file @
81d591c9
...
...
@@ -6,6 +6,7 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.Componen
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol
;
import
de.monticore.lang.monticar.generator.FileContent
;
import
de.monticore.lang.monticar.generator.cmake.CMakeConfig
;
import
de.monticore.lang.monticar.generator.cpp.converter.MathConverter
;
import
de.monticore.lang.monticar.generator.cpp.template.AllTemplates
;
import
de.monticore.lang.monticar.generator.cpp.viewmodel.ComponentStreamTestViewModel
;
...
...
@@ -90,9 +91,19 @@ public final class TestsGeneratorCPP {
files
.
add
(
new
FileContent
(
getExistingComponentNames
(),
"/reporting/"
+
"existingComponents.txt"
));
files
.
add
(
new
FileContent
(
getComponentNamesThatHaveTests
(),
"/reporting/"
+
"testComponents.txt"
));
}
// add to cmake lists
if
(
generator
.
isGenerateCMakeEnabled
())
addTestExecutionToCMakeConfig
();
return
files
;
}
private
void
addTestExecutionToCMakeConfig
()
{
CMakeConfig
cmake
=
generator
.
getCMakeConfig
();
cmake
.
addCMakeCommandEnd
(
"include_directories(test)"
);
cmake
.
addCMakeCommandEnd
(
"add_executable(StreamTests test/tests_main.cpp)"
);
cmake
.
addCMakeCommandEnd
(
"target_compile_definitions(StreamTests PRIVATE CATCH_CONFIG_MAIN=1 ARMA_DONT_USE_WRAPPER)"
);
}
private
String
getExistingComponentNames
()
{
String
result
=
"Components:\n"
;
for
(
String
s
:
availableComponents
)
{
...
...
src/test/java/de/monticore/lang/monticar/generator/cmake/GenerateCMakeTest.java
View file @
81d591c9
...
...
@@ -10,6 +10,7 @@ import org.junit.Test;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -54,17 +55,37 @@ public class GenerateCMakeTest extends AbstractSymtabTest {
testCMakeFilesEqual
(
files
,
restPath
);
}
@Test
public
void
testCMakeStreamTestGenerationForBasicPortsMath
()
throws
IOException
{
ExpandedComponentInstanceSymbol
componentSymbol
=
symtab
.<
ExpandedComponentInstanceSymbol
>
resolve
(
"test.basicPortsMath"
,
ExpandedComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentSymbol
);
generatorCPP
.
setGenerationTargetPath
(
"./target/generated-sources-cpp/cmake/test/BasicPortsMath"
);
generatorCPP
.
setModelsDirPath
(
Paths
.
get
(
"src/test/resources"
));
generatorCPP
.
setGenerateTests
(
true
);
generatorCPP
.
setCheckModelDir
(
true
);
List
<
File
>
files
=
generatorCPP
.
generateFiles
(
componentSymbol
,
symtab
);
String
restPath
=
"cmake/test/BasicPortsMath/"
;
testCMakeFilesEqual
(
files
,
restPath
);
}
private
void
testCMakeFilesEqual
(
List
<
File
>
files
,
String
restPath
)
{
List
<
File
>
srcFiles
=
new
ArrayList
<>();
List
<
File
>
findFiles
=
new
ArrayList
<>();
List
<
File
>
testFiles
=
new
ArrayList
<>();
for
(
File
f
:
files
)
{
if
(
f
.
getName
().
startsWith
(
"Find"
))
findFiles
.
add
(
f
);
else
if
(
f
.
getName
().
endsWith
(
".hpp"
)
||
f
.
getName
().
endsWith
(
".cpp"
))
testFiles
.
add
(
f
);
else
if
(
f
.
getName
().
endsWith
(
".txt"
))
{
//don't care about reporting files
}
else
srcFiles
.
add
(
f
);
}
testFilesAreEqual
(
srcFiles
,
restPath
);
testFilesAreEqual
(
findFiles
,
restPath
+
"cmake/"
);
testFilesAreEqual
(
testFiles
,
restPath
+
"test/"
);
}
}
src/test/resources/results/cmake/test/BasicPortsMath/CMakeLists.txt
0 → 100644
View file @
81d591c9
cmake_minimum_required
(
VERSION 3.5
)
set
(
CMAKE_CXX_STANDARD 11
)
project
(
test_basicPortsMath LANGUAGES CXX
)
#set cmake module path
set
(
CMAKE_MODULE_PATH
${
CMAKE_MODULE_PATH
}
${
CMAKE_CURRENT_SOURCE_DIR
}
/cmake
)
# add dependencies
find_package
(
Armadillo REQUIRED
)
set
(
INCLUDE_DIRS
${
INCLUDE_DIRS
}
${
Armadillo_INCLUDE_DIRS
}
)
set
(
LIBS
${
LIBS
}
${
Armadillo_LIBRARIES
}
)
# additional commands
# create static library
include_directories
(
${
INCLUDE_DIRS
}
)
add_library
(
test_basicPortsMath test_basicPortsMath.h
)
target_include_directories
(
test_basicPortsMath PUBLIC
${
CMAKE_CURRENT_SOURCE_DIR
}
)
target_link_libraries
(
test_basicPortsMath PUBLIC
${
LIBS
}
)
set_target_properties
(
test_basicPortsMath PROPERTIES LINKER_LANGUAGE CXX
)
# export cmake project
export
(
TARGETS test_basicPortsMath FILE test_basicPortsMath.cmake
)
# additional commands end
include_directories
(
test
)
add_executable
(
StreamTests test/tests_main.cpp
)
target_compile_definitions
(
StreamTests PRIVATE CATCH_CONFIG_MAIN=1 ARMA_DONT_USE_WRAPPER
)
src/test/resources/results/cmake/test/BasicPortsMath/HelperA.h
0 → 100644
View file @
81d591c9
#ifndef HELPERA_H
#define HELPERA_H
#include
<iostream>
#include
"armadillo.h"
#include
<stdarg.h>
#include
<initializer_list>
using
namespace
arma
;
class
HelperA
{
public:
static
mat
getEigenVectors
(
mat
A
){
vec
eigenValues
;
mat
eigenVectors
;
eig_sym
(
eigenValues
,
eigenVectors
,
A
);
return
eigenVectors
;
}
static
vec
getEigenValues
(
mat
A
){
vec
eigenValues
;
mat
eigenVectors
;
eig_sym
(
eigenValues
,
eigenVectors
,
A
);
return
eigenValues
;
}
static
mat
getKMeansClusters
(
mat
A
,
int
k
){
mat
clusters
;
kmeans
(
clusters
,
A
.
t
(),
k
,
random_subset
,
20
,
true
);
/*printf("cluster centroid calculation done\n");
std::ofstream myfile;
myfile.open("data after cluster.txt");
myfile << A;
myfile.close();
std::ofstream myfile2;
myfile2.open("cluster centroids.txt");
myfile2 << clusters;
myfile2.close();*/
mat
indexedData
=
getKMeansClustersIndexData
(
A
.
t
(),
clusters
);
/*std::ofstream myfile3;
myfile3.open("data after index.txt");
myfile3 << indexedData;
myfile3.close();
*/
return
indexedData
;
}
static
mat
getKMeansClustersIndexData
(
mat
A
,
mat
centroids
){
mat
result
=
mat
(
A
.
n_cols
,
1
);
for
(
int
i
=
0
;
i
<
A
.
n_cols
;
++
i
){
result
(
i
,
0
)
=
getIndexForClusterCentroids
(
A
,
i
,
centroids
);
}
return
result
;
}
static
int
getIndexForClusterCentroids
(
mat
A
,
int
colIndex
,
mat
centroids
){
int
index
=
1
;
double
lowestDistance
=
getEuclideanDistance
(
A
,
colIndex
,
centroids
,
0
);
for
(
int
i
=
1
;
i
<
centroids
.
n_cols
;
++
i
){
double
curDistance
=
getEuclideanDistance
(
A
,
colIndex
,
centroids
,
i
);
if
(
curDistance
<
lowestDistance
){
lowestDistance
=
curDistance
;
index
=
i
+
1
;
}
}
return
index
;
}
static
double
getEuclideanDistance
(
mat
A
,
int
colIndexA
,
mat
B
,
int
colIndexB
){
double
distance
=
0
;
for
(
int
i
=
0
;
i
<
A
.
n_rows
;
++
i
){
double
elementA
=
A
(
i
,
colIndexA
);
double
elementB
=
B
(
i
,
colIndexB
);
double
diff
=
elementA
-
elementB
;
distance
+=
diff
*
diff
;
}
return
sqrt
(
distance
);
}
static
mat
getSqrtMat
(
mat
A
){
cx_mat
result
=
sqrtmat
(
A
);
return
real
(
result
);
}
static
mat
getSqrtMatDiag
(
mat
A
){
for
(
int
i
=
0
;
i
<
A
.
n_rows
;
++
i
){
double
curVal
=
A
(
i
,
i
);
A
(
i
,
i
)
=
sqrt
(
curVal
);
}
return
A
;
}
static
mat
invertDiagMatrix
(
mat
A
){
for
(
int
i
=
0
;
i
<
A
.
n_rows
;
++
i
){
double
curVal
=
A
(
i
,
i
);
A
(
i
,
i
)
=
1
/
curVal
;
}
return
A
;
}
};
#endif
src/test/resources/results/cmake/test/BasicPortsMath/cmake/FindArmadillo.cmake
0 → 100644
View file @
81d591c9
# Automatically generated file
#
# - Try to find Armadillo
# Once done this will define
# Armadillo_FOUND - System has Armadillo
# Armadillo_INCLUDE_DIRS - The Armadillo include directories
# Armadillo_LIBRARY_DIRS - The library directories needed to use Armadillo
# Armadillo_LIBRARIES - The libraries needed to use Armadillo
find_path
(
Armadillo_INCLUDE_DIR
NAMES armadillo
PATH_SUFFIXES
"include"
PATHS
HINTS $ENV{Armadillo_HOME}
)
find_library
(
Armadillo_LIBRARY
NAMES armadillo
PATH_SUFFIXES
"lib"
"lib64"
"lib/x86_64-linux-gnu"
"examples/lib_win64"
"build"
"Release"
PATHS
HINTS $ENV{Armadillo_HOME}
)
include
(
FindPackageHandleStandardArgs
)
# if all listed variables are TRUE
find_package_handle_standard_args
(
Armadillo
DEFAULT_MSG
Armadillo_INCLUDE_DIR
Armadillo_LIBRARY
)
mark_as_advanced
(
Armadillo_INCLUDE_DIR
Armadillo_LIBRARY
)
set
(
Armadillo_INCLUDE_DIRS
${
Armadillo_INCLUDE_DIR
}
)
set
(
Armadillo_LIBRARIES
${
Armadillo_LIBRARY
}
)
\ No newline at end of file
src/test/resources/results/cmake/test/BasicPortsMath/test/catch.hpp
0 → 100644
View file @
81d591c9
This diff is collapsed.
Click to expand it.
src/test/resources/results/cmake/test/BasicPortsMath/test/test_basicPortsMath_test.hpp
0 → 100644
View file @
81d591c9
#ifndef TEST_BASICPORTSMATH_TEST
#define TEST_BASICPORTSMATH_TEST
#include
"catch.hpp"
#include
"../test_basicPortsMath.h"
TEST_CASE
(
"test.BasicPortsMath"
,
"[test_basicPortsMath]"
)
{
test_basicPortsMath
component
;
component
.
init
();
component
.
counter
=
-
10.0
;
component
.
execute
();
REQUIRE
(
component
.
result
>=
0.0
);
REQUIRE
(
component
.
result
<=
0.0
);
component
.
counter
=
-
1.0
;
component
.
execute
();
REQUIRE
(
component
.
result
>=
0.0
);
REQUIRE
(
component
.
result
<=
0.0
);
component
.
counter
=
0.0
;
component
.
execute
();
REQUIRE
(
component
.
result
>=
0.0
);
REQUIRE
(
component
.
result
<=
0.0
);
component
.
counter
=
1.0
;
component
.
execute
();
REQUIRE
(
component
.
result
>=
1.0
);
REQUIRE
(
component
.
result
<=
1.0
);
component
.
counter
=
100.0
;
component
.
execute
();
REQUIRE
(
component
.
result
>=
100.0
);
REQUIRE
(
component
.
result
<=
100.0
);
component
.
counter
=
1000.0
;
component
.
execute
();
REQUIRE
(
component
.
result
>=
100.0
);
REQUIRE
(
component
.
result
<=
100.0
);
std
::
cout
<<
"test.BasicPortsMath: success
\n
"
;
}
#endif
src/test/resources/results/cmake/test/BasicPortsMath/test/tests_main.cpp
0 → 100644
View file @
81d591c9
#ifndef TESTS_MAIN
#define TESTS_MAIN
//#define CATCH_CONFIG_RUNNER
#define CATCH_CONFIG_FAST_COMPILE
#include
"catch.hpp"
/*
int main(int argc, char* argv[]) {
Catch::Session session;
int returnCode = session.applyCommandLine(argc, argv);
if (returnCode != 0) {
return returnCode;
}
int numFailed = session.run();
return numFailed;
}*/
#include
"test_basicPortsMath_test.hpp"
#endif
src/test/resources/results/cmake/test/BasicPortsMath/test_basicPortsMath.h
0 → 100644
View file @
81d591c9
#ifndef TEST_BASICPORTSMATH
#define TEST_BASICPORTSMATH
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include
"armadillo.h"
using
namespace
arma
;
class
test_basicPortsMath
{
public:
double
counter
;
double
result
;
void
init
()
{
}
void
execute
()
{
if
((
counter
<
0
)){
result
=
0
;
}
else
if
((
counter
<
100
)){
result
=
counter
;
}
else
{
result
=
100
;
}
}
};
#endif
src/test/resources/test/BasicPortsMath.stream
0 → 100644
View file @
81d591c9
package
test
;
stream
BasicPortsMath
for
BasicPortsMath
{
counter
:
-
10
tick
-
1
tick
0
tick
1
tick
100
tick
1000
;
result
:
0
tick
0
tick
0
tick
1
tick
100
tick
100
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment