pipeline {
    environment {
        BUILDDIR = 'cmake-build-tests'
    }
    agent {
        docker { image 'fsfw-ci:d3'}
    }
    stages {
        stage('Clean') {
            steps {
                sh 'rm -rf $BUILDDIR'
            }
        }
        stage('Configure') {
            steps {
                dir(BUILDDIR) {
                    sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_TESTS=ON -DFSFW_CICD_BUILD=ON ..'
                }
            }
        }
        stage('Build') {
            steps {
                dir(BUILDDIR) {
                    sh 'cmake --build . -j4'
                }
            }
        }
        stage('Unittests') {
            steps {
                dir(BUILDDIR) {
                    sh 'cmake --build . -- fsfw-tests_coverage -j4'
                }
            }
        }
        stage('Valgrind') {
            steps {
                dir(BUILDDIR) {
                    sh 'valgrind --leak-check=full --error-exitcode=1 ./fsfw-tests'
                }
            }
        }
    }
}