Add code coverage action test

Signed-off-by: Zheng, Qi <huaiqing.zq@antgroup.com>
This commit is contained in:
Zheng, Qi 2021-09-27 11:13:19 +08:00 committed by Zongmin.Gu
parent c6d474bb7b
commit d1e9ed12f1
2 changed files with 50 additions and 74 deletions

50
.github/workflows/code_coverage.yaml vendored Normal file

@ -0,0 +1,50 @@
name: Code Coverage
# Controls when the action will run. Triggers the workflow on push or pull request
on: [push, pull_request]
env:
nap_time: 60
jobs:
Collect-code-coverage:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Get Occlum version
run: echo "OCCLUM_VERSION=$(grep 'Version =' src/pal/include/occlum_version.h | awk '{print $4}')" >> $GITHUB_ENV;
- name: Create container
run: docker run -itd --name=code_coverage -v $GITHUB_WORKSPACE:/root/occlum occlum/occlum:${{ env.OCCLUM_VERSION }}-ubuntu18.04
- name: Change download source of crates.io
run: |
docker exec code_coverage bash -c "cat <<- EOF >/root/.cargo/config
[source.crates-io]
registry = \"https://github.com/rust-lang/crates.io-index\"
replace-with = 'ustc'
[source.ustc]
registry = \"git://mirrors.ustc.edu.cn/crates.io-index\"
EOF"
- name: Build dependencies
run: docker exec code_coverage bash -c "cargo uninstall sccache || true; cd /root/occlum; make submodule"
- name: Build source
run: docker exec code_coverage bash -c "source /opt/intel/sgxsdk/environment; cd /root/occlum; OCCLUM_COV=1 make install"
- name: Integration test
run: docker exec code_coverage bash -c "cd /root/occlum; SGX_MODE=SIM make test"
- name: Integration test with Glibc
run: docker exec code_coverage bash -c "cd /root/occlum; SGX_MODE=SIM make test-glibc"
- name: Upload coverage report
run: docker exec code_coverage bash -c "cd /root/occlum/build/internal/src/libos/cargo-target/debug/deps; export CODECOV_TOKEN="${{ secrets.COV_TOKEN }}"; bash <(curl -s https://codecov.io/bash)"
- name: Clean the environment
if: ${{ always() }}
run: docker stop code_coverage

@ -10,80 +10,6 @@ env:
nap_time: 60 nap_time: 60
jobs: jobs:
Collect-code-coverage:
if: github.event_name == 'push' || ${{ contains(github.event.pull_request.labels.*.name, 'SGX-hardware-test-required') }}
runs-on: ${{ matrix.self_runner }}
strategy:
matrix:
self_runner: [[self-hosted, SGX1-HW], [self-hosted, SGX2-HW]]
steps:
- name: Clean before running
run: |
sudo chown -R ${{ secrets.CI_ADMIN }} "${{ github.workspace }}"
- name: Checkout code
if: github.event_name == 'push'
uses: actions/checkout@v2
with:
submodules: true
- name: Checkout code from fork
# This step is only needed when the pull request is labeled.
if: ${{ contains(github.event.pull_request.labels.*.name, 'SGX-hardware-test-required') }}
uses: actions/checkout@v2
with:
# For pull request, we need to merge the commit from fork to the base
ref: refs/pull/${{ github.event.pull_request.number }}/merge
submodules: true
- name: Get Occlum version
run: echo "OCCLUM_VERSION=$(grep 'Version =' src/pal/include/occlum_version.h | awk '{print $4}')" >> $GITHUB_ENV;
- name: Create container
run: |
if [[ "${{ matrix.self_runner[1] }}" == "SGX1-HW" ]]; then
occlum_test=$(docker run -itd --privileged --rm --env CARGO_HTTP_MULTIPLEXING=false --net host --device /dev/isgx -v $GITHUB_WORKSPACE:/root/occlum occlum/occlum:$OCCLUM_VERSION-ubuntu18.04);
elif [[ "${{ matrix.self_runner[1] }}" == "SGX2-HW" ]]; then
occlum_test=$(docker run -itd --privileged --rm --env CARGO_HTTP_MULTIPLEXING=false --net host -v /dev/sgx:/dev/sgx -v $GITHUB_WORKSPACE:/root/occlum occlum/occlum:$OCCLUM_VERSION-ubuntu18.04);
else
echo "Unsupported Hardware"
fi;
echo "occlum_test=$occlum_test" >> $GITHUB_ENV
- name: Update PCCS server
run: docker exec $occlum_test bash -c "sed -r -i 's/PCCS_URL=https:\/\/localhost:8081\/sgx\/certification\/v3\//PCCS_URL=https:\/\/sgx-dcap-server.cn-shanghai.aliyuncs.com\/sgx\/certification\/v3\//g' /etc/sgx_default_qcnl.conf"
- name: Change download source of crates.io
run: |
docker exec $occlum_test bash -c "cat <<- EOF >/root/.cargo/config
[source.crates-io]
registry = \"https://github.com/rust-lang/crates.io-index\"
replace-with = 'ustc'
[source.ustc]
registry = \"git://mirrors.ustc.edu.cn/crates.io-index\"
EOF"
- name: Build dependencies
run: docker exec $occlum_test bash -c "cargo uninstall sccache || true; cd /root/occlum; make submodule"
- name: Build source
run: docker exec $occlum_test bash -c "source /opt/intel/sgxsdk/environment; cd /root/occlum; OCCLUM_COV=1 make install"
- name: Integration test
run: docker exec $occlum_test bash -c "cd /root/occlum; make test"
- name: Integration test with Glibc
run: docker exec $occlum_test bash -c "cd /root/occlum; make test-glibc"
- name: Upload coverage report
run: docker exec $occlum_test bash -c "cd /root/occlum/build/internal/src/libos/cargo-target/debug/deps; export CODECOV_TOKEN="${{ secrets.COV_TOKEN }}"; bash <(curl -s https://codecov.io/bash)"
- name: Clean the environment
if: ${{ always() }}
run: docker stop $occlum_test
Make-test-on-ubuntu: Make-test-on-ubuntu:
if: github.event_name == 'push' || ${{ contains(github.event.pull_request.labels.*.name, 'SGX-hardware-test-required') }} if: github.event_name == 'push' || ${{ contains(github.event.pull_request.labels.*.name, 'SGX-hardware-test-required') }}
runs-on: ${{ matrix.self_runner }} runs-on: ${{ matrix.self_runner }}