Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revive the C++ tests, make them pass and enable them on the CI #160

Merged
merged 7 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ jobs:
export PATH=$HOME/miniconda/bin:$PATH
. activate habitat
export PYTHONPATH=$PYTHONPATH:$(pwd)
./build.sh --headless
GTEST_COLOR=yes ./build.sh --headless --run-tests
pytest
- run:
name: Install api
Expand Down
16 changes: 2 additions & 14 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ fi
python setup.py build_ext --inplace "${builder_args[@]}"

if [ "$RUN_TESTS" = true ] ; then
cd ..
echo "Running tests..."
TEST_SCRIPTS=$(find "build/tests" -type f -perm +111)
declare -i RET_VAL=0
for test_script in $TEST_SCRIPTS ; do
echo "Running $test_script"
$test_script
RET_VAL+=$?
done
if [ "$RET_VAL" -ne 0 ] ; then
echo "Some tests failed."
else
echo "All tests passed."
fi
cd build
ctest -V
fi
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ endif()
# build tests
if(BUILD_TEST)
message("Building TESTS")
enable_testing()
add_subdirectory(tests)
endif()

Expand Down
5 changes: 5 additions & 0 deletions src/cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ include_directories(SYSTEM "${DEPS_DIR}/Sophus")
if(CORRADE_TARGET_EMSCRIPTEN)
add_library(glog INTERFACE)
else()
# We don't want glog tests to be run as part of our build. The BUILD_TESTING
# variable is set by include(CTest) as an option(). In CMake 3.13+ it should
# be enough to do just set(BUILD_TESTING OFF) to avoid the option()
# overriding it, but https://cmake.org/cmake/help/latest/policy/CMP0077.html.
option(BUILD_TESTING "ugh" OFF)
add_subdirectory("${DEPS_DIR}/glog")
endif()

Expand Down
2 changes: 1 addition & 1 deletion src/deps/googletest
Submodule googletest updated 214 files
41 changes: 27 additions & 14 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
cmake_minimum_required(VERSION 3.0)

macro(TEST TEST_NAME)
add_executable(${TEST_NAME} "${TEST_NAME}.cpp")
target_link_libraries(${TEST_NAME} core gtest_main)
set(DEPENDENCIES "${ARGN}")
foreach(DEPENDENCY IN LISTS DEPENDENCIES)
target_link_libraries(${TEST_NAME} ${DEPENDENCY})
endforeach()
# set_target_properties(${TEST_NAME} PROPERTIES FOLDER "tests"
# RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests")
add_test(${TEST_NAME} ${TEST_NAME})
endmacro(TEST)

set(SCENE_DATASETS ${CMAKE_CURRENT_SOURCE_DIR}/../../data/scene_datasets)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/configure.h)

TEST(CoreTest io)

