Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test build env #16

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,36 +122,40 @@ target_link_libraries(verifier rapidsnarkStatic)

add_library(rapidsnark SHARED ${LIB_SOURCES})

add_executable(test_prover test_prover.cpp)
target_link_libraries(test_prover rapidsnarkStatic)

enable_testing()
add_executable(test_public_size test_public_size.c)
target_link_libraries(test_public_size rapidsnarkStaticFrFq)
add_test(NAME test_public_size COMMAND test_public_size circuit_final.zkey 86
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/testdata)


if(USE_LOGGER OR NOT USE_OPENMP)
target_link_libraries(prover pthread)
target_link_libraries(verifier pthread)
target_link_libraries(test_public_size pthread)
target_link_libraries(test_prover pthread)
endif()

if(USE_SODIUM)
target_link_libraries(prover sodium)
endif()


enable_testing()
add_executable(test_public_size test_public_size.c)
target_link_libraries(test_public_size rapidsnarkStaticFrFq)
add_test(NAME test_public_size COMMAND test_public_size circuit_final.zkey 86
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/testdata)

if(OpenMP_CXX_FOUND)

if(TARGET_PLATFORM MATCHES "android")
target_link_libraries(prover -static-openmp -fopenmp)
target_link_libraries(verifier -static-openmp -fopenmp)
target_link_libraries(rapidsnark -static-openmp -fopenmp)
target_link_libraries(test_prover -static-openmp -fopenmp)

elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(prover OpenMP::OpenMP_CXX)
target_link_libraries(verifier OpenMP::OpenMP_CXX)
target_link_libraries(test_public_size OpenMP::OpenMP_CXX)
target_link_libraries(test_prover OpenMP::OpenMP_CXX)
endif()

endif()


add_executable(test_prover test_prover.cpp)
33 changes: 33 additions & 0 deletions src/prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string>
#include <cstring>
#include <stdexcept>
#include <sstream>
#include <alt_bn128.hpp>
#include <nlohmann/json.hpp>

Expand Down Expand Up @@ -222,3 +223,35 @@ groth16_prover_zkey_file(const char *zkey_file_path,
public_buffer, public_size,
error_msg, error_msg_maxsize);
}

int
groth16_test_env(char *buffer, unsigned long buffer_maxsize)
{
std::ostringstream stream;

#ifdef USE_ASM
#if defined(ARCH_X86_64)
stream << "ASM: x86_64" << std::endl;
#elif defined(ARCH_ARM64)
stream << "ASM: arm64" << std::endl;
#endif
#else
stream << "ASM is disabled" << std::endl;
#endif

#ifdef USE_OPENMP
stream << "OpenMP max threads: " << omp_get_max_threads() << std::endl;
#else
stream << "OpenMP is disabled" << std::endl;
#endif

if (buffer_maxsize < stream.str().size() + 1) {
return PROVER_ERROR_SHORT_BUFFER;
}

const std::string str = stream.str();

strncpy(buffer, str.c_str(), buffer_maxsize);

return PROVER_OK;
}
10 changes: 10 additions & 0 deletions src/prover.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ groth16_prover_zkey_file(const char *zkey_file_path,
char *public_buffer, unsigned long *public_size,
char *error_msg, unsigned long error_msg_maxsize);

/**
* groth16_test_env
* @return error code:
* PROVER_OK - in case of success
* PROVER_ERROR_SHORT_BUFFER - in case of a short buffer error
*/
int
groth16_test_env(char *buffer, unsigned long buffer_maxsize);


#ifdef __cplusplus
}
#endif
Expand Down
15 changes: 15 additions & 0 deletions src/test_prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#include <cstring>
#include "fr.hpp"
#include "fq.hpp"
#include "prover.h"

#ifdef USE_OPENMP
#include <omp.h>
#endif

int tests_run = 0;
int tests_failed = 0;
Expand Down Expand Up @@ -10928,8 +10933,18 @@ void print_results()
std::cout << "Results: " << std::dec << tests_run << " tests were run, " << tests_failed << " failed." << std::endl;
}

void test_env()
{
char buffer[4096];
groth16_test_env(buffer, 4096);

std::cout << buffer << std::endl;
}

int main()
{
test_env();

Fr_Rw_add_unit_test();
Fr_Rw_sub_unit_test();
Fr_Rw_copy_unit_test();
Expand Down
Loading