Build and run all tests found by the glob. (#258)

master
Wolfgang Hess 2017-05-03 16:55:13 +02:00 committed by GitHub
parent ff06e37579
commit 6d2feaa8c7
16 changed files with 10 additions and 581 deletions

View File

@ -86,6 +86,13 @@ list(APPEND ALL_SRCS ${ALL_PROTO_SRCS} ${ALL_PROTO_HDRS})
add_library(${PROJECT_NAME} ${ALL_SRCS})
add_subdirectory("cartographer")
foreach(ABS_FIL ${ALL_TESTS})
file(RELATIVE_PATH REL_FIL ${PROJECT_SOURCE_DIR} ${ABS_FIL})
get_filename_component(DIR ${REL_FIL} DIRECTORY)
get_filename_component(FIL_WE ${REL_FIL} NAME_WE)
google_test("${DIR}/${FIL_WE}" ${ABS_FIL})
endforeach()
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC
"${EIGEN3_INCLUDE_DIR}")
target_link_libraries(${PROJECT_NAME} PUBLIC ${EIGEN3_LIBRARIES})

View File

@ -14,10 +14,3 @@
add_subdirectory("common")
add_subdirectory("ground_truth")
add_subdirectory("io")
add_subdirectory("kalman_filter")
add_subdirectory("mapping")
add_subdirectory("mapping_2d")
add_subdirectory("mapping_3d")
add_subdirectory("sensor")
add_subdirectory("transform")

View File

