Skip to content

Commit 0acff41

Browse files
yiylinYiyong Lin
andauthored
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]>
1 parent db61936 commit 0acff41

File tree

13 files changed

+185
-3
lines changed

13 files changed

+185
-3
lines changed

.github/actions/build/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ runs:
88
if: ${{ runner.os == 'Linux' }}
99
run: |
1010
sudo scripts/dev/install-dev-deps-ubuntu.bash
11-
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
11+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DUNIT_TEST=True
1212
cmake --build build -- -j
1313
cmake --install build --prefix="dist"
1414
shell: bash
@@ -20,9 +20,9 @@ runs:
2020
- name: Run configure and build for Windows
2121
if: runner.os == 'Windows'
2222
run: |
23-
mkdir build && cd build && cmake .. && msbuild diskann.sln /m /nologo /t:Build /p:Configuration="Release" /property:Platform="x64" -consoleloggerparameters:"ErrorsOnly;Summary"
23+
mkdir build && cd build && cmake .. -DUNIT_TEST=True && msbuild diskann.sln /m /nologo /t:Build /p:Configuration="Release" /property:Platform="x64" -consoleloggerparameters:"ErrorsOnly;Summary"
2424
cd ..
2525
mkdir dist
26-
mv .\x64\Release\ .\dist\bin
26+
mklink /j .\dist\bin .\x64\Release\
2727
shell: cmd
2828
# ------------ End Windows Build ---------------

.github/workflows/pr-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ jobs:
66
fail-fast: true
77
name: DiskANN Common Build Checks
88
uses: ./.github/workflows/common.yml
9+
unit-tests:
10+
name: Unit tests
11+
uses: ./.github/workflows/unit-tests.yml
912
in-mem-pq:
1013
name: In-Memory with PQ
1114
uses: ./.github/workflows/in-mem-pq.yml

.github/workflows/unit-tests.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Unit Tests
2+
on: [workflow_call]
3+
jobs:
4+
acceptance-tests-labels:
5+
name: Unit Tests
6+
strategy:
7+
fail-fast: false
8+
matrix:
9+
os: [ubuntu-latest, windows-2019, windows-latest]
10+
runs-on: ${{matrix.os}}
11+
defaults:
12+
run:
13+
shell: bash
14+
steps:
15+
- name: Checkout repository
16+
if: ${{ runner.os == 'Linux' }}
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 1
20+
- name: Checkout repository
21+
if: ${{ runner.os == 'Windows' }}
22+
uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 1
25+
submodules: true
26+
- name: DiskANN Build CLI Applications
27+
uses: ./.github/actions/build
28+
29+
- name: Run Unit Tests
30+
run: |
31+
cd build
32+
ctest -C Release

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ MigrationBackup/
357357
cscope*
358358

359359
build/
360+
build_linux/
360361
!.github/actions/build
361362

362363
# jetbrains specific stuff

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ if (NOT PYBIND)
298298
add_subdirectory(apps/utils)
299299
endif()
300300
301+
if (UNIT_TEST)
302+
enable_testing()
303+
add_subdirectory(tests)
304+
endif()
305+
301306
if (MSVC)
302307
message(STATUS "The ${PROJECT_NAME}.sln has been created, opened it from VisualStudio to build Release or Debug configurations.\n"
303308
"Alternatively, use MSBuild to build:\n\n"

DockerfileDev

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#Copyright(c) Microsoft Corporation.All rights reserved.
2+
#Licensed under the MIT license.
3+
4+
FROM ubuntu:jammy
5+
6+
RUN apt update
7+
RUN apt install -y software-properties-common
8+
RUN add-apt-repository -y ppa:git-core/ppa
9+
RUN apt update
10+
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
11+
12+
WORKDIR /app
13+
RUN git clone https://github.com/microsoft/DiskANN.git
14+
WORKDIR /app/DiskANN
15+
RUN mkdir build
16+
RUN cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DUNIT_TEST=True
17+
RUN cmake --build build -- -j

include/parameters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <typeinfo>
77
#include <unordered_map>
88

9+
#include "omp.h"
910
#include "defaults.h"
1011

1112
namespace diskann

scripts/dev/install-dev-deps-ubuntu.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ apt install cmake \
88
clang-format \
99
libboost-dev \
1010
libboost-program-options-dev \
11+
libboost-test-dev \
1112
libmkl-full-dev

tests/CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT license.
3+
4+
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
5+
6+
find_package(Boost COMPONENTS unit_test_framework)
7+
8+
# For Windows, fall back to nuget version if find_package didn't find it.
9+
if (MSVC AND NOT Boost_FOUND)
10+
set(DISKANN_BOOST_INCLUDE "${DISKANN_MSVC_PACKAGES}/boost/lib/native/include")
11+
# Multi-threaded static library.
12+
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")
13+
file(GLOB DISKANN_BOOST_UNIT_TEST_FRAMEWORK_LIB ${UNIT_TEST_FRAMEWORK_LIB_PATTERN})
14+
15+
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")
16+
file(GLOB DISKANN_BOOST_UNIT_TEST_FRAMEWORK_DLIB ${UNIT_TEST_FRAMEWORK_DLIB_PATTERN})
17+
18+
if (EXISTS ${DISKANN_BOOST_INCLUDE} AND EXISTS ${DISKANN_BOOST_UNIT_TEST_FRAMEWORK_LIB} AND EXISTS ${DISKANN_BOOST_UNIT_TEST_FRAMEWORK_DLIB})
19+
set(Boost_FOUND ON)
20+
set(Boost_INCLUDE_DIR ${DISKANN_BOOST_INCLUDE})
21+
add_library(Boost::unit_test_framework STATIC IMPORTED)
22+
set_target_properties(Boost::unit_test_framework PROPERTIES IMPORTED_LOCATION_RELEASE "${DISKANN_BOOST_UNIT_TEST_FRAMEWORK_LIB}")
23+
set_target_properties(Boost::unit_test_framework PROPERTIES IMPORTED_LOCATION_DEBUG "${DISKANN_BOOST_UNIT_TEST_FRAMEWORK_DLIB}")
24+
message(STATUS "Falling back to using Boost from the nuget package")
25+
else()
26+
message(WARNING "Couldn't find Boost. Was looking for ${DISKANN_BOOST_INCLUDE} and ${UNIT_TEST_FRAMEWORK_LIB_PATTERN}")
27+
endif()
28+
endif()
29+
30+
if (NOT Boost_FOUND)
31+
message(FATAL_ERROR "Couldn't find Boost dependency")
32+
endif()
33+
34+
35+
set(DISKANN_UNIT_TEST_SOURCES main.cpp index_write_parameters_builder_tests.cpp)
36+
37+
add_executable(${PROJECT_NAME}_unit_tests ${DISKANN_SOURCES} ${DISKANN_UNIT_TEST_SOURCES})
38+
target_link_libraries(${PROJECT_NAME}_unit_tests ${PROJECT_NAME} ${DISKANN_TOOLS_TCMALLOC_LINK_OPTIONS} Boost::unit_test_framework)
39+
40+
add_test(NAME ${PROJECT_NAME}_unit_tests COMMAND ${PROJECT_NAME}_unit_tests)
41+

tests/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Unit Test project
2+
3+
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).
4+
5+
## How to add unit test
6+
7+
- 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
8+
9+
- 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)
10+
11+
- Update the [CMakeLists.txt](CMakeLists.txt) file to add the new cpp file to the test project

0 commit comments

Comments
 (0)