mirror of
https://github.com/outbackdingo/parodus.git
synced 2026-01-27 18:20:04 +00:00
Compare commits
25 Commits
hostname-v
...
nopoll_par
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83090240b1 | ||
|
|
4944f0a527 | ||
|
|
7732aa02f2 | ||
|
|
52e048b5ab | ||
|
|
434c84773a | ||
|
|
03d420f8f7 | ||
|
|
5f2d73e0af | ||
|
|
8909054630 | ||
|
|
a7ad3d9ea0 | ||
|
|
dd868da93f | ||
|
|
6f57f6e7c4 | ||
|
|
bf65687658 | ||
|
|
f05c67197d | ||
|
|
b029551ddd | ||
|
|
ef52fb77a6 | ||
|
|
d24717e56e | ||
|
|
85c2ccb91b | ||
|
|
aff39c7671 | ||
|
|
e324314c2d | ||
|
|
d67235b877 | ||
|
|
d1c3bc6a0a | ||
|
|
fdcdbbf430 | ||
|
|
a68b2b8913 | ||
|
|
0c17727af7 | ||
|
|
9113ce1dee |
@@ -21,12 +21,12 @@ before_install:
|
||||
|
||||
install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -y -qq libcunit1 libcunit1-dev uuid-dev
|
||||
- sudo apt-get install -y -qq libcunit1 libcunit1-dev uuid-dev valgrind
|
||||
|
||||
script:
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake .. -DINTEGRATION_TESTING:BOOL=false
|
||||
- cmake .. -DINTEGRATION_TESTING:BOOL=false -DDISABLE_VALGRIND:BOOL=true
|
||||
- make
|
||||
- make test
|
||||
|
||||
|
||||
@@ -68,13 +68,11 @@ add_dependencies(libtrower-base64 trower-base64)
|
||||
|
||||
# nopoll external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
set(PATCHES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/patches)
|
||||
set(NOPOLL_LOG_SRC ${PREFIX_DIR}/nopoll/src/nopoll/src/nopoll_log.c)
|
||||
ExternalProject_Add(nopoll
|
||||
PREFIX ${PREFIX_DIR}/nopoll
|
||||
GIT_REPOSITORY https://github.com/ASPLes/nopoll.git
|
||||
GIT_TAG "b18aacc06b4dc9700e0a261efc201a8e125e4328"
|
||||
PATCH_COMMAND patch -p1 < ${PATCHES_DIR}/nopoll.patch
|
||||
GIT_REPOSITORY https://github.com/Comcast/nopoll.git
|
||||
GIT_TAG "nopoll_yocto"
|
||||
PATCH_COMMAND ""
|
||||
COMMAND touch NEWS README AUTHORS ChangeLog
|
||||
COMMAND libtoolize --force
|
||||
COMMAND aclocal
|
||||
@@ -145,6 +143,7 @@ add_dependencies(libcimplog cimplog)
|
||||
# wrp-c external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
ExternalProject_Add(wrp-c
|
||||
DEPENDS trower-base64 msgpack cimplog
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/wrp-c
|
||||
GIT_REPOSITORY https://github.com/Comcast/wrp-c.git
|
||||
GIT_TAG "master"
|
||||
@@ -152,6 +151,9 @@ ExternalProject_Add(wrp-c
|
||||
-DMSGPACK_ENABLE_CXX=OFF
|
||||
-DMSGPACK_BUILD_EXAMPLES=OFF
|
||||
-DBUILD_TESTING=OFF
|
||||
-DMAIN_PROJ_BUILD=ON
|
||||
-DMAIN_PROJ_LIB_PATH=${LIBRARY_DIR}
|
||||
-DMAIN_PROJ_INCLUDE_PATH=${INCLUDE_DIR}
|
||||
)
|
||||
add_library(libwrp-c STATIC SHARED IMPORTED)
|
||||
add_dependencies(libwrp-c wrp-c)
|
||||
@@ -159,10 +161,16 @@ add_dependencies(libwrp-c wrp-c)
|
||||
# libparodus external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
ExternalProject_Add(libparodus
|
||||
DEPENDS trower-base64 msgpack nanomsg wrp-c
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/libparodus
|
||||
GIT_REPOSITORY https://github.com/Comcast/libparodus.git
|
||||
GIT_TAG "master"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
-DMAIN_PROJ_BUILD=ON
|
||||
-DMAIN_PROJ_LIB_PATH=${LIBRARY_DIR}
|
||||
-DMAIN_PROJ_LIB64_PATH=${LIBRARY_DIR64}
|
||||
-DMAIN_PROJ_COMMON_PATH=${COMMON_LIBRARY_DIR}
|
||||
-DMAIN_PROJ_INCLUDE_PATH=${INCLUDE_DIR}
|
||||
)
|
||||
add_library(liblibparodus STATIC SHARED IMPORTED)
|
||||
add_dependencies(liblibparodus libparodus)
|
||||
@@ -170,9 +178,15 @@ add_dependencies(liblibparodus libparodus)
|
||||
# libseshat external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
ExternalProject_Add(libseshat
|
||||
DEPENDS cJSON trower-base64 msgpack wrp-c
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/libseshat
|
||||
GIT_REPOSITORY https://github.com/comcast/seshat.git
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
-DMAIN_PROJ_BUILD=ON
|
||||
-DMAIN_PROJ_LIB_PATH=${LIBRARY_DIR}
|
||||
-DMAIN_PROJ_LIB64_PATH=${LIBRARY_DIR64}
|
||||
-DMAIN_PROJ_COMMON_PATH=${COMMON_LIBRARY_DIR}
|
||||
-DMAIN_PROJ_INCLUDE_PATH=${INCLUDE_DIR}
|
||||
)
|
||||
add_library(liblibseshat STATIC SHARED IMPORTED)
|
||||
add_dependencies(liblibseshat libseshat)
|
||||
|
||||
@@ -97,6 +97,7 @@ char* getWebpaConveyHeader()
|
||||
encodedData[j]='\0';
|
||||
ParodusPrint("Encoded X-WebPA-Convey Header: [%zd]%s\n", strlen(encodedData), encodedData);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
cJSON_Delete(response);
|
||||
return encodedData;
|
||||
}
|
||||
|
||||
10
src/config.c
10
src/config.c
@@ -249,6 +249,16 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
ParodusPrint("partner_id is NULL. read from tmp file\n");
|
||||
}
|
||||
|
||||
if( strlen(pConfig->seshat_url) !=0)
|
||||
{
|
||||
strncpy(cfg->seshat_url, pConfig->seshat_url,strlen(pConfig->seshat_url)+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("seshat_url is NULL. Read from tmp file\n");
|
||||
|
||||
}
|
||||
|
||||
cfg->boot_time = pConfig->boot_time;
|
||||
cfg->secureFlag = 1;
|
||||
cfg->webpa_ping_timeout = pConfig->webpa_ping_timeout;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#define HEARTBEAT_RETRY_SEC 30 /* Heartbeat (ping/pong) timeout in seconds */
|
||||
#define SESHAT_SERVICE_NAME "Parodus"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
@@ -34,6 +35,12 @@ bool LastReasonStatus = false;
|
||||
volatile unsigned int heartBeatTimer = 0;
|
||||
pthread_mutex_t close_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
static bool __registerWithSeshat(void);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -43,7 +50,7 @@ void createSocketConnection(void *config_in, void (* initKeypress)())
|
||||
int intTimer=0;
|
||||
ParodusCfg *tmpCfg = (ParodusCfg*)config_in;
|
||||
noPollCtx *ctx;
|
||||
bool seshat_started;
|
||||
bool seshat_registered = false;
|
||||
|
||||
loadParodusCfg(tmpCfg,get_parodus_cfg());
|
||||
ParodusPrint("Configure nopoll thread handlers in Parodus\n");
|
||||
@@ -73,14 +80,7 @@ void createSocketConnection(void *config_in, void (* initKeypress)())
|
||||
(* initKeypress) ();
|
||||
}
|
||||
|
||||
/* Start seshat lib interface */
|
||||
seshat_started = (0 == init_lib_seshat(get_parodus_cfg()->seshat_url));
|
||||
if (false == seshat_started) {
|
||||
ParodusPrint("init_lib_seshat() Failed, seshatlib not available!\n");
|
||||
} else {
|
||||
ParodusPrint("init_lib_seshat() seshatlib initialized! (url %s)\n",
|
||||
get_parodus_cfg()->seshat_url);
|
||||
}
|
||||
seshat_registered = __registerWithSeshat();
|
||||
|
||||
do
|
||||
{
|
||||
@@ -92,6 +92,7 @@ void createSocketConnection(void *config_in, void (* initKeypress)())
|
||||
if(!close_retry)
|
||||
{
|
||||
ParodusError("ping wait time > %d. Terminating the connection with WebPA server and retrying\n", get_parodus_cfg()->webpa_ping_timeout);
|
||||
ParodusInfo("Reconnect detected, setting Ping_Miss reason for Reconnect\n");
|
||||
set_global_reconnect_reason("Ping_Miss");
|
||||
LastReasonStatus = true;
|
||||
pthread_mutex_lock (&close_mut);
|
||||
@@ -111,6 +112,10 @@ void createSocketConnection(void *config_in, void (* initKeypress)())
|
||||
intTimer = 0;
|
||||
}
|
||||
|
||||
if( false == seshat_registered ) {
|
||||
seshat_registered = __registerWithSeshat();
|
||||
}
|
||||
|
||||
if(close_retry)
|
||||
{
|
||||
ParodusInfo("close_retry is %d, hence closing the connection and retrying\n", close_retry);
|
||||
@@ -123,10 +128,46 @@ void createSocketConnection(void *config_in, void (* initKeypress)())
|
||||
close_and_unref_connection(get_global_conn());
|
||||
nopoll_ctx_unref(ctx);
|
||||
nopoll_cleanup_library();
|
||||
|
||||
if (seshat_started) {
|
||||
shutdown_seshat_lib();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Internal functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Helper function to register with seshat.
|
||||
*
|
||||
* @note return whether successfully registered.
|
||||
*
|
||||
* @return true when registered, false otherwise.
|
||||
*/
|
||||
static bool __registerWithSeshat()
|
||||
{
|
||||
char *seshat_url = get_parodus_cfg()->seshat_url;
|
||||
char *parodus_url = get_parodus_cfg()->local_url;
|
||||
char *discover_url = NULL;
|
||||
bool rv = false;
|
||||
|
||||
if( 0 == init_lib_seshat(seshat_url) ) {
|
||||
ParodusInfo("seshatlib initialized! (url %s)\n", seshat_url);
|
||||
|
||||
if( 0 == seshat_register(SESHAT_SERVICE_NAME, parodus_url) ) {
|
||||
ParodusInfo("seshatlib registered! (url %s)\n", parodus_url);
|
||||
|
||||
discover_url = seshat_discover(SESHAT_SERVICE_NAME);
|
||||
if( (NULL != discover_url) && (0 == strcmp(parodus_url, discover_url)) ) {
|
||||
ParodusInfo("seshatlib discovered url = %s\n", discover_url);
|
||||
rv = true;
|
||||
} else {
|
||||
ParodusError("seshatlib registration error (url %s)!", discover_url);
|
||||
}
|
||||
free(discover_url);
|
||||
} else {
|
||||
ParodusError("seshatlib not registered! (url %s)\n", parodus_url);
|
||||
}
|
||||
} else {
|
||||
ParodusPrint("seshatlib not initialized! (url %s)\n", seshat_url);
|
||||
}
|
||||
|
||||
shutdown_seshat_lib();
|
||||
return rv;
|
||||
}
|
||||
|
||||
137
src/connection.c
137
src/connection.c
@@ -26,6 +26,8 @@
|
||||
char deviceMAC[32]={'\0'};
|
||||
static char *reconnect_reason = "webpa_process_starts";
|
||||
static noPollConn *g_conn = NULL;
|
||||
static noPollConnOpts * createConnOpts ();
|
||||
static noPollConn * nopoll_tls_common_conn (noPollCtx * ctx,char * serverAddr,char *serverPort);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
@@ -60,20 +62,10 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
bool initial_retry = false;
|
||||
int backoffRetryTime = 0;
|
||||
int max_retry_sleep;
|
||||
char device_id[32]={'\0'};
|
||||
char user_agent[512]={'\0'};
|
||||
const char * headerNames[HTTP_CUSTOM_HEADER_COUNT] = {"X-WebPA-Device-Name","X-WebPA-Device-Protocols","User-Agent", "X-WebPA-Convey"};
|
||||
const char *headerValues[HTTP_CUSTOM_HEADER_COUNT];
|
||||
int headerCount = HTTP_CUSTOM_HEADER_COUNT; /* Invalid X-Webpa-Convey header Bug # WEBPA-787 */
|
||||
char port[8];
|
||||
noPollConnOpts * opts;
|
||||
char server_Address[256];
|
||||
char redirectURL[128]={'\0'};
|
||||
char *temp_ptr, *conveyHeader;
|
||||
int connErr=0;
|
||||
struct timespec connErr_start,connErr_end,*connErr_startPtr,*connErr_endPtr;
|
||||
connErr_startPtr = &connErr_start;
|
||||
connErr_endPtr = &connErr_end;
|
||||
char *temp_ptr;
|
||||
//Retry Backoff count shall start at c=2 & calculate 2^c - 1.
|
||||
int c=2;
|
||||
|
||||
@@ -81,44 +73,9 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
return nopoll_false;
|
||||
}
|
||||
|
||||
FILE *fp;
|
||||
fp = fopen("/tmp/parodus_ready", "r");
|
||||
|
||||
if (fp!=NULL)
|
||||
{
|
||||
unlink("/tmp/parodus_ready");
|
||||
ParodusPrint("Closing Parodus_Ready FIle \n");
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
parStrncpy(deviceMAC, get_parodus_cfg()->hw_mac,sizeof(deviceMAC));
|
||||
snprintf(device_id, sizeof(device_id), "mac:%s", deviceMAC);
|
||||
ParodusInfo("Device_id %s\n",device_id);
|
||||
|
||||
headerValues[0] = device_id;
|
||||
headerValues[1] = "wrp-0.11,getset-0.1";
|
||||
|
||||
ParodusPrint("BootTime In sec: %d\n", get_parodus_cfg()->boot_time);
|
||||
ParodusInfo("Received reboot_reason as:%s\n", get_parodus_cfg()->hw_last_reboot_reason);
|
||||
ParodusInfo("Received reconnect_reason as:%s\n", reconnect_reason);
|
||||
snprintf(user_agent, sizeof(user_agent),
|
||||
"%s (%s; %s/%s;)",
|
||||
((0 != strlen(get_parodus_cfg()->webpa_protocol)) ? get_parodus_cfg()->webpa_protocol : "unknown"),
|
||||
((0 != strlen(get_parodus_cfg()->fw_name)) ? get_parodus_cfg()->fw_name : "unknown"),
|
||||
((0 != strlen(get_parodus_cfg()->hw_model)) ? get_parodus_cfg()->hw_model : "unknown"),
|
||||
((0 != strlen(get_parodus_cfg()->hw_manufacturer)) ? get_parodus_cfg()->hw_manufacturer : "unknown"));
|
||||
|
||||
ParodusInfo("User-Agent: %s\n",user_agent);
|
||||
headerValues[2] = user_agent;
|
||||
conveyHeader = getWebpaConveyHeader();
|
||||
if(strlen(conveyHeader) > 0)
|
||||
{
|
||||
headerValues[3] = conveyHeader;
|
||||
}
|
||||
else
|
||||
{
|
||||
headerValues[3] = "";
|
||||
headerCount -= 1;
|
||||
}
|
||||
snprintf(port,sizeof(port),"%d",8080);
|
||||
parStrncpy(server_Address, get_parodus_cfg()->webpa_url, sizeof(server_Address));
|
||||
ParodusInfo("server_Address %s\n",server_Address);
|
||||
@@ -139,20 +96,13 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
if(get_parodus_cfg()->secureFlag)
|
||||
{
|
||||
ParodusPrint("secure true\n");
|
||||
/* disable verification */
|
||||
opts = nopoll_conn_opts_new ();
|
||||
nopoll_conn_opts_ssl_peer_verify (opts, nopoll_false);
|
||||
nopoll_conn_opts_set_ssl_protocol (opts, NOPOLL_METHOD_TLSV1_2);
|
||||
connection = nopoll_conn_tls_new(ctx, opts, server_Address, port, NULL,
|
||||
get_parodus_cfg()->webpa_path_url, NULL, NULL, get_parodus_cfg()->webpa_interface_used,
|
||||
headerNames, headerValues, headerCount);// WEBPA-787
|
||||
connection = nopoll_tls_common_conn(ctx,server_Address, port);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("secure false\n");
|
||||
connection = nopoll_conn_new(ctx, server_Address, port, NULL,
|
||||
get_parodus_cfg()->webpa_path_url, NULL, NULL, get_parodus_cfg()->webpa_interface_used,
|
||||
headerNames, headerValues, headerCount);// WEBPA-787
|
||||
get_parodus_cfg()->webpa_path_url, NULL, NULL);// WEBPA-787
|
||||
}
|
||||
set_global_conn(connection);
|
||||
|
||||
@@ -220,32 +170,6 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* If the connect error is due to DNS resolving to 10.0.0.1 then start timer.
|
||||
* Timeout after 15 minutes if the error repeats continuously and kill itself.
|
||||
*/
|
||||
if((checkHostIp(server_Address) == -2))
|
||||
{
|
||||
if(connErr == 0)
|
||||
{
|
||||
getCurrentTime(connErr_startPtr);
|
||||
connErr = 1;
|
||||
ParodusInfo("First connect error occurred, initialized the connect error timer\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
getCurrentTime(connErr_endPtr);
|
||||
ParodusPrint("checking timeout difference:%ld\n", timeValDiff(connErr_startPtr, connErr_endPtr));
|
||||
if(timeValDiff(connErr_startPtr, connErr_endPtr) >= (15*60*1000))
|
||||
{
|
||||
ParodusError("WebPA unable to connect due to DNS resolving to 10.0.0.1 for over 15 minutes; crashing service.\n");
|
||||
reconnect_reason = "Dns_Res_webpa_reconnect";
|
||||
LastReasonStatus = true;
|
||||
|
||||
kill(getpid(),SIGTERM);
|
||||
}
|
||||
}
|
||||
}
|
||||
initial_retry = true;
|
||||
ParodusInfo("Waiting with backoffRetryTime %d seconds\n", backoffRetryTime);
|
||||
sleep(backoffRetryTime);
|
||||
@@ -273,7 +197,6 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
ParodusPrint("createNopollConnection(): close_mut unlock\n");
|
||||
heartBeatTimer = 0;
|
||||
// Reset connErr flag on successful connection
|
||||
connErr = 0;
|
||||
reconnect_reason = "webpa_process_starts";
|
||||
LastReasonStatus =false;
|
||||
ParodusPrint("LastReasonStatus reset after successful connection\n");
|
||||
@@ -281,6 +204,54 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
|
||||
return nopoll_true;
|
||||
}
|
||||
static noPollConn * nopoll_tls_common_conn (noPollCtx * ctx,char * serverAddr,char *serverPort)
|
||||
{
|
||||
noPollConnOpts * opts;
|
||||
noPollConn *connection = NULL;
|
||||
opts = createConnOpts();
|
||||
ParodusInfo("Try connecting with Ipv6 mode\n");
|
||||
connection = nopoll_conn_tls_new6 (ctx, opts,serverAddr,serverPort,NULL,get_parodus_cfg()->webpa_path_url,NULL,NULL);
|
||||
if(connection == NULL)
|
||||
{
|
||||
ParodusInfo("Ipv6 connection failed. Try connecting with Ipv4 mode \n");
|
||||
opts = createConnOpts();
|
||||
connection = nopoll_conn_tls_new (ctx, opts,serverAddr,serverPort,NULL,get_parodus_cfg()->webpa_path_url,NULL,NULL);
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
static noPollConnOpts * createConnOpts ()
|
||||
{
|
||||
noPollConnOpts * opts;
|
||||
char device_id[32]={'\0'};
|
||||
char * extra_headers, *conveyHeader = NULL;
|
||||
char user_agent[512]={'\0'};
|
||||
|
||||
opts = nopoll_conn_opts_new ();
|
||||
nopoll_conn_opts_ssl_peer_verify (opts, nopoll_false);
|
||||
nopoll_conn_opts_set_ssl_protocol (opts, NOPOLL_METHOD_TLSV1_2);
|
||||
nopoll_conn_opts_set_interface (opts,get_parodus_cfg()->webpa_interface_used);
|
||||
snprintf(user_agent, sizeof(user_agent),"%s (%s; %s/%s;)",
|
||||
((0 != strlen(get_parodus_cfg()->webpa_protocol)) ? get_parodus_cfg()->webpa_protocol : "unknown"),
|
||||
((0 != strlen(get_parodus_cfg()->fw_name)) ? get_parodus_cfg()->fw_name : "unknown"),
|
||||
((0 != strlen(get_parodus_cfg()->hw_model)) ? get_parodus_cfg()->hw_model : "unknown"),
|
||||
((0 != strlen(get_parodus_cfg()->hw_manufacturer)) ? get_parodus_cfg()->hw_manufacturer : "unknown"));
|
||||
|
||||
ParodusInfo("User-Agent: %s\n",user_agent);
|
||||
conveyHeader = getWebpaConveyHeader();
|
||||
|
||||
parStrncpy(deviceMAC, get_parodus_cfg()->hw_mac,sizeof(deviceMAC));
|
||||
snprintf(device_id, sizeof(device_id), "mac:%s", deviceMAC);
|
||||
ParodusInfo("Device_id %s\n",device_id);
|
||||
|
||||
extra_headers = nopoll_strdup_printf("\r\nX-WebPA-Device-Name: %s"
|
||||
"\r\nX-WebPA-Device-Protocols: wrp-0.11,getset-0.1"
|
||||
"\r\nUser-Agent: %s" "\r\nX-WebPA-Convey: %s",device_id,user_agent,(strlen(conveyHeader) > 0)? conveyHeader :"");
|
||||
|
||||
nopoll_conn_opts_set_extra_headers (opts,extra_headers);
|
||||
return opts;
|
||||
}
|
||||
|
||||
|
||||
void close_and_unref_connection(noPollConn *conn)
|
||||
{
|
||||
|
||||
@@ -53,6 +53,11 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
ParodusPrint("\nDecoded recivedMsg of size:%d\n", rv);
|
||||
msgType = message->msg_type;
|
||||
ParodusInfo("msgType received:%d\n", msgType);
|
||||
|
||||
if(message->msg_type == WRP_MSG_TYPE__AUTH)
|
||||
{
|
||||
ParodusInfo("Authorization Status received with Status code :%d\n", message->u.auth.status);
|
||||
}
|
||||
|
||||
if(message->msg_type == WRP_MSG_TYPE__REQ)
|
||||
{
|
||||
@@ -127,6 +132,9 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
sendUpstreamMsgToServer(&resp_bytes, size);
|
||||
}
|
||||
free(str);
|
||||
cJSON_Delete(response);
|
||||
free(resp_bytes);
|
||||
resp_bytes = NULL;
|
||||
}
|
||||
free(resp_msg);
|
||||
}
|
||||
|
||||
59
src/main.c
59
src/main.c
@@ -16,10 +16,11 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "stdlib.h"
|
||||
#include "config.h"
|
||||
#include "conn_interface.h"
|
||||
#include "parodus_log.h"
|
||||
#include "signal.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
@@ -39,13 +40,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* none */
|
||||
static void sig_handler(int sig);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int main( int argc, char **argv)
|
||||
{
|
||||
signal(SIGTERM, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGUSR1, sig_handler);
|
||||
signal(SIGUSR2, sig_handler);
|
||||
signal(SIGSEGV, sig_handler);
|
||||
signal(SIGBUS, sig_handler);
|
||||
signal(SIGKILL, sig_handler);
|
||||
signal(SIGFPE, sig_handler);
|
||||
signal(SIGILL, sig_handler);
|
||||
signal(SIGQUIT, sig_handler);
|
||||
signal(SIGHUP, sig_handler);
|
||||
signal(SIGALRM, sig_handler);
|
||||
|
||||
ParodusCfg parodusCfg;
|
||||
memset(&parodusCfg,0,sizeof(parodusCfg));
|
||||
|
||||
@@ -65,4 +79,43 @@ const char *rdk_logger_module_fetch(void)
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Internal functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* none */
|
||||
static void sig_handler(int sig)
|
||||
{
|
||||
|
||||
if ( sig == SIGINT )
|
||||
{
|
||||
signal(SIGINT, sig_handler); /* reset it to this function */
|
||||
ParodusInfo("SIGINT received!\n");
|
||||
exit(0);
|
||||
}
|
||||
else if ( sig == SIGUSR1 )
|
||||
{
|
||||
signal(SIGUSR1, sig_handler); /* reset it to this function */
|
||||
ParodusInfo("SIGUSR1 received!\n");
|
||||
}
|
||||
else if ( sig == SIGUSR2 )
|
||||
{
|
||||
ParodusInfo("SIGUSR2 received!\n");
|
||||
}
|
||||
else if ( sig == SIGCHLD )
|
||||
{
|
||||
signal(SIGCHLD, sig_handler); /* reset it to this function */
|
||||
ParodusInfo("SIGHLD received!\n");
|
||||
}
|
||||
else if ( sig == SIGPIPE )
|
||||
{
|
||||
signal(SIGPIPE, sig_handler); /* reset it to this function */
|
||||
ParodusInfo("SIGPIPE received!\n");
|
||||
}
|
||||
else if ( sig == SIGALRM )
|
||||
{
|
||||
signal(SIGALRM, sig_handler); /* reset it to this function */
|
||||
ParodusInfo("SIGALRM received!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("Signal %d received!\n", sig);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -119,11 +119,13 @@ void listenerOnCloseMessage (noPollCtx * ctx, noPollConn * conn, noPollPtr user_
|
||||
|
||||
if((user_data != NULL) && (strstr(user_data, "SSL_Socket_Close") != NULL) && !LastReasonStatus)
|
||||
{
|
||||
ParodusInfo("Reconnect detected, setting Reconnect reason as Server close\n");
|
||||
set_global_reconnect_reason("Server_closed_connection");
|
||||
LastReasonStatus = true;
|
||||
}
|
||||
else if ((user_data == NULL) && !LastReasonStatus)
|
||||
{
|
||||
ParodusInfo("Reconnect detected, setting Reconnect reason as Unknown\n");
|
||||
set_global_reconnect_reason("Unknown");
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ int sendResponse(noPollConn * conn, void * buffer, size_t length)
|
||||
{
|
||||
if (-1 == bytes_sent || (bytes_sent = nopoll_conn_flush_writes(conn, FLUSH_WAIT_TIME, bytes_sent)) != len_to_send)
|
||||
{
|
||||
ParodusPrint("sendResponse() Failed to send all the data\n");
|
||||
ParodusError("sendResponse() Failed to send all the data\n");
|
||||
cp = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ void *serviceAliveTask()
|
||||
else
|
||||
{
|
||||
ParodusInfo("No clients are registered, waiting ..\n");
|
||||
sleep(70);
|
||||
sleep(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,6 +275,8 @@ void *processUpstreamMessage()
|
||||
sendUpstreamMsgToServer(&bytes, size);
|
||||
}
|
||||
free(eventMsg);
|
||||
free(bytes);
|
||||
bytes = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -19,26 +19,30 @@ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-cov
|
||||
set (PARODUS_COMMON_SRC ../src/string_helpers.c ../src/mutex.c ../src/time.c ../src/config.c ../src/spin_thread.c)
|
||||
set (PARODUS_COMMON_LIBS gcov -lcunit -lcimplog -llibseshat -lwrp-c -luuid -lpthread -lm -lmsgpackc -lcjson -ltrower-base64 -lnopoll -lnanomsg -Wl,--no-as-needed -lrt)
|
||||
|
||||
if(NOT DISABLE_VALGRIND)
|
||||
set (MEMORY_CHECK valgrind --leak-check=full --show-reachable=yes -v)
|
||||
endif ()
|
||||
|
||||
link_directories ( ${LIBRARY_DIR} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_mutex
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_mutex COMMAND test_mutex)
|
||||
add_test(NAME test_mutex COMMAND ${MEMORY_CHECK} ./test_mutex)
|
||||
add_executable(test_mutex test_mutex.c ../src/mutex.c)
|
||||
target_link_libraries (test_mutex ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_networking
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_networking COMMAND test_networking)
|
||||
add_test(NAME test_networking COMMAND ${MEMORY_CHECK} ./test_networking)
|
||||
add_executable(test_networking test_networking.c ../src/networking.c)
|
||||
target_link_libraries (test_networking ${PARODUS_COMMON_LIBS})
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_nopoll_helpers
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_nopoll_helpers COMMAND test_nopoll_helpers)
|
||||
add_test(NAME test_nopoll_helpers COMMAND ${MEMORY_CHECK} ./test_nopoll_helpers)
|
||||
add_executable(test_nopoll_helpers test_nopoll_helpers.c ../src/nopoll_helpers.c)
|
||||
target_link_libraries (test_nopoll_helpers -Wl,--no-as-needed -lrt -lcmocka -lcimplog -lnopoll)
|
||||
|
||||
@@ -64,112 +68,112 @@ target_link_libraries (libpd_test
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_time
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_time COMMAND test_time)
|
||||
add_test(NAME test_time COMMAND ${MEMORY_CHECK} ./test_time)
|
||||
add_executable(test_time test_time.c ../src/time.c)
|
||||
target_link_libraries (test_time ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_spin_thread error
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_spin_thread_e COMMAND test_spin_thread_e)
|
||||
add_test(NAME test_spin_thread_e COMMAND ${MEMORY_CHECK} ./test_spin_thread_e)
|
||||
add_executable(test_spin_thread_e test_spin_thread_e.c ../src/spin_thread.c)
|
||||
target_link_libraries (test_spin_thread_e ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_spin_thread success
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_spin_thread_s COMMAND test_spin_thread_s)
|
||||
add_test(NAME test_spin_thread_s COMMAND ${MEMORY_CHECK} ./test_spin_thread_s)
|
||||
add_executable(test_spin_thread_s test_spin_thread_s.c ../src/spin_thread.c)
|
||||
target_link_libraries (test_spin_thread_s ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_string_helpers
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_string_helpers COMMAND test_string_helpers)
|
||||
add_test(NAME test_string_helpers COMMAND ${MEMORY_CHECK} ./test_string_helpers)
|
||||
add_executable(test_string_helpers test_string_helpers.c ../src/string_helpers.c)
|
||||
target_link_libraries (test_string_helpers ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_nopoll_handlers
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_nopoll_handlers COMMAND test_nopoll_handlers)
|
||||
add_test(NAME test_nopoll_handlers COMMAND ${MEMORY_CHECK} ./test_nopoll_handlers)
|
||||
add_executable(test_nopoll_handlers test_nopoll_handlers.c ../src/nopoll_handlers.c)
|
||||
target_link_libraries (test_nopoll_handlers -lnopoll -lcunit -lcimplog -Wl,--no-as-needed -lrt -lpthread -lm)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_connection
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_connection COMMAND test_connection)
|
||||
add_test(NAME test_connection COMMAND ${MEMORY_CHECK} ./test_connection)
|
||||
add_executable(test_connection test_connection.c ../src/connection.c ${PARODUS_COMMON_SRC})
|
||||
target_link_libraries (test_connection ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_connection - function createNopollConnection
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_createConnection COMMAND test_createConnection)
|
||||
add_test(NAME test_createConnection COMMAND ${MEMORY_CHECK} ./test_createConnection)
|
||||
add_executable(test_createConnection test_createConnection.c ../src/connection.c ../src/string_helpers.c ../src/config.c)
|
||||
target_link_libraries (test_createConnection ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_client_list
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_client_list COMMAND test_client_list)
|
||||
add_test(NAME test_client_list COMMAND ${MEMORY_CHECK} ./test_client_list)
|
||||
add_executable(test_client_list test_client_list.c ../src/client_list.c ../src/service_alive.c ../src/upstream.c ../src/networking.c ../src/nopoll_helpers.c ../src/downstream.c ../src/connection.c ../src/nopoll_handlers.c ../src/ParodusInternal.c ../src/thread_tasks.c ../src/conn_interface.c ../src/partners_check.c ${PARODUS_COMMON_SRC})
|
||||
target_link_libraries (test_client_list ${PARODUS_COMMON_LIBS})
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_service_alive
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_service_alive COMMAND test_service_alive)
|
||||
add_test(NAME test_service_alive COMMAND ${MEMORY_CHECK} ./test_service_alive)
|
||||
add_executable(test_service_alive test_service_alive.c ../src/client_list.c ../src/service_alive.c ../src/upstream.c ../src/networking.c ../src/nopoll_helpers.c ../src/nopoll_handlers.c ../src/config.c ../src/connection.c ../src/ParodusInternal.c ../src/downstream.c ../src/thread_tasks.c ../src/conn_interface.c ../src/partners_check.c ${PARODUS_COMMON_SRC})
|
||||
target_link_libraries (test_service_alive ${PARODUS_COMMON_LIBS})
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_config
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_config COMMAND test_config)
|
||||
add_test(NAME test_config COMMAND ${MEMORY_CHECK} ./test_config)
|
||||
add_executable(test_config test_config.c ../src/config.c ../src/string_helpers.c)
|
||||
target_link_libraries (test_config -lcmocka -lm -Wl,--no-as-needed -lrt -lcimplog)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_upstream
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_upstream COMMAND test_upstream)
|
||||
add_test(NAME test_upstream COMMAND ${MEMORY_CHECK} ./test_upstream)
|
||||
add_executable(test_upstream test_upstream.c ../src/upstream.c)
|
||||
target_link_libraries (test_upstream -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_downstream
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_downstream COMMAND test_downstream)
|
||||
add_test(NAME test_downstream COMMAND ${MEMORY_CHECK} ./test_downstream)
|
||||
add_executable(test_downstream test_downstream.c ../src/downstream.c ../src/string_helpers.c)
|
||||
target_link_libraries (test_downstream -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_thread_tasks
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_thread_tasks COMMAND test_thread_tasks)
|
||||
add_test(NAME test_thread_tasks COMMAND ${MEMORY_CHECK} ./test_thread_tasks)
|
||||
add_executable(test_thread_tasks test_thread_tasks.c ../src/thread_tasks.c)
|
||||
target_link_libraries (test_thread_tasks -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_conn_interface
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_conn_interface COMMAND test_conn_interface)
|
||||
add_test(NAME test_conn_interface COMMAND ${MEMORY_CHECK} ./test_conn_interface)
|
||||
add_executable(test_conn_interface test_conn_interface.c ../src/conn_interface.c ../src/config.c ../src/string_helpers.c ../src/mutex.c)
|
||||
target_link_libraries (test_conn_interface -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_ParodusInternal
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_ParodusInternal COMMAND test_ParodusInternal)
|
||||
add_test(NAME test_ParodusInternal COMMAND ${MEMORY_CHECK} ./test_ParodusInternal)
|
||||
add_executable(test_ParodusInternal test_ParodusInternal.c ../src/ParodusInternal.c ../src/config.c ../src/string_helpers.c)
|
||||
target_link_libraries (test_ParodusInternal -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_partners_check
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_partners_check COMMAND test_partners_check)
|
||||
add_test(NAME test_partners_check COMMAND ${MEMORY_CHECK} ./test_partners_check)
|
||||
add_executable(test_partners_check test_partners_check.c ../src/partners_check.c)
|
||||
target_link_libraries (test_partners_check -lcmocka -lwrp-c -llibseshat ${PARODUS_COMMON_LIBS})
|
||||
|
||||
@@ -177,7 +181,7 @@ if (INTEGRATION_TESTING)
|
||||
#-------------------------------------------------------------------------------
|
||||
# simple_connection test
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME simple_connection COMMAND simple_connection)
|
||||
add_test(NAME simple_connection COMMAND ${MEMORY_CHECK} ./simple_connection)
|
||||
add_executable(simple_connection simple_connection.c ${PARODUS_COMMON_SRC}
|
||||
../src/upstream.c
|
||||
../src/conn_interface.c
|
||||
@@ -193,28 +197,4 @@ add_executable(simple_connection simple_connection.c ${PARODUS_COMMON_SRC}
|
||||
../src/service_alive.c)
|
||||
target_link_libraries (simple_connection ${PARODUS_COMMON_LIBS})
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# simple test
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME simple COMMAND simple)
|
||||
add_executable(simple simple.c
|
||||
../src/upstream.c
|
||||
../src/conn_interface.c
|
||||
../src/downstream.c
|
||||
../src/thread_tasks.c
|
||||
../src/networking.c
|
||||
../src/nopoll_helpers.c
|
||||
../src/nopoll_handlers.c
|
||||
../src/string_helpers.c
|
||||
../src/mutex.c
|
||||
../src/time.c
|
||||
../src/config.c
|
||||
../src/connection.c
|
||||
../src/ParodusInternal.c
|
||||
../src/spin_thread.c
|
||||
../src/client_list.c
|
||||
../src/partners_check.c
|
||||
../src/service_alive.c)
|
||||
|
||||
target_link_libraries (simple ${PARODUS_COMMON_LIBS} gcov -lnopoll -lnanomsg )
|
||||
endif (INTEGRATION_TESTING)
|
||||
|
||||
712
tests/simple.c
712
tests/simple.c
@@ -1,712 +0,0 @@
|
||||
/**
|
||||
* Copyright 2010-2016 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* Licensed 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 <stdarg.h>
|
||||
|
||||
#include <CUnit/Basic.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <nopoll.h>
|
||||
|
||||
//#include <nanomsg/bus.h>
|
||||
|
||||
#include "../src/ParodusInternal.h"
|
||||
#include "../src/config.h"
|
||||
#include "../src/nopoll_helpers.h"
|
||||
#include "../src/downstream.h"
|
||||
#include "../src/upstream.h"
|
||||
|
||||
#include<errno.h>
|
||||
|
||||
/* Nanomsg related Macros */
|
||||
#define ENDPOINT "tcp://127.0.0.1:6666"
|
||||
#define CLIENT1_URL "tcp://127.0.0.1:6667"
|
||||
#define CLIENT2_URL "tcp://127.0.0.1:6668"
|
||||
#define CLIENT3_URL "tcp://127.0.0.1:6669"
|
||||
#define HTTP_CUSTOM_HEADER_COUNT 4
|
||||
|
||||
static void send_nanomsg_upstream(void **buf, int size);
|
||||
void *handle_testsuites();
|
||||
headers_t headers = { 2, {"Header 1", "Header 2"}};
|
||||
|
||||
void test_nanomsg_client_registration1()
|
||||
{
|
||||
|
||||
/*****Test svc registation for nanomsg client1 ***/
|
||||
ParodusInfo("test_nanomsg_client_registration1\n");
|
||||
|
||||
const wrp_msg_t reg = { .msg_type = WRP_MSG_TYPE__SVC_REGISTRATION,
|
||||
.u.reg.service_name = "iot",
|
||||
.u.reg.url = CLIENT1_URL};
|
||||
|
||||
void *bytes;
|
||||
int size =0;
|
||||
int rv1, rc;
|
||||
wrp_msg_t *msg1;
|
||||
int sock, bind;
|
||||
int byte =0;
|
||||
int t=25000;
|
||||
|
||||
// msgpack encode
|
||||
ParodusPrint("msgpack encode\n");
|
||||
size = wrp_struct_to( ®, WRP_BYTES, &bytes );
|
||||
|
||||
/*** Enable this to decode and verify upstream registration msg **/
|
||||
/***
|
||||
rv = wrp_to_struct(bytes, size, WRP_BYTES, &message);
|
||||
ParodusPrint("decoded msgType:%d\n", message->msg_type);
|
||||
ParodusPrint("decoded service_name:%s\n", message->u.reg.service_name);
|
||||
ParodusPrint("decoded dest:%s\n", message->u.reg.url);
|
||||
wrp_free_struct(message);
|
||||
***/
|
||||
|
||||
//nanomsg socket
|
||||
sock = nn_socket (AF_SP, NN_PUSH);
|
||||
int connect = nn_connect (sock, ENDPOINT);
|
||||
CU_ASSERT(connect >= 0);
|
||||
rc = nn_setsockopt(sock, NN_SOL_SOCKET, NN_SNDTIMEO, &t, sizeof(t));
|
||||
CU_ASSERT(rc >= 0);
|
||||
byte = nn_send (sock, bytes, size, 0);
|
||||
ParodusInfo("----->Expected byte to be sent:%d\n", size);
|
||||
ParodusInfo("----->actual byte sent:%d\n", byte);
|
||||
ParodusInfo("Nanomsg client1 - Testing Upstream Registration msg send\n");
|
||||
CU_ASSERT_EQUAL( byte, size );
|
||||
|
||||
//************************************************************
|
||||
|
||||
int sock1 = nn_socket (AF_SP, NN_PULL);
|
||||
byte = 0;
|
||||
bind = nn_bind(sock1, reg.u.reg.url);
|
||||
CU_ASSERT(bind >= 0);
|
||||
|
||||
void *buf = NULL;
|
||||
rc = nn_setsockopt(sock1, NN_SOL_SOCKET, NN_RCVTIMEO, &t, sizeof(t));
|
||||
CU_ASSERT(rc >= 0);
|
||||
|
||||
ParodusPrint("Client 1 waiting for acknowledgement \n");
|
||||
byte = nn_recv(sock1, &buf, NN_MSG, 0);
|
||||
ParodusInfo("Data Received for client 1 : %s \n", (char * )buf);
|
||||
|
||||
rv1 = wrp_to_struct((void *)buf, byte, WRP_BYTES, &msg1);
|
||||
|
||||
CU_ASSERT_EQUAL( rv1, byte );
|
||||
|
||||
ParodusPrint("msg1->msg_type for client 1 = %d \n", msg1->msg_type);
|
||||
ParodusPrint("msg1->status for client 1 = %d \n", msg1->u.auth.status);
|
||||
CU_ASSERT_EQUAL(msg1->msg_type, 2);
|
||||
CU_ASSERT_EQUAL(msg1->u.auth.status, 200);
|
||||
|
||||
rc = nn_freemsg(buf);
|
||||
CU_ASSERT(rc == 0);
|
||||
free(bytes);
|
||||
wrp_free_struct(msg1);
|
||||
rc = nn_shutdown(sock1, bind);
|
||||
CU_ASSERT(rc == 0);
|
||||
}
|
||||
|
||||
void test_nanomsg_client_registration2()
|
||||
{
|
||||
|
||||
/*****Test svc registation for upstream - nanomsg client2 ***/
|
||||
ParodusInfo("test_nanomsg_client_registration2\n");
|
||||
|
||||
const wrp_msg_t reg = { .msg_type = WRP_MSG_TYPE__SVC_REGISTRATION,
|
||||
.u.reg.service_name = "iot2",
|
||||
.u.reg.url = CLIENT2_URL};
|
||||
|
||||
void *bytes;
|
||||
int size;
|
||||
int rv1, rc;
|
||||
wrp_msg_t *msg1;
|
||||
int sock, bind;
|
||||
int byte =0;
|
||||
int t=28000;
|
||||
|
||||
// msgpack encode
|
||||
ParodusPrint("msgpack encode\n");
|
||||
size = wrp_struct_to( ®, WRP_BYTES, &bytes );
|
||||
|
||||
/*** Enable this to decode and verify packed upstream registration msg **/
|
||||
/**
|
||||
rv = wrp_to_struct(bytes, size, WRP_BYTES, &message);
|
||||
ParodusPrint("decoded msgType:%d\n", message->msg_type);
|
||||
ParodusPrint("decoded service_name:%s\n", message->u.reg.service_name);
|
||||
ParodusPrint("decoded dest:%s\n", message->u.reg.url);
|
||||
wrp_free_struct(message);
|
||||
***/
|
||||
|
||||
//nanomsg socket
|
||||
sock = nn_socket (AF_SP, NN_PUSH);
|
||||
int connect = nn_connect (sock, ENDPOINT);
|
||||
CU_ASSERT( connect >= 0);
|
||||
rc = nn_setsockopt(sock, NN_SOL_SOCKET, NN_SNDTIMEO, &t, sizeof(t));
|
||||
CU_ASSERT(rc >= 0);
|
||||
byte = nn_send (sock, bytes, size,0);
|
||||
ParodusInfo("----->Expected byte to be sent:%d\n", size);
|
||||
ParodusInfo("----->actual byte sent:%d\n", byte);
|
||||
ParodusInfo("Nanomsg client2 - Testing Upstream Registration msg send\n");
|
||||
CU_ASSERT_EQUAL( byte, size );
|
||||
|
||||
int sock1 = nn_socket (AF_SP, NN_PULL);
|
||||
byte = 0;
|
||||
bind = nn_bind(sock1, reg.u.reg.url);
|
||||
CU_ASSERT(bind >= 0);
|
||||
|
||||
void *buf1 = NULL;
|
||||
|
||||
rc = nn_setsockopt(sock1, NN_SOL_SOCKET, NN_RCVTIMEO, &t, sizeof(t));
|
||||
CU_ASSERT(rc >= 0);
|
||||
|
||||
ParodusPrint("Client 2 waiting for acknowledgement \n");
|
||||
|
||||
byte = nn_recv(sock1, &buf1, NN_MSG, 0);
|
||||
ParodusInfo("Data Received : %s \n", (char * )buf1);
|
||||
|
||||
rv1 = wrp_to_struct((void *)buf1, byte, WRP_BYTES, &msg1);
|
||||
CU_ASSERT_EQUAL( rv1, byte );
|
||||
ParodusPrint("msg1->msg_type for client 2 = %d \n", msg1->msg_type);
|
||||
ParodusPrint("msg1->status for client 2 = %d \n", msg1->u.auth.status);
|
||||
CU_ASSERT_EQUAL(msg1->msg_type, 2);
|
||||
CU_ASSERT_EQUAL(msg1->u.auth.status, 200);
|
||||
|
||||
rc = nn_freemsg(buf1);
|
||||
CU_ASSERT(rc == 0);
|
||||
free(bytes);
|
||||
wrp_free_struct(msg1);
|
||||
rc = nn_shutdown(sock1, bind);
|
||||
CU_ASSERT(rc == 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void test_nanomsg_client_registration3()
|
||||
{
|
||||
|
||||
/*****Test svc registation for upstream - nanomsg client2 ***/
|
||||
ParodusInfo("test_nanomsg_client_registration3\n");
|
||||
|
||||
const wrp_msg_t reg = { .msg_type = WRP_MSG_TYPE__SVC_REGISTRATION,
|
||||
.u.reg.service_name = "iot",
|
||||
.u.reg.url = CLIENT3_URL};
|
||||
void *bytes;
|
||||
int size;
|
||||
int rv1, rc;
|
||||
wrp_msg_t *msg1;
|
||||
int sock;
|
||||
int byte =0;
|
||||
int t=35000;
|
||||
|
||||
// msgpack encode
|
||||
ParodusPrint("msgpack encode\n");
|
||||
size = wrp_struct_to( ®, WRP_BYTES, &bytes );
|
||||
|
||||
/*** Enable this to decode and verify packed upstream registration msg **/
|
||||
/**
|
||||
rv = wrp_to_struct(bytes, size, WRP_BYTES, &message);
|
||||
ParodusPrint("decoded msgType:%d\n", message->msg_type);
|
||||
ParodusPrint("decoded service_name:%s\n", message->u.reg.service_name);
|
||||
ParodusPrint("decoded dest:%s\n", message->u.reg.url);
|
||||
wrp_free_struct(message);
|
||||
***/
|
||||
|
||||
//nanomsg socket
|
||||
sock = nn_socket (AF_SP, NN_PUSH);
|
||||
int connect = nn_connect (sock, ENDPOINT);
|
||||
CU_ASSERT(connect >= 0);
|
||||
rc = nn_setsockopt(sock, NN_SOL_SOCKET, NN_SNDTIMEO, &t, sizeof(t));
|
||||
CU_ASSERT(rc >= 0);
|
||||
byte = nn_send (sock, bytes, size,0);
|
||||
ParodusInfo("----->Expected byte to be sent:%d\n", size);
|
||||
ParodusInfo("----->actual byte sent:%d\n", byte);
|
||||
ParodusInfo("Nanomsg client3 - Testing Upstream Registration msg send\n");
|
||||
CU_ASSERT_EQUAL( byte, size );
|
||||
|
||||
int sock1 = nn_socket (AF_SP, NN_PULL);
|
||||
byte = 0;
|
||||
|
||||
int bind = nn_bind(sock1, reg.u.reg.url);
|
||||
CU_ASSERT(bind >= 0);
|
||||
ParodusPrint("Need to close this bind %d \n", bind);
|
||||
|
||||
void *buf2 = NULL;
|
||||
|
||||
rc = nn_setsockopt(sock1, NN_SOL_SOCKET, NN_RCVTIMEO, &t, sizeof(t));
|
||||
CU_ASSERT(rc >= 0);
|
||||
ParodusPrint("Client 3 is waiting for acknowledgement \n");
|
||||
byte = nn_recv(sock1, &buf2, NN_MSG, 0);
|
||||
|
||||
ParodusInfo("Data Received : %s \n", (char * )buf2);
|
||||
|
||||
rv1 = wrp_to_struct((void *)buf2, byte, WRP_BYTES, &msg1);
|
||||
CU_ASSERT_EQUAL( rv1, byte );
|
||||
ParodusPrint("msg1->msg_type for client 3 = %d \n", msg1->msg_type);
|
||||
ParodusPrint("msg1->status for client 3 = %d \n", msg1->u.auth.status);
|
||||
CU_ASSERT_EQUAL(msg1->msg_type, 2);
|
||||
CU_ASSERT_EQUAL(msg1->u.auth.status, 200);
|
||||
|
||||
rc = nn_freemsg(buf2);
|
||||
CU_ASSERT(rc == 0);
|
||||
free(bytes);
|
||||
wrp_free_struct(msg1);
|
||||
rc = nn_shutdown(sock1, bind);
|
||||
CU_ASSERT(rc == 0);
|
||||
|
||||
}
|
||||
|
||||
void test_nanomsg_downstream_success()
|
||||
{
|
||||
|
||||
ParodusInfo("test_nanomsg_downstream_success\n");
|
||||
|
||||
int sock;
|
||||
int bit=0, rc;
|
||||
wrp_msg_t *message;
|
||||
void *buf =NULL;
|
||||
char* destVal = NULL;
|
||||
// char dest[32] = {'\0'};
|
||||
char *dest = NULL;
|
||||
//char *temp_ptr;
|
||||
int bind = -1;
|
||||
|
||||
const wrp_msg_t msg = { .msg_type = WRP_MSG_TYPE__SVC_REGISTRATION,
|
||||
.u.reg.service_name = "iot",
|
||||
.u.reg.url = CLIENT3_URL};
|
||||
|
||||
sock = nn_socket (AF_SP, NN_PULL);
|
||||
|
||||
while(bind == -1)
|
||||
{
|
||||
bind = nn_bind(sock, msg.u.reg.url);
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
ParodusPrint("Bind returns = %d \n", bind);
|
||||
ParodusPrint("***** Nanomsg client3 in Receiving mode in %s *****\n", msg.u.reg.url);
|
||||
bit = nn_recv (sock, &buf, NN_MSG, 0);
|
||||
ParodusInfo ("----->Received downstream request from server to client3 : \"%s\"\n", (char *)buf);
|
||||
ParodusPrint("Received %d bytes\n", bit);
|
||||
CU_ASSERT(bit >= 0);
|
||||
|
||||
//Decode and verify downstream request has received by correct registered client
|
||||
|
||||
wrp_to_struct(buf, bit, WRP_BYTES, &message);
|
||||
destVal = message->u.req.dest;
|
||||
dest = strtok(destVal , "/");
|
||||
//temp_ptr = strtok(destVal , "/");
|
||||
// ParodusPrint("temp_ptr = %s \n", temp_ptr);
|
||||
strcpy(dest,strtok(NULL , "/"));
|
||||
ParodusInfo("------>decoded dest:%s\n", dest);
|
||||
CU_ASSERT_STRING_EQUAL( msg.u.reg.service_name, dest );
|
||||
wrp_free_struct(message);
|
||||
|
||||
//To send nanomsg client response upstream
|
||||
send_nanomsg_upstream(&buf, bit);
|
||||
|
||||
rc = nn_freemsg(buf);
|
||||
CU_ASSERT(rc == 0);
|
||||
rc = nn_shutdown(sock, bind);
|
||||
CU_ASSERT(rc == 0);
|
||||
//Need to wait for parodus to finish it's task.
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
|
||||
void test_nanomsg_downstream_failure()
|
||||
{
|
||||
int sock, bind, rc;
|
||||
int bit =0;
|
||||
char *buf =NULL;
|
||||
ParodusError("test_nanomsg_downstream_failure\n");
|
||||
|
||||
sleep(60);
|
||||
sock = nn_socket (AF_SP, NN_PULL);
|
||||
bind = nn_bind (sock, CLIENT3_URL);
|
||||
CU_ASSERT(bind >= 0);
|
||||
ParodusPrint("***** Nanomsg client3 in Receiving mode *****\n");
|
||||
|
||||
bit = nn_recv (sock, &buf, NN_MSG, 0);
|
||||
ParodusInfo ("Received downstream request from server for client3 : \"%s\"\n", buf);
|
||||
CU_ASSERT(bit >= 0);
|
||||
rc = nn_freemsg(buf);
|
||||
CU_ASSERT(rc == 0);
|
||||
rc = nn_shutdown(sock, bind);
|
||||
CU_ASSERT(rc == 0);
|
||||
}
|
||||
|
||||
|
||||
void test_checkHostIp()
|
||||
{
|
||||
int ret;
|
||||
|
||||
ParodusPrint("**********************************Calling check_host_ip \n");
|
||||
ret = checkHostIp("fabric.webpa.comcast.net");
|
||||
ParodusPrint("------------------> Ret = %d \n", ret);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
}
|
||||
|
||||
void test_sendMessage()
|
||||
{
|
||||
noPollConnOpts * opts;
|
||||
noPollCtx *ctx = NULL;
|
||||
noPollConn *conn = NULL;
|
||||
|
||||
ParodusPrint("**********************************Calling sendMessage \n");
|
||||
const char * headerNames[HTTP_CUSTOM_HEADER_COUNT] = {"X-WebPA-Device-Name","X-WebPA-Device-Protocols","User-Agent", "X-WebPA-Convey"};
|
||||
const char * headerValues[HTTP_CUSTOM_HEADER_COUNT];
|
||||
|
||||
headerValues[0] = "123567892366";
|
||||
headerValues[1] = "wrp-0.11,getset-0.1";
|
||||
headerValues[2] = "WebPA-1.6 (TG1682_DEV_master_2016000000sdy;TG1682/ARRISGroup,Inc.;)";
|
||||
headerValues[3] = "zacbvfxcvglodfjdigjkdshuihgkvn";
|
||||
|
||||
int headerCount = HTTP_CUSTOM_HEADER_COUNT;
|
||||
|
||||
//ctx = nopoll_ctx_new();
|
||||
|
||||
opts = nopoll_conn_opts_new ();
|
||||
nopoll_conn_opts_ssl_peer_verify (opts, nopoll_false);
|
||||
nopoll_conn_opts_set_ssl_protocol (opts, NOPOLL_METHOD_TLSV1_2);
|
||||
conn = nopoll_conn_tls_new(ctx, opts, "fabric.webpa.comcast.net", "8080", NULL, "/api/v2/device", NULL, NULL, "eth0",
|
||||
headerNames, headerValues, headerCount);
|
||||
/*while(conn == NULL)
|
||||
{
|
||||
opts = nopoll_conn_opts_new ();
|
||||
nopoll_conn_opts_ssl_peer_verify (opts, nopoll_false);
|
||||
nopoll_conn_opts_set_ssl_protocol (opts, NOPOLL_METHOD_TLSV1_2);
|
||||
conn = nopoll_conn_tls_new(ctx, opts, "fabric.webpa.comcast.net", 8080, NULL, "/api/v2/device", NULL, NULL, "eth0",
|
||||
headerNames, headerValues, headerCount);
|
||||
}*/
|
||||
|
||||
ParodusPrint("Sending conn as %p \n", conn);
|
||||
sendMessage(conn, "hello", 6);
|
||||
|
||||
}
|
||||
|
||||
void test_parseCommandLine()
|
||||
{
|
||||
int argc =11;
|
||||
char * command[15]={'\0'};
|
||||
|
||||
command[0] = "parodus";
|
||||
command[1] = "--hw-model=TG1682";
|
||||
command[2] = "--hw-serial-number=Fer23u948590";
|
||||
command[3] = "--hw-manufacturer=ARRISGroup,Inc.";
|
||||
command[4] = "--hw-mac=123567892366";
|
||||
command[5] = "--hw-last-reboot-reason=unknown";
|
||||
command[6] = "--fw-name=TG1682_DEV_master_2016000000sdy";
|
||||
command[7] = "--webpa-ping-time=180";
|
||||
command[8] = "--webpa-inteface-used=eth0";
|
||||
command[9] = "--webpa-url=fabric.webpa.comcast.net";
|
||||
command[10] = "--webpa-backoff-max=0";
|
||||
|
||||
ParodusCfg parodusCfg;
|
||||
memset(&parodusCfg,0,sizeof(parodusCfg));
|
||||
ParodusPrint("call parseCommand\n");
|
||||
parseCommandLine(argc,command,&parodusCfg);
|
||||
|
||||
ParodusPrint("parodusCfg.webpa_ping_timeout is %d\n", parodusCfg.webpa_ping_timeout);
|
||||
ParodusPrint("parodusCfg.webpa_backoff_max is %d\n", parodusCfg.webpa_backoff_max);
|
||||
CU_ASSERT_STRING_EQUAL( parodusCfg.hw_model, "TG1682");
|
||||
CU_ASSERT_STRING_EQUAL( parodusCfg.hw_serial_number, "Fer23u948590");
|
||||
CU_ASSERT_STRING_EQUAL( parodusCfg.hw_manufacturer, "ARRISGroup,Inc.");
|
||||
CU_ASSERT_STRING_EQUAL( parodusCfg.hw_mac, "123567892366");
|
||||
CU_ASSERT_STRING_EQUAL( parodusCfg.hw_last_reboot_reason, "unknown");
|
||||
CU_ASSERT_STRING_EQUAL( parodusCfg.fw_name, "TG1682_DEV_master_2016000000sdy");
|
||||
CU_ASSERT( parodusCfg.webpa_ping_timeout==180);
|
||||
CU_ASSERT_STRING_EQUAL( parodusCfg.webpa_interface_used, "eth0");
|
||||
CU_ASSERT_STRING_EQUAL( parodusCfg.webpa_url, "fabric.webpa.comcast.net");
|
||||
CU_ASSERT( parodusCfg.webpa_backoff_max==0);
|
||||
}
|
||||
|
||||
|
||||
void test_loadParodusCfg()
|
||||
{
|
||||
|
||||
ParodusPrint("Calling test_loadParodusCfg \n");
|
||||
//ParodusCfg parodusCfg, tmpcfg;
|
||||
ParodusCfg tmpcfg;
|
||||
ParodusCfg *Cfg;
|
||||
Cfg = (ParodusCfg*)malloc(sizeof(ParodusCfg));
|
||||
|
||||
strcpy(Cfg->hw_model, "TG1682");
|
||||
strcpy(Cfg->hw_serial_number, "Fer23u948590");
|
||||
strcpy(Cfg->hw_manufacturer , "ARRISGroup,Inc.");
|
||||
strcpy(Cfg->hw_mac , "123567892366");
|
||||
memset(&tmpcfg,0,sizeof(tmpcfg));
|
||||
loadParodusCfg(Cfg,&tmpcfg);
|
||||
ParodusInfo("tmpcfg.hw_model = %s, tmpcfg.hw_serial_number = %s, tmpcfg.hw_manufacturer = %s, tmpcfg.hw_mac = %s, \n", tmpcfg.hw_model,tmpcfg.hw_serial_number, tmpcfg.hw_manufacturer, tmpcfg.hw_mac);
|
||||
|
||||
CU_ASSERT_STRING_EQUAL( tmpcfg.hw_model, "TG1682");
|
||||
CU_ASSERT_STRING_EQUAL( tmpcfg.hw_serial_number, "Fer23u948590");
|
||||
CU_ASSERT_STRING_EQUAL( tmpcfg.hw_manufacturer, "ARRISGroup,Inc.");
|
||||
CU_ASSERT_STRING_EQUAL( tmpcfg.hw_mac, "123567892366");
|
||||
|
||||
}
|
||||
|
||||
void add_suites( CU_pSuite *suite )
|
||||
{
|
||||
ParodusInfo("--------Start of Test Cases Execution ---------\n");
|
||||
*suite = CU_add_suite( "tests", NULL, NULL );
|
||||
CU_add_test( *suite, "Test 1", test_nanomsg_client_registration1 );
|
||||
CU_add_test( *suite, "Test 2", test_nanomsg_client_registration2 );
|
||||
CU_add_test( *suite, "Test 3", test_nanomsg_client_registration3 );
|
||||
CU_add_test( *suite, "Test 4", test_nanomsg_downstream_success );
|
||||
//CU_add_test( *suite, "Test 5", test_nanomsg_downstream_failure );
|
||||
|
||||
ParodusInfo("-------------Integration testing is completed-----------\n");
|
||||
ParodusInfo("******************************************************************\n");
|
||||
//sleep(10);
|
||||
ParodusInfo("-------------Start of Unit Test Cases Execution---------\n");
|
||||
CU_add_test( *suite, "UnitTest 1", test_parseCommandLine );
|
||||
CU_add_test( *suite, "UnitTest 2", test_checkHostIp );
|
||||
|
||||
CU_add_test( *suite, "UnitTest 3", test_sendMessage );
|
||||
|
||||
CU_add_test( *suite, "UnitTest 4", test_loadParodusCfg );
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int main( void )
|
||||
{
|
||||
pid_t pid, pid1;
|
||||
char value[512] = {'\0'};
|
||||
char* data =NULL;
|
||||
int status;
|
||||
char commandUrl[255];
|
||||
pid_t curl_pid;
|
||||
|
||||
char * command[] = {"parodus","--hw-model=TG1682", "--hw-serial-number=Fer23u948590","--hw-manufacturer=ARRISGroup,Inc.","--hw-mac=123567892366","--hw-last-reboot-reason=unknown","--fw-name=TG1682_DEV_master_2016000000sdy","--boot-time=10","--webpa-ping-time=180","--webpa-inteface-used=eth0","--webpa-url=fabric-cd.webpa.comcast.net","--webpa-backoff-max=9", NULL};
|
||||
|
||||
//int size = sizeof(command)/sizeof(command[0]);
|
||||
//int i;
|
||||
//ParodusInfo("commad: ");
|
||||
//for(i=0;i<size-1;i++)
|
||||
//ParodusInfo("command:%s",command);
|
||||
|
||||
ParodusInfo("Starting parodus process \n");
|
||||
const char *s = getenv("WEBPA_AUTH_HEADER");
|
||||
|
||||
sprintf(commandUrl, "curl -i -H \"Authorization:Basic %s\" -H \"Accept: application/json\" -w %%{time_total} -k \"https://api-cd.webpa.comcast.net:8090/api/v2/device/mac:123567892366/iot?names=Device.DeviceInfo.Webpa.X_COMCAST-COM_SyncProtocolVersion\"", s);
|
||||
ParodusPrint("---------------------->>>>Executing system(commandUrl)\n");
|
||||
|
||||
curl_pid = getpid();
|
||||
ParodusPrint("child process execution with curl_pid:%d\n", curl_pid);
|
||||
pid = fork();
|
||||
if (pid == -1)
|
||||
{
|
||||
ParodusError("fork was unsuccessful for pid (errno=%d, %s)\n",errno, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
else if (pid == 0)
|
||||
{
|
||||
int err;
|
||||
ParodusPrint("child process created for parodus\n");
|
||||
pid = getpid();
|
||||
ParodusPrint("child process execution with pid:%d\n", pid);
|
||||
|
||||
err = execv("../src/parodus", command);
|
||||
if(errno == 2)
|
||||
{
|
||||
err = execv("./src/parodus", command);
|
||||
}
|
||||
ParodusError("err is %d, errno is %d\n",err, errno);
|
||||
|
||||
}
|
||||
else if (pid > 0)
|
||||
{
|
||||
int link[2];
|
||||
sleep(5);
|
||||
|
||||
//Starting test suites execution in new thread
|
||||
ParodusPrint("Creating new thread for test suite execution\n");
|
||||
|
||||
pthread_t testId;
|
||||
int err1 = 0;
|
||||
err1 = pthread_create(&testId,NULL,handle_testsuites,(void *)&pid);
|
||||
if(err1 != 0)
|
||||
ParodusError("Error creating test suite thread %s\n",strerror(err1));
|
||||
else
|
||||
ParodusPrint("test suite thread created successfully\n");
|
||||
|
||||
if (pipe(link)==-1)
|
||||
{
|
||||
ParodusError("Failed to create pipe\n");
|
||||
}
|
||||
else
|
||||
ParodusPrint("Created pipe to read curl output\n");
|
||||
|
||||
pid1 = fork();
|
||||
if (pid1 == -1)
|
||||
{
|
||||
ParodusError("fork was unsuccessful for pid1 (errno=%d, %s)\n",errno, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
else if(pid1 == 0)
|
||||
{
|
||||
while(NULL == fopen("/tmp/parodus_ready", "r"))
|
||||
{
|
||||
sleep(5);
|
||||
}
|
||||
dup2 (link[1], STDOUT_FILENO);
|
||||
close(link[0]);
|
||||
close(link[1]);
|
||||
sleep(40);
|
||||
system(commandUrl);
|
||||
ParodusInfo("\n----Executed first Curl request for downstream ------- \n");
|
||||
}
|
||||
|
||||
else if(pid1 > 0)
|
||||
{
|
||||
//wait fro child process to finish and read from pipe
|
||||
waitpid(pid1, &status, 0);
|
||||
//reading from pipe
|
||||
ParodusPrint("parent process...:%d\n", pid1);
|
||||
close(link[1]);
|
||||
int nbytes = read(link[0], value, sizeof(value));
|
||||
ParodusPrint("Read %d \n", nbytes);
|
||||
|
||||
if ((data = strstr(value, "message:Success")) !=NULL)
|
||||
{
|
||||
ParodusInfo("curl success\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("curl failure..\n");
|
||||
}
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void *handle_testsuites(void* pid)
|
||||
{
|
||||
unsigned rv = 1;
|
||||
CU_pSuite suite = NULL;
|
||||
pid_t pid_parodus = *((int *)pid);
|
||||
|
||||
ParodusPrint("Starting handle_testsuites thread\n");
|
||||
sleep(25);
|
||||
|
||||
if( CUE_SUCCESS == CU_initialize_registry() )
|
||||
{
|
||||
add_suites( &suite );
|
||||
if( NULL != suite )
|
||||
{
|
||||
CU_basic_set_mode( CU_BRM_VERBOSE );
|
||||
CU_basic_run_tests();
|
||||
ParodusPrint( "\n" );
|
||||
CU_basic_show_failures( CU_get_failure_list() );
|
||||
ParodusPrint( "\n\n" );
|
||||
rv = CU_get_number_of_tests_failed();
|
||||
}
|
||||
CU_cleanup_registry();
|
||||
}
|
||||
kill(pid_parodus, SIGKILL);
|
||||
ParodusInfo("parodus process with pid %d is stopped\n", pid_parodus);
|
||||
|
||||
if( 0 != rv )
|
||||
{
|
||||
_exit(-1);
|
||||
}
|
||||
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
|
||||
static void send_nanomsg_upstream(void **buf, int size)
|
||||
{
|
||||
/**** To send nanomsg response to server ****/
|
||||
int rv;
|
||||
void *bytes;
|
||||
int resp_size;
|
||||
int sock;
|
||||
int byte;
|
||||
wrp_msg_t *message;
|
||||
|
||||
ParodusInfo("Decoding downstream request received from server\n");
|
||||
rv = wrp_to_struct(*buf, size, WRP_BYTES, &message);
|
||||
ParodusPrint("after downstream req decode:%d\n", rv);
|
||||
/**** Preparing Nanomsg client response ****/
|
||||
wrp_msg_t resp_m;
|
||||
resp_m.msg_type = WRP_MSG_TYPE__REQ;
|
||||
ParodusPrint("resp_m.msg_type:%d\n", resp_m.msg_type);
|
||||
|
||||
resp_m.u.req.source = message->u.req.dest;
|
||||
ParodusPrint("------resp_m.u.req.source is:%s\n", resp_m.u.req.source);
|
||||
|
||||
resp_m.u.req.dest = message->u.req.source;
|
||||
ParodusPrint("------resp_m.u.req.dest is:%s\n", resp_m.u.req.dest);
|
||||
|
||||
resp_m.u.req.transaction_uuid = message->u.req.transaction_uuid;
|
||||
ParodusPrint("------resp_m.u.req.transaction_uuid is:%s\n", resp_m.u.req.transaction_uuid);
|
||||
|
||||
resp_m.u.req.headers = NULL;
|
||||
resp_m.u.req.payload = "{statusCode:200,message:Success}";
|
||||
ParodusPrint("------resp_m.u.req.payload is:%s\n", (char *)resp_m.u.req.payload);
|
||||
resp_m.u.req.payload_size = strlen(resp_m.u.req.payload);
|
||||
|
||||
resp_m.u.req.metadata = NULL;
|
||||
resp_m.u.req.include_spans = false;
|
||||
resp_m.u.req.spans.spans = NULL;
|
||||
resp_m.u.req.spans.count = 0;
|
||||
|
||||
ParodusPrint("Encoding downstream response\n");
|
||||
resp_size = wrp_struct_to( &resp_m, WRP_BYTES, &bytes );
|
||||
|
||||
/*** Enable this to verify downstream response by decoding ***/
|
||||
/***
|
||||
wrp_msg_t *message1;
|
||||
rv = wrp_to_struct(bytes, resp_size, WRP_BYTES, &message1);
|
||||
ParodusPrint("after downstream response decode:%d\n", rv);
|
||||
ParodusPrint("downstream response decoded msgType:%d\n", message1->msg_type);
|
||||
ParodusPrint("downstream response decoded source:%s\n", message1->u.req.source);
|
||||
ParodusPrint("downstream response decoded dest:%s\n", message1->u.req.dest);
|
||||
ParodusPrint("downstream response decoded transaction_uuid:%s\n", message1->u.req.transaction_uuid);
|
||||
ParodusPrint("downstream response decoded payload:%s\n", (char*)message1->u.req.payload);
|
||||
wrp_free_struct(message1);
|
||||
***/
|
||||
|
||||
/**** Nanomsg client sending msgs ****/
|
||||
|
||||
sock = nn_socket (AF_SP, NN_PUSH);
|
||||
int connect = nn_connect (sock, ENDPOINT);
|
||||
CU_ASSERT(connect >= 0);
|
||||
sleep(1);
|
||||
|
||||
ParodusInfo("nanomsg client sending response upstream\n");
|
||||
byte = nn_send (sock, bytes, resp_size,0);
|
||||
ParodusInfo("----->Expected byte to be sent:%d\n", resp_size);
|
||||
ParodusInfo("----->actual byte sent:%d\n", byte);
|
||||
CU_ASSERT(byte==resp_size );
|
||||
wrp_free_struct(message);
|
||||
|
||||
free(bytes);
|
||||
ParodusPrint("---- End of send_nanomsg_upstream ----\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -59,45 +59,45 @@ void test_set_global_conn()
|
||||
set_global_conn(conn);
|
||||
CU_ASSERT(conn == get_global_conn());
|
||||
close_and_unref_connection(get_global_conn());
|
||||
free(opts);
|
||||
}
|
||||
|
||||
void test_set_parodus_cfg()
|
||||
{
|
||||
ParodusCfg *cfg;
|
||||
ParodusCfg cfg;
|
||||
|
||||
cfg = (ParodusCfg*)malloc(sizeof(ParodusCfg));
|
||||
strcpy(cfg->hw_model, "TG1682");
|
||||
strcpy(cfg->hw_serial_number, "Fer23u948590");
|
||||
strcpy(cfg->hw_manufacturer , "ARRISGroup,Inc.");
|
||||
strcpy(cfg->hw_mac , "123567892366");
|
||||
strcpy(cfg->hw_last_reboot_reason , "unknown");
|
||||
strcpy(cfg->fw_name , "2.364s2");
|
||||
strcpy(cfg->webpa_path_url , "/api/v2/device");
|
||||
strcpy(cfg->webpa_url , "fabric-cd.webpa.comcast.net");
|
||||
strcpy(cfg->webpa_interface_used , "eth0");
|
||||
strcpy(cfg->webpa_protocol , "WebPA-1.6");
|
||||
strcpy(cfg->webpa_uuid , "1234567-345456546");
|
||||
cfg->secureFlag = 1;
|
||||
cfg->boot_time = 423457;
|
||||
cfg->webpa_ping_timeout = 30;
|
||||
cfg->webpa_backoff_max = 255;
|
||||
strcpy(cfg.hw_model, "TG1682");
|
||||
strcpy(cfg.hw_serial_number, "Fer23u948590");
|
||||
strcpy(cfg.hw_manufacturer , "ARRISGroup,Inc.");
|
||||
strcpy(cfg.hw_mac , "123567892366");
|
||||
strcpy(cfg.hw_last_reboot_reason , "unknown");
|
||||
strcpy(cfg.fw_name , "2.364s2");
|
||||
strcpy(cfg.webpa_path_url , "/api/v2/device");
|
||||
strcpy(cfg.webpa_url , "fabric-cd.webpa.comcast.net");
|
||||
strcpy(cfg.webpa_interface_used , "eth0");
|
||||
strcpy(cfg.webpa_protocol , "WebPA-1.6");
|
||||
strcpy(cfg.webpa_uuid , "1234567-345456546");
|
||||
cfg.secureFlag = 1;
|
||||
cfg.boot_time = 423457;
|
||||
cfg.webpa_ping_timeout = 30;
|
||||
cfg.webpa_backoff_max = 255;
|
||||
|
||||
set_parodus_cfg(cfg);
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
CU_ASSERT_STRING_EQUAL(cfg->hw_model, get_parodus_cfg()->hw_model);
|
||||
CU_ASSERT_STRING_EQUAL(cfg->webpa_uuid, get_parodus_cfg()->webpa_uuid);
|
||||
CU_ASSERT_STRING_EQUAL(cfg->hw_serial_number, get_parodus_cfg()->hw_serial_number);
|
||||
CU_ASSERT_STRING_EQUAL(cfg->hw_manufacturer , get_parodus_cfg()->hw_manufacturer);
|
||||
CU_ASSERT_STRING_EQUAL(cfg->hw_mac, get_parodus_cfg()->hw_mac);
|
||||
CU_ASSERT_STRING_EQUAL(cfg->hw_last_reboot_reason,get_parodus_cfg()->hw_last_reboot_reason);
|
||||
CU_ASSERT_STRING_EQUAL(cfg->fw_name,get_parodus_cfg()->fw_name);
|
||||
CU_ASSERT_STRING_EQUAL(cfg->webpa_url, get_parodus_cfg()->webpa_url);
|
||||
CU_ASSERT_STRING_EQUAL(cfg->webpa_interface_used , get_parodus_cfg()->webpa_interface_used);
|
||||
CU_ASSERT_STRING_EQUAL(cfg->webpa_protocol, get_parodus_cfg()->webpa_protocol);
|
||||
CU_ASSERT_EQUAL(cfg->boot_time, get_parodus_cfg()->boot_time);
|
||||
CU_ASSERT_EQUAL(cfg->webpa_ping_timeout, get_parodus_cfg()->webpa_ping_timeout);
|
||||
CU_ASSERT_EQUAL(cfg->webpa_backoff_max, get_parodus_cfg()->webpa_backoff_max);
|
||||
CU_ASSERT_EQUAL(cfg->secureFlag, get_parodus_cfg()->secureFlag);
|
||||
CU_ASSERT_STRING_EQUAL(cfg.hw_model, get_parodus_cfg()->hw_model);
|
||||
CU_ASSERT_STRING_EQUAL(cfg.webpa_uuid, get_parodus_cfg()->webpa_uuid);
|
||||
CU_ASSERT_STRING_EQUAL(cfg.hw_serial_number, get_parodus_cfg()->hw_serial_number);
|
||||
CU_ASSERT_STRING_EQUAL(cfg.hw_manufacturer , get_parodus_cfg()->hw_manufacturer);
|
||||
CU_ASSERT_STRING_EQUAL(cfg.hw_mac, get_parodus_cfg()->hw_mac);
|
||||
CU_ASSERT_STRING_EQUAL(cfg.hw_last_reboot_reason,get_parodus_cfg()->hw_last_reboot_reason);
|
||||
CU_ASSERT_STRING_EQUAL(cfg.fw_name,get_parodus_cfg()->fw_name);
|
||||
CU_ASSERT_STRING_EQUAL(cfg.webpa_url, get_parodus_cfg()->webpa_url);
|
||||
CU_ASSERT_STRING_EQUAL(cfg.webpa_interface_used , get_parodus_cfg()->webpa_interface_used);
|
||||
CU_ASSERT_STRING_EQUAL(cfg.webpa_protocol, get_parodus_cfg()->webpa_protocol);
|
||||
CU_ASSERT_EQUAL(cfg.boot_time, get_parodus_cfg()->boot_time);
|
||||
CU_ASSERT_EQUAL(cfg.webpa_ping_timeout, get_parodus_cfg()->webpa_ping_timeout);
|
||||
CU_ASSERT_EQUAL(cfg.webpa_backoff_max, get_parodus_cfg()->webpa_backoff_max);
|
||||
CU_ASSERT_EQUAL(cfg.secureFlag, get_parodus_cfg()->secureFlag);
|
||||
}
|
||||
|
||||
void test_getWebpaConveyHeader()
|
||||
@@ -117,6 +117,7 @@ void test_getWebpaConveyHeader()
|
||||
CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->webpa_protocol, cJSON_GetObjectItem(payload, WEBPA_PROTOCOL)->valuestring);
|
||||
CU_ASSERT_EQUAL((int)get_parodus_cfg()->boot_time, cJSON_GetObjectItem(payload, BOOT_TIME)->valueint);
|
||||
|
||||
cJSON_Delete(payload);
|
||||
}
|
||||
|
||||
void test_createSecureConnection()
|
||||
@@ -175,7 +176,7 @@ void test_WebpaConveyHeaderWithNullValues()
|
||||
CU_ASSERT_PTR_NULL(cJSON_GetObjectItem(payload, FIRMWARE_NAME));
|
||||
CU_ASSERT_PTR_NULL(cJSON_GetObjectItem(payload, WEBPA_INTERFACE));
|
||||
free(cfg);
|
||||
|
||||
cJSON_Delete(payload);
|
||||
}
|
||||
|
||||
void add_suites( CU_pSuite *suite )
|
||||
|
||||
@@ -75,6 +75,7 @@ void test_client_addtolist()
|
||||
}
|
||||
|
||||
wrp_free_struct(message);
|
||||
free(bytes);
|
||||
ParodusInfo("test_client_addtolist done..\n");
|
||||
|
||||
}
|
||||
@@ -187,6 +188,7 @@ void test_addtolist_multiple_clients()
|
||||
}
|
||||
|
||||
wrp_free_struct(message);
|
||||
free(bytes);
|
||||
ParodusInfo("test_addtolist_multiple_clients done..\n");
|
||||
|
||||
}
|
||||
|
||||
@@ -40,10 +40,10 @@ pthread_mutex_t close_mut;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
noPollConn * nopoll_conn_tls_new (noPollCtx * ctx, noPollConnOpts * options, const char * host_ip, const char * host_port, const char * host_name, const char * get_url, const char * protocols, const char * origin, const char * outbound_interface, const char * headerNames[], const char * headerValues[], const int headerCount)
|
||||
noPollConn * nopoll_conn_tls_new (noPollCtx * ctx, noPollConnOpts * options, const char * host_ip, const char * host_port, const char * host_name, const char * get_url, const char * protocols, const char * origin)
|
||||
{
|
||||
UNUSED(options); UNUSED(host_port); UNUSED(host_name); UNUSED(get_url); UNUSED(protocols);
|
||||
UNUSED(origin); UNUSED(outbound_interface); UNUSED(headerNames); UNUSED(headerValues); UNUSED(headerCount);
|
||||
UNUSED(origin);
|
||||
|
||||
function_called();
|
||||
check_expected((intptr_t)ctx);
|
||||
@@ -51,11 +51,10 @@ noPollConn * nopoll_conn_tls_new (noPollCtx * ctx, noPollConnOpts * options, co
|
||||
return (noPollConn *) (intptr_t)mock();
|
||||
}
|
||||
|
||||
noPollConn * nopoll_conn_new (noPollCtx * ctx, const char * host_ip, const char * host_port, const char * host_name, const char * get_url, const char * protocols, const char * origin, const char * outbound_interface, const char * headerNames[], const char * headerValues[], const int headerCount)
|
||||
noPollConn * nopoll_conn_new (noPollCtx * ctx, const char * host_ip, const char * host_port, const char * host_name, const char * get_url, const char * protocols, const char * origin)
|
||||
{
|
||||
UNUSED(host_port); UNUSED(host_name); UNUSED(get_url); UNUSED(protocols); UNUSED(origin);
|
||||
UNUSED(outbound_interface); UNUSED(headerNames); UNUSED(headerValues); UNUSED(headerCount);
|
||||
|
||||
|
||||
function_called();
|
||||
check_expected((intptr_t)ctx);
|
||||
check_expected((intptr_t)host_ip);
|
||||
@@ -177,6 +176,7 @@ void test_createSecureConnection()
|
||||
int ret = createNopollConnection(ctx);
|
||||
assert_int_equal(ret, nopoll_true);
|
||||
free(cfg);
|
||||
nopoll_ctx_unref (ctx);
|
||||
}
|
||||
|
||||
void test_createConnection()
|
||||
@@ -205,6 +205,7 @@ void test_createConnection()
|
||||
int ret = createNopollConnection(ctx);
|
||||
assert_int_equal(ret, nopoll_true);
|
||||
free(cfg);
|
||||
nopoll_ctx_unref (ctx);
|
||||
}
|
||||
|
||||
void test_createConnectionConnNull()
|
||||
@@ -255,6 +256,7 @@ void test_createConnectionConnNull()
|
||||
expect_function_call(setMessageHandlers);
|
||||
createNopollConnection(ctx);
|
||||
free(cfg);
|
||||
nopoll_ctx_unref (ctx);
|
||||
}
|
||||
|
||||
void test_createConnectionConnNotOk()
|
||||
@@ -328,6 +330,7 @@ void test_createConnectionConnNotOk()
|
||||
int ret = createNopollConnection(ctx);
|
||||
assert_int_equal(ret, nopoll_true);
|
||||
free(cfg);
|
||||
nopoll_ctx_unref (ctx);
|
||||
}
|
||||
|
||||
void err_createConnectionCtxNull()
|
||||
|
||||
@@ -100,15 +100,14 @@ void test_Mutex()
|
||||
|
||||
void err_mutex()
|
||||
{
|
||||
noPollPtr mutex = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
|
||||
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
|
||||
noPollPtr mutex = &mtx;
|
||||
|
||||
will_return(pthread_mutex_destroy, -1);
|
||||
destroyMutex(mutex);
|
||||
|
||||
will_return(pthread_mutex_init, -1);
|
||||
mutex = createMutex();
|
||||
|
||||
free(mutex);
|
||||
}
|
||||
|
||||
void err_mutexNull()
|
||||
|
||||
@@ -56,7 +56,8 @@ void test_validate_partner_id_for_req()
|
||||
will_return(get_parodus_cfg, (intptr_t)&cfg);
|
||||
expect_function_call(get_parodus_cfg);
|
||||
int ret = validate_partner_id(msg, NULL);
|
||||
assert_int_equal(ret, 1);
|
||||
assert_int_equal(ret, 1);
|
||||
free(msg);
|
||||
}
|
||||
|
||||
void test_validate_partner_id_for_req_listNULL()
|
||||
@@ -72,7 +73,8 @@ void test_validate_partner_id_for_req_listNULL()
|
||||
will_return(get_parodus_cfg, (intptr_t)&cfg);
|
||||
expect_function_call(get_parodus_cfg);
|
||||
int ret = validate_partner_id(msg, NULL);
|
||||
assert_int_equal(ret, 1);
|
||||
assert_int_equal(ret, 1);
|
||||
free(msg);
|
||||
}
|
||||
|
||||
void test_validate_partner_id_for_req_withoutId()
|
||||
@@ -87,7 +89,8 @@ void test_validate_partner_id_for_req_withoutId()
|
||||
will_return(get_parodus_cfg, (intptr_t)&cfg);
|
||||
expect_function_call(get_parodus_cfg);
|
||||
int ret = validate_partner_id(msg, NULL);
|
||||
assert_int_equal(ret, 0);
|
||||
assert_int_equal(ret, 0);
|
||||
free(msg);
|
||||
}
|
||||
|
||||
void err_validate_partner_id_for_req()
|
||||
@@ -105,7 +108,8 @@ void err_validate_partner_id_for_req()
|
||||
will_return(get_parodus_cfg, (intptr_t)&cfg);
|
||||
expect_function_call(get_parodus_cfg);
|
||||
int ret = validate_partner_id(msg, NULL);
|
||||
assert_int_equal(ret, -1);
|
||||
assert_int_equal(ret, -1);
|
||||
free(msg);
|
||||
}
|
||||
|
||||
void test_validate_partner_id_for_event()
|
||||
@@ -126,6 +130,7 @@ void test_validate_partner_id_for_event()
|
||||
partners_t *list = NULL;
|
||||
int ret = validate_partner_id(msg, &list);
|
||||
assert_int_equal(ret, 1);
|
||||
free(msg);
|
||||
}
|
||||
|
||||
void test_validate_partner_id_for_event_listNULL()
|
||||
@@ -145,6 +150,13 @@ void test_validate_partner_id_for_event_listNULL()
|
||||
assert_int_equal(ret, 1);
|
||||
assert_int_equal(list->count, 1);
|
||||
assert_string_equal(list->partner_ids[0], "comcast");
|
||||
int i;
|
||||
for(i = 0; i< (int) list->count; i++)
|
||||
{
|
||||
free(list->partner_ids[i]);
|
||||
}
|
||||
free(list);
|
||||
free(msg);
|
||||
}
|
||||
|
||||
void err_validate_partner_id_for_event()
|
||||
@@ -159,16 +171,21 @@ void err_validate_partner_id_for_event()
|
||||
will_return(get_parodus_cfg, (intptr_t)&cfg);
|
||||
expect_function_call(get_parodus_cfg);
|
||||
int ret = validate_partner_id(msg, NULL);
|
||||
assert_int_equal(ret, 0);
|
||||
assert_int_equal(ret, 0);
|
||||
free(msg);
|
||||
}
|
||||
|
||||
void test_validate_partner_id_for_event_withoutId()
|
||||
{
|
||||
static partners_t partner_ids = {1,{"shaw"}};
|
||||
partners_t *partner_ids = (partners_t *) malloc(sizeof(partners_t));
|
||||
partner_ids->count = 1;
|
||||
partner_ids->partner_ids[0] = (char *) malloc(sizeof(char)*64);
|
||||
strcpy(partner_ids->partner_ids[0], "shaw");
|
||||
|
||||
wrp_msg_t *msg = (wrp_msg_t*) malloc(sizeof(wrp_msg_t));
|
||||
memset(msg, 0, sizeof(wrp_msg_t));
|
||||
msg->msg_type = WRP_MSG_TYPE__EVENT;
|
||||
msg->u.event.partner_ids = &partner_ids;
|
||||
msg->u.event.partner_ids = partner_ids;
|
||||
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg, 0, sizeof(ParodusCfg));
|
||||
@@ -182,6 +199,14 @@ void test_validate_partner_id_for_event_withoutId()
|
||||
assert_int_equal(list->count, 2);
|
||||
assert_string_equal(list->partner_ids[0], "shaw");
|
||||
assert_string_equal(list->partner_ids[1], "comcast");
|
||||
int i;
|
||||
for(i = 0; i< (int) list->count; i++)
|
||||
{
|
||||
free(list->partner_ids[i]);
|
||||
}
|
||||
free(list);
|
||||
free(msg);
|
||||
free(partner_ids);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -67,6 +67,8 @@ static void add_client()
|
||||
ParodusPrint("addToList status is %d\n", status);
|
||||
|
||||
CU_ASSERT_EQUAL( status, 0 );
|
||||
wrp_free_struct(message);
|
||||
free(bytes);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -234,6 +234,8 @@ void test_handle_upstream()
|
||||
will_return(nn_recv, 12);
|
||||
expect_function_call(nn_recv);
|
||||
handle_upstream();
|
||||
free(UpStreamMsgQ->next);
|
||||
free(UpStreamMsgQ);
|
||||
}
|
||||
|
||||
void err_handleUpstreamBindFailure()
|
||||
@@ -285,6 +287,8 @@ void test_processUpstreamMessage()
|
||||
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ->next);
|
||||
free(UpStreamMsgQ);
|
||||
}
|
||||
|
||||
void test_processUpstreamMessageInvalidPartner()
|
||||
@@ -319,6 +323,8 @@ void test_processUpstreamMessageInvalidPartner()
|
||||
expect_function_call(nn_freemsg);
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ->next);
|
||||
free(UpStreamMsgQ);
|
||||
}
|
||||
|
||||
void test_processUpstreamMessageRegMsg()
|
||||
@@ -377,6 +383,8 @@ void test_processUpstreamMessageRegMsg()
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(head);
|
||||
free(UpStreamMsgQ->next);
|
||||
free(UpStreamMsgQ);
|
||||
}
|
||||
|
||||
void test_processUpstreamMessageRegMsgNoClients()
|
||||
@@ -417,6 +425,8 @@ void test_processUpstreamMessageRegMsgNoClients()
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(head);
|
||||
free(UpStreamMsgQ->next);
|
||||
free(UpStreamMsgQ);
|
||||
}
|
||||
|
||||
void err_processUpstreamMessage()
|
||||
@@ -447,6 +457,7 @@ void err_processUpstreamMessageDecodeErr()
|
||||
expect_function_call(nn_freemsg);
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ);
|
||||
}
|
||||
|
||||
void err_processUpstreamMessageMetapackFailure()
|
||||
@@ -470,6 +481,7 @@ void err_processUpstreamMessageMetapackFailure()
|
||||
expect_function_call(nn_freemsg);
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ);
|
||||
}
|
||||
|
||||
void err_processUpstreamMessageRegMsg()
|
||||
@@ -533,7 +545,10 @@ void err_processUpstreamMessageRegMsg()
|
||||
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(head->next);
|
||||
free(head);
|
||||
free(UpStreamMsgQ->next);
|
||||
free(UpStreamMsgQ);
|
||||
}
|
||||
|
||||
void test_sendUpstreamMsgToServer()
|
||||
@@ -550,6 +565,7 @@ void test_sendUpstreamMsgToServer()
|
||||
expect_function_call(appendEncodedData);
|
||||
expect_function_call(sendMessage);
|
||||
sendUpstreamMsgToServer(&bytes, 110);
|
||||
free(bytes);
|
||||
}
|
||||
|
||||
void err_sendUpstreamMsgToServer()
|
||||
|
||||
Reference in New Issue
Block a user