Skip to content

Commit

Permalink
add test cases to github ci
Browse files Browse the repository at this point in the history
Signed-off-by: Achim Völker <achim.voelker@rwth-aachen.de>

install xerces-c in dockerfile

Signed-off-by: Achim Völker <achim.voelker@rwth-aachen.de>
  • Loading branch information
achim-voelker authored and m-mirz committed May 23, 2021
1 parent ae250e8 commit 6eee70a
Show file tree
Hide file tree
Showing 17 changed files with 1,437 additions and 10 deletions.
83 changes: 82 additions & 1 deletion .github/workflows/build-src.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,25 @@ jobs:
cmake ../.. -DUSE_CIM_VERSION=${{env.USE_CIM_VERSION}}
make -j8
- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/libcimpp/examples/cmake/build/${{env.USE_CIM_VERSION}}

- name: Configure CMake and compile
shell: bash
working-directory: ${{runner.workspace}}/libcimpp/examples/cmake/build/${{env.USE_CIM_VERSION}}/
run: |
cd ${{runner.workspace}}/libcimpp/examples/cmake/build/${{env.USE_CIM_VERSION}}
cmake ../.. -DUSE_CIM_VERSION=${{env.USE_CIM_VERSION}}
make -j8
- name: Run tests
shell: bash
working-directory: ${{runner.workspace}}/libcimpp/test
run: |
./testFiles.py $USE_CIM_VERSION
- uses: actions/upload-artifact@master
with:
name: test_results_${{env.USE_CIM_VERSION}}
path: ${{runner.workspace}}/libcimpp/test/outputs/${{env.USE_CIM_VERSION}}

build-src-IEC61970_17v07:
runs-on: ubuntu-latest
Expand All @@ -54,6 +72,27 @@ jobs:
cd ${{runner.workspace}}/libcimpp/build/${{env.USE_CIM_VERSION}}
cmake ../.. -DUSE_CIM_VERSION=${{env.USE_CIM_VERSION}}
make -j8
- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/libcimpp/examples/cmake/build/${{env.USE_CIM_VERSION}}

- name: Configure CMake and compile
shell: bash
working-directory: ${{runner.workspace}}/libcimpp/examples/cmake/build/${{env.USE_CIM_VERSION}}/
run: |
cd ${{runner.workspace}}/libcimpp/examples/cmake/build/${{env.USE_CIM_VERSION}}
cmake ../.. -DUSE_CIM_VERSION=${{env.USE_CIM_VERSION}}
make -j8
- name: Run tests
shell: bash
working-directory: ${{runner.workspace}}/libcimpp/test
run: |
./testFiles.py $USE_CIM_VERSION
- uses: actions/upload-artifact@master
with:
name: test_results_${{env.USE_CIM_VERSION}}
path: ${{runner.workspace}}/libcimpp/test/outputs/${{env.USE_CIM_VERSION}}



build-src-IEC61970_16v29a_IEC61968_12v08:
runs-on: ubuntu-latest
Expand All @@ -79,6 +118,27 @@ jobs:
cmake ../.. -DUSE_CIM_VERSION=${{env.USE_CIM_VERSION}}
make -j8
- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/libcimpp/examples/cmake/build/${{env.USE_CIM_VERSION}}

- name: Configure CMake and compile
shell: bash
working-directory: ${{runner.workspace}}/libcimpp/examples/cmake/build/${{env.USE_CIM_VERSION}}/
run: |
cd ${{runner.workspace}}/libcimpp/examples/cmake/build/${{env.USE_CIM_VERSION}}
cmake ../.. -DUSE_CIM_VERSION=${{env.USE_CIM_VERSION}}
make -j8
- name: Run tests
shell: bash
working-directory: ${{runner.workspace}}/libcimpp/test
run: |
./testFiles.py $USE_CIM_VERSION
- uses: actions/upload-artifact@master
with:
name: test_results_${{env.USE_CIM_VERSION}}
path: ${{runner.workspace}}/libcimpp/test/outputs/${{env.USE_CIM_VERSION}}