@ -15,33 +15,3 @@
configure_file (
${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/config.h)
google_test(common_blocking_queue_test
SRCS
blocking_queue_test.cc
)
google_test(common_configuration_files_test
SRCS
configuration_files_test.cc
)
google_test(common_fixed_ratio_sampler_test
SRCS
fixed_ratio_sampler_test.cc
)
google_test(common_lua_parameter_dictionary_test
SRCS
lua_parameter_dictionary_test.cc
)
google_test(common_math_test
SRCS
math_test.cc
)
google_test(common_rate_timer_test
SRCS
rate_timer_test.cc
)

View File

@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
google_binary(cartographer_compute_relations_metrics
SRCS
compute_relations_metrics_main.cc

View File

@ -1,18 +0,0 @@
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
google_test(io_proto_stream_test
SRCS
proto_stream_test.cc
)

View File

@ -1,28 +0,0 @@
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
google_test(kalman_filter_gaussian_distribution_test
SRCS
gaussian_distribution_test.cc
)
google_test(kalman_filter_pose_tracker_test
SRCS
pose_tracker_test.cc
)
google_test(kalman_filter_unscented_kalman_filter_test
SRCS
unscented_kalman_filter_test.cc
)

View File

@ -1,33 +0,0 @@
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
google_test(mapping_probability_values_test
SRCS
probability_values_test.cc
)
google_test(mapping_sparse_pose_graph_test
SRCS
sparse_pose_graph_test.cc
)
google_test(mapping_submaps_test
SRCS
submaps_test.cc
)
google_test(mapping_trajectory_connectivity_test
SRCS
trajectory_connectivity_test.cc
)

View File

@ -1,45 +0,0 @@
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
add_subdirectory("scan_matching")
google_test(mapping_2d_range_data_inserter_test
SRCS
range_data_inserter_test.cc
)
google_test(mapping_2d_map_limits_test
SRCS
map_limits_test.cc
)
google_test(mapping_2d_probability_grid_test
SRCS
probability_grid_test.cc
)
google_test(mapping_2d_sparse_pose_graph_test
SRCS
sparse_pose_graph_test.cc
)
google_test(mapping_2d_submaps_test
SRCS
submaps_test.cc
)
google_test(mapping_2d_xy_index_test
SRCS
xy_index_test.cc
)

View File

@ -1,33 +0,0 @@
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
google_test(mapping_2d_scan_matching_ceres_scan_matcher_test
SRCS
ceres_scan_matcher_test.cc
)
google_test(mapping_2d_scan_matching_correlative_scan_matcher_test
SRCS
correlative_scan_matcher_test.cc
)
google_test(mapping_2d_scan_matching_fast_correlative_scan_matcher_test
SRCS
fast_correlative_scan_matcher_test.cc
)
google_test(mapping_2d_scan_matching_real_time_correlative_scan_matcher_test
SRCS
real_time_correlative_scan_matcher_test.cc
)

View File

@ -1,36 +0,0 @@
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
add_subdirectory("scan_matching")
add_subdirectory("sparse_pose_graph")
google_test(mapping_3d_hybrid_grid_test
SRCS
hybrid_grid_test.cc
)
google_test(mapping_3d_kalman_local_trajectory_builder_test
SRCS
kalman_local_trajectory_builder_test.cc
)
google_test(mapping_3d_range_data_inserter_test
SRCS
range_data_inserter_test.cc
)
google_test(mapping_3d_motion_filter_test
SRCS
motion_filter_test.cc
)

View File

@ -1,38 +0,0 @@
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
google_test(mapping_3d_scan_matching_ceres_scan_matcher_test
SRCS
ceres_scan_matcher_test.cc
)
google_test(mapping_3d_scan_matching_fast_correlative_scan_matcher_test
SRCS
fast_correlative_scan_matcher_test.cc
)
google_test(mapping_3d_scan_matching_interpolated_grid_test
SRCS
interpolated_grid_test.cc
)
google_test(mapping_3d_scan_matching_precomputation_grid_test
SRCS
precomputation_grid_test.cc
)
google_test(mapping_3d_scan_matching_real_time_correlative_scan_matcher_test
SRCS
real_time_correlative_scan_matcher_test.cc
)

View File

@ -1,18 +0,0 @@
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
google_test(mapping_3d_sparse_pose_graph_optimization_problem_test
SRCS
optimization_problem_test.cc
)

View File

@ -1,43 +0,0 @@
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
google_test(sensor_collator_test
SRCS
collator_test.cc
)
google_test(sensor_compressed_point_cloud_test
SRCS
compressed_point_cloud_test.cc
)
google_test(sensor_range_data_test
SRCS
range_data_test.cc
)
google_test(sensor_ordered_multi_queue_test
SRCS
ordered_multi_queue_test.cc
)
google_test(sensor_point_cloud_test
SRCS
point_cloud_test.cc
)
google_test(sensor_voxel_filter_test
SRCS
voxel_filter_test.cc
)

View File

@ -1,23 +0,0 @@
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
google_test(transform_transform_interpolation_buffer_test
SRCS
transform_interpolation_buffer_test.cc
)
google_test(transform_transform_test
SRCS
transform_test.cc
)

View File

@ -32,12 +32,8 @@ macro(_common_compile_stuff VISIBILITY)
target_link_libraries(${NAME} PUBLIC ${PROJECT_NAME})
endmacro(_common_compile_stuff)
function(google_test NAME)
_parse_arguments("${ARGN}")
add_executable(${NAME}
${ARG_SRCS} ${ARG_HDRS}
)
function(google_test NAME ARG_SRC)
add_executable(${NAME} ${ARG_SRC})
_common_compile_stuff("PRIVATE")
# Make sure that gmock always includes the correct gtest/gtest.h.
@ -51,9 +47,7 @@ endfunction()
function(google_binary NAME)
_parse_arguments("${ARGN}")
add_executable(${NAME}
${ARG_SRCS} ${ARG_HDRS}
)
add_executable(${NAME} ${ARG_SRCS})
_common_compile_stuff("PRIVATE")

View File

@ -1,219 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2016 The Cartographer Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""A dumb CMakeLists.txt generator that relies on source name conventions."""
from os import path
import argparse
import collections
import os
import re
def MakeRelative(filename, directory):
absolute_directory = path.realpath(directory)
filename = path.realpath(filename)
return path.relpath(filename, absolute_directory)
def MaybeUseCmakeFile(filename):
cmake_filename = filename + ".cmake"
return cmake_filename if os.path.exists(cmake_filename) else filename
class Target(object):
"""Container for data for a cmake target."""
def __init__(self, target_type, name, directory, srcs, hdrs):
self.type = target_type
self.name = name
self.directory = directory
self.srcs = srcs
self.hdrs = hdrs
self.depends = set()
self.uses = set()
def __repr__(self):
return "%s(%s, nsrcs:%s, %s)" % (self.type, self.name, len(self.srcs),
self.depends)
def Format(self, directory):
"""Formats the target for writing into a CMakeLists.txt file."""
lines = ["%s(%s" % (self.type, self.name),]
for use in sorted(self.uses):
lines.append(" " + use)
if self.srcs:
lines.append(" SRCS")
lines.extend(" " + MakeRelative(s, directory)
for s in sorted(self.srcs))
if self.hdrs:
lines.append(" HDRS")
lines.extend(" " + MakeRelative(s, directory)
for s in sorted(self.hdrs))
if self.depends:
lines.append(" DEPENDS")
lines.extend(" " + s for s in sorted(self.depends))
lines.append(")")
return "\n".join(lines) + "\n\n"
def ExtractProjectIncludes(project_name, source):
"""Returns all locally included files."""
includes = set()
for line in open(MaybeUseCmakeFile(source)):
match = re.match(r'^#include "(' + project_name + r'/[^"]+)"', line)
if match:
includes.add(match.group(1))
return includes
def FindSourceFiles(basedir):
sources = set()
for (directory, _, filenames) in os.walk(basedir):
for filename in filenames:
ext = path.splitext(filename)[-1]
if ext in [".h", ".cc"]:
sources.add(path.join(directory, filename))
elif filename.endswith(".h.cmake"):
sources.add(path.join(directory, path.splitext(filename)[0]))
yield (directory, sources)
def GetNonGoogleTargetLines(filename):
"""Returns text not written by this script.
Returns a dictionary where keys are target names and values are list of
lines that came after this target in the file. It also contains a special key
called 'START'
for lines that came before any target.
"""
GOOGLE_TARGET = re.compile(r"^google_[a-z_]*\((.*)$")
parts = collections.defaultdict(list)
current_target = "START"
if path.exists(filename):
ignoring = False
for line in open(filename):
m = GOOGLE_TARGET.match(line)
if m is not None:
current_target = m.group(1)
ignoring = True
continue
if line == "\n" and ignoring:
ignoring = False
continue
if not ignoring:
parts[current_target].append(line)
return parts
def ParseArgs():
p = argparse.ArgumentParser(
description="Automatically update cMakeFiles using build conventions.")
p.add_argument("root", type=str, nargs="*", help="Source directory.")
args = p.parse_args()
return args
def main():
args = ParseArgs()
for root in args.root:
RunOnDirectory(root)
def RunOnDirectory(root):
root = root.rstrip("/")
targets_by_src = {}
targets = []
project_name = os.path.basename(root)
base_directory = path.realpath(path.join(root, path.pardir))
directories = set()
def AddTarget(target_type, name, directory, srcs, hdrs):
"""Adds a new target to 'targets' and updates 'targets_by_src'."""
target = Target(target_type, name, directory, srcs, hdrs)
targets.append(target)
for s in srcs + hdrs:
relative_s = MakeRelative(s, base_directory)
targets_by_src[relative_s] = target
directories.add(directory)
for (directory, sources) in FindSourceFiles(root):
module_name = path.relpath(directory, path.realpath(root)).replace("/", "_")
prepend_module_name = lambda s: (module_name + "_" + s) if module_name != "." else s
headers = set(fn for fn in sources if fn.endswith(".h"))
sources -= headers
for h in sorted(headers):
cc_file = path.splitext(h)[0] + ".cc"
if cc_file in sources:
sources.remove(cc_file)
tests = set(fn for fn in sources if fn.endswith("_test.cc"))
sources -= tests
for c in sorted(tests):
name = prepend_module_name(path.basename(path.splitext(c)[0]))
AddTarget("google_test", name, directory, [c], [])
mains = set(fn for fn in sources if fn.endswith("_main.cc"))
sources -= mains
for c in sorted(mains):
# Binaries do not get their full subpath appended, but we prepend
# 'cartographer' to distinguish them after installation. So,
# 'io/assets_writer_main.cc' will generate a binary called
# 'cartographer_assets_writer'.
name = "cartographer_" + path.basename(path.splitext(c)[0][:-5])
AddTarget("google_binary", name, directory, [c], [])
assert (not sources), "Remaining sources without target: %s" % sources
# Write the CMakeLists.txt files.
for directory in directories:
cmake_file = path.join(directory, "CMakeLists.txt")
parts = GetNonGoogleTargetLines(cmake_file)
sorted_parts = []
def dump(lines_as_list):
lines = "".join(lines_as_list)
if not lines:
return
sorted_parts.append(lines)
dump(parts["START"])
del parts["START"]
for target in [t for t in targets if t.directory == directory]:
dump(target.Format(directory))
if target.name in parts:
dump(parts[target.name])
del parts[target.name]
for target in sorted(parts.keys()):
dump(parts[target])
with open(cmake_file, "w") as outfile:
outfile.write("".join(sorted_parts).rstrip() + "\n")
if __name__ == "__main__":
main()