Commits (10)
stages:
- build
- test
- deploy
build-mpp:
stage: build
variables:
GIT_SUBMODULE_STRATEGY: recursive
before_script:
- module add foss
- module add Anaconda3
script:
- mkdir build
- cd build
- cmake ..
- make -j
artifacts:
paths:
- build
unit-test:
stage: test
script:
before_script:
- cd build
script:
- ./TestCellConstruction
- ./TestCellInterface
- ./TestChainConfig
- ./TestConfig
- ./TestMesh
- ./TestQuadrature
from subprocess import Popen, PIPE
import shutil
import socket
import sys
import os
import re
PY_FILE_DIR = os.path.dirname(os.path.realpath(__file__))
MPP_DIR = os.path.abspath(os.path.join(PY_FILE_DIR, '..'))
MPP_BUILD_DIR = os.path.abspath(os.path.join(MPP_DIR, 'build'))
MPP_LOG_DIR = os.path.abspath(os.path.join(MPP_BUILD_DIR, 'log'))
MPP_DATA_DIR = os.path.abspath(os.path.join(MPP_BUILD_DIR, 'data'))
MPP_VTK_DATA_DIR = os.path.abspath(os.path.join(MPP_DATA_DIR, 'vtk'))
MPP_PY_DATA_DIR = os.path.abspath(os.path.join(MPP_DATA_DIR, 'py'))
PROJECT_ROOT_DIR = os.path.abspath(os.path.join(MPP_DIR, '..'))
PROJECT_BUILD_DIR = os.path.abspath(os.path.join(PROJECT_ROOT_DIR, 'build'))
PROJECT_LOG_DIR = os.path.abspath(os.path.join(PROJECT_BUILD_DIR, 'log'))
PROJECT_DATA_DIR = os.path.abspath(os.path.join(PROJECT_BUILD_DIR, 'data'))
PROJECT_VTK_DATA_DIR = os.path.abspath(os.path.join(PROJECT_DATA_DIR, 'vtk'))
PROJECT_PY_DATA_DIR = os.path.abspath(os.path.join(PROJECT_DATA_DIR, 'py'))
import shutil
import socket
from subprocess import Popen, PIPE
class Mpp:
PY_FILE_DIR = os.path.dirname(os.path.realpath(__file__))
MPP_DIR = os.path.abspath(os.path.join(PY_FILE_DIR, '..'))
MPP_BUILD_DIR = os.path.abspath(os.path.join(MPP_DIR, 'build'))
MPP_LOG_DIR = os.path.abspath(os.path.join(MPP_BUILD_DIR, 'log'))
MPP_DATA_DIR = os.path.abspath(os.path.join(MPP_BUILD_DIR, 'data'))
MPP_VTK_DATA_DIR = os.path.abspath(os.path.join(MPP_DATA_DIR, 'vtk'))
MPP_PY_DATA_DIR = os.path.abspath(os.path.join(MPP_DATA_DIR, 'py'))
PROJECT_ROOT_DIR = os.path.abspath(os.path.join(MPP_DIR, '..'))
PROJECT_BUILD_DIR = os.path.abspath(os.path.join(PROJECT_ROOT_DIR, 'build'))
PROJECT_LOG_DIR = os.path.abspath(os.path.join(PROJECT_BUILD_DIR, 'log'))
PROJECT_DATA_DIR = os.path.abspath(os.path.join(PROJECT_BUILD_DIR, 'data'))
PROJECT_VTK_DATA_DIR = os.path.abspath(os.path.join(PROJECT_DATA_DIR, 'vtk'))
PROJECT_PY_DATA_DIR = os.path.abspath(os.path.join(PROJECT_DATA_DIR, 'py'))
def __init__(self):
self.mute = False
self.executable = 'M++'
self.git_mpp_address = 'https://git.scc.kit.edu/yq8188/mpp.git'
self.git_project_address = None
def check_git_project(self):
return self.run_subprocess(['git', 'ls-remote', self.git_project_address],
self.PROJECT_ROOT_DIR)
def check_git_mpp(self):
return self.run_subprocess(['git', 'ls-remote', self.git_mpp_address],
self.MPP_DIR)
def git_pull_project(self, branch='master'):
rc_project = self.run_subprocess(['git', 'pull', 'origin', branch],
self.PROJECT_ROOT_DIR)
rc_mpp = self.git_pull_mpp()
rc_sub = self.run_subprocess(['git', 'submodule', 'update'],
self.PROJECT_ROOT_DIR)
if rc_project == 0 and rc_mpp == 0 and rc_sub == 0:
return 0
else:
return 1
@staticmethod
def run_subprocess(args, cwd):
def git_pull_mpp(self, branch='master'):
return self.run_subprocess(['git', 'pull', 'origin', branch],
self.MPP_DIR)
def run_subprocess(self, args, cwd):
if isinstance(args, list):
process = Popen(args, cwd=cwd, stdout=PIPE, stderr=PIPE)
while True:
stdout = process.stdout.readline()
if stdout == b'' and process.poll() is not None:
break
if stdout:
print(stdout.decode('utf-8').strip('\n'))
if not self.mute:
while True:
stdout = process.stdout.readline()
if stdout == b'' and process.poll() is not None:
break
if stdout:
print(stdout.decode('utf-8').strip('\n'))
process.wait()
process.stdout.close()
process.stderr.close()
return process.poll()
@staticmethod
def create_working_dir():
if not os.path.isdir(PROJECT_BUILD_DIR):
os.mkdir(PROJECT_BUILD_DIR)
def create_working_dir(self):
if not os.path.isdir(self.PROJECT_BUILD_DIR):
os.mkdir(self.PROJECT_BUILD_DIR)
def setup_cluster(self):
print('\n================ setup cluster ================\n')
if not self.mute:
print('\n================ setup cluster ================\n')
if socket.gethostname().find('ma-pde') != -1:
rc = self.run_subprocess(['module', 'add', 'foss'], cwd=PROJECT_ROOT_DIR)
return self.run_subprocess(['module', 'add', 'foss'],
cwd=self.PROJECT_ROOT_DIR)
def run_cmake(self):
print('\n================ running cmake ================\n')
rc = self.run_subprocess(['cmake', '..'], cwd=PROJECT_BUILD_DIR)
if not self.mute:
print('\n================ running cmake ================\n')
return self.run_subprocess(['cmake', '..'], cwd=self.PROJECT_BUILD_DIR)
def run_make(self):
print('\n================ running make ================\n')
self.run_subprocess(['make', '-j'], cwd=PROJECT_BUILD_DIR)
if not self.mute:
print('\n================ running make ================\n')
return self.run_subprocess(['make', '-j'], cwd=self.PROJECT_BUILD_DIR)
def kill(self):
print('\n================ kill every mpp ================\n')
self.run_subprocess(['killall', self.executable], cwd=PROJECT_BUILD_DIR)
if not self.mute:
print('\n================ kill every mpp ================\n')
return self.run_subprocess(['killall', self.executable],
cwd=self.PROJECT_BUILD_DIR)
def run_tests(self):
print('\n================ running tests ================\n')
files = os.listdir(PROJECT_BUILD_DIR)
if not self.mute:
print('\n================ running tests ================\n')
files = os.listdir(self.PROJECT_BUILD_DIR)
for file in files:
if file.find("Test") != -1:
run_parameters = self.chain_run_parameters(1, None, executable=file)
self.run_subprocess(run_parameters, cwd=PROJECT_BUILD_DIR)
run_parameters = self.chain_run_parameters(1, None, None, executable=file)
return self.run_subprocess(run_parameters, cwd=self.PROJECT_BUILD_DIR)
def chain_run_parameters(self, kernels, args, executable=None):
def chain_run_parameters(self, kernels, config, kwargs, executable=None):
executable = self.executable if executable is None else executable
if args is None:
args = []
run_parameters = ['mpirun', '-np', str(kernels), executable]
for arg in args:
run_parameters.append(arg)
if kwargs is None:
kwargs = {}
if config is None:
run_parameters = ['mpirun', '-np', str(kernels), executable]
else:
run_parameters = ['mpirun', '-np', str(kernels), executable, config]
for key, arg in kwargs.items():
kwarg = key + '=' + str(arg)
run_parameters.append(kwarg)
return run_parameters
def build(self):
self.create_working_dir()
self.run_cmake()
self.run_make()
rc_cmake = self.run_cmake()
rc_make = self.run_make()
if rc_cmake == 0 and rc_make == 0:
return 0
else:
return 1
@staticmethod
def remove_file(file):
if os.path.isfile(file):
try:
os.unlink(file)
except Exception as e:
print(e)
@staticmethod
def clean_directory(directory, recursive):
......@@ -93,13 +144,13 @@ class Mpp:
print(e)
def clean_vtk(self):
self.clean_directory(PROJECT_VTK_DATA_DIR, True)
self.clean_directory(self.PROJECT_VTK_DATA_DIR, True)
def clean_log(self):
self.clean_directory(PROJECT_LOG_DIR, False)
self.clean_directory(self.PROJECT_LOG_DIR, False)
def clean_python_plots(self):
self.clean_directory(PROJECT_PY_DATA_DIR, False)
self.clean_directory(self.PROJECT_PY_DATA_DIR, False)
def clean_data(self):
self.clean_vtk()
......@@ -107,16 +158,20 @@ class Mpp:
self.clean_python_plots()
def clean_build(self):
if os.path.isdir(PROJECT_BUILD_DIR):
self.clean_directory(PROJECT_BUILD_DIR, True)
if os.path.isdir(self.PROJECT_BUILD_DIR):
self.clean_directory(self.PROJECT_BUILD_DIR, True)
def run(self, kernels, args=None):
run_parameters = self.chain_run_parameters(kernels, args)
self.run_subprocess(run_parameters, cwd=PROJECT_BUILD_DIR)
def clean_cmake_cache(self):
cmake_cache = self.PROJECT_BUILD_DIR + 'CMakeCache.txt'
self.remove_file(cmake_cache)
@staticmethod
def read_log(log_file=None):
log_file = PROJECT_LOG_DIR + '/log' if log_file is None else PROJECT_LOG_DIR + log_file
def run(self, kernels, config=None, kwargs=None):
run_parameters = self.chain_run_parameters(kernels, config, kwargs)
return self.run_subprocess(run_parameters, cwd=self.PROJECT_BUILD_DIR)
def read_log(self, log_file=None):
log_file = self.PROJECT_LOG_DIR + '/log' if log_file is None else \
self.PROJECT_LOG_DIR + log_file
if os.path.isfile(log_file):
with open(log_file) as file:
content = file.readlines()
......@@ -133,12 +188,4 @@ class Mpp:
mpp = Mpp()
if __name__ == "__main__":
# mpp.setup_cluster()
mpp.create_working_dir()
mpp.run_cmake()
mpp.run_make()
# mpp.clean_build()
# mpp.setup_cluster()
# mpp.kill()
# mpp.build()
# mpp.run_tests()
mpp.check_git()