mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
chore(webfuse) Increase test coverage (#34)
* removes unnecessary code * adds test of wf_status * adds tests of wf_message * adds tests of wf_message_queue * changed branch of coverage badge to display correct results * moves core tests into separate subdirectory * increases coverage of timer test * moves adapter specific tests into separate directory * moves provider specific tests into separate directory * adds tests of jsonrpc utilities * adds tests of jsonrpc request * adds test of jsonrpc response * adds tests of jsonrpc server * adds tests of jsonrpc proxy * adds integration test (found some issues) * disables problematic tests * fixes resource leak: pending timer after cleanup proxy * fixes order of cleanup to prevent processing pending requests after filesystem shut down * fixes some memcheck and helgrind errors: initialization of lws_log; setup of client and server * disabled a test * fixes error in msleep utility * fixes deadlock at IntegrationTest using valgrind * removes unit test code from coverage report * adds some integration tests * makes badge show coverage of master * fixes some coding style issues * fixes eary trigger of is_connected (provider) * fixes read error in 32 bit environments\n\ninode is always 64 bit, but variadic wf_impl_jsonrpc_proxy_invoke expects int
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
|
||||
#include "webfuse/adapter/impl/jsonrpc/response.h"
|
||||
|
||||
#define WF_DEFAULT_TIMEOUT (10 * 1000)
|
||||
|
||||
static void wf_impl_jsonrpc_proxy_timeout(
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
@@ -53,8 +51,9 @@ static json_t * wf_impl_jsonrpc_request_create(
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "fatal: unknown param_type '%c'\n", *param_type);
|
||||
exit(EXIT_FAILURE);
|
||||
break;
|
||||
json_decref(params);
|
||||
json_decref(request);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,10 +70,12 @@ static json_t * wf_impl_jsonrpc_request_create(
|
||||
void wf_impl_jsonrpc_proxy_init(
|
||||
struct wf_impl_jsonrpc_proxy * proxy,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
int timeout,
|
||||
wf_impl_jsonrpc_send_fn * send,
|
||||
void * user_data)
|
||||
{
|
||||
proxy->send = send;
|
||||
proxy->timeout = timeout;
|
||||
proxy->user_data = user_data;
|
||||
proxy->request.is_pending = false;
|
||||
|
||||
@@ -84,13 +85,21 @@ void wf_impl_jsonrpc_proxy_init(
|
||||
void wf_impl_jsonrpc_proxy_cleanup(
|
||||
struct wf_impl_jsonrpc_proxy * proxy)
|
||||
{
|
||||
wf_impl_timer_cleanup(&proxy->request.timer);
|
||||
|
||||
if (proxy->request.is_pending)
|
||||
{
|
||||
proxy->request.finished(proxy->request.user_data, WF_BAD, NULL);
|
||||
void * user_data = proxy->request.user_data;
|
||||
wf_impl_jsonrpc_proxy_finished_fn * finished = proxy->request.finished;
|
||||
|
||||
proxy->request.is_pending = false;
|
||||
proxy->request.finished = NULL;
|
||||
proxy->request.user_data = NULL;
|
||||
proxy->request.id = 0;
|
||||
wf_impl_timer_cancel(&proxy->request.timer);
|
||||
|
||||
finished(user_data, WF_BAD, NULL);
|
||||
}
|
||||
|
||||
wf_impl_timer_cleanup(&proxy->request.timer);
|
||||
}
|
||||
|
||||
void wf_impl_jsonrpc_proxy_invoke(
|
||||
@@ -108,25 +117,29 @@ void wf_impl_jsonrpc_proxy_invoke(
|
||||
proxy->request.finished = finished;
|
||||
proxy->request.user_data = user_data;
|
||||
proxy->request.id = 42;
|
||||
wf_impl_timer_start(&proxy->request.timer, wf_impl_timepoint_in_msec(WF_DEFAULT_TIMEOUT),
|
||||
wf_impl_timer_start(&proxy->request.timer, wf_impl_timepoint_in_msec(proxy->timeout),
|
||||
&wf_impl_jsonrpc_proxy_timeout, proxy);
|
||||
|
||||
va_list args;
|
||||
va_start(args, param_info);
|
||||
json_t * request = wf_impl_jsonrpc_request_create(method_name, proxy->request.id, param_info, args);
|
||||
va_end(args);
|
||||
|
||||
bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data)));
|
||||
if (!is_send)
|
||||
{
|
||||
proxy->request.is_pending = false;
|
||||
proxy->request.finished = NULL;
|
||||
proxy->request.user_data = NULL;
|
||||
proxy->request.id = 0;
|
||||
wf_impl_timer_cancel(&proxy->request.timer);
|
||||
|
||||
finished(user_data, WF_BAD, NULL);
|
||||
|
||||
}
|
||||
|
||||
if (NULL != request)
|
||||
{
|
||||
if (!proxy->send(request, proxy->user_data))
|
||||
{
|
||||
proxy->request.is_pending = false;
|
||||
proxy->request.finished = NULL;
|
||||
proxy->request.user_data = NULL;
|
||||
proxy->request.id = 0;
|
||||
wf_impl_timer_cancel(&proxy->request.timer);
|
||||
|
||||
finished(user_data, WF_BAD, NULL);
|
||||
}
|
||||
json_decref(request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ struct wf_impl_jsonrpc_request
|
||||
struct wf_impl_jsonrpc_proxy
|
||||
{
|
||||
struct wf_impl_jsonrpc_request request;
|
||||
int timeout;
|
||||
wf_impl_jsonrpc_send_fn * send;
|
||||
void * user_data;
|
||||
};
|
||||
@@ -46,6 +47,7 @@ struct wf_impl_jsonrpc_proxy
|
||||
extern void wf_impl_jsonrpc_proxy_init(
|
||||
struct wf_impl_jsonrpc_proxy * proxy,
|
||||
struct wf_impl_timeout_manager * manager,
|
||||
int timeout,
|
||||
wf_impl_jsonrpc_send_fn * send,
|
||||
void * user_data);
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ void wf_impl_operation_read(
|
||||
{
|
||||
int const length = (size <= WF_MAX_READ_LENGTH) ? (int) size : WF_MAX_READ_LENGTH;
|
||||
int handle = (file_info->fh & INT_MAX);
|
||||
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, inode, handle, (int) offset, length);
|
||||
wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
#include "webfuse/adapter/impl/server_config.h"
|
||||
#include "webfuse/adapter/impl/server_protocol.h"
|
||||
#include "webfuse/core/lws_log.h"
|
||||
|
||||
#define WF_DISABLE_LWS_LOG 0
|
||||
#define WF_SERVER_PROTOCOL_COUNT 3
|
||||
|
||||
struct wf_server
|
||||
@@ -33,7 +33,7 @@ static bool wf_impl_server_tls_enabled(
|
||||
static struct lws_context * wf_impl_server_context_create(
|
||||
struct wf_server * server)
|
||||
{
|
||||
lws_set_log_level(WF_DISABLE_LWS_LOG, NULL);
|
||||
wf_lwslog_disable();
|
||||
|
||||
memset(server->ws_protocols, 0, sizeof(struct lws_protocols) * WF_SERVER_PROTOCOL_COUNT);
|
||||
server->ws_protocols[0].name = "http";
|
||||
@@ -125,6 +125,12 @@ void wf_impl_server_dispose(
|
||||
free(server);
|
||||
}
|
||||
|
||||
bool wf_impl_server_is_operational(
|
||||
struct wf_server * server)
|
||||
{
|
||||
return server->protocol.is_operational;
|
||||
}
|
||||
|
||||
void wf_impl_server_service(
|
||||
struct wf_server * server,
|
||||
int timeout_ms)
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef WF_ADAPTER_IMPL_SERVER_H
|
||||
#define WF_ADAPTER_IMPL_SERVER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
@@ -15,6 +19,9 @@ extern struct wf_server * wf_impl_server_create(
|
||||
extern void wf_impl_server_dispose(
|
||||
struct wf_server * server);
|
||||
|
||||
extern bool wf_impl_server_is_operational(
|
||||
struct wf_server * server);
|
||||
|
||||
extern void wf_impl_server_service(
|
||||
struct wf_server * server,
|
||||
int timeout_ms);
|
||||
|
||||
@@ -30,6 +30,9 @@ static int wf_impl_server_protocol_callback(
|
||||
|
||||
switch (reason)
|
||||
{
|
||||
case LWS_CALLBACK_PROTOCOL_INIT:
|
||||
protocol->is_operational = true;
|
||||
break;
|
||||
case LWS_CALLBACK_ESTABLISHED:
|
||||
session = wf_impl_session_manager_add(
|
||||
&protocol->session_manager,
|
||||
@@ -206,6 +209,7 @@ void wf_impl_server_protocol_init(
|
||||
char * mount_point)
|
||||
{
|
||||
protocol->mount_point = strdup(mount_point);
|
||||
protocol->is_operational = false;
|
||||
|
||||
wf_impl_timeout_manager_init(&protocol->timeout_manager);
|
||||
wf_impl_session_manager_init(&protocol->session_manager);
|
||||
@@ -220,6 +224,8 @@ void wf_impl_server_protocol_cleanup(
|
||||
struct wf_server_protocol * protocol)
|
||||
{
|
||||
free(protocol->mount_point);
|
||||
protocol->is_operational = false;
|
||||
|
||||
wf_impl_jsonrpc_server_cleanup(&protocol->server);
|
||||
wf_impl_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wf_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
#include "webfuse/adapter/impl/session_manager.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
@@ -21,6 +25,7 @@ struct wf_server_protocol
|
||||
struct wf_impl_authenticators authenticators;
|
||||
struct wf_impl_session_manager session_manager;
|
||||
struct wf_impl_jsonrpc_server server;
|
||||
bool is_operational;
|
||||
};
|
||||
|
||||
extern void wf_impl_server_protocol_init(
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define WF_DEFAULT_TIMEOUT (10 * 1000)
|
||||
|
||||
static bool wf_impl_session_send(
|
||||
json_t * request,
|
||||
void * user_data)
|
||||
@@ -55,7 +57,7 @@ struct wf_impl_session * wf_impl_session_create(
|
||||
session->is_authenticated = false;
|
||||
session->authenticators = authenticators;
|
||||
session->server = server;
|
||||
wf_impl_jsonrpc_proxy_init(&session->rpc, timeout_manager, &wf_impl_session_send, session);
|
||||
wf_impl_jsonrpc_proxy_init(&session->rpc, timeout_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
|
||||
wf_slist_init(&session->messages);
|
||||
}
|
||||
|
||||
@@ -79,10 +81,10 @@ static void wf_impl_session_dispose_filesystems(
|
||||
void wf_impl_session_dispose(
|
||||
struct wf_impl_session * session)
|
||||
{
|
||||
wf_impl_session_dispose_filesystems(&session->filesystems);
|
||||
|
||||
wf_impl_jsonrpc_proxy_cleanup(&session->rpc);
|
||||
wf_message_queue_cleanup(&session->messages);
|
||||
|
||||
wf_impl_session_dispose_filesystems(&session->filesystems);
|
||||
session->is_authenticated = false;
|
||||
session->wsi = NULL;
|
||||
session->authenticators = NULL;
|
||||
|
||||
18
lib/webfuse/core/lws_log.c
Normal file
18
lib/webfuse/core/lws_log.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "webfuse/core/lws_log.h"
|
||||
#include <stdbool.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#define WF_LWSLOG_DISABLE 0
|
||||
|
||||
static bool wf_lwslog_is_diabled = false;
|
||||
|
||||
void wf_lwslog_disable(void)
|
||||
{
|
||||
if (!wf_lwslog_is_diabled)
|
||||
{
|
||||
lws_set_log_level(WF_LWSLOG_DISABLE, NULL);
|
||||
wf_lwslog_is_diabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
15
lib/webfuse/core/lws_log.h
Normal file
15
lib/webfuse/core/lws_log.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef WF_LWS_LOG_H
|
||||
#define WF_LWS_LOG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wf_lwslog_disable(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -27,11 +27,6 @@ void wf_slist_append(
|
||||
item->next = NULL;
|
||||
list->last->next = item;
|
||||
list->last = item;
|
||||
|
||||
if (NULL == list->head.next)
|
||||
{
|
||||
list->head.next = item;
|
||||
}
|
||||
}
|
||||
|
||||
struct wf_slist_item * wf_slist_remove_first(
|
||||
|
||||
@@ -23,7 +23,7 @@ char const * wf_status_tostring(wf_status status)
|
||||
{
|
||||
case WF_GOOD: return "Good";
|
||||
case WF_BAD: return "Bad";
|
||||
case WF_BAD_NOTIMPLEMENTED: return "Bad (not implelemted)";
|
||||
case WF_BAD_NOTIMPLEMENTED: return "Bad (not implemented)";
|
||||
case WF_BAD_TIMEOUT: return "Bad (timeout)";
|
||||
case WF_BAD_BUSY: return "Bad (busy)";
|
||||
case WF_BAD_FORMAT: return "Bad (format)";
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include "webfuse/provider/impl/client_protocol.h"
|
||||
#include "webfuse/provider/impl/client_config.h"
|
||||
#include "webfuse/provider/impl/url.h"
|
||||
#include "webfuse/core/lws_log.h"
|
||||
|
||||
#define WFP_PROTOCOL ("fs")
|
||||
#define WFP_DISABLE_LWS_LOG 0
|
||||
#define WFP_CLIENT_PROTOCOL_COUNT 2
|
||||
|
||||
struct wfp_client
|
||||
@@ -29,7 +29,7 @@ struct wfp_client
|
||||
struct wfp_client * wfp_impl_client_create(
|
||||
struct wfp_client_config * config)
|
||||
{
|
||||
lws_set_log_level(WFP_DISABLE_LWS_LOG, NULL);
|
||||
wf_lwslog_disable();
|
||||
|
||||
struct wfp_client * client = malloc(sizeof(struct wfp_client));
|
||||
if (NULL != client)
|
||||
@@ -99,6 +99,12 @@ void wfp_impl_client_disconnect(
|
||||
// ToDo: implement me
|
||||
}
|
||||
|
||||
bool wfp_impl_client_is_connected(
|
||||
struct wfp_client * client)
|
||||
{
|
||||
return client->protocol.is_connected;
|
||||
}
|
||||
|
||||
void wfp_impl_client_service(
|
||||
struct wfp_client * client,
|
||||
int timeout_ms)
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef WF_PROVIDER_IMPL_CLIENT_H
|
||||
#define WF_PROVIDER_IMPL_CLIENT_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
@@ -27,13 +31,12 @@ extern void wfp_impl_client_connect(
|
||||
extern void wfp_impl_client_disconnect(
|
||||
struct wfp_client * client);
|
||||
|
||||
extern void wfp_impl_client_settimeout(
|
||||
struct wfp_client * client,
|
||||
unsigned int timepoint);
|
||||
|
||||
extern void wfp_impl_client_dispose(
|
||||
struct wfp_client * client);
|
||||
|
||||
extern bool wfp_impl_client_is_connected(
|
||||
struct wfp_client * client);
|
||||
|
||||
extern void wfp_impl_client_service(
|
||||
struct wfp_client * client,
|
||||
int timeout_ms);
|
||||
|
||||
@@ -35,6 +35,15 @@ static void wfp_impl_client_protocol_process_request(
|
||||
json_t * request = json_loadb(message, length, 0, NULL);
|
||||
if (NULL != request)
|
||||
{
|
||||
// FIXME: is_connected should be invoked, when filesystem added
|
||||
if ((!protocol->is_connected) && (NULL != json_object_get(request, "result")))
|
||||
{
|
||||
protocol->is_connected = true;
|
||||
protocol->provider.connected(protocol->user_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct wfp_impl_invokation_context context =
|
||||
{
|
||||
.provider = &protocol->provider,
|
||||
@@ -84,13 +93,15 @@ static int wfp_impl_client_protocol_callback(
|
||||
{
|
||||
case LWS_CALLBACK_CLIENT_ESTABLISHED:
|
||||
wfp_impl_client_protocol_add_filesystem(protocol);
|
||||
protocol->provider.connected(protocol->user_data);
|
||||
// Defer is_connected until response received
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
|
||||
protocol->is_connected = false;
|
||||
protocol->provider.disconnected(protocol->user_data);
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_CLOSED:
|
||||
protocol->provider.connected(protocol->user_data);
|
||||
protocol->is_connected = false;
|
||||
protocol->provider.disconnected(protocol->user_data);
|
||||
break;
|
||||
case LWS_CALLBACK_CLIENT_RECEIVE:
|
||||
wfp_impl_client_protocol_process_request(protocol, in, len);
|
||||
@@ -126,6 +137,7 @@ void wfp_impl_client_protocol_init(
|
||||
struct wfp_provider const * provider,
|
||||
void * user_data)
|
||||
{
|
||||
protocol->is_connected = false;
|
||||
wf_slist_init(&protocol->messages);
|
||||
|
||||
protocol->wsi = NULL;
|
||||
|
||||
@@ -16,6 +16,7 @@ struct lws_protocols;
|
||||
|
||||
struct wfp_client_protocol
|
||||
{
|
||||
bool is_connected;
|
||||
struct wfp_request request;
|
||||
struct wfp_provider provider;
|
||||
void * user_data;
|
||||
|
||||
Reference in New Issue
Block a user