This is an automated email from the ASF dual-hosted git repository. tschoening pushed a commit to branch ghpr_14_replace-ant-build-with-cmake in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit b971dd0bba2c548539aefb60ca6b1ff0e2bbf10e Author: Stephen Webb <[email protected]> AuthorDate: Sun Feb 9 09:52:25 2020 +1100 Make socketservertestcase work independently of ant build --- build.xml | 45 ------------- src/test/CMakeLists.txt | 6 +- src/test/cpp/CMakeLists.txt | 13 +++- src/test/cpp/net/CMakeLists.txt | 6 +- src/test/cpp/net/socketserverstarter.cpp | 108 ++++++++++++++++++++++++++++++ src/test/cpp/net/socketservertestcase.cpp | 3 +- src/test/java/CMakeLists.txt | 18 +++++ 7 files changed, 147 insertions(+), 52 deletions(-) diff --git a/build.xml b/build.xml index 8c7fed7..6e1a811 100644 --- a/build.xml +++ b/build.xml @@ -229,51 +229,6 @@ </delete> </target> - <target name="run-socketserver" - depends="clean-output" - description="Runs SocketServer test"> - <property environment="env" /> - <mkdir dir="${tests.output.dir}" /> - <delete> - <fileset dir="${tests.output.dir}" - includes="*" - /> - </delete> - <mkdir dir="target/test-classes" /> - <javac srcdir="src/test/java" - includes="org/apache/log4j/net/ShortSocketServer.java" - destdir="target/test-classes" - classpath="${log4j.jar}" - /> - <parallel> - <java classname="org.apache.log4j.net.ShortSocketServer" - fork="yes" dir="src/test/resources" - classpath="target/test-classes:${log4j.jar}"> - <arg value="8" /> - <arg value="input/socketServer" /> - </java> - <sequential> - <sleep seconds="2" /> - <exec executable="${testsuite.exe}" - dir="${tests.resources.dir}" - failonerror="true"> - <arg value="-v" /> - <arg value="socketservertestcase" /> - - <env key="LD_LIBRARY_PATH" - value="${log4cxx.lib.dir}:${apr.lib.dir}:${apr-util.lib.dir}:${env.LD_LIBRARY_PATH}" - /> - <env key="DYLD_LIBRARY_PATH" - value="${log4cxx.lib.dir}:${apr.lib.dir}:${apr-util.lib.dir}:${env.DYLD_LIBRARY_PATH}" - /> - <env key="Path" - value="${log4cxx.lib.dir};${env.Path}" - /> - </exec> - </sequential> - </parallel> - </target> - <target name="apidocs" description="Build log4cxx manual"> <copy file="${base.dir}/src/site/doxy/Doxyfile.in" diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index da8ed95..42ff357 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1 +1,5 @@ -add_subdirectory(cpp) \ No newline at end of file +find_package(Java COMPONENTS Development) +if(Java_Development_FOUND) + add_subdirectory(java) +endif(Java_Development_FOUND) +add_subdirectory(cpp) diff --git a/src/test/cpp/CMakeLists.txt b/src/test/cpp/CMakeLists.txt index cc5d250..bbe01e3 100644 --- a/src/test/cpp/CMakeLists.txt +++ b/src/test/cpp/CMakeLists.txt @@ -56,9 +56,16 @@ foreach(testName IN LISTS ALL_LOG4CXX_TESTS) COMMAND ${testName} -v WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../resources ) - set_tests_properties(${testName} PROPERTIES - ENVIRONMENT "TOTO=wonderful;key1=value1;key2=value2" - ) + + if(${testName} STREQUAL socketservertestcase) + set_tests_properties(socketservertestcase PROPERTIES + ENVIRONMENT "SOCKET_SERVER_COMMAND=$<JOIN:${START_SOCKET_SERVER_COMMAND}, >" + ) + else() + set_tests_properties(${testName} PROPERTIES + ENVIRONMENT "TOTO=wonderful;key1=value1;key2=value2" + ) + endif() if(WIN32) set_tests_properties(${testName} PROPERTIES ENVIRONMENT "PATH=$<SHELL_PATH:$<TARGET_FILE_DIR:log4cxx>>$<SEMICOLON>$ENV{PATH}" diff --git a/src/test/cpp/net/CMakeLists.txt b/src/test/cpp/net/CMakeLists.txt index 888dec6..a11e603 100644 --- a/src/test/cpp/net/CMakeLists.txt +++ b/src/test/cpp/net/CMakeLists.txt @@ -3,7 +3,6 @@ set(NET_TESTS socketappendertestcase sockethubappendertestcase - socketservertestcase syslogappendertestcase telnetappendertestcase xmlsocketappendertestcase @@ -14,4 +13,9 @@ endif(HAS_LIBESMPT) foreach(fileName IN LISTS NET_TESTS) add_executable(${fileName} "${fileName}.cpp") endforeach() +if(Java_Development_FOUND) + add_executable(socketservertestcase socketserverstarter.cpp socketservertestcase.cpp) + add_dependencies(socketservertestcase test-classes) + list(APPEND NET_TESTS socketservertestcase) +endif(Java_Development_FOUND) set(ALL_LOG4CXX_TESTS ${ALL_LOG4CXX_TESTS} ${NET_TESTS} PARENT_SCOPE) diff --git a/src/test/cpp/net/socketserverstarter.cpp b/src/test/cpp/net/socketserverstarter.cpp new file mode 100644 index 0000000..43e9d56 --- /dev/null +++ b/src/test/cpp/net/socketserverstarter.cpp @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#include "../logunit.h" + +#include <apr_thread_proc.h> +#include <apr_env.h> +#include <apr_file_io.h> +#include <apr_strings.h> +#include <apr_time.h> +#include <log4cxx/helpers/pool.h> + + +using namespace log4cxx; + +LOGUNIT_CLASS(SocketServerStarter) +{ + LOGUNIT_TEST_SUITE(SocketServerStarter); + LOGUNIT_TEST(startServer); + LOGUNIT_TEST_SUITE_END(); + +public: + void setUp() + { + } + + void tearDown() + { + } + + void startServer() + { + helpers::Pool p; + apr_pool_t* pool = p.getAPRPool(); + char* cmd = NULL; + apr_status_t stat = apr_env_get(&cmd, "SOCKET_SERVER_COMMAND", pool); + + if (cmd && *cmd) + { + // prepare to launch the server + // + apr_proc_t server_pid; + apr_procattr_t* attr = NULL; + stat = apr_procattr_create(&attr, pool); + LOGUNIT_ASSERT(stat == APR_SUCCESS); + stat = apr_procattr_io_set(attr, APR_NO_PIPE, APR_NO_PIPE, APR_NO_PIPE); + LOGUNIT_ASSERT(stat == APR_SUCCESS); + + //fprintf(stdout, "SOCKET_SERVER_COMMAND=%s\n", cmd); +#ifdef SHELL_CMD_TYPE_WORKS + stat = apr_procattr_cmdtype_set(attr, APR_SHELLCMD); + LOGUNIT_ASSERT(stat == APR_SUCCESS); + stat = apr_proc_create(&server_pid, cmd, NULL, NULL, attr, pool); +#else + stat = apr_procattr_cmdtype_set(attr, APR_PROGRAM); + LOGUNIT_ASSERT(stat == APR_SUCCESS); + // convert the space separated cmd string to the argument list + // + char** args = (char**)apr_palloc(pool, 15 * sizeof(*args)); + char* pcmd = apr_pstrdup(pool, cmd); + int i = 0; + for (; i < 14 && pcmd && *pcmd; ++i) + { + args[i] = pcmd; + if (NULL != (pcmd = strchr(pcmd, ' '))) + { + while(' ' == *pcmd) + { + *pcmd = 0; + ++pcmd; + } + } + } + args[i] = 0; + //fprintf(stdout, "starting=%s with %d arguments\n", args[0], i); + stat = apr_proc_create(&server_pid, args[0], args, NULL, attr, pool); +#endif + + + if (stat == APR_SUCCESS) // Allow server time to load + apr_sleep(1000000); // 1 seconds + } + else + fputs("The environment variable SOCKET_SERVER_COMMAND" + " must contain the server process path" + " followed by space separated command arguments\n", stderr); + + LOGUNIT_ASSERT(stat == APR_SUCCESS); + } +}; + + +LOGUNIT_TEST_SUITE_REGISTRATION(SocketServerStarter) + diff --git a/src/test/cpp/net/socketservertestcase.cpp b/src/test/cpp/net/socketservertestcase.cpp index ce4444f..d46b378 100644 --- a/src/test/cpp/net/socketservertestcase.cpp +++ b/src/test/cpp/net/socketservertestcase.cpp @@ -38,7 +38,6 @@ #include "../logunit.h" #include <log4cxx/spi/loggerrepository.h> - //Define INT64_C for compilers that don't have it #if (!defined(INT64_C)) #define INT64_C(value) value ## LL @@ -478,4 +477,4 @@ public: const File SocketServerTestCase::TEMP("output/temp"); const File SocketServerTestCase::FILTERED("output/filtered"); -LOGUNIT_TEST_SUITE_REGISTRATION_DISABLED(SocketServerTestCase) +LOGUNIT_TEST_SUITE_REGISTRATION(SocketServerTestCase) diff --git a/src/test/java/CMakeLists.txt b/src/test/java/CMakeLists.txt new file mode 100644 index 0000000..ff4af4b --- /dev/null +++ b/src/test/java/CMakeLists.txt @@ -0,0 +1,18 @@ +include(FetchContent) +FetchContent_Declare(log4j + URL https://www-us.apache.org/dist/logging/log4j/1.2.17/log4j-1.2.17.tar.gz + URL_HASH MD5=8218714e41ee0c6509dcfeafa2e1f53f +) +FetchContent_GetProperties(log4j) +if(NOT log4j_POPULATED) + FetchContent_Populate(log4j) +endif() +set(log4j_CLASSPATH "${log4j_SOURCE_DIR}/log4j-1.2.17.jar" ) +set(SOCKET_SERVER_SOURCES org/apache/log4j/net/ShortSocketServer.java) +add_custom_target(test-classes + COMMAND ${Java_JAVAC_EXECUTABLE} -d ${CMAKE_CURRENT_BINARY_DIR} + --class-path "${log4j_CLASSPATH}" ${SOCKET_SERVER_SOURCES} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) +set(SOCKET_SERVER_CLASSPATH "${CMAKE_CURRENT_BINARY_DIR}:${log4j_CLASSPATH}" ) +set(START_SOCKET_SERVER_COMMAND ${Java_JAVA_EXECUTABLE} --class-path ${SOCKET_SERVER_CLASSPATH} org.apache.log4j.net.ShortSocketServer 8 input/socketServer PARENT_SCOPE)