build-src-CGMES_2-4-15_27JAN2020:
runs-on: ubuntu-latest
Expand All @@ -105,3 +165,24 @@ jobs:
cmake ../.. -DUSE_CIM_VERSION=${{env.USE_CIM_VERSION}}
make -j8
- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/libcimpp/examples/cmake/build/${{env.USE_CIM_VERSION}}

- name: Configure CMake and compile
shell: bash
working-directory: ${{runner.workspace}}/libcimpp/examples/cmake/build/${{env.USE_CIM_VERSION}}/
run: |
cd ${{runner.workspace}}/libcimpp/examples/cmake/build/${{env.USE_CIM_VERSION}}
cmake ../.. -DUSE_CIM_VERSION=${{env.USE_CIM_VERSION}}
make -j8
- name: Run tests
shell: bash
working-directory: ${{runner.workspace}}/libcimpp/test
run: |
./testFiles.py $USE_CIM_VERSION
- uses: actions/upload-artifact@master
with:
name: test_results_${{env.USE_CIM_VERSION}}
path: ${{runner.workspace}}/libcimpp/test/outputs/${{env.USE_CIM_VERSION}}

48 changes: 45 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ variables:
stages:
- prepare
- build-src
- test-files
- build-doc
- deploy

Expand All @@ -17,7 +18,7 @@ docker:
tags:
- shell

# Template
# SRC Template
.build-src: &build-src
stage: build-src
image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV}
Expand Down Expand Up @@ -48,7 +49,7 @@ build-src-16v29a-12v08:
variables:
CIM_VERSION: IEC61970_16v29a_IEC61968_12v08

# Documentation
# Documentation Template
.build-doc: &build-doc
stage: build-doc
image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV}
Expand Down Expand Up @@ -76,4 +77,45 @@ build-doc-17v07:
build-doc-16v29a-12v08:
<<: *build-doc
variables:
CIM_VERSION: IEC61970_16v29a_IEC61968_12v08
CIM_VERSION: IEC61970_16v29a_IEC61968_12v08

# Test Files
.test-files: &test-files
stage: test-files
image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV}
tags:
- docker
before_script:
- cd examples/cmake
- mkdir -p build/${CIM_VERSION} && cd build/${CIM_VERSION}
- cmake ../.. -DUSE_CIM_VERSION=${CIM_VERSION}
- make -j8
script:
- cd ../../../../test/
- python3 testFiles.py ${CIM_VERSION}
- ls -l
artifacts:
paths:
- test/outputs/${CIM_VERSION}

test-files-CGMES:
<<: *test-files
variables:
CIM_VERSION: CGMES_2.4.15_27JAN2020

test-files-16v29a:
<<: *test-files
variables:
CIM_VERSION: IEC61970_16v29a

test-files-17v07:
<<: *test-files
variables:
CIM_VERSION: IEC61970_17v07

test-files-16v29a-12v08:
<<: *test-files
variables:
CIM_VERSION: IEC61970_16v29a_IEC61968_12v08


2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN dnf -y install \
gcc-c++ \
make \
doxygen graphviz \
libxerces-c-dev \
xerces-c-devel \
python3-pip rpmdevtools


Expand Down
102 changes: 97 additions & 5 deletions examples/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,57 @@
#include "CIMModel.hpp"
#include "IEC61970.hpp"
#include "CIMExceptions.hpp"

#include <regex>
#include <dirent.h>
#include <fstream>
#ifndef CGMES_BUILD
#include "CIMNamespaces.hpp"
#endif


std::string getFileName(const std::string& s) {

char sep = '/';

size_t i = s.rfind(sep, s.length());
if (i != std::string::npos) {
return(s.substr(i+1, s.length() - i));
}

return("");
}


std::vector<std::string> search_folder(const char *path) {

struct dirent *ent = NULL;
DIR *pDir;
pDir = opendir(path);
std::vector<std::string> files;
if(NULL == pDir){
std::cerr << "The specified directory does not exist. " << path<<
" Maybe you want to use the option -f to read a single File" << std::endl;
return files;
}

while (NULL != (ent = readdir(pDir))) {
std::string _path(path);
std::string _dirName(ent->d_name);
if(strcmp(ent->d_name,".") == 0 || strcmp(ent->d_name,"..") == 0 )
continue;
std::string file_path = _path + _dirName;
files.push_back(file_path);
}

return files;
}

