diff options
-rw-r--r-- | infrastructure/BoxPlatform.pm.in | 9 | ||||
-rw-r--r-- | infrastructure/cmake/CMakeLists.txt | 42 | ||||
-rw-r--r-- | lib/common/Test.h | 8 | ||||
-rw-r--r-- | lib/win32/emu.h | 4 | ||||
-rw-r--r-- | modules.txt | 2 | ||||
-rwxr-xr-x | runtest.pl.in | 89 | ||||
-rw-r--r-- | test/backupstore/testbackupstore.cpp | 2 | ||||
-rw-r--r-- | test/basicserver/testbasicserver.cpp | 8 |
8 files changed, 141 insertions, 23 deletions
diff --git a/infrastructure/BoxPlatform.pm.in b/infrastructure/BoxPlatform.pm.in index e6a335f8..8f9daa81 100644 --- a/infrastructure/BoxPlatform.pm.in +++ b/infrastructure/BoxPlatform.pm.in @@ -1,7 +1,7 @@ package BoxPlatform; use Exporter; @ISA = qw/Exporter/; -@EXPORT = qw/$build_os $build_os_ver $ac_target $ac_target_cpu $ac_target_vendor $ac_target_os $make_command $bsd_make $platform_define $platform_cpu $gcc_v3 $product_version $product_name $install_into_dir $sub_make_options $platform_compile_line_extra $platform_link_line_extra $platform_lib_files $platform_exe_ext $target_windows/; +@EXPORT = qw/$build_os $build_os_ver $ac_target $ac_target_cpu $ac_target_vendor $ac_target_os $make_command $bsd_make $platform_define $platform_cpu $gcc_v3 $product_version $product_name $install_into_dir $sub_make_options $platform_compile_line_extra $platform_link_line_extra $platform_lib_files $platform_exe_ext $target_windows $target_msvc/; BEGIN { @@ -11,17 +11,20 @@ BEGIN $ac_target_vendor = '@target_vendor@'; $ac_target_os = '@target_os@'; $target_windows = 0; - $target_windows = 1 if $ac_target_os =~ m'^mingw32' - or $ac_target_os eq "winnt"; if ($^O eq "MSWin32" and not -x "/usr/bin/uname") { + $target_windows = 1; + $target_msvc = 1; $build_os = "winnt"; eval "use Win32"; $build_os_ver = Win32::GetOSName(); } else { + $target_windows = 1 if $ac_target_os =~ m'^mingw32' + or $ac_target_os eq "winnt"; + $target_msvc = 0; $build_os = `uname`; $build_os_ver = `uname -r`; chomp $build_os; diff --git a/infrastructure/cmake/CMakeLists.txt b/infrastructure/cmake/CMakeLists.txt index 54164cfa..d00d90b0 100644 --- a/infrastructure/cmake/CMakeLists.txt +++ b/infrastructure/cmake/CMakeLists.txt @@ -61,8 +61,9 @@ if(NOT status EQUAL 0) "status ${status}: ${command_output}") endif() -# Parsing Makefile.extra files in CMake script is a pain, so the relevant rules are -# hard-coded here. +# Parsing Makefile.extra files in CMake script is a pain, so the relevant rules for +# code-generating Perl scripts are hard-coded here. + set(exception_files lib/backupclient/ClientException.txt lib/backupstore/BackupStoreException.txt @@ -113,12 +114,25 @@ foreach(protocol_file ${protocol_files}) set(${module_name}_extra_files ${${module_name}_extra_files} ${output_file}) endforeach() -set(output_file "${base_dir}/${CMAKE_MATCH_1}/autogen_${CMAKE_MATCH_2}.cpp") -add_custom_command(OUTPUT "${output_file}" - MAIN_DEPENDENCY "${base_dir}/bin/bbackupquery/documentation.txt" - COMMAND ${PERL_EXECUTABLE} "${base_dir}/bin/bbackupquery/makedocumentation.pl" - WORKING_DIRECTORY "${base_dir}/bin/bbackupquery") -set(bin_bbackupquery_extra_files ${bin_bbackupquery_extra_files} ${output_file}) +set(documentation_files + bin/bbackupquery/documentation.txt +) + +foreach(documentation_file ${documentation_files}) + string(REGEX MATCH "(.*)/(.*).txt" valid_documentation_file ${documentation_file}) + if(NOT valid_documentation_file) + message(FATAL_ERROR "invalid documentation file: '${documentation_file}'") + endif() + + set(output_file "${base_dir}/${CMAKE_MATCH_1}/autogen_${CMAKE_MATCH_2}.cpp") + add_custom_command(OUTPUT "${output_file}" + MAIN_DEPENDENCY "${base_dir}/${documentation_file}" + COMMAND ${PERL_EXECUTABLE} "${base_dir}/bin/bbackupquery/makedocumentation.pl" + WORKING_DIRECTORY "${base_dir}/${CMAKE_MATCH_1}") + + string(REPLACE "/" "_" module_name ${CMAKE_MATCH_1}) + set(${module_name}_extra_files ${${module_name}_extra_files} ${output_file}) +endforeach() file(STRINGS ${base_dir}/modules.txt module_deps REGEX "^[^#]") # qdbm, lib/common and lib/win32 aren't listed in modules.txt, so hard-code them. @@ -178,7 +192,7 @@ foreach(module_dep target_compile_definitions(${module_name} PRIVATE -DBOX_MODULE="${module_dir}") - if(dependencies MATCHES ".") + if(dependencies) string(REGEX REPLACE "[ ]+" ";" dependency_list "${dependencies}") foreach(dependency ${dependency_list}) @@ -190,6 +204,16 @@ foreach(module_dep # message(STATUS "add link library to '${module_name}': '${dependency}'") target_link_libraries(${module_name} PUBLIC ${dependency}) endif() + + # We can't make a binary depend on another binary, so we need to + # add the dependency's directory directly to our include path. + if(dependency MATCHES "^bin_") + get_property(dep_include_dirs + TARGET ${dependency} + PROPERTY INTERFACE_INCLUDE_DIRECTORIES) + target_include_directories(${module_name} + PUBLIC ${dep_include_dirs}) + endif() endforeach() endif() diff --git a/lib/common/Test.h b/lib/common/Test.h index 15a3db6f..36cd6a59 100644 --- a/lib/common/Test.h +++ b/lib/common/Test.h @@ -243,4 +243,12 @@ void safe_sleep(int seconds); std::auto_ptr<Configuration> load_config_file(const std::string& config_file, const ConfigurationVerify& verify); +#ifdef _MSC_VER + // Our CMakeFiles compile tests to different executable filenames, + // e.g. test_common.exe instead of _test.exe. + #define TEST_EXECUTABLE BOX_MODULE ".exe" +#else + #define TEST_EXECUTABLE "./_test" +#endif + #endif // TEST__H diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 8014316a..b0fa2832 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -162,6 +162,10 @@ inline int geteuid(void) { return 0; } +inline int getpid(void) +{ + return GetCurrentProcessId(); +} #ifndef PATH_MAX #define PATH_MAX MAX_PATH diff --git a/modules.txt b/modules.txt index aed59ef1..25a9a979 100644 --- a/modules.txt +++ b/modules.txt @@ -40,12 +40,12 @@ test/backupstorefix bin/bbstored bin/bbstoreaccounts lib/backupclient bin/bbacku test/backupstorepatch bin/bbstored bin/bbstoreaccounts lib/backupclient test/backupdiff lib/backupclient test/bbackupd bin/bbackupd bin/bbstored bin/bbstoreaccounts bin/bbackupquery bin/bbackupctl lib/server lib/backupstore lib/backupclient lib/intercept +bin/s3simulator lib/httpserver test/s3store lib/backupclient lib/httpserver bin/s3simulator bin/bbstoreaccounts # HTTP server system lib/httpserver lib/server test/httpserver lib/httpserver -bin/s3simulator lib/httpserver # END_IF_DISTRIBUTION diff --git a/runtest.pl.in b/runtest.pl.in index f01f2936..7d197d4c 100755 --- a/runtest.pl.in +++ b/runtest.pl.in @@ -3,7 +3,10 @@ use strict; use warnings; -use lib 'infrastructure'; +use File::Basename; +chdir(dirname($0)); +use lib dirname($0).'/infrastructure'; + use BoxPlatform; my ($test_name,$test_mode) = @ARGV; @@ -97,9 +100,65 @@ sub runtest { my ($t) = @_; - # attempt to make this test + # Attempt to make this test. my $flag = ($test_mode eq 'release')?(BoxPlatform::make_flag('RELEASE')):''; - my $make_res = system("cd test/$t && $make_command $flag"); + my ($make_res, $test_project_exe); + + if($target_msvc) + { + $test_project_exe = "test_$t"; + # Assume that MSVC projects are built with CMake, so we can use + # MSBuild to run the tests. + my $test_src_dir = "test\\$t"; + my $test_dst_dir = "$test_mode\\test\\$t"; + + my @commands = ( + "msbuild /nologo /consoleloggerparameters:ErrorsOnly ". + "infrastructure\\cmake\\$test_project_exe.vcxproj", + "xcopy /s /i /y /q $test_src_dir $test_dst_dir", + "copy infrastructure\\cmake\\$test_mode\\$test_project_exe.exe $test_dst_dir" + ); + + if(-d $test_dst_dir) + { + unshift @commands, "rmdir /s /q $test_dst_dir"; + } + + foreach my $command (@commands) + { + $make_res = system($command); + if ($make_res != 0) + { + push @results, "$t: make failed: $command"; + last; + } + } + + # Windows doesn't support testextra files either, so fake it. + if ($make_res == 0 and -r "$test_src_dir/testextra") + { + open EXTRA, "$test_src_dir/testextra" + or die "$test_src_dir/testextra: $!"; + foreach my $line (<EXTRA>) + { + if ($line =~ m/^mkdir (.*)/) + { + mkdir("$test_dst_dir/$1") + or die "$test_dst_dir/$1: $!"; + } + else + { + die "Unsupported command in ". + "$test_src_dir/testextra: $!"; + } + } + } + } + else + { + $make_res = system("cd test/$t && $make_command $flag"); + } + if($make_res != 0) { push @results,"$t: make failed"; @@ -108,10 +167,30 @@ sub runtest } my $logfile = "test-$t.log"; + my $test_res; # run it - my $test_res = system("cd $test_mode/test/$t ; ./t 2>&1 " . - "| tee ../../../$logfile"); + if($target_msvc) + { + # no tee.exe, so let's do it ourselves. + open LOG, ">$logfile" or die "$logfile: $!"; + chdir("$test_mode/test/$t"); + open TEE, "$test_project_exe.exe |" + or die "$test_project_exe.exe: $!"; + while (my $line = <TEE>) + { + print $line; + print LOG $line; + } + close LOG; + close TEE; + chdir("../../.."); + } + else + { + $test_res = system("cd $test_mode/test/$t ; ./t 2>&1 " . + "| tee ../../../$logfile"); + } # open test results if(open RESULTS, $logfile) diff --git a/test/backupstore/testbackupstore.cpp b/test/backupstore/testbackupstore.cpp index c7cfee6f..00e16ad5 100644 --- a/test/backupstore/testbackupstore.cpp +++ b/test/backupstore/testbackupstore.cpp @@ -2601,7 +2601,7 @@ bool test_login_with_disabled_account() // Login TEST_COMMAND_RETURNS_ERROR(protocol, QueryLogin(0x01234567, 0), - BackupProtocolError::Err_DisabledAccount); + Err_DisabledAccount); // Finish the connection protocol.QueryFinished(); diff --git a/test/basicserver/testbasicserver.cpp b/test/basicserver/testbasicserver.cpp index 9e3b8890..6a1e15ad 100644 --- a/test/basicserver/testbasicserver.cpp +++ b/test/basicserver/testbasicserver.cpp @@ -485,7 +485,7 @@ int test(int argc, const char *argv[]) // Launch a basic server { - std::string cmd = "./_test --test-daemon-args="; + std::string cmd = TEST_EXECUTABLE " --test-daemon-args="; cmd += test_args; cmd += " srv1 testfiles/srv1.conf"; int pid = LaunchServer(cmd, "testfiles/srv1.pid"); @@ -531,7 +531,7 @@ int test(int argc, const char *argv[]) // Launch a test forking server { - std::string cmd = "./_test --test-daemon-args="; + std::string cmd = TEST_EXECUTABLE " --test-daemon-args="; cmd += test_args; cmd += " srv2 testfiles/srv2.conf"; int pid = LaunchServer(cmd, "testfiles/srv2.pid"); @@ -601,7 +601,7 @@ int test(int argc, const char *argv[]) // Launch a test SSL server { - std::string cmd = "./_test --test-daemon-args="; + std::string cmd = TEST_EXECUTABLE " --test-daemon-args="; cmd += test_args; cmd += " srv3 testfiles/srv3.conf"; int pid = LaunchServer(cmd, "testfiles/srv3.pid"); @@ -682,7 +682,7 @@ int test(int argc, const char *argv[]) //protocolserver: // Launch a test protocol handling server { - std::string cmd = "./_test --test-daemon-args="; + std::string cmd = TEST_EXECUTABLE " --test-daemon-args="; cmd += test_args; cmd += " srv4 testfiles/srv4.conf"; int pid = LaunchServer(cmd, "testfiles/srv4.pid"); |