From 2453f5b71717f86547f3794e3424625573af6a2c Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Tue, 10 Sep 2019 12:19:22 -0700 Subject: [PATCH] restructure project --- CMakeLists.txt | 16 +++++++--- ixcobra/CMakeLists.txt | 30 +++++++++++++++++++ {ws => ixcobra}/ixcobra/IXCobraConnection.cpp | 0 {ws => ixcobra}/ixcobra/IXCobraConnection.h | 0 .../ixcobra/IXCobraMetricsPublisher.cpp | 0 .../ixcobra/IXCobraMetricsPublisher.h | 0 .../IXCobraMetricsThreadedPublisher.cpp | 0 .../ixcobra/IXCobraMetricsThreadedPublisher.h | 0 {ws => ixcobra}/ixcobra/README.md | 0 ixcore/CMakeLists.txt | 19 ++++++++++++ {ws => ixcore}/ixcore/utils/IXCoreLogger.cpp | 0 {ws => ixcore}/ixcore/utils/IXCoreLogger.h | 0 ixcrypto/CMakeLists.txt | 29 ++++++++++++++++++ {ws => ixcrypto}/ixcrypto/IXBase64.cpp | 0 {ws => ixcrypto}/ixcrypto/IXBase64.h | 0 {ws => ixcrypto}/ixcrypto/IXHMac.cpp | 0 {ws => ixcrypto}/ixcrypto/IXHMac.h | 0 {ws => ixcrypto}/ixcrypto/IXHash.cpp | 0 {ws => ixcrypto}/ixcrypto/IXHash.h | 0 {ws => ixcrypto}/ixcrypto/IXUuid.cpp | 0 {ws => ixcrypto}/ixcrypto/IXUuid.h | 0 makefile | 7 +++-- test/CMakeLists.txt | 17 +++-------- test/IXCobraChatTest.cpp | 2 ++ test/run.py | 29 ++++++++++-------- ws/CMakeLists.txt | 14 ++------- 26 files changed, 119 insertions(+), 44 deletions(-) create mode 100644 ixcobra/CMakeLists.txt rename {ws => ixcobra}/ixcobra/IXCobraConnection.cpp (100%) rename {ws => ixcobra}/ixcobra/IXCobraConnection.h (100%) rename {ws => ixcobra}/ixcobra/IXCobraMetricsPublisher.cpp (100%) rename {ws => ixcobra}/ixcobra/IXCobraMetricsPublisher.h (100%) rename {ws => ixcobra}/ixcobra/IXCobraMetricsThreadedPublisher.cpp (100%) rename {ws => ixcobra}/ixcobra/IXCobraMetricsThreadedPublisher.h (100%) rename {ws => ixcobra}/ixcobra/README.md (100%) create mode 100644 ixcore/CMakeLists.txt rename {ws => ixcore}/ixcore/utils/IXCoreLogger.cpp (100%) rename {ws => ixcore}/ixcore/utils/IXCoreLogger.h (100%) create mode 100644 ixcrypto/CMakeLists.txt rename {ws => ixcrypto}/ixcrypto/IXBase64.cpp (100%) rename {ws => ixcrypto}/ixcrypto/IXBase64.h (100%) rename {ws => ixcrypto}/ixcrypto/IXHMac.cpp (100%) rename {ws => ixcrypto}/ixcrypto/IXHMac.h (100%) rename {ws => ixcrypto}/ixcrypto/IXHash.cpp (100%) rename {ws => ixcrypto}/ixcrypto/IXHash.h (100%) rename {ws => ixcrypto}/ixcrypto/IXUuid.cpp (100%) rename {ws => ixcrypto}/ixcrypto/IXUuid.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b86f2e5..f3a7b8d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,8 +12,7 @@ set (CMAKE_CXX_STANDARD 14) set (CXX_STANDARD_REQUIRED ON) set (CMAKE_CXX_EXTENSIONS OFF) -# -Wshorten-64-to-32 does not work with clang -if (NOT WIN32) +if (UNIX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") endif() @@ -211,6 +210,15 @@ install(TARGETS ixwebsocket PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include/ixwebsocket/ ) -if (USE_WS) - add_subdirectory(ws) +if (USE_WS OR USE_TEST) + add_subdirectory(ixcore) + add_subdirectory(ixcrypto) + add_subdirectory(ixcobra) + + if (USE_WS) + add_subdirectory(ws) + endif() + if (USE_TEST) + add_subdirectory(test) + endif() endif() diff --git a/ixcobra/CMakeLists.txt b/ixcobra/CMakeLists.txt new file mode 100644 index 00000000..f7245cbd --- /dev/null +++ b/ixcobra/CMakeLists.txt @@ -0,0 +1,30 @@ +# +# Author: Benjamin Sergeant +# Copyright (c) 2019 Machine Zone, Inc. All rights reserved. +# + +set (IXCOBRA_SOURCES + ixcobra/IXCobraConnection.cpp + ixcobra/IXCobraMetricsThreadedPublisher.cpp + ixcobra/IXCobraMetricsPublisher.cpp +) + +set (IXCOBRA_HEADERS + ixcobra/IXCobraConnection.h + ixcobra/IXCobraMetricsThreadedPublisher.h + ixcobra/IXCobraMetricsPublisher.h +) + +add_library(ixcobra STATIC + ${IXCOBRA_SOURCES} + ${IXCOBRA_HEADERS} +) + +set(IXCOBRA_INCLUDE_DIRS + . + ../ixcore + ../ixcrypto + ../ixwebsocket + ../third_party) + +target_include_directories( ixcobra PUBLIC ${IXCOBRA_INCLUDE_DIRS} ) diff --git a/ws/ixcobra/IXCobraConnection.cpp b/ixcobra/ixcobra/IXCobraConnection.cpp similarity index 100% rename from ws/ixcobra/IXCobraConnection.cpp rename to ixcobra/ixcobra/IXCobraConnection.cpp diff --git a/ws/ixcobra/IXCobraConnection.h b/ixcobra/ixcobra/IXCobraConnection.h similarity index 100% rename from ws/ixcobra/IXCobraConnection.h rename to ixcobra/ixcobra/IXCobraConnection.h diff --git a/ws/ixcobra/IXCobraMetricsPublisher.cpp b/ixcobra/ixcobra/IXCobraMetricsPublisher.cpp similarity index 100% rename from ws/ixcobra/IXCobraMetricsPublisher.cpp rename to ixcobra/ixcobra/IXCobraMetricsPublisher.cpp diff --git a/ws/ixcobra/IXCobraMetricsPublisher.h b/ixcobra/ixcobra/IXCobraMetricsPublisher.h similarity index 100% rename from ws/ixcobra/IXCobraMetricsPublisher.h rename to ixcobra/ixcobra/IXCobraMetricsPublisher.h diff --git a/ws/ixcobra/IXCobraMetricsThreadedPublisher.cpp b/ixcobra/ixcobra/IXCobraMetricsThreadedPublisher.cpp similarity index 100% rename from ws/ixcobra/IXCobraMetricsThreadedPublisher.cpp rename to ixcobra/ixcobra/IXCobraMetricsThreadedPublisher.cpp diff --git a/ws/ixcobra/IXCobraMetricsThreadedPublisher.h b/ixcobra/ixcobra/IXCobraMetricsThreadedPublisher.h similarity index 100% rename from ws/ixcobra/IXCobraMetricsThreadedPublisher.h rename to ixcobra/ixcobra/IXCobraMetricsThreadedPublisher.h diff --git a/ws/ixcobra/README.md b/ixcobra/ixcobra/README.md similarity index 100% rename from ws/ixcobra/README.md rename to ixcobra/ixcobra/README.md diff --git a/ixcore/CMakeLists.txt b/ixcore/CMakeLists.txt new file mode 100644 index 00000000..54babb44 --- /dev/null +++ b/ixcore/CMakeLists.txt @@ -0,0 +1,19 @@ +# +# Author: Benjamin Sergeant +# Copyright (c) 2019 Machine Zone, Inc. All rights reserved. +# + +set (IXCORE_SOURCES + ixcore/utils/IXCoreLogger.cpp +) + +set (IXCORE_HEADERS + ixcore/utils/IXCoreLogger.h +) + +add_library(ixcore STATIC + ${IXCORE_SOURCES} + ${IXCORE_HEADERS} +) + +target_include_directories( ixcore PUBLIC . ) diff --git a/ws/ixcore/utils/IXCoreLogger.cpp b/ixcore/ixcore/utils/IXCoreLogger.cpp similarity index 100% rename from ws/ixcore/utils/IXCoreLogger.cpp rename to ixcore/ixcore/utils/IXCoreLogger.cpp diff --git a/ws/ixcore/utils/IXCoreLogger.h b/ixcore/ixcore/utils/IXCoreLogger.h similarity index 100% rename from ws/ixcore/utils/IXCoreLogger.h rename to ixcore/ixcore/utils/IXCoreLogger.h diff --git a/ixcrypto/CMakeLists.txt b/ixcrypto/CMakeLists.txt new file mode 100644 index 00000000..420c0937 --- /dev/null +++ b/ixcrypto/CMakeLists.txt @@ -0,0 +1,29 @@ +# +# Author: Benjamin Sergeant +# Copyright (c) 2019 Machine Zone, Inc. All rights reserved. +# + +set (IXCRYPTO_SOURCES + ixcrypto/IXHMac.cpp + ixcrypto/IXBase64.cpp + ixcrypto/IXUUid.cpp + ixcrypto/IXHash.cpp +) + +set (IXCRYPTO_HEADERS + ixcrypto/IXHMac.h + ixcrypto/IXBase64.h + ixcrypto/IXUUid.h + ixcrypto/IXHash.h +) + +add_library(ixcrypto STATIC + ${IXCRYPTO_SOURCES} + ${IXCRYPTO_HEADERS} +) + +set(IXCRYPTO_INCLUDE_DIRS + . + ../ixcore) + +target_include_directories( ixcrypto PUBLIC ${IXCRYPTO_INCLUDE_DIRS} ) diff --git a/ws/ixcrypto/IXBase64.cpp b/ixcrypto/ixcrypto/IXBase64.cpp similarity index 100% rename from ws/ixcrypto/IXBase64.cpp rename to ixcrypto/ixcrypto/IXBase64.cpp diff --git a/ws/ixcrypto/IXBase64.h b/ixcrypto/ixcrypto/IXBase64.h similarity index 100% rename from ws/ixcrypto/IXBase64.h rename to ixcrypto/ixcrypto/IXBase64.h diff --git a/ws/ixcrypto/IXHMac.cpp b/ixcrypto/ixcrypto/IXHMac.cpp similarity index 100% rename from ws/ixcrypto/IXHMac.cpp rename to ixcrypto/ixcrypto/IXHMac.cpp diff --git a/ws/ixcrypto/IXHMac.h b/ixcrypto/ixcrypto/IXHMac.h similarity index 100% rename from ws/ixcrypto/IXHMac.h rename to ixcrypto/ixcrypto/IXHMac.h diff --git a/ws/ixcrypto/IXHash.cpp b/ixcrypto/ixcrypto/IXHash.cpp similarity index 100% rename from ws/ixcrypto/IXHash.cpp rename to ixcrypto/ixcrypto/IXHash.cpp diff --git a/ws/ixcrypto/IXHash.h b/ixcrypto/ixcrypto/IXHash.h similarity index 100% rename from ws/ixcrypto/IXHash.h rename to ixcrypto/ixcrypto/IXHash.h diff --git a/ws/ixcrypto/IXUuid.cpp b/ixcrypto/ixcrypto/IXUuid.cpp similarity index 100% rename from ws/ixcrypto/IXUuid.cpp rename to ixcrypto/ixcrypto/IXUuid.cpp diff --git a/ws/ixcrypto/IXUuid.h b/ixcrypto/ixcrypto/IXUuid.h similarity index 100% rename from ws/ixcrypto/IXUuid.h rename to ixcrypto/ixcrypto/IXUuid.h diff --git a/makefile b/makefile index 48ee6207..547c742f 100644 --- a/makefile +++ b/makefile @@ -9,7 +9,7 @@ install: brew # on osx it is good practice to make /usr/local user writable # sudo chown -R `whoami`/staff /usr/local brew: - mkdir -p build && (cd build ; cmake -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 .. ; make -j install) + mkdir -p build && (cd build ; cmake -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 -DUSE_TEST=1 .. ; make -j install) ws: mkdir -p build && (cd build ; cmake -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 .. ; make -j) @@ -57,8 +57,9 @@ test_server: # env TEST=Websocket_server make test # env TEST=Websocket_chat make test # env TEST=heartbeat make test -test: - python2.7 test/run.py +test: brew + # (cd test ; ../build/test/ixwebsocket_unittest) + (cd test ; python2.7 run.py -r) ws_test: ws (cd ws ; env DEBUG=1 PATH=../ws/build:$$PATH bash test_ws.sh) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 205b9b4a..6b8503aa 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,8 +15,6 @@ if (MAC) option(USE_TLS "Add TLS support" ON) endif() -add_subdirectory(${PROJECT_SOURCE_DIR}/.. ixwebsocket) - set (WS ../ws) include_directories( @@ -36,17 +34,6 @@ set (SOURCES ../third_party/msgpack11/msgpack11.cpp ../third_party/jsoncpp/jsoncpp.cpp - ${WS}/ixcore/utils/IXCoreLogger.cpp - - ${WS}/ixcrypto/IXBase64.cpp - ${WS}/ixcrypto/IXHash.cpp - ${WS}/ixcrypto/IXUuid.cpp - ${WS}/ixcrypto/IXHMac.cpp - - ${WS}/ixcobra/IXCobraConnection.cpp - ${WS}/ixcobra/IXCobraMetricsPublisher.cpp - ${WS}/ixcobra/IXCobraMetricsThreadedPublisher.cpp - ${WS}/snake/IXSnakeServer.cpp ${WS}/snake/IXSnakeProtocol.cpp ${WS}/snake/IXAppConfig.cpp @@ -99,5 +86,9 @@ if (APPLE AND USE_TLS) target_link_libraries(ixwebsocket_unittest "-framework foundation" "-framework security") endif() +target_link_libraries(ixwebsocket_unittest ixcore) +target_link_libraries(ixwebsocket_unittest ixcrypto) +target_link_libraries(ixwebsocket_unittest ixcobra) target_link_libraries(ixwebsocket_unittest ixwebsocket) + install(TARGETS ixwebsocket_unittest DESTINATION bin) diff --git a/test/IXCobraChatTest.cpp b/test/IXCobraChatTest.cpp index e4e568c5..8f43e206 100644 --- a/test/IXCobraChatTest.cpp +++ b/test/IXCobraChatTest.cpp @@ -309,6 +309,7 @@ TEST_CASE("Cobra_chat", "[cobra_chat]") timeout -= 10; if (timeout <= 0) { + snakeServer.stop(); REQUIRE(false); // timeout } } @@ -332,6 +333,7 @@ TEST_CASE("Cobra_chat", "[cobra_chat]") timeout -= 10; if (timeout <= 0) { + snakeServer.stop(); REQUIRE(false); // timeout } } diff --git a/test/run.py b/test/run.py index d324dfc0..8740caff 100755 --- a/test/run.py +++ b/test/run.py @@ -350,21 +350,22 @@ def generateXmlOutput(results, xmlOutput, testRunName, runTime): def run(testName, buildDir, sanitizer, xmlOutput, - testRunName, buildOnly, useLLDB, cpuCount): + testRunName, buildOnly, useLLDB, cpuCount, runOnly): '''Main driver. Run cmake, compiles, execute and validate the testsuite.''' # gen build files with CMake - runCMake(sanitizer, buildDir) + if not runOnly: + runCMake(sanitizer, buildDir) - if platform.system() == 'Linux': - # build with make -j - runCommand('make -C {} -j 2'.format(buildDir)) - elif platform.system() == 'Darwin': - # build with make - runCommand('make -C {} -j 8'.format(buildDir)) - else: - # build with cmake on recent - runCommand('cmake --build --parallel {}'.format(buildDir)) + if platform.system() == 'Linux': + # build with make -j + runCommand('make -C {} -j 2'.format(buildDir)) + elif platform.system() == 'Darwin': + # build with make + runCommand('make -C {} -j 8'.format(buildDir)) + else: + # build with cmake on recent + runCommand('cmake --build --parallel {}'.format(buildDir)) if buildOnly: return @@ -454,6 +455,8 @@ def main(): help='Validate XML output.') parser.add_argument('--build_only', '-b', action='store_true', help='Stop after building. Do not run the unittest.') + parser.add_argument('--run_only', '-r', action='store_true', + help='Only run the test, do not build anything.') parser.add_argument('--output', '-o', help='Output XML file.') parser.add_argument('--lldb', action='store_true', help='Run the test through lldb.') @@ -492,7 +495,7 @@ def main(): if platform.system() == 'Windows': TEST_EXE_PATH = os.path.join(buildDir, BUILD_TYPE, 'ixwebsocket_unittest.exe') else: - TEST_EXE_PATH = os.path.join(buildDir, 'ixwebsocket_unittest') + TEST_EXE_PATH = '../build/test/ixwebsocket_unittest' if args.list: # catch2 exit with a different error code when requesting the list of files @@ -511,7 +514,7 @@ def main(): args.lldb = False return run(args.test, buildDir, sanitizer, xmlOutput, - testRunName, args.build_only, args.lldb, args.cpu_count) + testRunName, args.build_only, args.lldb, args.cpu_count, args.run_only) if __name__ == '__main__': diff --git a/ws/CMakeLists.txt b/ws/CMakeLists.txt index 184306cc..6bd7b36e 100644 --- a/ws/CMakeLists.txt +++ b/ws/CMakeLists.txt @@ -35,17 +35,6 @@ add_executable(ws ../third_party/jsoncpp/jsoncpp.cpp ${STATSD_CLIENT_SOURCES} - ixcore/utils/IXCoreLogger.cpp - - ixcrypto/IXBase64.cpp - ixcrypto/IXHash.cpp - ixcrypto/IXUuid.cpp - ixcrypto/IXHMac.cpp - - ixcobra/IXCobraConnection.cpp - ixcobra/IXCobraMetricsPublisher.cpp - ixcobra/IXCobraMetricsThreadedPublisher.cpp - snake/IXSnakeServer.cpp snake/IXSnakeProtocol.cpp snake/IXAppConfig.cpp @@ -73,6 +62,9 @@ add_executable(ws ws_autobahn.cpp ws.cpp) +target_link_libraries(ws ixcore) +target_link_libraries(ws ixcrypto) +target_link_libraries(ws ixcobra) target_link_libraries(ws ixwebsocket) if(NOT APPLE AND NOT USE_MBED_TLS)