diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml index 59dbb1962b5..a7267b064eb 100644 --- a/.github/workflows/asan.yml +++ b/.github/workflows/asan.yml @@ -57,15 +57,14 @@ jobs: - name: Build run: cmake --build build - name: Run unit tests - run: | - cd build - ctest --verbose --output-on-failure + working-directory: build + run: ctest --output-on-failure --no-tests=error --exclude-regex w_iterations --label-regex VWTestList - name: Run python test script if: ${{ success() || failure() }} run: python3 test/run_tests.py -f --clean_dirty -E 0.001 --include_flatbuffers --jobs 1 test_ubsan_minimal: - # To avoid running out of disk space, build only VW executables and Boost unit tests on Linux + # To avoid running out of disk space, build only VW executables and some unit tests on Linux strategy: fail-fast: false matrix: @@ -95,9 +94,9 @@ jobs: cmakeListsTxtPath: "${{ github.workspace }}/CMakeLists.txt" configurePreset: "${{ matrix.preset }}" - name: Build - run: cmake --build build --target vw_cli_bin spanning_tree vw-unit-test.out + run: cmake --build build -t vw_cli_bin spanning_tree vw_core_test - name: Run unit tests - run: ./build/test/unit_test/vw-unit-test.out --run_test='!*w_iterations*' + run: ./build/vowpalwabbit/core/vw_core_test --gtest_filter=-\*w_iterations - name: Run python test script if: ${{ success() || failure() }} run: python3 test/run_tests.py -f --clean_dirty -E 0.001 --include_flatbuffers diff --git a/.github/workflows/build_macos.yml b/.github/workflows/build_macos.yml index 922ab14fe40..25bfad5f918 100644 --- a/.github/workflows/build_macos.yml +++ b/.github/workflows/build_macos.yml @@ -9,7 +9,7 @@ on: branches: - '*' -concurrency: +concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} cancel-in-progress: true @@ -30,10 +30,13 @@ jobs: run: cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DWARNINGS=Off -DVW_BUILD_VW_C_WRAPPER=Off -DBUILD_TESTING=On -DBUILD_EXPERIMENTAL_BINDING=On -DVW_BUILD_CSV=On -DVW_INSTALL=Off - name: Build run: cmake --build build --target all - - name: Test + - name: Unit tests + working-directory: build run: | # Run unit tests - ctest --test-dir build --extra-verbose --output-on-failure --label-regex VWTestList + ctest --output-on-failure --no-tests=error --label-regex VWTestList --parallel 2 + - name: Test + run: | # Run integration tests python3 test/run_tests.py --fuzzy_compare --exit_first_fail --epsilon 0.001 --ignore_dirty python3 test/run_tests.py --fuzzy_compare --exit_first_fail --epsilon 0.001 --ignore_dirty --extra_options=--onethread diff --git a/.github/workflows/build_vw_slim.yml b/.github/workflows/build_vw_slim.yml index 73b29e3d032..850b81be685 100644 --- a/.github/workflows/build_vw_slim.yml +++ b/.github/workflows/build_vw_slim.yml @@ -9,7 +9,7 @@ on: branches: - '*' -concurrency: +concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} cancel-in-progress: true @@ -27,4 +27,5 @@ jobs: run: ./.scripts/linux/build-slim.sh - name: Test VW Slim shell: bash - run: ./.scripts/linux/test-slim.sh + working-directory: build + run: ctest --output-on-failure --no-tests=error --tests-regex "VowpalWabbitSlim|ExploreTestSuite|CommandLineOptions" --parallel 2 diff --git a/.github/workflows/build_windows_cmake.yml b/.github/workflows/build_windows_cmake.yml index 85f3d652a3d..39401b272ee 100644 --- a/.github/workflows/build_windows_cmake.yml +++ b/.github/workflows/build_windows_cmake.yml @@ -9,7 +9,7 @@ on: branches: - '*' -concurrency: +concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} cancel-in-progress: true @@ -52,7 +52,7 @@ jobs: - name: Bootstrap vcpkg run: ${{ env.VCPKG_ROOT }}/bootstrap-vcpkg.bat - name: Install vcpkg dependencies - run: ${{ env.VCPKG_ROOT }}/vcpkg.exe --triplet x64-windows install zlib boost-test flatbuffers + run: ${{ env.VCPKG_ROOT }}/vcpkg.exe --triplet x64-windows install zlib flatbuffers - name: Generate project files run: | cmake -S "${{ env.SOURCE_DIR }}" -B "${{ env.CMAKE_BUILD_DIR }}" -A "x64" -DVCPKG_MANIFEST_MODE=OFF -DCMAKE_TOOLCHAIN_FILE="${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" -DBUILD_FLATBUFFERS=On -DVW_BUILD_CSV=On -Dvw_BUILD_NET_FRAMEWORK=On @@ -60,6 +60,5 @@ jobs: run: | cmake --build "${{ env.CMAKE_BUILD_DIR }}" --config ${{ matrix.build_config }} --verbose - name: Run tests - run: | - cd ${{ env.CMAKE_BUILD_DIR }} - ctest --verbose --output-on-failure -C ${{ matrix.build_config }} --label-regex VWTestList + working-directory: ${{ env.CMAKE_BUILD_DIR }} + run: ctest --output-on-failure --no-tests=error --label-regex VWTestList --build-config ${{ matrix.build_config }} diff --git a/.github/workflows/upload_coverage.yml b/.github/workflows/upload_coverage.yml index 08f51a1e8fd..4cbc0ecf531 100644 --- a/.github/workflows/upload_coverage.yml +++ b/.github/workflows/upload_coverage.yml @@ -9,7 +9,7 @@ on: branches: - '*' -concurrency: +concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} cancel-in-progress: true diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index f1d45a57a24..cb45fb486f9 100644 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -5,7 +5,7 @@ on: branches: - '*' -concurrency: +concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} cancel-in-progress: true @@ -20,7 +20,9 @@ jobs: with: submodules: recursive - name: Build C++ VW binary - run: ./.scripts/linux/build-minimal.sh Release + run: | + cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_EXPERIMENTAL_BINDING=On -DBUILD_FLATBUFFERS=On -DVW_BUILD_CSV=On + cmake --build build - name: Upload vw binary uses: actions/upload-artifact@v2 with: @@ -40,7 +42,8 @@ jobs: path: build/utl/flatbuffer/to_flatbuff if-no-files-found: error - name: Run unit tests with Valgrind - run: ./.scripts/linux/unit-tests-valgrind.sh + working-directory: build + run: ctest --output-on-failure --exclude-regex "w_iterations" --label-regex VWTestList --timeout 10 -T memcheck --overwrite MemoryCheckCommandOptions="--leak-check=full --error-exitcode=100" --parallel 2 run-valgrind-tests: name: ubuntu2004.amd64.valgrind-test.[${{ matrix.test-segment }}] needs: build-valgrind diff --git a/.github/workflows/vendor_build.yml b/.github/workflows/vendor_build.yml index 4ed88a9ae9a..b10c49921a4 100644 --- a/.github/workflows/vendor_build.yml +++ b/.github/workflows/vendor_build.yml @@ -9,8 +9,8 @@ on: branches: - '*' -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} cancel-in-progress: true jobs: @@ -49,13 +49,12 @@ jobs: -DWARNING_AS_ERROR=On -DUSE_LATEST_STD=On - name: Build - run: | - cmake --build build + run: cmake --build build + - name: Unit tests + working-directory: build + run: ctest --output-on-failure --no-tests=error --label-regex VWTestList --parallel 2 - name: Test - run: | - python3 test/run_tests.py -f --clean_dirty -E 0.001 - cd build - ctest --verbose --output-on-failure --label-regex VWTestList + run: python3 test/run_tests.py -f --clean_dirty -E 0.001 build_vendor_windows: name: core-cli.${{ matrix.os }}.amd64.${{ matrix.build_type }}.msvc.standalone runs-on: ${{matrix.os}} @@ -66,39 +65,15 @@ jobs: env: CMAKE_BUILD_DIR: ${{ github.workspace }}/vw/build SOURCE_DIR: ${{ github.workspace }}/vw - VCPKG_ROOT: ${{ github.workspace }}/vcpkg - VCPKG_REF: 6ca56aeb457f033d344a7106cb3f9f1abf8f4e98 steps: - uses: actions/checkout@v2 with: path: 'vw' submodules: 'recursive' - - uses: actions/checkout@v2 - with: - path: 'vcpkg' - repository: 'microsoft/vcpkg' - ref: ${{ env.VCPKG_REF }} - - name: Restore vcpkg and build artifacts - uses: actions/cache@v2 - with: - path: | - ${{ env.VCPKG_ROOT }}/installed/ - ${{ env.VCPKG_ROOT }} - !${{ env.VCPKG_ROOT }}/buildtrees - !${{ env.VCPKG_ROOT }}/packages - !${{ env.VCPKG_ROOT }}/downloads - key: | - ${{ env.VCPKG_REF }}-${{matrix.os}}-standalone-vcpkg-cache-invalidate-0 - uses: ilammy/msvc-dev-cmd@v1 - - name: Bootstrap vcpkg - run: ${{ env.VCPKG_ROOT }}/bootstrap-vcpkg.bat - - name: Install vcpkg dependencies - run: ${{ env.VCPKG_ROOT }}/vcpkg.exe --triplet x64-windows install boost-test - name: Configure run: > cmake -S "${{ env.SOURCE_DIR }}" -B "${{ env.CMAKE_BUILD_DIR }}" -A "x64" - -DCMAKE_TOOLCHAIN_FILE="${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" - -DVCPKG_MANIFEST_MODE=OFF -DUSE_LATEST_STD=On -DBUILD_FLATBUFFERS=Off -DVW_BUILD_CSV=On @@ -109,14 +84,12 @@ jobs: -DVW_BOOST_MATH_SYS_DEP=Off -DVW_INSTALL=Off - name: Build - run: | - cmake --build "${{ env.CMAKE_BUILD_DIR }}" --config ${{ matrix.build_type }} + run: cmake --build "${{ env.CMAKE_BUILD_DIR }}" --config ${{ matrix.build_type }} - name: Test run_tests.py run: python3 ${{ env.SOURCE_DIR }}/test/run_tests.py -f --clean_dirty -E 0.01 --skip_spanning_tree_tests --vw_bin_path ${{ env.CMAKE_BUILD_DIR }}/vowpalwabbit/cli/${{ matrix.build_type }}/vw.exe - name: Test unit tests - run: | - cd ${{ env.CMAKE_BUILD_DIR }} - ctest --verbose --output-on-failure --config ${{ matrix.build_type }} --label-regex VWTestList + working-directory: ${{ github.workspace }}/vw/build + run: ctest --output-on-failure --no-tests=error --label-regex VWTestList --build-config ${{ matrix.build_type }} --parallel 2 build_vendor_macos: runs-on: ${{matrix.os}} name: core-cli.${{ matrix.os }}.amd64.${{ matrix.build_type }}.AppleClang.standalone @@ -129,7 +102,7 @@ jobs: with: submodules: 'recursive' - name: Install dependencies - run: brew install cmake boost ninja + run: brew install cmake ninja - name: Configure run: > cmake -S . -B build -G Ninja @@ -143,10 +116,9 @@ jobs: -DVW_BOOST_MATH_SYS_DEP=Off -DVW_INSTALL=Off - name: Build - run: | - cmake --build build + run: cmake --build build + - name: Unit tests + working-directory: build + run: ctest --output-on-failure --no-tests=error --label-regex VWTestList --parallel 2 - name: Test - run: | - python3 test/run_tests.py -f --clean_dirty -E 0.001 - cd build - ctest --verbose --output-on-failure --label-regex VWTestList + run: python3 test/run_tests.py -f --clean_dirty -E 0.001 diff --git a/.scripts/linux/build-las-reduction.sh b/.scripts/linux/build-las-reduction.sh deleted file mode 100755 index 2206509a080..00000000000 --- a/.scripts/linux/build-las-reduction.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -e -set -x - -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -REPO_DIR=$SCRIPT_DIR/../../ -cd $REPO_DIR - -rm -rf build -cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DWARNINGS=OFF -DVW_BUILD_LARGE_ACTION_SPACE=On -DBUILD_JAVA=Off -DBUILD_PYTHON=Off -DBUILD_TESTING=On -DBUILD_FLATBUFFERS=Off -cmake --build build --target vw_cli_bin vw-unit-test.out diff --git a/.scripts/linux/build-minimal.sh b/.scripts/linux/build-minimal.sh deleted file mode 100755 index 279670c2938..00000000000 --- a/.scripts/linux/build-minimal.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -set -e -set -x - -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -REPO_DIR=$SCRIPT_DIR/../../ -cd $REPO_DIR - -# If parameter 1 is not supplied, it defaults to Release -BUILD_CONFIGURATION=${1:-Release} - -cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_EXPERIMENTAL_BINDING=On -DBUILD_FLATBUFFERS=On -DVW_BUILD_CSV=On -DVW_UNIT_TEST_WITH_VALGRIND_INTERNAL=On -cmake --build build diff --git a/.scripts/linux/test-las-reduction.sh b/.scripts/linux/test-las-reduction.sh deleted file mode 100755 index cbf96a0f436..00000000000 --- a/.scripts/linux/test-las-reduction.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e -set -x - -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -REPO_DIR=$SCRIPT_DIR/../../ -cd $REPO_DIR - -cd build -./test/unit_test/vw-unit-test.out --run_test=test_suite_las \ No newline at end of file diff --git a/.scripts/linux/test-slim.sh b/.scripts/linux/test-slim.sh deleted file mode 100755 index f5a83d19fef..00000000000 --- a/.scripts/linux/test-slim.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e -set -x - -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -REPO_DIR=$SCRIPT_DIR/../../ -cd $REPO_DIR - -cd build -ctest -R vw_slim_test --extra-verbose --output-on-failure diff --git a/.scripts/linux/test-with-coverage.sh b/.scripts/linux/test-with-coverage.sh index 96acc5a33ec..eb7bdd218dd 100755 --- a/.scripts/linux/test-with-coverage.sh +++ b/.scripts/linux/test-with-coverage.sh @@ -7,7 +7,7 @@ REPO_DIR=$SCRIPT_DIR/../../ cd $REPO_DIR cd $REPO_DIR/build -ctest --verbose --output-on-failure --label-regex VWTestList +ctest --verbose --output-on-failure --label-regex VWTestList --parallel 2 cd $REPO_DIR/test python3 run_tests.py -f -j $(nproc) --include_flatbuffers --clean_dirty -E 0.001 diff --git a/.scripts/linux/test.sh b/.scripts/linux/test.sh index 17d4d0d6a48..85f8c0dbab2 100755 --- a/.scripts/linux/test.sh +++ b/.scripts/linux/test.sh @@ -8,7 +8,7 @@ cd $REPO_DIR # Run unit tests cd $REPO_DIR/build -ctest --verbose --output-on-failure --label-regex VWTestList +ctest --verbose --output-on-failure --label-regex VWTestList --parallel 2 # Run integration tests cd $REPO_DIR diff --git a/.scripts/linux/unit-tests-valgrind.sh b/.scripts/linux/unit-tests-valgrind.sh deleted file mode 100755 index 0eba0c9c450..00000000000 --- a/.scripts/linux/unit-tests-valgrind.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -e -set -x - -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -REPO_DIR=$SCRIPT_DIR/../../ -cd $REPO_DIR - -cd build -export BOOST_TEST_LOG_LEVEL=unit_scope -ctest --verbose --output-on-failure --label-regex VWTestList --timeout 2400 diff --git a/.scripts/restore.cmd b/.scripts/restore.cmd index 964fdde3d83..d525bb584ec 100644 --- a/.scripts/restore.cmd +++ b/.scripts/restore.cmd @@ -11,6 +11,6 @@ REM CD out of the repo dir as we need to avoid vcpkg recognizing the manifest cd .. REM TODO: This really should be out-of-source -%VCPKG_INSTALLATION_ROOT%\vcpkg install flatbuffers:x64-windows boost-test:x64-windows +%VCPKG_INSTALLATION_ROOT%\vcpkg install flatbuffers:x64-windows ENDLOCAL diff --git a/.scripts/test.cmd b/.scripts/test.cmd index 87dc3d0c9e4..3c086f0e4e5 100644 --- a/.scripts/test.cmd +++ b/.scripts/test.cmd @@ -7,14 +7,6 @@ SETLOCAL CALL %~dp0init.cmd -ECHO Running VW Unit Tests in C++ -"%vwRoot%\build\binaries\Release\vw-unit-test.out.exe" - -IF "%ERRORLEVEL%" NEQ "0" ( - ENDLOCAL - EXIT /B %ERRORLEVEL% -) - ECHO Running VW Unit Tests in C# REM TODO: Add explicit logging configuration so it can be uploaded to pipeline results. "%vstestPath%" /Platform:x64 /inIsolation "%vwRoot%\build\binaries\Release\cs_unittest.dll" /TestCaseFilter:"TestCategory!=NotOnVSO" --logger:trx "--ResultsDirectory:%vwRoot%\vowpalwabbit\out\test\Release\x64" diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a10ebe5668..d24ff7bd4ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,29 +171,6 @@ if(DEFINED BUILD_TESTS) message(WARNING "Value of BUILD_TESTS option ignored. Please use the standard option BUILD_TESTING.") endif() -if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) - include(CTest) - if(BUILD_TESTING) - if(${CMAKE_VERSION} VERSION_LESS "3.11.0") - message(WARNING "BUILD_TESTING requires CMake >= 3.11.0. You can turn if off by setting BUILD_TESTING=OFF") - endif() - if(VW_GTEST_SYS_DEP) - find_package(GTest REQUIRED) - else() - cmake_minimum_required(VERSION 3.11) - include(FetchContent) - FetchContent_Declare( - googletest - URL https://github.com/google/googletest/archive/refs/tags/release-1.11.0.zip - ) - # For Windows: Prevent overriding the parent project's compiler/linker settings - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) - FetchContent_MakeAvailable(googletest) - endif() - endif() -endif() - if(VW_INSTALL AND NOT FMT_SYS_DEP) message(WARNING "Installing with a vendored version of fmt is not recommended. Use FMT_SYS_DEP to use a system dependency or specify VW_INSTALL=OFF to silence this warning.") endif() @@ -272,8 +249,6 @@ if(BUILD_BENCHMARKS) endif() if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - # Boost test is only required if we are building tests - find_package(Boost REQUIRED COMPONENTS unit_test_framework) add_subdirectory(test) # Don't offer these make dependent targets on Windows diff --git a/CMakePresets.json b/CMakePresets.json index d3380c06ddc..b9a2700fa97 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -162,14 +162,16 @@ { "name": "vcpkg-debug", "configurePreset": "vcpkg-debug", - "output": { "outputOnFailure": true, "verbosity": "verbose" }, - "execution": { "noTestsAction": "error", "stopOnFailure": true } + "output": { "outputOnFailure": true }, + "execution": { "noTestsAction": "error", "stopOnFailure": true }, + "filter": { "include": { "label": "VWTestList" } } }, { "name": "vcpkg-release", "configurePreset": "vcpkg-release", - "output": { "outputOnFailure": true, "verbosity": "verbose" }, - "execution": { "noTestsAction": "error", "stopOnFailure": true } + "output": { "outputOnFailure": true }, + "execution": { "noTestsAction": "error", "stopOnFailure": true }, + "filter": { "include": { "label": "VWTestList" } } } ] } diff --git a/Makefile b/Makefile index 8f23418ac21..b58fe78f7a7 100644 --- a/Makefile +++ b/Makefile @@ -47,9 +47,6 @@ test_build: @echo "vw running test-suite..." cd build; make -j$(nproc) all; make test -unit_test_build: - cd build/test/unit_test; make -j$(nproc) vw-unit-test.out test - bigtests_build: cd build; make -j$(nproc) bigtests BIG_TEST_ARGS="$(MAKEFLAGS)" diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt index c3fa337eac9..52151cf7f88 100644 --- a/bindings/c/CMakeLists.txt +++ b/bindings/c/CMakeLists.txt @@ -24,6 +24,4 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/../../vowpalwabbit/common/include/vw/co add_library(vw_c_api ${vw_c_public_headers} ${vw_c_impl_files} ${vw_c_private_headers}) target_include_directories(vw_c_api PUBLIC include/ ${CMAKE_CURRENT_BINARY_DIR}/include/) target_link_libraries(vw_c_api PRIVATE vw_core vw_io) -target_compile_definitions(vw_c_api PRIVATE VWDLL_EXPORTS) - -add_subdirectory(test) \ No newline at end of file +target_compile_definitions(vw_c_api PRIVATE VWDLL_EXPORTS) \ No newline at end of file diff --git a/bindings/c/test/CMakeLists.txt b/bindings/c/test/CMakeLists.txt deleted file mode 100644 index ecf4ac462dd..00000000000 --- a/bindings/c/test/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -if(BUILD_TESTING) - add_executable(vw_c_api_unit_test - test_main.cc - placeholder_test.cc - ) - - target_link_libraries(vw_c_api_unit_test PRIVATE vw_c_api Boost::unit_test_framework) - - add_test( - NAME vw_c_api_unit_test - COMMAND ./vw_c_api_unit_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) -endif() diff --git a/bindings/c/test/placeholder_test.cc b/bindings/c/test/placeholder_test.cc deleted file mode 100644 index 5a3db181c06..00000000000 --- a/bindings/c/test/placeholder_test.cc +++ /dev/null @@ -1,5 +0,0 @@ -#include "vw/experimental/placeholder.h" - -#include - -BOOST_AUTO_TEST_CASE(placeholder_test) {} \ No newline at end of file diff --git a/bindings/c/test/test_main.cc b/bindings/c/test/test_main.cc deleted file mode 100644 index 5511a45cf24..00000000000 --- a/bindings/c/test/test_main.cc +++ /dev/null @@ -1,2 +0,0 @@ -#define BOOST_TEST_MODULE Main -#include \ No newline at end of file diff --git a/cmake/VowpalWabbitUtils.cmake b/cmake/VowpalWabbitUtils.cmake index 21303a6efb0..8ab59160f45 100644 --- a/cmake/VowpalWabbitUtils.cmake +++ b/cmake/VowpalWabbitUtils.cmake @@ -7,9 +7,28 @@ if(USE_LATEST_STD) DetectCXXStandard(VW_CXX_STANDARD) endif() -option(VW_UNIT_TEST_WITH_VALGRIND_INTERNAL "Internal flag." OFF) -if(VW_UNIT_TEST_WITH_VALGRIND_INTERNAL) - find_program(VALGRIND "valgrind" REQUIRED) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + include(CTest) + if(BUILD_TESTING) + if(${CMAKE_VERSION} VERSION_LESS "3.11.0") + message(WARNING "BUILD_TESTING requires CMake >= 3.11.0. You can turn if off by setting BUILD_TESTING=OFF") + endif() + if(VW_GTEST_SYS_DEP) + find_package(GTest REQUIRED) + else() + cmake_minimum_required(VERSION 3.11) + include(FetchContent) + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/release-1.11.0.zip + ) + # For Windows: Prevent overriding the parent project's compiler/linker settings + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) + endif() + include(GoogleTest) + endif() endif() # Given a lib name writes to OUTPUT what the correspinding target name will be @@ -253,6 +272,16 @@ function(vw_add_executable) endif() endfunction() + +set(GTEST_MAIN_FILE_CONTENTS "#include \n\ +\n\ +int main(int argc, char** argv)\n\ +{\n\ + ::testing::InitGoogleTest(&argc, argv);\n\ + return RUN_ALL_TESTS();\n\ +}\n" +) + function(vw_add_test_executable) cmake_parse_arguments(VW_TEST "" @@ -276,22 +305,19 @@ function(vw_add_test_executable) vw_get_test_target(FULL_TEST_NAME ${VW_TEST_FOR_LIB}) - add_executable(${FULL_TEST_NAME} ${VW_TEST_SOURCES}) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${FULL_TEST_NAME}_main.cc "${GTEST_MAIN_FILE_CONTENTS}") + + add_executable(${FULL_TEST_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${FULL_TEST_NAME}_main.cc ${VW_TEST_SOURCES}) target_link_libraries(${FULL_TEST_NAME} PUBLIC ${FULL_FOR_LIB_NAME} ${VW_TEST_EXTRA_DEPS} - GTest::gmock GTest::gtest_main + GTest::gmock GTest::gtest ) target_compile_definitions(${FULL_TEST_NAME} PRIVATE ${VW_TEST_COMPILE_DEFS}) target_compile_options(${FULL_TEST_NAME} PRIVATE ${WARNING_OPTIONS} ${WARNING_AS_ERROR_OPTIONS}) set_property(TARGET ${FULL_TEST_NAME} PROPERTY CXX_STANDARD ${VW_CXX_STANDARD}) set_property(TARGET ${FULL_TEST_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) set_property(TARGET ${FULL_TEST_NAME} PROPERTY CMAKE_CXX_EXTENSIONS OFF) - if(VW_UNIT_TEST_WITH_VALGRIND_INTERNAL) - add_test(NAME ${FULL_TEST_NAME} COMMAND ${VALGRIND} --error-exitcode=100 --track-origins=yes --leak-check=full $) - else() - add_test(NAME ${FULL_TEST_NAME} COMMAND ${FULL_TEST_NAME}) - endif() - set_tests_properties(${FULL_TEST_NAME} PROPERTIES LABELS "VWTestList") + gtest_discover_tests(${FULL_TEST_NAME} PROPERTIES LABELS VWTestList DISCOVERY_TIMEOUT 60) endif() endfunction() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index eeea053dc44..142b0cd3747 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,2 +1 @@ -add_subdirectory(unit_test) add_subdirectory(tools) diff --git a/test/unit_test/CMakeLists.txt b/test/unit_test/CMakeLists.txt deleted file mode 100644 index dc4b6d5552c..00000000000 --- a/test/unit_test/CMakeLists.txt +++ /dev/null @@ -1,77 +0,0 @@ -if(VW_UNIT_TEST_WITH_VALGRIND_INTERNAL) - find_program(VALGRIND "valgrind" REQUIRED) -endif() - -add_executable(vw-unit-test.out - cats_user_provided_pdf.cc - cb_large_actions_test.cc - cb_las_one_pass_svd_test.cc - cb_las_spanner_test.cc - ccb_parser_test.cc - ccb_test.cc - chain_hashing.cc - confidence_sequence_test.cc - continuous_actions_parser_test.cc - custom_reduction_test.cc - distributionally_robust_test.cc - main.cc - tag_utils_test.cc - test_common.cc - test_common.h -) - -if (VW_BUILD_LAS_WITH_SIMD AND (UNIX AND NOT APPLE) AND (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")) - target_compile_definitions(vw-unit-test.out PUBLIC BUILD_LAS_WITH_SIMD) -endif() - -# Add the include directories from vw target for testing -target_link_libraries(vw-unit-test.out PRIVATE vw_core vw_test_common Boost::unit_test_framework) -target_include_directories(vw-unit-test.out PRIVATE $) - -# Automatically set BOOST_TEST_DYN_LINK if the dependency is shared. -get_target_property(boost_test_target_type Boost::unit_test_framework TYPE) -if (boost_test_target_type STREQUAL SHARED_LIBRARY) - message(STATUS "Boost::unit_test_framework looks to be a shared library. Adding BOOST_TEST_DYN_LINK") - target_compile_definitions(vw-unit-test.out PRIVATE BOOST_TEST_DYN_LINK) -elseif(boost_test_target_type STREQUAL UNKNOWN_LIBRARY) - # Try inferring type if vcpkg is used - if (DEFINED VCPKG_TARGET_TRIPLET) - if (VCPKG_TARGET_TRIPLET EQUAL "x64-windows" OR VCPKG_TARGET_TRIPLET EQUAL "x86-windows" OR VCPKG_TARGET_TRIPLET EQUAL "arm64-osx-dynamic" OR VCPKG_TARGET_TRIPLET EQUAL "x64-osx-dynamic") - message(STATUS "Boost::unit_test_framework looks to be a shared library based on vcpkg triplet ${VCPKG_TARGET_TRIPLET}. Adding BOOST_TEST_DYN_LINK") - target_compile_definitions(vw-unit-test.out PRIVATE BOOST_TEST_DYN_LINK) - endif() - # If find_package is used then by default we're looking at a shared dependency unless Boost_USE_STATIC_LIBS was set. - elseif(NOT Boost_USE_STATIC_LIBS) - get_target_property(boost_test_path Boost::unit_test_framework LOCATION) - get_filename_component(boost_test_lib_ext ${boost_test_path} EXT) - if(NOT ${boost_test_lib_ext} IN_LIST STATIC_LIB_SUFFIXES) - message(STATUS "Found Boost::unit_test_framework library at: ${boost_test_path}") - message(STATUS "Looks like a shared library. Adding BOOST_TEST_DYN_LINK") - target_compile_definitions(vw-unit-test.out PRIVATE BOOST_TEST_DYN_LINK) - endif() - endif() -endif() - -if(VW_UNIT_TEST_WITH_VALGRIND_INTERNAL) - add_test( - NAME vw_unit_test - COMMAND ${VALGRIND} --error-exitcode=100 --track-origins=yes --leak-check=full $ "--run_test=!*w_iterations*" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) -else() - if (VW_USE_ASAN OR VW_USE_ASAN) - add_test( - NAME vw_unit_test - COMMAND $ "--run_test=!*w_iterations*" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) - else() - add_test( - NAME vw_unit_test - COMMAND $ - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) - endif() -endif() - -set_tests_properties(vw_unit_test PROPERTIES LABELS "VWTestList") diff --git a/test/unit_test/ccb_parser_test.cc b/test/unit_test/ccb_parser_test.cc deleted file mode 100644 index 0317505f20a..00000000000 --- a/test/unit_test/ccb_parser_test.cc +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright (c) by respective owners including Yahoo!, Microsoft, and -// individual contributors. All rights reserved. Released under a BSD (revised) -// license as described in the file LICENSE. - -#include "test_common.h" -#include "vw/common/string_view.h" -#include "vw/common/text_utils.h" -#include "vw/core/ccb_label.h" -#include "vw/core/memory.h" -#include "vw/core/parse_primitives.h" -#include "vw/core/parser.h" -#include "vw/core/reductions/conditional_contextual_bandit.h" -#include "vw/io/logger.h" - -#include -#include -#include -#include - -void parse_ccb_label(VW::string_view label, VW::ccb_label& l) -{ - std::vector words; - VW::tokenize(' ', label, words); - l.reset_to_default(); - VW::label_parser_reuse_mem mem; - auto null_logger = VW::io::create_null_logger(); - VW::parse_ccb_label(l, mem, words, null_logger); -} - -BOOST_AUTO_TEST_CASE(ccb_parse_label) -{ - { - auto label = VW::make_unique(); - parse_ccb_label("ccb shared", *label); - BOOST_CHECK_EQUAL(label->explicit_included_actions.size(), 0); - BOOST_CHECK(label->outcome == nullptr); - BOOST_CHECK_EQUAL(label->type, VW::ccb_example_type::SHARED); - } - { - auto label = VW::make_unique(); - parse_ccb_label("ccb action", *label.get()); - BOOST_CHECK_EQUAL(label->explicit_included_actions.size(), 0); - BOOST_CHECK(label->outcome == nullptr); - BOOST_CHECK_EQUAL(label->type, VW::ccb_example_type::ACTION); - } - { - auto label = VW::make_unique(); - parse_ccb_label("ccb slot", *label.get()); - BOOST_CHECK_EQUAL(label->explicit_included_actions.size(), 0); - BOOST_CHECK(label->outcome == nullptr); - BOOST_CHECK_EQUAL(label->type, VW::ccb_example_type::SLOT); - } - { - auto label = VW::make_unique(); - parse_ccb_label("ccb slot 1,3,4", *label.get()); - BOOST_CHECK_EQUAL(label->explicit_included_actions.size(), 3); - BOOST_CHECK_EQUAL(label->explicit_included_actions[0], 1); - BOOST_CHECK_EQUAL(label->explicit_included_actions[1], 3); - BOOST_CHECK_EQUAL(label->explicit_included_actions[2], 4); - BOOST_CHECK(label->outcome == nullptr); - BOOST_CHECK_EQUAL(label->type, VW::ccb_example_type::SLOT); - } - { - auto label = VW::make_unique(); - parse_ccb_label("ccb slot 1:1.0:0.5 3", *label.get()); - BOOST_CHECK_EQUAL(label->explicit_included_actions.size(), 1); - BOOST_CHECK_EQUAL(label->explicit_included_actions[0], 3); - BOOST_CHECK_CLOSE(label->outcome->cost, 1.0f, FLOAT_TOL); - BOOST_CHECK_EQUAL(label->outcome->probabilities.size(), 1); - BOOST_CHECK_EQUAL(label->outcome->probabilities[0].action, 1); - BOOST_CHECK_CLOSE(label->outcome->probabilities[0].score, .5f, FLOAT_TOL); - BOOST_CHECK_EQUAL(label->type, VW::ccb_example_type::SLOT); - } - { - auto label = VW::make_unique(); - parse_ccb_label("ccb slot 1:-2.0:0.5,2:0.25,3:0.25 3,4", *label.get()); - BOOST_CHECK_EQUAL(label->explicit_included_actions.size(), 2); - BOOST_CHECK_EQUAL(label->explicit_included_actions[0], 3); - BOOST_CHECK_EQUAL(label->explicit_included_actions[1], 4); - BOOST_CHECK_CLOSE(label->outcome->cost, -2.0f, FLOAT_TOL); - BOOST_CHECK_EQUAL(label->outcome->probabilities.size(), 3); - BOOST_CHECK_EQUAL(label->outcome->probabilities[0].action, 1); - BOOST_CHECK_CLOSE(label->outcome->probabilities[0].score, .5f, FLOAT_TOL); - BOOST_CHECK_EQUAL(label->outcome->probabilities[1].action, 2); - BOOST_CHECK_CLOSE(label->outcome->probabilities[1].score, .25f, FLOAT_TOL); - BOOST_CHECK_EQUAL(label->outcome->probabilities[2].action, 3); - BOOST_CHECK_CLOSE(label->outcome->probabilities[2].score, .25f, FLOAT_TOL); - BOOST_CHECK_EQUAL(label->type, VW::ccb_example_type::SLOT); - } - { - auto label = VW::make_unique(); - BOOST_REQUIRE_THROW(parse_ccb_label("shared", *label.get()), VW::vw_exception); - } - { - auto label = VW::make_unique(); - BOOST_REQUIRE_THROW(parse_ccb_label("other shared", *label.get()), VW::vw_exception); - } - { - auto label = VW::make_unique(); - BOOST_REQUIRE_THROW(parse_ccb_label("other", *label.get()), VW::vw_exception); - } - { - auto label = VW::make_unique(); - BOOST_REQUIRE_THROW(parse_ccb_label("ccb unknown", *label.get()), VW::vw_exception); - } - { - auto label = VW::make_unique(); - BOOST_REQUIRE_THROW(parse_ccb_label("ccb slot 1:1.0:0.5,4:0.7", *label.get()), VW::vw_exception); - } -} - -BOOST_AUTO_TEST_CASE(ccb_cache_label) -{ - auto backing_vector = std::make_shared>(); - io_buf io_writer; - io_writer.add_file(VW::io::create_vector_writer(backing_vector)); - - auto label = VW::make_unique(); - parse_ccb_label("ccb slot 1:-2.0:0.5,2:0.25,3:0.25 3,4", *label.get()); - VW::model_utils::write_model_field(io_writer, *label, "", false); - io_writer.flush(); - - io_buf io_reader; - io_reader.add_file(VW::io::create_buffer_view(backing_vector->data(), backing_vector->size())); - - auto uncached_label = VW::make_unique(); - uncached_label->reset_to_default(); - VW::model_utils::read_model_field(io_reader, *uncached_label); - - BOOST_CHECK_EQUAL(uncached_label->explicit_included_actions.size(), 2); - BOOST_CHECK_EQUAL(uncached_label->explicit_included_actions[0], 3); - BOOST_CHECK_EQUAL(uncached_label->explicit_included_actions[1], 4); - BOOST_CHECK_CLOSE(uncached_label->outcome->cost, -2.0f, FLOAT_TOL); - BOOST_CHECK_EQUAL(uncached_label->outcome->probabilities.size(), 3); - BOOST_CHECK_EQUAL(uncached_label->outcome->probabilities[0].action, 1); - BOOST_CHECK_CLOSE(uncached_label->outcome->probabilities[0].score, .5f, FLOAT_TOL); - BOOST_CHECK_EQUAL(uncached_label->outcome->probabilities[1].action, 2); - BOOST_CHECK_CLOSE(uncached_label->outcome->probabilities[1].score, .25f, FLOAT_TOL); - BOOST_CHECK_EQUAL(uncached_label->outcome->probabilities[2].action, 3); - BOOST_CHECK_CLOSE(uncached_label->outcome->probabilities[2].score, .25f, FLOAT_TOL); - BOOST_CHECK_EQUAL(uncached_label->type, VW::ccb_example_type::SLOT); -} - -BOOST_AUTO_TEST_CASE(ccb_copy_label) -{ - auto label = VW::make_unique(); - parse_ccb_label("ccb slot 1:-2.0:0.5,2:0.25,3:0.25 3,4", *label.get()); - - auto copied_to = VW::make_unique(); - copied_to->reset_to_default(); - - *copied_to = *label; - BOOST_CHECK_EQUAL(copied_to->explicit_included_actions.size(), 2); - BOOST_CHECK_EQUAL(copied_to->explicit_included_actions[0], 3); - BOOST_CHECK_EQUAL(copied_to->explicit_included_actions[1], 4); - BOOST_CHECK_CLOSE(copied_to->outcome->cost, -2.0f, FLOAT_TOL); - BOOST_CHECK_EQUAL(copied_to->outcome->probabilities.size(), 3); - BOOST_CHECK_EQUAL(copied_to->outcome->probabilities[0].action, 1); - BOOST_CHECK_CLOSE(copied_to->outcome->probabilities[0].score, .5f, FLOAT_TOL); - BOOST_CHECK_EQUAL(copied_to->outcome->probabilities[1].action, 2); - BOOST_CHECK_CLOSE(copied_to->outcome->probabilities[1].score, .25f, FLOAT_TOL); - BOOST_CHECK_EQUAL(copied_to->outcome->probabilities[2].action, 3); - BOOST_CHECK_CLOSE(copied_to->outcome->probabilities[2].score, .25f, FLOAT_TOL); - BOOST_CHECK_EQUAL(copied_to->type, VW::ccb_example_type::SLOT); -} diff --git a/test/unit_test/continuous_actions_parser_test.cc b/test/unit_test/continuous_actions_parser_test.cc deleted file mode 100644 index 2949501a00f..00000000000 --- a/test/unit_test/continuous_actions_parser_test.cc +++ /dev/null @@ -1,219 +0,0 @@ -// Copyright (c) by respective owners including Yahoo!, Microsoft, and -// individual contributors. All rights reserved. Released under a BSD (revised) -// license as described in the file LICENSE. - -#include "test_common.h" -#include "vw/common/string_view.h" -#include "vw/common/text_utils.h" -#include "vw/core/cb_continuous_label.h" -#include "vw/core/memory.h" -#include "vw/core/parse_primitives.h" -#include "vw/core/parser.h" -#include "vw/io/logger.h" - -#include -#include -#include -#include - -void parse_label(VW::label_parser& lp, VW::string_view label, VW::polylabel& l, VW::reduction_features& red_fts) -{ - std::vector words; - VW::tokenize(' ', label, words); - lp.default_label(l); - VW::label_parser_reuse_mem mem; - auto null_logger = VW::io::create_null_logger(); - lp.parse_label(l, red_fts, mem, nullptr, words, null_logger); -} - -BOOST_AUTO_TEST_CASE(continuous_actions_parse_label) -{ - auto lp = VW::cb_continuous::the_label_parser; - { - auto plabel = VW::make_unique(); - VW::reduction_features red_features; - parse_label(lp, "ca 185.121:0.657567:6.20426e-05", *plabel, red_features); - BOOST_CHECK_CLOSE(plabel->cb_cont.costs[0].pdf_value, 6.20426e-05, FLOAT_TOL); - BOOST_CHECK_CLOSE(plabel->cb_cont.costs[0].cost, 0.657567, FLOAT_TOL); - BOOST_CHECK_CLOSE(plabel->cb_cont.costs[0].action, 185.121, FLOAT_TOL); - - const auto& cats_reduction_features = red_features.template get(); - BOOST_CHECK_EQUAL(cats_reduction_features.is_chosen_action_set(), false); - BOOST_CHECK_EQUAL(cats_reduction_features.is_pdf_set(), false); - } -} - -BOOST_AUTO_TEST_CASE(continuous_actions_parse_label_and_pdf) -{ - auto lp = VW::cb_continuous::the_label_parser; - { - auto plabel = VW::make_unique(); - VW::reduction_features red_features; - - parse_label(lp, "ca 185.121:0.657567:6.20426e-05 pdf 185:8109.67:2.10314e-06 8109.67:23959:6.20426e-05", *plabel, - red_features); - // check label - BOOST_CHECK_CLOSE(plabel->cb_cont.costs[0].pdf_value, 6.20426e-05, FLOAT_TOL); - BOOST_CHECK_CLOSE(plabel->cb_cont.costs[0].cost, 0.657567, FLOAT_TOL); - BOOST_CHECK_CLOSE(plabel->cb_cont.costs[0].action, 185.121, FLOAT_TOL); - - // check pdf - const auto& cats_reduction_features = red_features.template get(); - BOOST_CHECK_EQUAL(cats_reduction_features.pdf.size(), 2); - BOOST_CHECK_EQUAL(cats_reduction_features.is_chosen_action_set(), false); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[0].left, 185., FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[0].right, 8109.67, FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[0].pdf_value, 2.10314e-06, FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[1].left, 8109.67, FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[1].right, 23959., FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[1].pdf_value, 6.20426e-05, FLOAT_TOL); - } -} - -BOOST_AUTO_TEST_CASE(continuous_actions_parse_only_pdf_no_label) -{ - auto lp = VW::cb_continuous::the_label_parser; - { - auto plabel = VW::make_unique(); - VW::reduction_features red_features; - parse_label(lp, "ca pdf 185:8109.67:2.10314e-06 8109.67:23959:6.20426e-05", *plabel, red_features); - BOOST_CHECK_EQUAL(plabel->cb_cont.costs.size(), 0); - - const auto& cats_reduction_features = red_features.template get(); - BOOST_CHECK_EQUAL(cats_reduction_features.pdf.size(), 2); - BOOST_CHECK_EQUAL(cats_reduction_features.is_chosen_action_set(), false); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[0].left, 185., FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[0].right, 8109.67, FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[0].pdf_value, 2.10314e-06, FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[1].left, 8109.67, FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[1].right, 23959., FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[1].pdf_value, 6.20426e-05, FLOAT_TOL); - } -} - -BOOST_AUTO_TEST_CASE(continuous_actions_parse_malformed_pdf) -{ - auto lp = VW::cb_continuous::the_label_parser; - { - auto plabel = VW::make_unique(); - VW::reduction_features red_features; - - parse_label(lp, "ca pdf 185:8109.67 8109.67:23959:6.20426e-05", *plabel, red_features); - - // check pdf - const auto& cats_reduction_features = red_features.template get(); - BOOST_CHECK_EQUAL(cats_reduction_features.pdf.size(), 0); - BOOST_CHECK_EQUAL(cats_reduction_features.is_chosen_action_set(), false); - BOOST_CHECK_EQUAL(cats_reduction_features.is_pdf_set(), false); - } -} - -BOOST_AUTO_TEST_CASE(continuous_actions_parse_label_and_chosen_action) -{ - auto lp = VW::cb_continuous::the_label_parser; - { - auto plabel = VW::make_unique(); - VW::reduction_features red_features; - parse_label(lp, "ca 185.121:0.657567:6.20426e-05 chosen_action 8110.121", *plabel, red_features); - - // check label - BOOST_CHECK_CLOSE(plabel->cb_cont.costs[0].pdf_value, 6.20426e-05, FLOAT_TOL); - BOOST_CHECK_CLOSE(plabel->cb_cont.costs[0].cost, 0.657567, FLOAT_TOL); - BOOST_CHECK_CLOSE(plabel->cb_cont.costs[0].action, 185.121, FLOAT_TOL); - - // check chosen action - const auto& cats_reduction_features = red_features.template get(); - BOOST_CHECK_EQUAL(cats_reduction_features.is_pdf_set(), false); - BOOST_CHECK_EQUAL(cats_reduction_features.is_chosen_action_set(), true); - BOOST_CHECK_CLOSE(cats_reduction_features.chosen_action, 8110.121, FLOAT_TOL); - } -} - -BOOST_AUTO_TEST_CASE(continuous_actions_chosen_action_only_no_label) -{ - auto lp = VW::cb_continuous::the_label_parser; - { - auto plabel = VW::make_unique(); - VW::reduction_features red_features; - parse_label(lp, "ca chosen_action 8110.121", *plabel, red_features); - - BOOST_CHECK_EQUAL(plabel->cb_cont.costs.size(), 0); - // check chosen action - const auto& cats_reduction_features = red_features.template get(); - BOOST_CHECK_EQUAL(cats_reduction_features.is_pdf_set(), false); - BOOST_CHECK_EQUAL(cats_reduction_features.is_chosen_action_set(), true); - BOOST_CHECK_CLOSE(cats_reduction_features.chosen_action, 8110.121, FLOAT_TOL); - } -} - -BOOST_AUTO_TEST_CASE(continuous_actions_parse_label_pdf_and_chosen_action) -{ - auto lp = VW::cb_continuous::the_label_parser; - { - auto plabel = VW::make_unique(); - VW::reduction_features red_features; - parse_label(lp, - "ca 185.121:0.657567:6.20426e-05 pdf 185:8109.67:2.10314e-06 8109.67:23959:6.20426e-05 chosen_action 8110.121", - *plabel, red_features); - - // check label - BOOST_CHECK_CLOSE(plabel->cb_cont.costs[0].pdf_value, 6.20426e-05, FLOAT_TOL); - BOOST_CHECK_CLOSE(plabel->cb_cont.costs[0].cost, 0.657567, FLOAT_TOL); - BOOST_CHECK_CLOSE(plabel->cb_cont.costs[0].action, 185.121, FLOAT_TOL); - - const auto& cats_reduction_features = red_features.template get(); - - // check chosen action - BOOST_CHECK_EQUAL(cats_reduction_features.is_chosen_action_set(), true); - BOOST_CHECK_CLOSE(cats_reduction_features.chosen_action, 8110.121, FLOAT_TOL); - - // check pdf - BOOST_CHECK_EQUAL(cats_reduction_features.pdf.size(), 2); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[0].left, 185., FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[0].right, 8109.67, FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[0].pdf_value, 2.10314e-06, FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[1].left, 8109.67, FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[1].right, 23959., FLOAT_TOL); - BOOST_CHECK_CLOSE(cats_reduction_features.pdf[1].pdf_value, 6.20426e-05, FLOAT_TOL); - } -} - -BOOST_AUTO_TEST_CASE(continuous_actions_parse_no_label) -{ - auto lp = VW::cb_continuous::the_label_parser; - { - auto plabel = VW::make_unique(); - VW::reduction_features red_features; - parse_label(lp, "", *plabel, red_features); - - BOOST_CHECK_EQUAL(plabel->cb_cont.costs.size(), 0); - const auto& cats_reduction_features = red_features.template get(); - BOOST_CHECK_EQUAL(cats_reduction_features.is_pdf_set(), false); - BOOST_CHECK_EQUAL(cats_reduction_features.is_chosen_action_set(), false); - } -} - -BOOST_AUTO_TEST_CASE(continuous_actions_parse_no_label_w_prefix) -{ - auto lp = VW::cb_continuous::the_label_parser; - { - auto plabel = VW::make_unique(); - VW::reduction_features red_features; - parse_label(lp, "ca", *plabel, red_features); - - BOOST_CHECK_EQUAL(plabel->cb_cont.costs.size(), 0); - const auto& cats_reduction_features = red_features.template get(); - BOOST_CHECK_EQUAL(cats_reduction_features.is_pdf_set(), false); - BOOST_CHECK_EQUAL(cats_reduction_features.is_chosen_action_set(), false); - } -} - -BOOST_AUTO_TEST_CASE(continus_actions_check_label_for_prefix) -{ - auto lp = VW::cb_continuous::the_label_parser; - { - auto plabel = VW::make_unique(); - VW::reduction_features red_features; - BOOST_REQUIRE_THROW(parse_label(lp, "185.121:0.657567:6.20426e-05", *plabel, red_features), VW::vw_exception); - } -} diff --git a/test/unit_test/main.cc b/test/unit_test/main.cc deleted file mode 100644 index 24e83be6b55..00000000000 --- a/test/unit_test/main.cc +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) by respective owners including Yahoo!, Microsoft, and -// individual contributors. All rights reserved. Released under a BSD (revised) -// license as described in the file LICENSE. - -#define BOOST_TEST_MODULE Main -#include diff --git a/test/unit_test/readme.md b/test/unit_test/readme.md new file mode 100644 index 00000000000..2fdbd7cd9a1 --- /dev/null +++ b/test/unit_test/readme.md @@ -0,0 +1,3 @@ +Unit tests have been moved to the relevant library test directory. + +For example, all `core` tests should be added [here](../../vowpalwabbit/core/tests/). \ No newline at end of file diff --git a/test/unit_test/test_common.cc b/test/unit_test/test_common.cc deleted file mode 100644 index b2e8a90d6a6..00000000000 --- a/test/unit_test/test_common.cc +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) by respective owners including Yahoo!, Microsoft, and -// individual contributors. All rights reserved. Released under a BSD (revised) -// license as described in the file LICENSE. - -#include "test_common.h" - -bool is_invoked_with(const std::string& arg) -{ - for (size_t i = 0; i < boost::unit_test::framework::master_test_suite().argc; i++) - { - if (VW::string_view(boost::unit_test::framework::master_test_suite().argv[i]).find(arg) != std::string::npos) - { - return true; - } - } - return false; -} \ No newline at end of file diff --git a/test/unit_test/test_common.h b/test/unit_test/test_common.h deleted file mode 100644 index a8d617fb82e..00000000000 --- a/test/unit_test/test_common.h +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) by respective owners including Yahoo!, Microsoft, and -// individual contributors. All rights reserved. Released under a BSD (revised) -// license as described in the file LICENSE. - -#pragma once - -#include "vw/core/action_score.h" -#include "vw/core/ccb_reduction_features.h" -#include "vw/core/shared_data.h" -#include "vw/core/slates_label.h" -#include "vw/core/vw.h" - -#include -#include -#include -#include - -constexpr float FLOAT_TOL = 0.0001f; - -inline void compare(float l, float r, float tol) { BOOST_CHECK_CLOSE(l, r, tol); } -inline void compare(const VW::action_score& l, const VW::action_score& r, float float_tolerance) -{ - BOOST_CHECK_EQUAL(l.action, r.action); - BOOST_CHECK_CLOSE(l.score, r.score, float_tolerance); -} - -template -void check_collections_with_float_tolerance( - const ContainerOneT& lhs, const ContainerTwoT& rhs, float float_tolerance = FLOAT_TOL) -{ - BOOST_CHECK_EQUAL(lhs.size(), rhs.size()); - auto l = std::begin(lhs); - auto r = std::begin(rhs); - for (; l < std::end(lhs); ++l, ++r) { compare(*l, *r, float_tolerance); } -} - -template