Skip to content

Commit

Permalink
Fix running Unix tests through CMake.
Browse files Browse the repository at this point in the history
Pass the compiled executable name to runtest.pl to make it independent of the
build-system and CMake's cross-platform incompatibilities.
  • Loading branch information
qris committed Jul 25, 2016
1 parent cea6a29 commit 53b876b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
34 changes: 31 additions & 3 deletions infrastructure/cmake/CMakeLists.txt
Expand Up @@ -248,16 +248,16 @@ foreach(module_dep
install(PROGRAMS "$<TARGET_FILE:${module_name}>"
CONFIGURATIONS Debug
DESTINATION "${base_dir}/debug/${module_dir}"
RENAME "${final_test_exe_name}")
RENAME "_test")
install(PROGRAMS "$<TARGET_FILE:${module_name}>"
CONFIGURATIONS Release
DESTINATION "${base_dir}/release/${module_dir}"
RENAME "${final_test_exe_name}")
RENAME "_test")
endif()

add_test(NAME ${test_name}
COMMAND ${PERL_EXECUTABLE} ${base_dir}/runtest.pl -c ${test_name}
$<CONFIG> WORKING_DIRECTORY ${base_dir})
$<CONFIG> "$<TARGET_FILE:${module_name}>" WORKING_DIRECTORY ${base_dir})
elseif(module_name MATCHES "^(lib_.*|qdbm)$")
if(DEBUG)
message(STATUS "add library '${module_name}': '${module_files}'")
Expand Down Expand Up @@ -515,6 +515,34 @@ check_symbol_exists(dirfd "dirent.h" HAVE_DECL_DIRFD)
file(APPEND "${boxconfig_h_file}" "#cmakedefine01 HAVE_DECL_DIRFD\n")

# Emulate ax_check_mount_point.m4
# These checks are run by multi-line M4 commands which are harder to parse/fake using
# regexps above, so we hard-code them here:
CHECK_CXX_SOURCE_COMPILES([=[
#include "BoxConfig.cmake.h"
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#include <sys/mount.h>
int main()
{
struct statfs foo;
return sizeof(foo.f_mntonname) > 0 ? 0 : 1;
}
]=] "HAVE_STRUCT_STATFS_F_MNTONNAME")
file(APPEND "${boxconfig_h_file}" "#cmakedefine HAVE_STRUCT_STATFS_F_MNTONNAME\n")
CHECK_CXX_SOURCE_COMPILES([=[
#include "BoxConfig.cmake.h"
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#include <sys/mount.h>
int main()
{
struct statvfs foo;
return sizeof(foo.f_mntonname) > 0 ? 0 : 1;
}
]=] "HAVE_STRUCT_STATVFS_F_MNTONNAME")
file(APPEND "${boxconfig_h_file}" "#cmakedefine HAVE_STRUCT_STATVFS_F_MNTONNAME\n")
if(HAVE_STRUCT_STATFS_F_MNTONNAME OR
HAVE_STRUCT_STATVFS_F_MNTONNAME OR
HAVE_STRUCT_MNTENT_MNT_DIR OR
Expand Down
4 changes: 1 addition & 3 deletions lib/common/ExcludeList.cpp
Expand Up @@ -199,11 +199,9 @@ void ExcludeList::AddRegexEntries(const std::string &rEntries)
{
char buf[1024];
regerror(errcode, pregex, buf, sizeof(buf));
BOX_LOG_CATEGORY(Log::ERROR,
ConfigurationVerify::VERIFY_ERROR,
THROW_EXCEPTION_MESSAGE(CommonException, BadRegularExpression,
"Invalid regular expression: " <<
entry << ": " << buf);
THROW_EXCEPTION(CommonException, BadRegularExpression)
}

// Store in list of regular expressions
Expand Down
28 changes: 20 additions & 8 deletions runtest.pl.in
Expand Up @@ -19,7 +19,22 @@ my $cmake_build = $opts{'c'};
my $prepare_only = $opts{'n'};
my $verbose_build = $opts{'v'};

my ($test_name,$test_mode) = @ARGV;
my $test_name = shift @ARGV;
my $test_mode = shift @ARGV;
my $test_project_exe;

if($cmake_build)
{
# To support different build environments (Windows/MSVC and Linux/Makefile) which
# place compiled executables in different locations, we need to accept the name of
# the compiled test executable as an additional command-line parameter.
die "test name is required in cmake mode" unless $test_name;
die "test mode is required in cmake mode" unless $test_mode;
die "only a single test name is supported in cmake mode" if $test_name =~ /,/;
$test_project_exe = shift @ARGV;
die "test project executable name is required in cmake mode" unless $test_project_exe;
}

$test_mode = 'debug' if not defined $test_mode or $test_mode eq '';
$test_mode = lc($test_mode);

Expand Down Expand Up @@ -51,7 +66,7 @@ if($test_name ne 'ALL')
}
else
{
runtest($test_name);
runtest($test_name, $test_project_exe);
}
}
else
Expand Down Expand Up @@ -108,26 +123,23 @@ exit $exit_code;

sub runtest
{
my ($t) = @_;
my ($t, $test_project_exe) = @_;

# Attempt to make this test.
my $flag = ($test_mode eq 'release')?(BoxPlatform::make_flag('RELEASE')):'';
my ($make_res, $test_project_exe);
my $make_res;
my $test_dst_dir = "$test_mode/test/$t";

if($cmake_build)
{
# Test executables have a different name on Windows to work around
# restrictions on running different executables with the same name.
$test_project_exe = "test_$t$platform_exe_ext";
my $test_src_dir = "test/$t";

my @commands = (
"cmake -E remove_directory $test_dst_dir",
"cmake -E copy_directory $test_src_dir $test_dst_dir",
"cmake -E copy ".
"infrastructure/cmake/build/$test_mode/$test_project_exe ".
"$test_dst_dir/$test_project_exe",
"cmake -E copy $test_project_exe $test_dst_dir",
);

# Our CMake buildsystem doesn't do anything to support testextra files
Expand Down

0 comments on commit 53b876b

Please sign in to comment.