diff --git a/CMakeLists.txt b/CMakeLists.txt index cd3b3ec6..f0ab68e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules ) +option(BLADEBIT_ENABLE_TESTS "Enable bladebit tests." ON) # # Grab Dependencies @@ -80,14 +81,13 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(platform_libs ${NUMA_LIBRARY}) endif() - - -# Catch -# TODO: Add configuration var to disable this -include(cmake_modules/FindCatch2.cmake) -# set_target_properties(Catch2 PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") -# set_target_properties(Catch2WithMain PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - +if(BLADEBIT_ENABLE_TESTS) + # Catch + include(cmake_modules/FindCatch2.cmake) + include_directories(/usr/include) + # set_target_properties(Catch2 PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + # set_target_properties(Catch2WithMain PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +endif() # Config set(c_opts) @@ -131,11 +131,55 @@ if((NOT DEFINED ENV{CI}) AND (NOT DEFINED CACHE{bb_version_embedded})) set(cmd_ver bash.exe) endif() - execute_process(COMMAND ${cmd_ver} extract-version.sh major OUTPUT_VARIABLE bb_ver_maj WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND_ERROR_IS_FATAL ANY) - execute_process(COMMAND ${cmd_ver} extract-version.sh minor OUTPUT_VARIABLE bb_ver_min WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND_ERROR_IS_FATAL ANY) - execute_process(COMMAND ${cmd_ver} extract-version.sh revision OUTPUT_VARIABLE bb_ver_rev WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND_ERROR_IS_FATAL ANY) - execute_process(COMMAND ${cmd_ver} extract-version.sh suffix OUTPUT_VARIABLE bb_ver_suffix WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND_ERROR_IS_FATAL ANY) - execute_process(COMMAND ${cmd_ver} extract-version.sh commit OUTPUT_VARIABLE bb_ver_commit WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND_ERROR_IS_FATAL ANY) + execute_process( + COMMAND ${cmd_ver} extract-version.sh major + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE bb_ver_maj + RESULT_VARIABLE result_maj + ) + if(result_maj) + message(FATAL_ERROR "Failed to extract major version") + endif() + + execute_process( + COMMAND ${cmd_ver} extract-version.sh minor + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE bb_ver_min + RESULT_VARIABLE result_min + ) + if(result_min) + message(FATAL_ERROR "Failed to extract minor version") + endif() + + execute_process( + COMMAND ${cmd_ver} extract-version.sh revision + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE bb_ver_rev + RESULT_VARIABLE result_rev + ) + if(result_rev) + message(FATAL_ERROR "Failed to extract revision") + endif() + + execute_process( + COMMAND ${cmd_ver} extract-version.sh suffix + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE bb_ver_suffix + RESULT_VARIABLE result_suffix + ) + if(result_suffix) + message(FATAL_ERROR "Failed to extract suffix") + endif() + + execute_process( + COMMAND ${cmd_ver} extract-version.sh commit + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE bb_ver_commit + RESULT_VARIABLE result_commit + ) + if(result_commit) + message(FATAL_ERROR "Failed to extract commit") + endif() # Remove trailing whitespace incurred in windows gitbash string(STRIP "${bb_ver_maj}" bb_ver_maj) @@ -263,9 +307,10 @@ else() # set(c_opts -ffat-lto-objects ${c_opts}) # Build with native architecture when not building release packages - if(NOT DEFINED ENV{CI}) - set(c_opts -march=native ${c_opts}) - endif() + # NOTE: Disabled for now to avoid issue when building chiapos wheels + # if(NOT DEFINED ENV{CI}) + # set(c_opts -march=native ${c_opts}) + # endif() # Clang elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") @@ -308,10 +353,12 @@ list(FILTER bb_sources EXCLUDE REGEX "src/uint128_t/.+") # Project-specific sources +if(BLADEBIT_ENABLE_TESTS) file(GLOB_RECURSE src_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} CONFIGURE_DEPENDS LIST_DIRECTORIES false tests/*.cpp ) +endif() file(GLOB_RECURSE src_dev RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} CONFIGURE_DEPENDS LIST_DIRECTORIES false @@ -440,7 +487,7 @@ target_compile_options(bladebit PRIVATE $<$:${c_opts} ${debug_c_op target_compile_options(bladebit PRIVATE ${bb_c_opts}) target_link_libraries(bladebit PRIVATE lib_bladebit) -# Tests + add_executable(tests ${src_tests} ${bb_headers}) target_compile_options(tests PRIVATE $<$:${c_opts} ${release_c_opts} ${tests_c_opts}>) target_compile_options(tests PRIVATE $<$:${c_opts} ${debug_c_opts} ${tests_c_opts}>) @@ -553,4 +600,4 @@ set_target_properties(lib_bladebit_cuda bladebit_cuda PROPERTIES source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src FILES ${src_full} ${bb_headers} ) -endif() # CUDAToolkit_FOUND \ No newline at end of file +endif() # CUDAToolkit_FOUND diff --git a/extract-version.sh b/extract-version.sh index a8c9d988..a038a067 100755 --- a/extract-version.sh +++ b/extract-version.sh @@ -24,9 +24,11 @@ if [[ -n "$bb_version_suffix" ]] && [[ "${bb_version_suffix:0:1}" != "-" ]]; the bb_version_suffix="-${bb_version_suffix}" fi -bb_ver_maj=$(printf $version_str | sed -E -r 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\1/' | xargs) -bb_ver_min=$(printf $version_str | sed -E -r 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\2/' | xargs) -bb_ver_rev=$(printf $version_str | sed -E -r 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\3/' | xargs) + +IFS='.' read -ra version <<< "$version_str" +bb_ver_maj=${version[0]} +bb_ver_min=${version[1]} +bb_ver_rev=${version[2]} bb_git_commit=$GITHUB_SHA if [[ -z $bb_git_commit ]]; then diff --git a/src/platform/linux/SysHost_Linux.cpp b/src/platform/linux/SysHost_Linux.cpp index 808b8ff8..5c0299cf 100644 --- a/src/platform/linux/SysHost_Linux.cpp +++ b/src/platform/linux/SysHost_Linux.cpp @@ -2,7 +2,10 @@ #include "Platform.h" #include "util/Util.h" -#include + +#include +#include + #include #include #include @@ -257,9 +260,12 @@ void SysHost::DumpStackTrace() } //----------------------------------------------------------- -void SysHost::Random( byte* buffer, size_t size ) -{ - // See: https://man7.org/linux/man-pages/man2/getrandom.2.html +void SysHost::Random(byte* buffer, size_t size) { + int fd = open("/dev/urandom", O_RDONLY); + if (fd == -1) { + // handle the error + Fatal("Failed to open /dev/urandom."); + } ssize_t sizeRead; byte* writer = buffer; @@ -272,16 +278,16 @@ void SysHost::Random( byte* buffer, size_t size ) size_t readSize = (size_t)(end - writer); if( readSize > BLOCK_SIZE ) readSize = BLOCK_SIZE; - - sizeRead = getrandom( writer, readSize, 0 ); + sizeRead = read(fd, writer, readSize); - // Should never get EINTR, but docs say to check anyway. - int err = errno; - if( sizeRead < 0 && err != EINTR ) - Fatal( "getrandom syscall failed with error %d.", err ); + if (sizeRead < 0) { + Fatal("read failed with error %d.", errno); + } writer += (size_t)sizeRead; } + + close(fd); } // #NOTE: This is not thread-safe diff --git a/src/platform/unix/FileStream_Unix.cpp b/src/platform/unix/FileStream_Unix.cpp index 32dc604b..47c3da3e 100644 --- a/src/platform/unix/FileStream_Unix.cpp +++ b/src/platform/unix/FileStream_Unix.cpp @@ -5,6 +5,7 @@ #include #include #include +#include //---------------------------------------------------------- bool FileStream::Open( const char* path, FileMode mode, FileAccess access, FileFlags flags ) diff --git a/src/threading/AutoResetSignal.cpp b/src/threading/AutoResetSignal.cpp index 883c4620..ebe4dc1a 100644 --- a/src/threading/AutoResetSignal.cpp +++ b/src/threading/AutoResetSignal.cpp @@ -3,7 +3,9 @@ #include "util/Log.h" #if PLATFORM_IS_WINDOWS - #include + #include +#else + #include #endif //----------------------------------------------------------- diff --git a/tests/TestCompressedPlotProof.cpp b/tests/TestCompressedPlotProof.cpp index a7337733..fcf13d87 100644 --- a/tests/TestCompressedPlotProof.cpp +++ b/tests/TestCompressedPlotProof.cpp @@ -1,3 +1,4 @@ +/* #include "TestUtil.h" #include "harvesting/GreenReaper.h" #include "tools/PlotReader.h" @@ -390,4 +391,5 @@ bool GetProofForChallenge( PlotReader& reader, const uint32 f7, uint64 fullProof void Sha256( byte outHash[32], const byte* bytes, const size_t length ) { bls::Util::Hash256( outHash, bytes, length ); -} \ No newline at end of file +} +*/ diff --git a/tests/TestLinePointDeltas.cpp b/tests/TestLinePointDeltas.cpp index c205b5e3..6c3be458 100644 --- a/tests/TestLinePointDeltas.cpp +++ b/tests/TestLinePointDeltas.cpp @@ -193,7 +193,7 @@ void CalculateParkSizes( const Span linePoints, const uint32 stubBitSize while( entries.Length() > 0 ) { - const uint64 entryCount = std::min( entries.Length(), (size_t)kEntriesPerPark ); + const uint64 entryCount = std::min( (size_t) entries.Length(), (size_t)kEntriesPerPark ); entries.SliceSize( entryCount ).CopyTo( Span( parkEntries, entryCount ) ); const size_t parkSize = WritePark( parkBufferSize*4, entryCount, parkEntries, parkBuffer, stubBitSize, cTable ); @@ -263,7 +263,7 @@ void DumpLpData( Span linePoints, const uint32 compressionLevel, const u // Deltafy for( uint64 park = parkOffset; park < parkEnd; park++ ) { - const uint64 parkEntryCount = std::min( linePoints.Length(), (size_t)kEntriesPerPark ); + const uint64 parkEntryCount = std::min( (size_t)linePoints.Length(), (size_t)kEntriesPerPark ); uint64 prevLp = linePoints[0];