Skip to content

Commit

Permalink
Add LLFIO_ENABLE_DEPENDENCY_SMOKE_TEST option for vcpkg.
Browse files Browse the repository at this point in the history
  • Loading branch information
ned14 committed Feb 2, 2021
1 parent 669e0b4 commit 1d77bfa
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 35 deletions.
27 changes: 24 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ include(QuickCppLibUtils)
include(QuickCppLibPolicies)

option(LLFIO_USE_EXPERIMENTAL_SG14_STATUS_CODE "Whether to use SG14 status_code for failure handling" OFF)
option(LLFIO_ENABLE_DEPENDENCY_SMOKE_TEST "Whether to build executables which are smoke tests that LLFIO is fully working. Used by various package managers such as vcpkg." OFF)
set(UNIT_TESTS_CXX_VERSION "latest" CACHE STRING "The version of C++ to use in the header-only unit tests")

ensure_git_subrepo("${CMAKE_CURRENT_SOURCE_DIR}/include/llfio/ntkernel-error-category/include" "https://github.com/ned14/ntkernel-error-category.git")

Expand Down Expand Up @@ -66,8 +68,6 @@ if(WIN32)
endif()
endif()

set(UNIT_TESTS_CXX_VERSION "latest" CACHE STRING "The version of C++ to use in the header-only unit tests")

# Make the standard static and shared libraries, and if supported by this compiler, C++ modules
# for both static and shared libraries as well. For the non-C++ module variants, makes the
# interface headers into precompiled headers. Only builds all of them if this is the topmost
Expand Down Expand Up @@ -161,7 +161,13 @@ if((MSVC AND MSVC_VERSION VERSION_GREATER_EQUAL 1923) OR APPLE)
endif()
endif()
# Set the library dependencies this library has
all_link_libraries(PUBLIC quickcpplib::hl outcome::hl Threads::Threads $<$<PLATFORM_ID:Linux>:rt>)
all_link_libraries(PUBLIC Threads::Threads $<$<PLATFORM_ID:Linux>:rt>)
if(TARGET outcome::hl)
all_link_libraries(PUBLIC outcome::hl)
endif()
if(TARGET quickcpplib::hl)
all_link_libraries(PUBLIC quickcpplib::hl)
endif()

# Set the system dependencies this library has
include(CheckCXXSourceCompiles)
Expand Down Expand Up @@ -390,6 +396,21 @@ if(NOT PROJECT_IS_DEPENDENCY)
endif()
endif()

if(LLFIO_ENABLE_DEPENDENCY_SMOKE_TEST)
set(LLFIO_SMOKE_TESTS)
add_executable(llfio-dependency-smoke-test "test-packaging/example.cpp")
list(APPEND LLFIO_SMOKE_TESTS llfio-dependency-smoke-test)
foreach(target ${LLFIO_SMOKE_TESTS})
target_link_libraries(${target} PRIVATE llfio::dl)
set_target_properties(${target} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
add_test(NAME ${target} CONFIGURATIONS Debug Release RelWithDebInfo MinSizeRel
COMMAND $<TARGET_FILE:${target}> --reporter junit --out $<TARGET_FILE:${target}>.junit.xml
)
endforeach()
endif()

# Cache this library's auto scanned sources for later reuse
include(QuickCppLibCacheLibrarySources)

Expand Down
4 changes: 3 additions & 1 deletion cmake/QuickCppLibBootstrap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ foreach(item ${CMAKE_MODULE_PATH})
set(quickcpplib_done ON)
endif()
endforeach()
if(DEFINED quickcpplib_DIR)
if(NOT quickcpplib_done AND quickcpplib_DIR)
find_package(quickcpplib QUIET CONFIG)
if(quickcpplib_FOUND)
if(EXISTS "${quickcpplib_DIR}/share/cmakelib")
Expand All @@ -53,6 +53,8 @@ if(NOT quickcpplib_done)
set(CTEST_QUICKCPPLIB_SCRIPTS "${CMAKE_SOURCE_DIR}/../quickcpplib/scripts")
# Copy latest version of myself into end user
file(COPY "${CTEST_QUICKCPPLIB_SCRIPTS}/../cmake/QuickCppLibBootstrap.cmake" DESTINATION "${CMAKE_SOURCE_DIR}/cmake/")
elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/quickcpplib/repo/cmakelib")
set(CTEST_QUICKCPPLIB_CLONE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/quickcpplib")
elseif(CMAKE_BINARY_DIR)
# Place into root binary directory, same place as where find_quickcpplib_library() puts dependencies.
set(CTEST_QUICKCPPLIB_CLONE_DIR "${CMAKE_BINARY_DIR}/quickcpplib")
Expand Down
6 changes: 3 additions & 3 deletions include/llfio/revision.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
#define LLFIO_PREVIOUS_COMMIT_REF 48ee8bae656cb5d53f38feb462caa53e1128b76d
#define LLFIO_PREVIOUS_COMMIT_DATE "2021-01-27 20:37:58 +00:00"
#define LLFIO_PREVIOUS_COMMIT_UNIQUE 48ee8bae
#define LLFIO_PREVIOUS_COMMIT_REF 669e0b45bbc60cf4d46a72559710d428f2863740
#define LLFIO_PREVIOUS_COMMIT_DATE "2021-02-02 11:20:42 +00:00"
#define LLFIO_PREVIOUS_COMMIT_UNIQUE 669e0b45
53 changes: 25 additions & 28 deletions test-packaging/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,34 @@ Distributed under the Boost Software License, Version 1.0.

#include <llfio.hpp>

#include <vector>
#include <iostream>

int main()
{
//! [file_entire_file1]
namespace llfio = LLFIO_V2_NAMESPACE;

// Open the file for read
llfio::file_handle fh = llfio::file( //
{}, // path_handle to base directory
"foo" // path_view to path fragment relative to base directory
// default mode is read only
// default creation is open existing
// default caching is all
// default flags is none
).value(); // If failed, throw a filesystem_error exception

// Make a vector sized the current maximum extent of the file
std::vector<llfio::byte> buffer(fh.maximum_extent().value());

// Synchronous scatter read from file
llfio::file_handle::size_type bytesread = llfio::read(
fh, // handle to read from
0, // offset
{{ buffer.data(), buffer.size() }} // Single scatter buffer of the vector
// default deadline is infinite
).value(); // If failed, throw a filesystem_error exception

// In case of racy truncation of file by third party to new length, adjust buffer to
// bytes actually read
buffer.resize(bytesread);
//! [file_entire_file1]
return 0;
auto r = []() -> llfio::result<int> {
OUTCOME_TRY(auto fh, llfio::file_handle::temp_file());
static const char *buffers[] = { "He", "llo", " world" };
OUTCOME_TRY(fh.write(0, { { (const llfio::byte *) buffers[0], 2 }, { (const llfio::byte *) buffers[1], 3 }, { (const llfio::byte *) buffers[2], 6 } } ));
llfio::byte buffer[64];
OUTCOME_TRY(auto read, fh.read(0, { {buffer, sizeof(buffer)} }));
if(read != 11)
{
std::cerr << "FAILURE: Did not read 11 bytes!" << std::endl;
return 1;
}
if(0 != memcmp(buffer, "Hello world", 11))
{
std::cerr << "FAILURE: Did not read what was written!" << std::endl;
return 1;
}
return 0;
}();
if(!r)
{
std::cerr << "ERROR: " << r.error().message().c_str() << std::endl;
return 1;
}
return r.value();
}

0 comments on commit 1d77bfa

Please sign in to comment.