TEST(NavTest nav assets)
target_include_directories(NavTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

TEST(IOTest io)
target_include_directories(IOTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

TEST(GeoTest geo)

TEST(Mp3dTest scene)
target_include_directories(Mp3dTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

TEST(SimTest sim)
target_include_directories(SimTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

TEST(SuncgTest scene)
TEST(main)

# file(GLOB_RECURSE TEST_SRCS "*.cpp")
# foreach(test_src ${TEST_SRCS})
# get_filename_component(test_name ${test_src} NAME_WE)
# add_executable(${test_name} "${test_src}")
# # target_link_libraries(${test_name} ${Caffe2_MAIN_LIBS} gtest_main)
# target_link_libraries(${test_name} assets glog gtest_main)
# add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
# endforeach()
target_include_directories(SuncgTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

# Some tests are LOUD, we don't want to include their full log (but OTOH we
# want to have full log from others, so this is a compromise)
set_tests_properties(
NavTest
Mp3dTest
SuncgTest
PROPERTIES ENVIRONMENT GLOG_minloglevel=1
)
set_tests_properties(SimTest PROPERTIES
ENVIRONMENT "GLOG_minloglevel=1;MAGNUM_LOG=QUIET")
4 changes: 0 additions & 4 deletions src/tests/CoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

using namespace esp::core;

TEST(CoreTest, TwoPlusTwo) {
EXPECT_EQ(4, 2 + 2);
}

TEST(CoreTest, ConfigurationTest) {
Configuration cfg;
cfg.set("myInt", 10);
Expand Down
6 changes: 4 additions & 2 deletions src/tests/IOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
#include "esp/core/esp.h"
#include "esp/io/io.h"

#include "configure.h"

using namespace esp::io;

TEST(IOTest, fileExistTest) {
std::string file = "build/tests/IOTest";
std::string file = FILE_THAT_EXISTS;
bool result = exists(file);
EXPECT_TRUE(result);

Expand All @@ -19,7 +21,7 @@ TEST(IOTest, fileExistTest) {
}

TEST(IOTest, fileSizeTest) {
std::string existingFile = "build/tests/IOTest";
std::string existingFile = FILE_THAT_EXISTS;
auto result = fileSize(existingFile);
LOG(INFO) << "File size of " << existingFile << " is " << result;

Expand Down
12 changes: 11 additions & 1 deletion src/tests/Mp3dTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

#include <Corrade/Utility/Directory.h>
#include <gtest/gtest.h>

#include "esp/scene/SemanticScene.h"

#include "configure.h"

namespace Cr = Corrade;

using namespace esp;
using namespace esp::geo;
using namespace esp::scene;

TEST(Mp3dTest, Load) {
const std::string filename = Cr::Utility::Directory::join(
SCENE_DATASETS, "mp3d/1LXtFkjw3qL/1LXtFkjw3qL.house");
if (!Cr::Utility::Directory::exists(filename))
GTEST_SKIP_("MP3D dataset not found.");

SemanticScene house;
const quatf alignGravity =
quatf::FromTwoVectors(-vec3f::UnitZ(), ESP_GRAVITY);
const quatf alignFront = quatf::FromTwoVectors(-vec3f::UnitX(), ESP_FRONT);
SemanticScene::loadMp3dHouse("test.house", house, alignFront * alignGravity);
SemanticScene::loadMp3dHouse(filename, house, alignFront * alignGravity);
LOG(INFO) << "House{nobjects:" << house.count("objects")
<< ",nlevels:" << house.count("levels")
<< ",nregions:" << house.count("regions")
Expand Down
12 changes: 10 additions & 2 deletions src/tests/NavTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

#include <Corrade/Utility/Directory.h>
#include <gtest/gtest.h>

#include "esp/agent/Agent.h"
#include "esp/core/esp.h"
#include "esp/core/random.h"
#include "esp/nav/PathFinder.h"
#include "esp/scene/ObjectControls.h"
#include "esp/scene/SceneGraph.h"

#include "configure.h"

namespace Cr = Corrade;

using namespace esp;
using namespace esp::nav;

Expand Down Expand Up @@ -44,7 +50,8 @@ void testPathFinder(PathFinder& pf) {

TEST(NavTest, PathFinderLoadTest) {
PathFinder pf;
pf.loadNavMesh("test.navmesh");
pf.loadNavMesh(Cr::Utility::Directory::join(
SCENE_DATASETS, "habitat-test-scenes/skokloster-castle.navmesh"));
testPathFinder(pf);
}

Expand Down Expand Up @@ -79,7 +86,8 @@ void printRandomizedPathSet(PathFinder& pf) {

TEST(NavTest, PathFinderTestCases) {
PathFinder pf;
pf.loadNavMesh("test.navmesh");
pf.loadNavMesh(Cr::Utility::Directory::join(
SCENE_DATASETS, "habitat-test-scenes/skokloster-castle.navmesh"));
ShortestPath testPath;
testPath.requestedStart = vec3f(-6.493, 0.072, -3.292);
testPath.requestedEnd = vec3f(-8.98, 0.072, -0.62);
Expand Down
28 changes: 17 additions & 11 deletions src/tests/SimTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,52 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

#include <Corrade/Utility/Directory.h>
#include <gtest/gtest.h>
#include <string>

#include "esp/sim/SimulatorWithAgents.h"

#include <string>
#include "configure.h"

namespace Cr = Corrade;

using esp::gfx::SimulatorConfiguration;
using esp::nav::PathFinder;
using esp::scene::SceneConfiguration;
using esp::sim::SimulatorWithAgents;

const std::string vangogh =
"../data/scene_datasets/habitat-test-scenes/van-gogh-room.glb";
Cr::Utility::Directory::join(SCENE_DATASETS,
"habitat-test-scenes/van-gogh-room.glb");
const std::string skokloster =
"../data/scene_datasets/habitat-test-scenes/skokloster-castle.glb";
Cr::Utility::Directory::join(SCENE_DATASETS,
"habitat-test-scenes/skokloster-castle.glb");

TEST(SimTest, Basic) {
SceneConfiguration scene{.id = vangogh};
SimulatorConfiguration cfg{.scene = scene};
SimulatorConfiguration cfg;
cfg.scene.id = vangogh;
SimulatorWithAgents simulator(cfg);
PathFinder::ptr pathfinder = simulator.getPathFinder();
ASSERT_NE(pathfinder, nullptr);
}

TEST(SimTest, Reconfigure) {
SceneConfiguration scene{.id = vangogh};
SimulatorConfiguration cfg{.scene = scene};
SimulatorConfiguration cfg;
cfg.scene.id = vangogh;
SimulatorWithAgents simulator(cfg);
PathFinder::ptr pathfinder = simulator.getPathFinder();
simulator.reconfigure(cfg);
ASSERT_EQ(pathfinder, simulator.getPathFinder());
SceneConfiguration scene2{.id = skokloster};
SimulatorConfiguration cfg2{.scene = scene2};
SimulatorConfiguration cfg2;
cfg2.scene.id = skokloster;
simulator.reconfigure(cfg2);
ASSERT_NE(pathfinder, simulator.getPathFinder());
}

TEST(SimTest, Reset) {
SceneConfiguration scene{.id = vangogh};
SimulatorConfiguration cfg{.scene = scene};
SimulatorConfiguration cfg;
cfg.scene.id = vangogh;
SimulatorWithAgents simulator(cfg);
PathFinder::ptr pathfinder = simulator.getPathFinder();
simulator.reset();
Expand Down
12 changes: 11 additions & 1 deletion src/tests/SuncgTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

#include <Corrade/Utility/Directory.h>
#include <gtest/gtest.h>

#include "esp/scene/SemanticScene.h"

#include "configure.h"

namespace Cr = Corrade;

using namespace esp;
using namespace esp::geo;
using namespace esp::scene;

TEST(SuncgTest, Load) {
const std::string filename = Cr::Utility::Directory::join(
SCENE_DATASETS, "suncg/0a0b9b45a1db29832dd84e80c1347854.json");
if (!Cr::Utility::Directory::exists(filename))
GTEST_SKIP_("SUNCG dataset not found.");

SemanticScene house;
SemanticScene::loadSuncgHouse("test.json", house);
SemanticScene::loadSuncgHouse(filename, house);
LOG(INFO) << "House, bbox:" << house.aabb();

for (auto& level : house.levels()) {
Expand Down
7 changes: 7 additions & 0 deletions src/tests/configure.h.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Facebook, Inc. and its affiliates.
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

#define SCENE_DATASETS "${SCENE_DATASETS}"

#define FILE_THAT_EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/IOTest.cpp"
14 changes: 0 additions & 14 deletions src/tests/main.cpp

This file was deleted.