Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2Cpp
Commits
a23002a2
Commit
a23002a2
authored
Jul 19, 2018
by
Christoph Richter
Browse files
CMake: Added tests
parent
2dbb6fdd
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/test/java/de/monticore/lang/monticar/generator/cmake/GenerateCMakeTest.java
0 → 100644
View file @
a23002a2
package
de.monticore.lang.monticar.generator.cmake
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol
;
import
de.monticore.lang.monticar.generator.AbstractSymtabTest
;
import
de.monticore.lang.monticar.generator.cpp.GeneratorCPP
;
import
de.monticore.lang.tagging._symboltable.TaggingResolver
;
import
de.se_rwth.commons.logging.Log
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
/**
* Tests the generation of cmake files
*
* @author Christoph Richter
*/
public
class
GenerateCMakeTest
extends
AbstractSymtabTest
{
private
static
TaggingResolver
symtab
;
private
static
GeneratorCPP
generatorCPP
;
@Before
public
void
setUpClass
()
{
Log
.
enableFailQuick
(
false
);
symtab
=
createSymTabAndTaggingResolver
(
"src/test/resources"
);
generatorCPP
=
new
GeneratorCPP
();
generatorCPP
.
useArmadilloBackend
();
generatorCPP
.
setGenerateCMake
(
true
);
}
@Test
public
void
testCMakeGenerationForBasicConstantAssignment
()
throws
IOException
{
ExpandedComponentInstanceSymbol
componentSymbol
=
symtab
.<
ExpandedComponentInstanceSymbol
>
resolve
(
"test.basicConstantAssignment"
,
ExpandedComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentSymbol
);
generatorCPP
.
setGenerationTargetPath
(
"./target/generated-sources-cpp/cmake/test/BasicConstantAssignment"
);
List
<
File
>
files
=
generatorCPP
.
generateFiles
(
componentSymbol
,
symtab
);
String
restPath
=
"cmake/test/BasicConstantAssignment/"
;
testCMakeFilesEqual
(
files
,
restPath
);
}
@Test
public
void
testCMakeGenerationForModel
()
throws
IOException
{
ExpandedComponentInstanceSymbol
componentSymbol
=
symtab
.<
ExpandedComponentInstanceSymbol
>
resolve
(
"testing.model"
,
ExpandedComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentSymbol
);
generatorCPP
.
setGenerationTargetPath
(
"./target/generated-sources-cpp/cmake/testing/Model"
);
List
<
File
>
files
=
generatorCPP
.
generateFiles
(
componentSymbol
,
symtab
);
String
restPath
=
"cmake/testing/Model/"
;
testCMakeFilesEqual
(
files
,
restPath
);
}
private
void
testCMakeFilesEqual
(
List
<
File
>
files
,
String
restPath
)
{
List
<
File
>
srcFiles
=
new
ArrayList
<>();
List
<
File
>
findFiles
=
new
ArrayList
<>();
for
(
File
f
:
files
)
{
if
(
f
.
getName
().
startsWith
(
"Find"
))
findFiles
.
add
(
f
);
else
srcFiles
.
add
(
f
);
}
testFilesAreEqual
(
srcFiles
,
restPath
);
testFilesAreEqual
(
findFiles
,
restPath
+
"cmake/"
);
}
}
src/test/resources/results/cmake/test/BasicConstantAssignment/CMakeLists.txt
0 → 100644
View file @
a23002a2
cmake_minimum_required
(
VERSION 3.5
)
set
(
CMAKE_CXX_STANDARD 11
)
project
(
test_basicConstantAssignment 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
}
)
# create static library
include_directories
(
${
INCLUDE_DIRS
}
)
add_library
(
test_basicConstantAssignment test_basicConstantAssignment.h
)
target_include_directories
(
test_basicConstantAssignment PUBLIC
${
CMAKE_CURRENT_SOURCE_DIR
}
)
target_link_libraries
(
test_basicConstantAssignment PUBLIC
${
LIBS
}
)
set_target_properties
(
test_basicConstantAssignment PROPERTIES LINKER_LANGUAGE CXX
)
# export cmake project
export
(
TARGETS test_basicConstantAssignment FILE test_basicConstantAssignment.cmake
)
src/test/resources/results/cmake/test/BasicConstantAssignment/HelperA.h
0 → 100644
View file @
a23002a2
#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/BasicConstantAssignment/cmake/FindArmadillo.cmake
0 → 100644
View file @
a23002a2
# 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
)
find_library
(
Armadillo_LIBRARY
NAMES armadillo
PATH_SUFFIXES
"lib"
"lib64"
"lib/x86_64-linux-gnu"
"examples/lib_win64"
"build"
PATHS
)
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/BasicConstantAssignment/test_basicConstantAssignment.h
0 → 100644
View file @
a23002a2
#ifndef TEST_BASICCONSTANTASSIGNMENT
#define TEST_BASICCONSTANTASSIGNMENT
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include
"armadillo.h"
using
namespace
arma
;
class
test_basicConstantAssignment
{
public:
mat
CONSTANTCONSTANTVECTOR0
;
void
init
()
{
CONSTANTCONSTANTVECTOR0
=
mat
(
4
,
4
);
CONSTANTCONSTANTVECTOR0
(
0
,
0
)
=
1
;
CONSTANTCONSTANTVECTOR0
(
0
,
1
)
=
2
;
CONSTANTCONSTANTVECTOR0
(
0
,
2
)
=
3
;
CONSTANTCONSTANTVECTOR0
(
0
,
3
)
=
4
;
CONSTANTCONSTANTVECTOR0
(
1
,
0
)
=
2
;
CONSTANTCONSTANTVECTOR0
(
1
,
1
)
=
3
;
CONSTANTCONSTANTVECTOR0
(
1
,
2
)
=
4
;
CONSTANTCONSTANTVECTOR0
(
1
,
3
)
=
1
;
CONSTANTCONSTANTVECTOR0
(
2
,
0
)
=
3
;
CONSTANTCONSTANTVECTOR0
(
2
,
1
)
=
4
;
CONSTANTCONSTANTVECTOR0
(
2
,
2
)
=
1
;
CONSTANTCONSTANTVECTOR0
(
2
,
3
)
=
2
;
CONSTANTCONSTANTVECTOR0
(
3
,
0
)
=
4
;
CONSTANTCONSTANTVECTOR0
(
3
,
1
)
=
1
;
CONSTANTCONSTANTVECTOR0
(
3
,
2
)
=
2
;
CONSTANTCONSTANTVECTOR0
(
3
,
3
)
=
3
;
}
void
execute
()
{
mat
m
=
CONSTANTCONSTANTVECTOR0
;
}
};
#endif
src/test/resources/results/cmake/testing/Model/CMakeLists.txt
0 → 100644
View file @
a23002a2
cmake_minimum_required
(
VERSION 3.5
)
set
(
CMAKE_CXX_STANDARD 11
)
project
(
testing_model 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
}
)
# create static library
include_directories
(
${
INCLUDE_DIRS
}
)
add_library
(
testing_model testing_model.h
)
target_include_directories
(
testing_model PUBLIC
${
CMAKE_CURRENT_SOURCE_DIR
}
)
target_link_libraries
(
testing_model PUBLIC
${
LIBS
}
)
set_target_properties
(
testing_model PROPERTIES LINKER_LANGUAGE CXX
)
# export cmake project
export
(
TARGETS testing_model FILE testing_model.cmake
)
src/test/resources/results/cmake/testing/Model/HelperA.h
0 → 100644
View file @
a23002a2
#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/testing/Model/cmake/FindArmadillo.cmake
0 → 100644
View file @
a23002a2
# 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
)
find_library
(
Armadillo_LIBRARY
NAMES armadillo
PATH_SUFFIXES
"lib"
"lib64"
"lib/x86_64-linux-gnu"
"examples/lib_win64"
"build"
PATHS
)
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/testing/Model/testing_model.h
0 → 100644
View file @
a23002a2
#ifndef TESTING_MODEL
#define TESTING_MODEL
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include
"armadillo.h"
#include
"testing_model_modelColor.h"
using
namespace
arma
;
class
testing_model
{
public:
imat
rgba
[
4
];
testing_model_modelColor
modelColor
;
void
init
()
{
rgba
[
0
]
=
imat
(
640
,
480
);
rgba
[
1
]
=
imat
(
640
,
480
);
rgba
[
2
]
=
imat
(
640
,
480
);
rgba
[
3
]
=
imat
(
640
,
480
);
modelColor
.
init
();
}
void
execute
()
{
modelColor
.
execute
();
rgba
[
0
]
=
modelColor
.
red
;
rgba
[
1
]
=
modelColor
.
green
;
rgba
[
1
]
=
modelColor
.
blue
;
rgba
[
3
]
=
modelColor
.
alpha
;
}
};
#endif
src/test/resources/results/cmake/testing/Model/testing_model_modelColor.h
0 → 100644
View file @
a23002a2
#ifndef TESTING_MODEL_MODELCOLOR
#define TESTING_MODEL_MODELCOLOR
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include
"armadillo.h"
using
namespace
arma
;
class
testing_model_modelColor
{
const
int
width
=
640
;
const
int
height
=
480
;
public:
imat
red
;
imat
green
;
imat
blue
;
imat
alpha
;
void
init
()
{
red
=
imat
(
width
,
height
);
green
=
imat
(
width
,
height
);
blue
=
imat
(
width
,
height
);
alpha
=
imat
(
width
,
height
);
}
void
execute
()
{
red
=
(
zeros
<
mat
>
(
640
,
480
));
green
=
(
zeros
<
mat
>
(
640
,
480
));
blue
=
(
zeros
<
mat
>
(
640
,
480
));
alpha
=
(
zeros
<
mat
>
(
640
,
480
));
}
};
#endif
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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