-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test project based on boost_unit_test_framework (#365)
* Add unit test project based on boost_unit_test_framework * Add another dockerfile for developers * update path --------- Co-authored-by: Yiyong Lin <[email protected]>
- Loading branch information
Showing
13 changed files
with
185 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Unit Tests | ||
on: [workflow_call] | ||
jobs: | ||
acceptance-tests-labels: | ||
name: Unit Tests | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, windows-2019, windows-latest] | ||
runs-on: ${{matrix.os}} | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- name: Checkout repository | ||
if: ${{ runner.os == 'Linux' }} | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 1 | ||
- name: Checkout repository | ||
if: ${{ runner.os == 'Windows' }} | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 1 | ||
submodules: true | ||
- name: DiskANN Build CLI Applications | ||
uses: ./.github/actions/build | ||
|
||
- name: Run Unit Tests | ||
run: | | ||
cd build | ||
ctest -C Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -357,6 +357,7 @@ MigrationBackup/ | |
cscope* | ||
|
||
build/ | ||
build_linux/ | ||
!.github/actions/build | ||
|
||
# jetbrains specific stuff | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#Copyright(c) Microsoft Corporation.All rights reserved. | ||
#Licensed under the MIT license. | ||
|
||
FROM ubuntu:jammy | ||
|
||
RUN apt update | ||
RUN apt install -y software-properties-common | ||
RUN add-apt-repository -y ppa:git-core/ppa | ||
RUN apt update | ||
RUN DEBIAN_FRONTEND=noninteractive apt install -y git make cmake g++ libaio-dev libgoogle-perftools-dev libunwind-dev clang-format libboost-dev libboost-program-options-dev libboost-test-dev libmkl-full-dev libcpprest-dev python3.10 | ||
|
||
WORKDIR /app | ||
RUN git clone https://github.com/microsoft/DiskANN.git | ||
WORKDIR /app/DiskANN | ||
RUN mkdir build | ||
RUN cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DUNIT_TEST=True | ||
RUN cmake --build build -- -j |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
#include <typeinfo> | ||
#include <unordered_map> | ||
|
||
#include "omp.h" | ||
#include "defaults.h" | ||
|
||
namespace diskann | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT license. | ||
|
||
set(CMAKE_COMPILE_WARNING_AS_ERROR ON) | ||
|
||
find_package(Boost COMPONENTS unit_test_framework) | ||
|
||
# For Windows, fall back to nuget version if find_package didn't find it. | ||
if (MSVC AND NOT Boost_FOUND) | ||
set(DISKANN_BOOST_INCLUDE "${DISKANN_MSVC_PACKAGES}/boost/lib/native/include") | ||
# Multi-threaded static library. | ||
set(UNIT_TEST_FRAMEWORK_LIB_PATTERN "${DISKANN_MSVC_PACKAGES}/boost_unit_test_framework-vc${MSVC_TOOLSET_VERSION}/lib/native/libboost_unit_test_framework-vc${MSVC_TOOLSET_VERSION}-mt-x64-*.lib") | ||
file(GLOB DISKANN_BOOST_UNIT_TEST_FRAMEWORK_LIB ${UNIT_TEST_FRAMEWORK_LIB_PATTERN}) | ||
|
||
set(UNIT_TEST_FRAMEWORK_DLIB_PATTERN "${DISKANN_MSVC_PACKAGES}/boost_unit_test_framework-vc${MSVC_TOOLSET_VERSION}/lib/native/libboost_unit_test_framework-vc${MSVC_TOOLSET_VERSION}-mt-gd-x64-*.lib") | ||
file(GLOB DISKANN_BOOST_UNIT_TEST_FRAMEWORK_DLIB ${UNIT_TEST_FRAMEWORK_DLIB_PATTERN}) | ||
|
||
if (EXISTS ${DISKANN_BOOST_INCLUDE} AND EXISTS ${DISKANN_BOOST_UNIT_TEST_FRAMEWORK_LIB} AND EXISTS ${DISKANN_BOOST_UNIT_TEST_FRAMEWORK_DLIB}) | ||
set(Boost_FOUND ON) | ||
set(Boost_INCLUDE_DIR ${DISKANN_BOOST_INCLUDE}) | ||
add_library(Boost::unit_test_framework STATIC IMPORTED) | ||
set_target_properties(Boost::unit_test_framework PROPERTIES IMPORTED_LOCATION_RELEASE "${DISKANN_BOOST_UNIT_TEST_FRAMEWORK_LIB}") | ||
set_target_properties(Boost::unit_test_framework PROPERTIES IMPORTED_LOCATION_DEBUG "${DISKANN_BOOST_UNIT_TEST_FRAMEWORK_DLIB}") | ||
message(STATUS "Falling back to using Boost from the nuget package") | ||
else() | ||
message(WARNING "Couldn't find Boost. Was looking for ${DISKANN_BOOST_INCLUDE} and ${UNIT_TEST_FRAMEWORK_LIB_PATTERN}") | ||
endif() | ||
endif() | ||
|
||
if (NOT Boost_FOUND) | ||
message(FATAL_ERROR "Couldn't find Boost dependency") | ||
endif() | ||
|
||
|
||
set(DISKANN_UNIT_TEST_SOURCES main.cpp index_write_parameters_builder_tests.cpp) | ||
|
||
add_executable(${PROJECT_NAME}_unit_tests ${DISKANN_SOURCES} ${DISKANN_UNIT_TEST_SOURCES}) | ||
target_link_libraries(${PROJECT_NAME}_unit_tests ${PROJECT_NAME} ${DISKANN_TOOLS_TCMALLOC_LINK_OPTIONS} Boost::unit_test_framework) | ||
|
||
add_test(NAME ${PROJECT_NAME}_unit_tests COMMAND ${PROJECT_NAME}_unit_tests) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Unit Test project | ||
|
||
This unit test project is based on the [boost unit test framework](https://www.boost.org/doc/libs/1_78_0/libs/test/doc/html/index.html). Below are the simple steps to add new unit test, you could find more usage from the [boost unit test document](https://www.boost.org/doc/libs/1_78_0/libs/test/doc/html/index.html). | ||
|
||
## How to add unit test | ||
|
||
- Create new [BOOST_AUTO_TEST_SUITE](https://www.boost.org/doc/libs/1_78_0/libs/test/doc/html/boost_test/utf_reference/test_org_reference/test_org_boost_auto_test_suite.html) for each class in an individual cpp file | ||
|
||
- Add [BOOST_AUTO_TEST_CASE](https://www.boost.org/doc/libs/1_78_0/libs/test/doc/html/boost_test/utf_reference/test_org_reference/test_org_boost_auto_test_case.html) for each test case in the [BOOST_AUTO_TEST_SUITE](https://www.boost.org/doc/libs/1_78_0/libs/test/doc/html/boost_test/utf_reference/test_org_reference/test_org_boost_auto_test_suite.html) | ||
|
||
- Update the [CMakeLists.txt](CMakeLists.txt) file to add the new cpp file to the test project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
#include "parameters.h" | ||
|
||
BOOST_AUTO_TEST_SUITE(IndexWriteParametersBuilder_tests) | ||
|
||
BOOST_AUTO_TEST_CASE(test_build) | ||
{ | ||
uint32_t search_list_size = rand(); | ||
uint32_t max_degree = rand(); | ||
float alpha = (float)rand(); | ||
uint32_t filter_list_size = rand(); | ||
uint32_t max_occlusion_size = rand(); | ||
uint32_t num_frozen_points = rand(); | ||
bool saturate_graph = true; | ||
|
||
diskann::IndexWriteParametersBuilder builder(search_list_size, max_degree); | ||
|
||
builder.with_alpha(alpha) | ||
.with_filter_list_size(filter_list_size) | ||
.with_max_occlusion_size(max_occlusion_size) | ||
.with_num_frozen_points(num_frozen_points) | ||
.with_num_threads(0) | ||
.with_saturate_graph(saturate_graph); | ||
|
||
{ | ||
auto parameters = builder.build(); | ||
|
||
BOOST_TEST(search_list_size == parameters.search_list_size); | ||
BOOST_TEST(max_degree == parameters.max_degree); | ||
BOOST_TEST(alpha == parameters.alpha); | ||
BOOST_TEST(filter_list_size == parameters.filter_list_size); | ||
BOOST_TEST(max_occlusion_size == parameters.max_occlusion_size); | ||
BOOST_TEST(num_frozen_points == parameters.num_frozen_points); | ||
BOOST_TEST(saturate_graph == parameters.saturate_graph); | ||
|
||
BOOST_TEST(parameters.num_threads > (uint32_t)0); | ||
} | ||
|
||
{ | ||
uint32_t num_threads = rand() + 1; | ||
saturate_graph = false; | ||
builder.with_num_threads(num_threads) | ||
.with_saturate_graph(saturate_graph); | ||
|
||
auto parameters = builder.build(); | ||
|
||
BOOST_TEST(search_list_size == parameters.search_list_size); | ||
BOOST_TEST(max_degree == parameters.max_degree); | ||
BOOST_TEST(alpha == parameters.alpha); | ||
BOOST_TEST(filter_list_size == parameters.filter_list_size); | ||
BOOST_TEST(max_occlusion_size == parameters.max_occlusion_size); | ||
BOOST_TEST(num_frozen_points == parameters.num_frozen_points); | ||
BOOST_TEST(saturate_graph == parameters.saturate_graph); | ||
|
||
BOOST_TEST(num_threads == parameters.num_threads); | ||
} | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
#define BOOST_TEST_MODULE diskann_unit_tests | ||
|
||
#include <boost/test/unit_test.hpp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters