Browse Source

adding ctest and changing structure

Sebastian Angel 1 year ago
parent
commit
cbbc5ac1c1
13 changed files with 30 additions and 20 deletions
  1. 4 14
      CMakeLists.txt
  2. 3 2
      README.md
  3. 8 0
      src/CMakeLists.txt
  4. 0 0
      src/main.cpp
  5. 0 0
      src/pir.cpp
  6. 0 0
      src/pir.hpp
  7. 0 0
      src/pir_client.cpp
  8. 0 0
      src/pir_client.hpp
  9. 0 0
      src/pir_server.cpp
  10. 0 0
      src/pir_server.hpp
  11. 9 0
      test/CMakeLists.txt
  12. 6 4
      test/expand_test.cpp
  13. 0 0
      test/query_test.cpp

+ 4 - 14
CMakeLists.txt

@@ -1,20 +1,10 @@
 cmake_minimum_required(VERSION 3.10)
-
 set(CMAKE_CXX_STANDARD 17)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
+project(SealPIR VERSION 2.2 LANGUAGES CXX)
 
-project(SealPIR VERSION 2.1 LANGUAGES CXX)
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
+add_subdirectory(src)
 
-add_executable(main main.cpp pir.cpp pir_client.cpp pir_server.cpp
-)
-
-add_executable(expand_test expand_test.cpp pir.cpp pir_client.cpp pir_server.cpp)
-add_executable(query_test query_test.cpp pir.cpp pir_client.cpp pir_server.cpp)
-
-find_package(SEAL 3.6 REQUIRED)
-
-target_link_libraries(main SEAL::seal)
-target_link_libraries(expand_test SEAL::seal)
-target_link_libraries(query_test SEAL::seal)
-
+enable_testing()
+add_subdirectory(test)

+ 3 - 2
README.md

@@ -18,11 +18,12 @@ Once Microsoft SEAL 3.6.5 is installed, to build SealPIR simply run:
 	cmake .
 	make
 	
-This should produce a binary file ``bin/sealpir``.
+This should produce a binary file ``bin/main``.
 
 # Using SealPIR
 
-Take a look at the example in main.cpp for how to use SealPIR. 
+Take a look at the example in `src/main.cpp` for how to use SealPIR. 
+You can also look at the tests in the `test` folder.
 Note: the parameter "d" stands for recursion levels, and for the current 
 configuration, the server-to-client reply has size (pow(10, d-1) * 32) KB. 
 Therefore we recommend using d <= 3.  

+ 8 - 0
src/CMakeLists.txt

@@ -0,0 +1,8 @@
+find_package(SEAL 3.6 REQUIRED)
+
+add_library(sealpir pir.hpp pir.cpp pir_client.hpp pir_client.cpp pir_server.hpp
+  pir_server.cpp)
+target_link_libraries(sealpir SEAL::seal)
+
+add_executable(main main.cpp)
+target_link_libraries(main sealpir)

+ 0 - 0
main.cpp → src/main.cpp


+ 0 - 0
pir.cpp → src/pir.cpp


+ 0 - 0
pir.hpp → src/pir.hpp


+ 0 - 0
pir_client.cpp → src/pir_client.cpp


+ 0 - 0
pir_client.hpp → src/pir_client.hpp


+ 0 - 0
pir_server.cpp → src/pir_server.cpp


+ 0 - 0
pir_server.hpp → src/pir_server.hpp


+ 9 - 0
test/CMakeLists.txt

@@ -0,0 +1,9 @@
+include_directories (${SealPIR_SOURCE_DIR}/src)
+
+add_executable(expand_test expand_test.cpp)
+target_link_libraries(expand_test sealpir)
+add_test(NAME expand_test COMMAND expand_test)
+
+add_executable(query_test query_test.cpp)
+target_link_libraries(query_test sealpir)
+add_test(NAME query_test COMMAND query_test)

+ 6 - 4
expand_test.cpp → test/expand_test.cpp

@@ -89,11 +89,13 @@ int main(int argc, char *argv[]) {
         }
         else if(decryption.is_zero()){
             cout << "Found zero where index should be" << endl;
-            return 1;
+            return -1;
         }
-        else{
-            cout << "Plaintext of query vector at index " << index << " should have value 1 (check below)" << endl;
-            cout << "Plaintext of query vector at index " << i << " has value " << decryption.to_string() << endl;
+        else if (std::stoi(decryption.to_string()) != 1) {
+            cout << "Query vector at index " << index << " should be 1 but is instead " << decryption.to_string() << endl;
+            return -1;
+        } else {
+            cout << "Query vector at index " << index << " is " << decryption.to_string() << endl;
         }
     }
 

+ 0 - 0
query_test.cpp → test/query_test.cpp