sanitizer cmake stuff
This commit is contained in:
parent
bf3e8195f7
commit
76f196206b
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "third_party/sanitizers-cmake"]
|
||||
path = third_party/sanitizers-cmake
|
||||
url = git://github.com/arsenm/sanitizers-cmake.git
|
@ -3,6 +3,9 @@
|
||||
# Copyright (c) 2018 Machine Zone, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../third_party/sanitizers-cmake/cmake" ${CMAKE_MODULE_PATH})
|
||||
find_package(Sanitizers)
|
||||
|
||||
cmake_minimum_required (VERSION 3.4.1)
|
||||
project (ixwebsocket_unittest)
|
||||
|
||||
@ -38,6 +41,7 @@ if (NOT WIN32)
|
||||
endif()
|
||||
|
||||
add_executable(ixwebsocket_unittest ${SOURCES})
|
||||
add_sanitizers(ixwebsocket_unittest)
|
||||
|
||||
if (APPLE AND USE_TLS)
|
||||
target_link_libraries(ixwebsocket_unittest "-framework foundation" "-framework security")
|
||||
|
133
test/IXWebSocketTestConnectionDisconnection.cpp
Normal file
133
test/IXWebSocketTestConnectionDisconnection.cpp
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* IXWebSocketTestConnectionDisconnection.cpp
|
||||
* Author: Benjamin Sergeant
|
||||
* Copyright (c) 2017 Machine Zone. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
#include <ixwebsocket/IXWebSocket.h>
|
||||
#include "IXTest.h"
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
using namespace ix;
|
||||
|
||||
namespace
|
||||
{
|
||||
const std::string WEBSOCKET_DOT_ORG_URL("wss://echo.websocket.org");
|
||||
const std::string GOOGLE_URL("wss://google.com");
|
||||
const std::string UNKNOWN_URL("wss://asdcasdcaasdcasdcasdcasdcasdcasdcasassdd.com");
|
||||
|
||||
void log(const std::string& msg)
|
||||
{
|
||||
std::cout << msg << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
class IXWebSocketTestConnectionDisconnection
|
||||
{
|
||||
public:
|
||||
IXWebSocketTestConnectionDisconnection();
|
||||
void start(const std::string& url);
|
||||
void stop();
|
||||
|
||||
private:
|
||||
ix::WebSocket _webSocket;
|
||||
};
|
||||
|
||||
IXWebSocketTestConnectionDisconnection::IXWebSocketTestConnectionDisconnection()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void IXWebSocketTestConnectionDisconnection::stop()
|
||||
{
|
||||
_webSocket.stop();
|
||||
}
|
||||
|
||||
void IXWebSocketTestConnectionDisconnection::start(const std::string& url)
|
||||
{
|
||||
_webSocket.setUrl(url);
|
||||
|
||||
std::stringstream ss;
|
||||
log(std::string("Connecting to url: ") + url);
|
||||
|
||||
_webSocket.setOnMessageCallback(
|
||||
[this](ix::WebSocketMessageType messageType,
|
||||
const std::string& str,
|
||||
size_t wireSize,
|
||||
const ix::WebSocketErrorInfo& error,
|
||||
const ix::WebSocketOpenInfo& openInfo,
|
||||
const ix::WebSocketCloseInfo& closeInfo)
|
||||
{
|
||||
std::stringstream ss;
|
||||
if (messageType == ix::WebSocket_MessageType_Open)
|
||||
{
|
||||
log("cmd_websocket_satori_chat: connected !");
|
||||
}
|
||||
else if (messageType == ix::WebSocket_MessageType_Close)
|
||||
{
|
||||
log("cmd_websocket_satori_chat: disconnected !");
|
||||
}
|
||||
else if (messageType == ix::WebSocket_MessageType_Error)
|
||||
{
|
||||
log("cmd_websocket_satori_chat: Error!");
|
||||
}
|
||||
else if (messageType == ix::WebSocket_MessageType_Message)
|
||||
{
|
||||
log("cmd_websocket_satori_chat: received message.!");
|
||||
}
|
||||
else if (messageType == ix::WebSocket_MessageType_Ping)
|
||||
{
|
||||
log("cmd_websocket_satori_chat: received ping message.!");
|
||||
}
|
||||
else if (messageType == ix::WebSocket_MessageType_Pong)
|
||||
{
|
||||
log("cmd_websocket_satori_chat: received pong message.!");
|
||||
}
|
||||
else
|
||||
{
|
||||
log("Invalid ix::WebSocketMessageType");
|
||||
}
|
||||
});
|
||||
|
||||
// Start the connection
|
||||
_webSocket.start();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// We try to connect to different servers, and make sure there are no crashes.
|
||||
// FIXME: We could do more checks (make sure that we were not able to connect to unknown servers, etc...)
|
||||
//
|
||||
TEST_CASE("websocket_connections", "[websocket]")
|
||||
{
|
||||
SECTION("Try to connect to invalid servers.")
|
||||
{
|
||||
IXWebSocketTestConnectionDisconnection chatA;
|
||||
|
||||
chatA.start(GOOGLE_URL);
|
||||
ix::msleep(1000);
|
||||
chatA.stop();
|
||||
|
||||
chatA.start(UNKNOWN_URL);
|
||||
ix::msleep(1000);
|
||||
chatA.stop();
|
||||
}
|
||||
|
||||
SECTION("Try to connect and disconnect with different timing.")
|
||||
{
|
||||
IXWebSocketTestConnectionDisconnection chatA;
|
||||
for (int i = 0; i < 50; ++i)
|
||||
{
|
||||
log(std::string("Run: ") + std::to_string(i));
|
||||
chatA.start(WEBSOCKET_DOT_ORG_URL);
|
||||
ix::msleep(i);
|
||||
chatA.stop();
|
||||
}
|
||||
}
|
||||
}
|
15
test/run.py
15
test/run.py
@ -22,7 +22,20 @@ else:
|
||||
make = 'make'
|
||||
testBinary ='./ixwebsocket_unittest'
|
||||
|
||||
os.system('cmake -DCMAKE_BUILD_TYPE=Debug {} ..'.format(generator))
|
||||
sanitizersFlags = {
|
||||
'asan': '-DSANITIZE_ADDRESS=On',
|
||||
'ubsan': '-DSANITIZE_UNDEFINED=On',
|
||||
'tsan': '-DSANITIZE_THREAD=On',
|
||||
'none': ''
|
||||
}
|
||||
sanitizer = 'tsan'
|
||||
sanitizerFlags = sanitizersFlags[sanitizer]
|
||||
|
||||
cmakeCmd = 'cmake -DCMAKE_BUILD_TYPE=Debug {} {} ..'.format(generator, sanitizerFlags)
|
||||
print(cmakeCmd)
|
||||
ret = os.system(cmakeCmd)
|
||||
assert ret == 0, 'CMake failed, exiting'
|
||||
|
||||
ret = os.system(make)
|
||||
assert ret == 0, 'Make failed, exiting'
|
||||
|
||||
|
1
third_party/sanitizers-cmake
vendored
Submodule
1
third_party/sanitizers-cmake
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 99e159ec9bc8dd362b08d18436bd40ff0648417b
|
Loading…
Reference in New Issue
Block a user