inline bool ends_with(std::string const & value, std::string const & ending)
{
if (ending.size() > value.size()) return false;
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
}

std::string formatName(std::string name) {
if (name.length() > 12) {
name.resize(10, ' ');
Expand All @@ -31,11 +77,48 @@ int main(int argc, char** argv)
CIMModel someModel;
someModel.setDependencyCheckOff();

bool writeToFile = false;
std::string output_file_name;
std::string some= "wtf";
std::regex match(".*xml$");


int c;
for(int i = 1; i < argc; i++)
{

if(some.compare(argv[i]) == 0){
writeToFile = true;
continue;
}
std::vector<std::string> files;
if(!someModel.addCIMFile(argv[i]))
{
std::cout << "File ' " << argv[i] << " ' is not XML or does not exist" << std::endl;

if(!ends_with(argv[i], "/")){
char dest[strlen(argv[i])];
strcpy(dest, argv[i]);
files = search_folder(strcat(dest, "/"));
}
else{
files = search_folder(argv[i]);
}
for (auto f : files)
{
if(!std::regex_match(f, match) ){
std::cout << "is not a .xml file" << ( f )<< " skipping" << std::endl;
}else{
//std::cout << "CIM-XML file is:" << f << std::endl;
someModel.addCIMFile(f);
}
}
if(files.size() == 0){
std::cout << "File ' " << argv[i] << " ' is no XML or does not exist" << std::endl;
}else{

output_file_name = getFileName(argv[i]);
}

};
}

Expand All @@ -48,22 +131,31 @@ int main(int argc, char** argv)
std::cerr << exp.what() << std::endl;
}


for (BaseClass* Object : someModel.Objects)
std::ofstream myfile;
if(writeToFile == true){
myfile.open (output_file_name+".IdentifiedObjects.txt");
}
for (BaseClass* Object : someModel.Objects)
{
if(CIMPP::IdentifiedObject* IdObj = dynamic_cast<CIMPP::IdentifiedObject*>(Object))
{
if(!IdObj->name.empty()) {
static unsigned int i = 0;
std::string outputName = formatName(IdObj->name);
std::cout << outputName;
std::cout << outputName;
if(writeToFile == true){
myfile << formatName(IdObj->name) << std::endl;
}
i++;
if (i % 5 == 0) {
std::cout << std::endl;
}
}
}
}
if(writeToFile == true){
myfile.close();
}
std::cout << std::endl;
return 0;
}
9 changes: 9 additions & 0 deletions test/create_output.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

fileName=$1
cimVersion=$2
currDir=$(pwd)
cd ../examples/cmake/build/$cimVersion

./example $currDir/xml/$fileName wtf
mv $fileName.IdentifiedObjects.txt $currDir/outputs/$cimVersion/$fileName.IdentifiedObjects.txt
7 changes: 7 additions & 0 deletions test/diff.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

fileName=$1
cimVersion=$2
comm -3 <(sort outputs/$cimVersion/$fileName) <(sort solutions/$fileName)


43 changes: 43 additions & 0 deletions test/solutions/CIGRE_MV_RightFeeder_NEPLAN.IdentifiedObjects.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
291
41
297
N0
N12
N13
Area 1
Zone 1
PATL
TATL
TATL
Load13-I
Load13-I_0
Load12-H
Load12-H_0
Load12-I
Load12-I_0
HV-Netz
HV-Netz_0
L12-13
L12-13_0
L12-13_1
Ratings
Normal
ShortTerm
Emergency
TR2
TR2_0
TR2
Ratings
Normal
ShortTerm
Emergency
TR2_1
TR2
Ratings
Normal
ShortTerm
Emergency
N13
N12
N0
Load6
Loading

0 comments on commit 6eee70a

Please sign in to comment.