io/sparse_file — the single O_WRONLY output file (docs/04 §4). open()
posix_fallocate's the full size (falls back to ftruncate on
EOPNOTSUPP/ENOSYS, reported via preallocated()); write_at() pwrites at an
absolute offset, looping short writes and retrying EINTR; sync() is
fdatasync (timer/pause only); advise_dontneed() is
posix_fadvise(DONTNEED); resize() trims a preallocated tail or sizes a
chunked download. errno -> vdm::Error (ENOSPC->disk_full,
EACCES->permission_denied, ENOENT/ENOTDIR/...->path_rejected). No lock on
write_at — POSIX makes each pwrite atomic for a regular file, so N
segment threads writing disjoint ranges is safe (tested, TSan-clean).
io/write_buffer — per-segment accumulate-and-flush buffer, preallocated
at construction; append() only memcpys (no allocation on the write-
callback hot path, docs/04 §8 — asserted by a global-new counter in the
test). Flushes on fill via a caller-supplied FlushFn; a chunk >= capacity
arriving on an empty buffer writes straight through. On a flush error
next_offset() stays at the last durable position. Single-threaded; the
disk-writer-thread handoff is stage 8.
Also: vtest.hpp VT_CHECK_EQ/NE now copy operands (auto, not auto&&) — an
assertion must not outlive a temporary the expression returned a
reference into (ASan caught this on Result<void>{}.error().code).
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HPPSGhiArbvQgwC2DNiURS
46 lines
2.1 KiB
CMake
46 lines
2.1 KiB
CMake
# CORE unit tests.
|
|
#
|
|
# Harness is the provisional header-only vtest (support/vtest.hpp); PKG owns the final
|
|
# framework choice (core/docs/pkg-requests-m1.md P2). vdm_add_test() is the only thing
|
|
# test files touch, so swapping harnesses is a one-function edit.
|
|
|
|
add_library(vtest_main STATIC support/vtest_main.cpp)
|
|
target_include_directories(vtest_main PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/support)
|
|
target_compile_features(vtest_main PUBLIC cxx_std_23)
|
|
|
|
function(vdm_add_test name)
|
|
add_executable(${name} ${ARGN})
|
|
target_link_libraries(${name} PRIVATE veloxcore vtest_main)
|
|
target_compile_options(${name} PRIVATE -Wall -Wextra -Wpedantic -Werror)
|
|
add_test(NAME ${name} COMMAND ${name})
|
|
endfunction()
|
|
|
|
vdm_add_test(veloxcore_result_test util/result_test.cpp)
|
|
vdm_add_test(veloxcore_event_bus_test util/event_bus_test.cpp)
|
|
vdm_add_test(veloxcore_thread_pool_test util/thread_pool_test.cpp)
|
|
vdm_add_test(veloxcore_bytes_test util/bytes_test.cpp)
|
|
vdm_add_test(veloxcore_log_test util/log_test.cpp)
|
|
|
|
# net/ integration tests drive tools/testserver (lane PKG/QA). Skip cleanly if it isn't
|
|
# in the tree yet (lanes merge independently).
|
|
vdm_add_test(veloxcore_content_disposition_test net/content_disposition_test.cpp)
|
|
vdm_add_test(veloxcore_url_test net/url_test.cpp)
|
|
vdm_add_test(veloxcore_sparse_file_test io/sparse_file_test.cpp)
|
|
vdm_add_test(veloxcore_write_buffer_test io/write_buffer_test.cpp)
|
|
|
|
set(_testserver ${CMAKE_SOURCE_DIR}/tools/testserver/testserver.py)
|
|
foreach(net_it http_client probe)
|
|
vdm_add_test(veloxcore_${net_it}_test net/${net_it}_test.cpp)
|
|
target_include_directories(veloxcore_${net_it}_test
|
|
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/net)
|
|
if(EXISTS ${_testserver})
|
|
target_compile_definitions(veloxcore_${net_it}_test
|
|
PRIVATE VDM_TESTSERVER_PY="${_testserver}")
|
|
set_tests_properties(veloxcore_${net_it}_test PROPERTIES TIMEOUT 120)
|
|
endif()
|
|
endforeach()
|
|
if(NOT EXISTS ${_testserver})
|
|
message(STATUS "veloxcore: tools/testserver not present; net integration tests will "
|
|
"skip their server-backed cases.")
|
|
endif()
|