From 08869bc998eb88b0ef16cf5309e244b57eb40eb7 Mon Sep 17 00:00:00 2001 From: youben11 Date: Mon, 8 Nov 2021 14:52:39 +0100 Subject: [PATCH] chore: separate unittests into different executables it's easier to run a specific set of tests if they are into separate executable. We shouldn't have to run them all for testing a specific set of tests --- compiler/Makefile | 40 ++++++++++++++++--- compiler/tests/unittest/CMakeLists.txt | 39 ++++++++++++++++-- .../unittest/end_to_end_jit_clear_tensor.cc | 2 + .../tests/unittest/end_to_end_jit_test.cc | 2 +- compiler/tests/unittest/end_to_end_jit_test.h | 4 +- 5 files changed, 75 insertions(+), 12 deletions(-) diff --git a/compiler/Makefile b/compiler/Makefile index 69158e809..f37dcb4ee 100644 --- a/compiler/Makefile +++ b/compiler/Makefile @@ -27,9 +27,6 @@ $(BUILD_DIR)/configured.stamp: build-initialized: $(BUILD_DIR)/configured.stamp -build-end-to-end-jit: build-initialized - cmake --build $(BUILD_DIR) --target end_to_end_jit_test - zamacompiler: build-initialized cmake --build $(BUILD_DIR) --target zamacompiler @@ -40,14 +37,41 @@ python-bindings: build-initialized test-check: zamacompiler file-check not $(BUILD_DIR)/bin/llvm-lit -v tests/ -test-end-to-end-jit: build-end-to-end-jit - $(BUILD_DIR)/bin/end_to_end_jit_test - test-python: python-bindings PYTHONPATH=${PYTHONPATH}:$(BUILD_DIR)/tools/zamalang/python_packages/zamalang_core LD_PRELOAD=$(BUILD_DIR)/lib/libZamalangRuntime.so pytest -vs tests/python test: test-check test-end-to-end-jit test-python +# Unittests + +build-end-to-end-jit-test: build-initialized + cmake --build $(BUILD_DIR) --target end_to_end_jit_test + +build-end-to-end-jit-clear-tensor: build-initialized + cmake --build $(BUILD_DIR) --target end_to_end_jit_clear_tensor + +build-end-to-end-jit-encrypted-tensor: build-initialized + cmake --build $(BUILD_DIR) --target end_to_end_jit_encrypted_tensor + +build-end-to-end-jit-hlfhelinalg: build-initialized + cmake --build $(BUILD_DIR) --target end_to_end_jit_hlfhelinalg + +build-end-to-end-jit: build-end-to-end-jit-test build-end-to-end-jit-clear-tensor build-end-to-end-jit-encrypted-tensor build-end-to-end-jit-hlfhelinalg + +test-end-to-end-jit-test: build-end-to-end-jit-test + $(BUILD_DIR)/bin/end_to_end_jit_test + +test-end-to-end-jit-clear-tensor: build-end-to-end-jit-clear-tensor + $(BUILD_DIR)/bin/end_to_end_jit_clear_tensor + +test-end-to-end-jit-encrypted-tensor: build-end-to-end-jit-encrypted-tensor + $(BUILD_DIR)/bin/end_to_end_jit_encrypted_tensor + +test-end-to-end-jit-hlfhelinalg: build-end-to-end-jit-hlfhelinalg + $(BUILD_DIR)/bin/end_to_end_jit_hlfhelinalg + +test-end-to-end-jit: test-end-to-end-jit-test test-end-to-end-jit-clear-tensor test-end-to-end-jit-encrypted-tensor test-end-to-end-jit-hlfhelinalg + # LLVM/MLIR dependencies all-deps: file-check not @@ -83,6 +107,10 @@ release_tarballs: python-bindings \ test-check \ test-end-to-end-jit \ + test-end-to-end-jit-test \ + test-end-to-end-jit-clear-tensor \ + test-end-to-end-jit-encrypted-tensor \ + test-end-to-end-jit-hlfhelinalg \ test-python \ test \ add-deps \ diff --git a/compiler/tests/unittest/CMakeLists.txt b/compiler/tests/unittest/CMakeLists.txt index f60467a69..3b455a405 100644 --- a/compiler/tests/unittest/CMakeLists.txt +++ b/compiler/tests/unittest/CMakeLists.txt @@ -4,12 +4,24 @@ include_directories(${PROJECT_SOURCE_DIR}/include) add_executable( end_to_end_jit_test - end_to_end_jit_clear_tensor.cc - end_to_end_jit_encrypted_tensor.cc - end_to_end_jit_hlfhelinalg.cc end_to_end_jit_test.cc ) +add_executable( + end_to_end_jit_clear_tensor + end_to_end_jit_clear_tensor.cc + ) + +add_executable( + end_to_end_jit_encrypted_tensor + end_to_end_jit_encrypted_tensor.cc + ) + +add_executable( + end_to_end_jit_hlfhelinalg + end_to_end_jit_hlfhelinalg.cc + ) + set_source_files_properties( end_to_end_jit_test.cc end_to_end_jit_clear_tensor.cc @@ -25,6 +37,27 @@ target_link_libraries( ZamalangSupport ) +target_link_libraries( + end_to_end_jit_clear_tensor + gtest_main + ZamalangSupport +) + +target_link_libraries( + end_to_end_jit_encrypted_tensor + gtest_main + ZamalangSupport +) + +target_link_libraries( + end_to_end_jit_hlfhelinalg + gtest_main + ZamalangSupport +) + include(GoogleTest) gtest_discover_tests(end_to_end_jit_test) +gtest_discover_tests(end_to_end_jit_clear_tensor) +gtest_discover_tests(end_to_end_jit_encrypted_tensor) +gtest_discover_tests(end_to_end_jit_hlfhelinalg) diff --git a/compiler/tests/unittest/end_to_end_jit_clear_tensor.cc b/compiler/tests/unittest/end_to_end_jit_clear_tensor.cc index bb8cc2328..e046c0aa4 100644 --- a/compiler/tests/unittest/end_to_end_jit_clear_tensor.cc +++ b/compiler/tests/unittest/end_to_end_jit_clear_tensor.cc @@ -1,5 +1,7 @@ #include "end_to_end_jit_test.h" +const mlir::zamalang::V0FHEConstraint defaultV0Constraints{10, 7}; + /////////////////////////////////////////////////////////////////////////////// // 1D tensor ////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// diff --git a/compiler/tests/unittest/end_to_end_jit_test.cc b/compiler/tests/unittest/end_to_end_jit_test.cc index 9ff9c878c..44135e34d 100644 --- a/compiler/tests/unittest/end_to_end_jit_test.cc +++ b/compiler/tests/unittest/end_to_end_jit_test.cc @@ -5,7 +5,7 @@ #include "end_to_end_jit_test.h" -mlir::zamalang::V0FHEConstraint defaultV0Constraints() { return {10, 7}; } +const mlir::zamalang::V0FHEConstraint defaultV0Constraints{10, 7}; TEST(CompileAndRunHLFHE, add_eint) { mlir::zamalang::JitCompilerEngine::Lambda lambda = checkedJit(R"XXX( diff --git a/compiler/tests/unittest/end_to_end_jit_test.h b/compiler/tests/unittest/end_to_end_jit_test.h index 0a779b1ba..69f6f01ca 100644 --- a/compiler/tests/unittest/end_to_end_jit_test.h +++ b/compiler/tests/unittest/end_to_end_jit_test.h @@ -6,7 +6,7 @@ #include "zamalang/Support/CompilerEngine.h" #include "zamalang/Support/JitCompilerEngine.h" -mlir::zamalang::V0FHEConstraint defaultV0Constraints(); +extern const mlir::zamalang::V0FHEConstraint defaultV0Constraints; #define ASSERT_LLVM_ERROR(err) \ if (err) { \ @@ -87,7 +87,7 @@ internalCheckedJit(F checkfunc, llvm::StringRef src, mlir::zamalang::JitCompilerEngine engine; if (useDefaultFHEConstraints) - engine.setFHEConstraints(defaultV0Constraints()); + engine.setFHEConstraints(defaultV0Constraints); llvm::Expected lambdaOrErr = engine.buildLambda(src, func);