pipeline {
        agent {
              dockerfile { filename 'Jenkinsfiles/ubuntu-16.04.dockerfile' }
        }
        stages {
                stage('Build') {
                    steps {
                        sh '''
                            cd LibOS
                            make -j 8 glibc-build/Build.success GLIBC_VERSION=2.19
                            rm -r glibc-build
                            make -j 8 glibc-build/Build.success GLIBC_VERSION=2.23
                            rm -r glibc-build
                            cd ..
                            make -j 8 WERROR=1
                            make -j 8 WERROR=1 test
                            cd Pal/ipc/linux
                            make KERNELDIR=/lib/modules/4.4.0-161-generic/build
                           '''
                        sh '''
                            cd Pal/src
                            make -j 8 PAL_HOST=Skeleton WERROR=1
                           '''
                    }
                }
                stage('Test') {
                    steps {
                        sh '''
                            cd Pal/regression
                            make regression
                            '''
                        sh '''
                            cd LibOS/shim/test/regression
                            make regression
                            '''
                        sh '''
                            cd LibOS/shim/test/apps/ltp
                            make
                            ./syscalls.sh
                            '''
                        timeout(time: 5, unit: 'MINUTES') {
                            sh '''
                                cd LibOS/shim/test/apps/python
                                make regression
                            '''
                        }
                        sh '''
                            cd LibOS/shim/test/apps/bash
                            make regression
                            '''
                        timeout(time: 5, unit: 'MINUTES') {
                            sh '''
                                cd LibOS/shim/test/apps/gcc
                                make regression
                           '''
                        }
                        timeout(time: 15, unit: 'MINUTES') {
                            sh '''
                                cd LibOS/shim/test/apps/lmbench
                                make regression N_RUNS=1 ENOUGH=100
                            '''
                        }
                        sh '''
                            cd LibOS/shim/test/apps/lighttpd
                            make
                            make start-graphene-server &
                            sleep 1
                            LOOP=1 CONCURRENCY_LIST="1 32" ./benchmark-http.sh 127.0.0.1:8000
                            '''
                        sh '''
                            cd LibOS/shim/test/apps/apache
                            make
                            make start-graphene-server &
                            sleep 1
                            LOOP=1 CONCURRENCY_LIST="1 32" ./benchmark-http.sh 127.0.0.1:8001
                            '''
                    }
                    post {
                        always {
                            junit 'Pal/regression/pal-regression.xml'
                            junit 'LibOS/shim/test/regression/libos-regression.xml'
                        }
                    }
                }
                stage('Deploy') {
                    steps {
                        sh 'echo Deploying code'
                    }
                }
        }
        post {
                success {
                        echo 'Deployment successful'
                }
                failure {
                        echo 'Failure while on the pipeline'
                }
                unstable {
                        echo 'Pipeline marked as "unstable"'
                }
        }
}