From 6949678eadbf65855d0bd0331a28f3aeff7e8327 Mon Sep 17 00:00:00 2001 From: Otto Bittner Date: Thu, 30 Jun 2022 13:26:21 +0200 Subject: [PATCH] Invoke tests through ctest (#230) Currently we define how tests should be executed in two places: CMakeLists.txt and the CI related files. With this commit the CI will invoke tests by calling ctest, thus making it necessary to add and define testcases in cmake first. As all tests starting with "integration-" or "unit-" are run, new tests don't have to added to the CI, unless you want to define a new category of test. Also remove the etcd store test workflow as it's part of test-integration now. Co-authored-by: Fabian Kammel --- .github/workflows/test-integration.yml | 21 +++++++-------------- .github/workflows/test-unittest.yml | 14 ++++++++------ CMakeLists.txt | 10 ++++++---- README.md | 8 ++++++++ 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml index e6520df9b..68d0c396f 100644 --- a/.github/workflows/test-integration.yml +++ b/.github/workflows/test-integration.yml @@ -17,6 +17,7 @@ jobs: runs-on: ubuntu-latest env: GOPRIVATE: github.com/edgelesssys/* + CTEST_OUTPUT_ON_FAILURE: True steps: - uses: actions/checkout@v2 - name: Setup Go environment @@ -25,22 +26,14 @@ jobs: go-version: "1.18" - name: Install Dependencies - run: sudo apt-get update && sudo apt-get install -y pkg-config libcryptsetup12 libcryptsetup-dev + run: sudo apt-get update && sudo apt-get install -y pkg-config libcryptsetup12 libcryptsetup-dev cmake - - name: Integration Test Coordinator - run: go test -v -tags integration ./test/ + - name: Create and populate build folder + run: mkdir build && cd build && cmake .. - - name: Integration Test mount - run: | - go test -tags integration -c ./test/ - sudo ./test.test -test.v -v 9 - working-directory: mount - - - name: Integration Test disk-mapper - run: | - go test -tags integration -c ./test/ - sudo ./test.test -test.v - working-directory: state + # Runs all test targets starting with "integration-" + - name: Integration Tests + run: ctest -R integration- - uses: actions/upload-artifact@v3 if: failure() diff --git a/.github/workflows/test-unittest.yml b/.github/workflows/test-unittest.yml index d7f493e47..0e3f2b277 100644 --- a/.github/workflows/test-unittest.yml +++ b/.github/workflows/test-unittest.yml @@ -17,6 +17,7 @@ jobs: runs-on: ubuntu-latest env: GOPRIVATE: github.com/edgelesssys/* + CTEST_OUTPUT_ON_FAILURE: True steps: - uses: actions/checkout@v2 @@ -26,11 +27,12 @@ jobs: go-version: 1.18 - name: Install Dependencies - run: sudo apt-get update && sudo apt-get install -y pkg-config libcryptsetup12 libcryptsetup-dev libvirt-dev + run: sudo apt-get update && sudo apt-get install -y pkg-config libcryptsetup12 libcryptsetup-dev cmake libvirt-dev - - name: Test main module - run: go test -race -count=3 ./... + - name: Create and populate build folder + run: mkdir build && cd build && cmake .. - - name: Test hack module - run: go test -race -count=3 ./... - working-directory: hack + # Runs all test targets starting with "unit-" + - name: Unit Tests + run: ctest -R unit- + working-directory: build diff --git a/CMakeLists.txt b/CMakeLists.txt index 18c75a20e..46dfa63b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,9 @@ add_custom_target(cdbg ALL BYPRODUCTS cdbg ) -add_test(NAME unittest COMMAND go test -race -count=3 ./... WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) -add_test(NAME unittest-hack COMMAND go test -race -count=3 ./... WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/hack) -add_test(NAME integrationtest COMMAND go test -v -tags integration ./test/ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) -add_test(NAME etcd-unittest COMMAND go test -v --race -cover -count=3 -tags integration WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/coordinator/store/) +add_test(NAME unit-main COMMAND go test -race -count=3 ./... WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) +add_test(NAME unit-hack COMMAND go test -race -count=3 ./... WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/hack) +add_test(NAME integration-coord COMMAND go test -v -tags integration ./test/ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) +add_test(NAME integration-mount COMMAND bash -c "go test -tags integration -c ./test/ && sudo ./test.test -test.v -v 9" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/mount) +add_test(NAME integration-dm COMMAND bash -c "go test -tags integration -c ./test/ && sudo ./test.test -test.v" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/state) +add_test(NAME integration-etcd COMMAND go test -v --race -cover -count=3 -tags integration WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/coordinator/store/) diff --git a/README.md b/README.md index 4b2cfed1b..ae0226241 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,14 @@ cmake .. make -j`nproc` ``` +## Testing + +You can run all integration and unitttests like this: + +```sh +ctest -j `nproc` +``` + ## Cloud credentials Using the CLI requires the user to make authorized API calls to the CSP API. See the [docs](https://constellation-docs.edgeless.systems/6c320851-bdd2-41d5-bf10-e27427398692/#/getting-started/install?id=cloud-credentials) for configuration.