summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Huerner <ingo.huerner@xse.de>2015-01-07 16:04:43 +0100
committerIngo Huerner <ingo.huerner@xse.de>2015-01-07 16:04:43 +0100
commit2fc0d0f76225e8c318a5c7e9995ceda8201ec1f7 (patch)
tree6e716cb31474a05cf6166c9d007682577127a03f
parent23bc755164fb299d40c7910efa4642f3cd35b87a (diff)
downloadpersistence-client-library-2fc0d0f76225e8c318a5c7e9995ceda8201ec1f7.tar.gz
Removed compiler warnings and obsolete files
-rw-r--r--test/Makefile.am8
-rw-r--r--test/persistence_admin_service_mockup.c589
-rw-r--r--test/persistence_client_library_test.c43
-rw-r--r--test/persistence_lifeCycle_mockup.c609
-rw-r--r--test/persistence_pfs_test.c155
-rw-r--r--test/persistence_test_customlib.c24
6 files changed, 68 insertions, 1360 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 08e47e8..7f91d36 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -11,8 +11,6 @@ endif
noinst_PROGRAMS = persistence_client_library_test \
persistence_client_library_dbus_test \
persistence_client_library_benchmark \
- persistence_admin_service_mockup \
- persistence_lifeCycle_mockup \
persistence_pfs_test
persistence_client_library_dbus_test_SOURCES = persistence_client_library_dbus_test.c
@@ -26,12 +24,6 @@ persistence_client_library_benchmark_LDADD = $(DEPS_LIBS) \
persistence_client_library_test_SOURCES = persistence_client_library_test.c
persistence_client_library_test_LDADD = $(DEPS_LIBS) $(CHECK_LIBS) \
$(top_srcdir)/src/libpersistence_client_library.la
-
-persistence_admin_service_mockup_SOURCES = persistence_admin_service_mockup.c
-persistence_admin_service_mockup_LDADD = $(DEPS_LIBS)
-
-persistence_lifeCycle_mockup_SOURCES = persistence_lifeCycle_mockup.c
-persistence_lifeCycle_mockup_LDADD = $(DEPS_LIBS)
persistence_pfs_test_SOURCES = persistence_pfs_test.c
persistence_pfs_test_LDADD = $(DEPS_LIBS) \
diff --git a/test/persistence_admin_service_mockup.c b/test/persistence_admin_service_mockup.c
deleted file mode 100644
index c21adb3..0000000
--- a/test/persistence_admin_service_mockup.c
+++ /dev/null
@@ -1,589 +0,0 @@
-/******************************************************************************
- * Project Persistency
- * (c) copyright 2012
- * Company XS Embedded GmbH
- *****************************************************************************/
-/******************************************************************************
- * This Source Code Form is subject to the terms of the
- * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
- * with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-******************************************************************************/
- /**
- * @file persistence_admin_service_mockup.c
- * @ingroup Persistence client library test
- * @author Ingo Huerner
- * @brief Persistence Administration Serivce mockup
- * @see
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h> /* exit */
-#include <check.h>
-#include <time.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <dbus/dbus.h>
-#include <poll.h>
-#include <pthread.h>
-#include <sys/eventfd.h>
-
-/*
- * N O T E
- *
- * To test the PAS notifications the "./persistence_client_library_dbus_test" can be used.
- * Use the dbus-send command to send shutdown notification to registered client if the lifecycle mockup will be used.
- * To get the correct destionation (example is :1.11) see console when this application has been started.
- * You sould find something like:
- * " checkAdminMsg ==> busName: :1.79 | objName: /org/genivi/persistence/adminconsumer | notificationFlag: 19 | gTimeoutMs: 5000"
- * when a client registeres itself to the lifecycle mockup.
- * Now use the the destination ":1.79" to communicate with the client library for dest in dbus-send command.
- *
-
- dbus-send --system --dest=:1.11 --type=method_call --print-reply /org/genivi/persistence/adminconsumer org.genivi.persistence.adminconsumer.PersistenceAdminRequest int32:17 int32:22
-
- parameter 1:
- int32:17 => PAS message block and write back
- int32:2 => PAS message unblock
-
- dbus-send return message value 32768 ==> invalid message:
- method return sender=:1.72 -> dest=:1.74 reply_serial=2
- int32 32768
-
- dbus-send return message value 1 ==> OK:
- method return sender=:1.72 -> dest=:1.76 reply_serial=2
- int32 1
-
-*/
-
-
-
-/// command definitions for main loop
-typedef enum ECmd
-{
- CMD_NONE = 0, /// command none
- CMD_PAS_BLOCK_AND_WRITE_BACK, /// command block access and write data back
- CMD_LC_PREPARE_SHUTDOWN, /// command to prepare shutdown
- CMD_QUIT, /// quit command
- CMD_REQUEST_NAME
-} tCmd;
-
-
-/// pipe file descriptors
-int gEfds;
-
-
-
-pthread_mutex_t gDbusInitializedMtx = PTHREAD_MUTEX_INITIALIZER;
-pthread_cond_t gDbusInitializedCond = PTHREAD_COND_INITIALIZER;
-
-/// polling structure
-typedef struct SPollInfo
-{
- int nfds;
- struct pollfd fds[10];
- DBusWatch * watches[10];
-} tPollInfo;
-
-
-/// polling information
-static tPollInfo gPollInfo;
-
-
-/// dbus connection
-DBusConnection* gDbusConn = NULL;
-
-
-DBusConnection* get_dbus_connection(void)
-{
- return gDbusConn;
-}
-
-//------------------------------------------------------------------------
-// debugging only until "correct" exit of main loop is possible!!!!!
-//------------------------------------------------------------------------
-#include "signal.h"
-static int endLoop = 0;
-
-void sigHandler(int signo)
-{
- switch(signo)
- {
- case SIGHUP:
- // noting to do
- printf("* * * * S I G H U P * * * *\n");
- break;
- default:
- endLoop = 1;
- break;
- }
-}
-//------------------------------------------------------------------------
-
-
-static int setupSignalHandler(const int nSignal, void (*pHandler)(int))
-{
- struct sigaction sa_old;
- int ret = sigaction(nSignal, NULL, &sa_old);
- if (0==ret)
- {
- if (pHandler!=sa_old.sa_handler)
- {
- /* setup own signal handler */
- struct sigaction sa_new;
- memset(&sa_new, 0, sizeof(sa_new));
- sa_new.sa_handler = pHandler;
- sa_new.sa_flags = 0;
- ret = sigaction(nSignal, &sa_new, 0);
- }
- }
-
- return ret;
-}
-
-
-
-#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
-
-
-
-int checkAdminMsg(DBusConnection *connection, DBusMessage *message)
-{
- char* busName = NULL;
- char* objName = NULL;
- int32_t notificationFlag = 0;
- uint32_t gTimeoutMs = 0;
- int msgReturn = 123321;
-
- DBusMessage *reply;
- DBusError error;
- dbus_error_init (&error);
-
- if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &busName, // bus name
- DBUS_TYPE_STRING, &objName,
- DBUS_TYPE_INT32, &notificationFlag,
- DBUS_TYPE_UINT32, &gTimeoutMs,
- DBUS_TYPE_INVALID))
- {
- reply = dbus_message_new_error(message, error.name, error.message);
-
- if (reply == 0)
- {
- //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
- printf("DBus No memory\n");
- }
-
- if (!dbus_connection_send(connection, reply, 0))
- {
- //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
- printf("DBus No memory\n");
- }
-
- dbus_message_unref(reply);
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
-
- printf(" checkAdminMsg ==> busName: %s | objName: %s | notificationFlag: %d | gTimeoutMs: %u\n\n", busName, objName, notificationFlag, gTimeoutMs);
- reply = dbus_message_new_method_return(message);
-
- if (reply == 0)
- {
- //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
- printf("DBus No memory\n");
- }
-
- if (!dbus_message_append_args(reply, DBUS_TYPE_INT32, &msgReturn, DBUS_TYPE_INVALID))
- {
- //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
- printf("DBus No memory\n");
- }
-
- if (!dbus_connection_send(connection, reply, NULL))
- {
- //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
- printf("DBus No memory\n");
- }
-
- dbus_connection_flush(connection);
- dbus_message_unref(reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-
-
-DBusHandlerResult checkPersAdminMsg(DBusConnection * connection, DBusMessage * message, void * user_data)
-{
- DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- //printf("checkPersAdminMsg '%s' -> '%s'\n", dbus_message_get_interface(message), dbus_message_get_member(message));
- if((0==strcmp("org.genivi.persistence.admin", dbus_message_get_interface(message))))
- {
- if((0==strcmp("RegisterPersAdminNotification", dbus_message_get_member(message))))
- {
- printf(" ==> org.genivi.persistence.admin - received - ==> RegisterPersAdminNotification \n");
-
- result = checkAdminMsg(connection, message);
- }
- else if((0==strcmp("UnRegisterPersAdminNotification", dbus_message_get_member(message))))
- {
- printf(" ==> org.genivi.persistence.admin - received - ==> UnRegisterPersAdminNotification \n");
-
- result = checkAdminMsg(connection, message);
- }
- else if((0==strcmp("PersistenceAdminRequestCompleted", dbus_message_get_member(message))))
- {
- printf(" ==> org.genivi.persistence.admin - received - ==> PersistenceAdminRequestCompleted \n");
- }
- else
- {
- printf(" ==> org.genivi.persistence.admin - received U N KN O W N-'%s'\n", dbus_message_get_interface(message));
- }
- }
- else
- {
- printf(" ==> org.genivi.persistence - received U N KN O W N-'%s'\n", dbus_message_get_interface(message));
- }
- return result;
-}
-
-
-/* function to unregister ojbect path message handler */
-static void unregisterMessageHandler(DBusConnection *connection, void *user_data)
-{
- printf("unregisterObjectPath\n");
-}
-
-/* catches messages not directed to any registered object path ("garbage collector") */
-static DBusHandlerResult handleObjectPathMessageFallback(DBusConnection * connection, DBusMessage * message, void * user_data)
-{
- DBusHandlerResult result = DBUS_HANDLER_RESULT_HANDLED;
-
- printf("handleObjectPathMessageFallback Object: '%s' -> Interface: '%s' -> Message: '%s'\n",
- dbus_message_get_sender(message), dbus_message_get_interface(message), dbus_message_get_member(message) );
-
- return result;
-}
-
-
-
-static void unregisterObjectPathFallback(DBusConnection *connection, void *user_data)
-{
- printf("unregisterObjectPathFallback\n");
-}
-
-
-
-
-
-
-static dbus_bool_t addWatch(DBusWatch *watch, void *data)
-{
- dbus_bool_t result = FALSE;
-
- //printf("addWatch called @%08x flags: %08x enabled: %c\n", (unsigned int)watch, dbus_watch_get_flags(watch), TRUE==dbus_watch_get_enabled(watch)?'x':'-');
-
- if (ARRAY_SIZE(gPollInfo.fds)>gPollInfo.nfds)
- {
- int flags = dbus_watch_get_flags(watch);
-
- gPollInfo.watches[gPollInfo.nfds] = watch;
-
- gPollInfo.fds[gPollInfo.nfds].fd = dbus_watch_get_unix_fd(watch);
-
- if (TRUE==dbus_watch_get_enabled(watch))
- {
- if (flags&DBUS_WATCH_READABLE)
- {
- gPollInfo.fds[gPollInfo.nfds].events |= POLLIN;
- }
- if (flags&DBUS_WATCH_WRITABLE)
- {
- gPollInfo.fds[gPollInfo.nfds].events |= POLLOUT;
- }
-
- ++gPollInfo.nfds;
- /* wakeup main-loop, just in case */
- static const uint64_t cmd = CMD_REQUEST_NAME;
- if (sizeof(uint64_t)!=write(gEfds, &cmd, sizeof(uint64_t)))
- {
- fprintf(stderr, "write failed w/ errno %d\n", errno);
- }
- }
-
- result = TRUE;
- }
-
- return result;
-}
-
-
-static void removeWatch(DBusWatch *watch, void *data)
-{
- void* w_data = dbus_watch_get_data(watch);
-
- printf("removeWatch called @0x%08x\n", (int)watch);
-
- if(w_data)
- free(w_data);
-
- dbus_watch_set_data(watch, NULL, NULL);
-}
-
-
-static void watchToggled(DBusWatch *watch, void *data)
-{
- printf("watchToggled called @0x%08x\n", (int)watch);
-
- if(dbus_watch_get_enabled(watch))
- addWatch(watch, data);
- else
- removeWatch(watch, data);
-}
-
-
-int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtableFallback, void* userData)
-{
- DBusError err;
- // lock mutex to make sure dbus main loop is running
- pthread_mutex_lock(&gDbusInitializedMtx);
-
- setupSignalHandler(SIGTERM, sigHandler);
- setupSignalHandler(SIGQUIT, sigHandler);
- setupSignalHandler(SIGINT, sigHandler);
- setupSignalHandler(SIGHUP, sigHandler);
-
- DBusConnection* conn = (DBusConnection*)userData;
- dbus_error_init(&err);
-
- if (dbus_error_is_set(&err))
- {
- printf("Connection Error (%s)\n", err.message);
- dbus_error_free(&err);
- }
- else if (NULL != conn)
- {
- dbus_connection_set_exit_on_disconnect (conn, FALSE);
- printf("connected as '%s'\n", dbus_bus_get_unique_name(conn));
- if (-1 == (gEfds = eventfd(0, 0)))
- {
- printf("eventfd() failed w/ errno %d\n", errno);
- }
- else
- {
- int ret;
- int bContinue = 0;
- memset(&gPollInfo, 0 , sizeof(gPollInfo));
-
- gPollInfo.nfds = 1;
- gPollInfo.fds[0].fd = gEfds;
- gPollInfo.fds[0].events = POLLIN;
-
- // register for messages
- if ( (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/persistence/admin", &vtable, userData))
- && (TRUE==dbus_connection_register_fallback(conn, "/", &vtableFallback, userData)) )
- {
- if (TRUE!=dbus_connection_set_watch_functions(conn, addWatch, removeWatch, watchToggled, NULL, NULL))
- {
- printf("dbus_connection_set_watch_functions() failed\n");
- }
- else
- {
- uint16_t buf[64];
-
- pthread_cond_signal(&gDbusInitializedCond);
- pthread_mutex_unlock(&gDbusInitializedMtx);
- do
- {
- bContinue = 0; /* assume error */
-
- while(DBUS_DISPATCH_DATA_REMAINS==dbus_connection_dispatch(conn));
-
- while((-1==(ret=poll(gPollInfo.fds, gPollInfo.nfds, 500)))&&(EINTR==errno));
-
- if(0>ret)
- {
- printf("poll() failed w/ errno %d\n", errno);
- }
- else
- {
- int i;
- bContinue = 1;
-
- for (i=0; gPollInfo.nfds>i; ++i)
- {
- if (0!=gPollInfo.fds[i].revents)
- {
- if (gPollInfo.fds[i].fd==gEfds)
- {
- if (0!=(gPollInfo.fds[i].revents & POLLIN))
- {
- bContinue = TRUE;
- while ((-1==(ret=read(gPollInfo.fds[i].fd, buf, 64)))&&(EINTR==errno));
- if (0>ret)
- {
- printf("read() failed w/ errno %d | %s\n", errno, strerror(errno));
- }
- else if (ret != -1)
- {
- switch (buf[0])
- {
- case CMD_REQUEST_NAME:
- if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER !=dbus_bus_request_name(conn, "org.genivi.persistence.admin", DBUS_NAME_FLAG_DO_NOT_QUEUE, &err))
- {
- fprintf(stderr, "Cannot acquire name 'org.genivi.persistence.admin': \n \"(%s)\". Bailing out!\n", err.message);
- dbus_error_free(&err);
- bContinue = FALSE;
- }
- break;
- case CMD_QUIT:
- bContinue = FALSE;
- break;
- default:
- printf("command %d not handled!\n", buf[0]);
- break;
- }
- }
- }
- }
- else
- {
- int flags = 0;
- if (0!=(gPollInfo.fds[i].revents & POLLIN))
- {
- flags |= DBUS_WATCH_READABLE;
- }
- if (0!=(gPollInfo.fds[i].revents & POLLOUT))
- {
- flags |= DBUS_WATCH_WRITABLE;
- }
- if (0!=(gPollInfo.fds[i].revents & POLLERR))
- {
- flags |= DBUS_WATCH_ERROR;
- }
- if (0!=(gPollInfo.fds[i].revents & POLLHUP))
- {
- flags |= DBUS_WATCH_HANGUP;
- }
- //printf("handle watch @0x%08x flags: %04x\n", (int)gPollInfo.watches[i], flags);
- bContinue = dbus_watch_handle(gPollInfo.watches[i], flags);
- }
- }
- }
- }
- if(endLoop == 1)
- break;
- }
- while (0!=bContinue);
- }
- dbus_connection_unregister_object_path(conn, "/org/genivi/persistence/admin");
- dbus_connection_unregister_object_path(conn, "/");
- }
- close(gEfds);
- }
- dbus_connection_close(conn);
- dbus_connection_unref(conn);
- dbus_shutdown();
- }
-
- pthread_cond_signal(&gDbusInitializedCond);
- pthread_mutex_unlock(&gDbusInitializedMtx);
- return 0;
-}
-
-
-void* run_mainloop(void* dataPtr)
-{
- // persistence admin message
- static const struct DBusObjectPathVTable vtablePersAdmin
- = {unregisterMessageHandler, checkPersAdminMsg, NULL, };
-
- // fallback
- static const struct DBusObjectPathVTable vtableFallback
- = {unregisterObjectPathFallback, handleObjectPathMessageFallback, NULL, };
-
- // setup the dbus
- mainLoop(vtablePersAdmin, vtableFallback, dataPtr);
-
- printf("Exit dbus main loop!!!!\n");
-
- return NULL;
-}
-
-
-int setup_dbus_mainloop(void)
-{
- int rval = 0;
- pthread_t thread;
- DBusError err;
- const char *pAddress = getenv("PERS_CLIENT_DBUS_ADDRESS");
- dbus_error_init(&err);
-
- // enable locking of data structures in the D-Bus library for multi threading.
- dbus_threads_init_default();
-
- // Connect to the bus and check for errors
- if(pAddress != NULL)
- {
- printf("Use specific dbus address: %s\n !", pAddress);
- gDbusConn = dbus_connection_open_private(pAddress, &err);
-
- if(gDbusConn != NULL)
- {
- if(!dbus_bus_register(gDbusConn, &err))
- {
- printf("dbus_bus_register() Error %s\n", err.message);
- dbus_error_free (&err);
- return -1;
- }
- else
- {
- printf("Registered connection successfully !\n");
- }
- }
- else
- {
- printf("dbus_connection_open() Error %s\n",err.message);
- dbus_error_free(&err);
- }
- }
- else
- {
- printf("Use default dbus bus!!!!!!\n");
- gDbusConn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
- }
-
- // wain until dbus main loop has been setup and running
- pthread_mutex_lock(&gDbusInitializedMtx);
-
- // create here the dbus connection and pass to main loop
- rval = pthread_create(&thread, NULL, run_mainloop, gDbusConn);
- if(rval)
- {
- fprintf(stderr, "Server: - ERROR! pthread_create( run_mainloop ) returned: %d\n", rval);
- }
-
- // wait for condition variable
- pthread_cond_wait(&gDbusInitializedCond, &gDbusInitializedMtx);
-
- pthread_mutex_unlock(&gDbusInitializedMtx);
- return rval;
-}
-
-
-
-int main(int argc, char *argv[])
-{
- setup_dbus_mainloop();
-
- printf("Wait, press enter to exit!!\n");
- getchar();
- printf("Exiting Persistence Admin mockup!!\n");
-
- return 0;
-}
-
diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c
index 89cdc84..e5e3b99 100644
--- a/test/persistence_client_library_test.c
+++ b/test/persistence_client_library_test.c
@@ -77,6 +77,7 @@ void data_teardown(void)
int myChangeCallback(pclNotification_s * notifyStruct)
{
printf(" ==> * - * myChangeCallback * - *\n");
+ (void)notifyStruct;
return 1;
}
@@ -240,7 +241,7 @@ START_TEST (test_GetDataHandle)
fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
size = pclKeyHandleWriteData(handle2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
- fail_unless(size == strlen(sysTimeBuffer));
+ fail_unless(size == (int)strlen(sysTimeBuffer));
// close
ret = pclKeyHandleClose(handle2);
// ---------------------------------------------------------------------------------------------
@@ -344,7 +345,7 @@ START_TEST(test_SetData)
* Resource ID: 69
*/
ret = pclKeyWriteData(PCL_LDBID_LOCAL, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
- fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
+ fail_unless(ret == (int)strlen(sysTimeBuffer), "Wrong write size");
#if 1
snprintf(write1, 128, "%s %s", "/70", sysTimeBuffer);
/**
@@ -353,7 +354,7 @@ START_TEST(test_SetData)
* Resource ID: 70
*/
ret = pclKeyWriteData(PCL_LDBID_LOCAL, "70", 1, 2, (unsigned char*)write1, strlen(write1));
- fail_unless(ret == strlen(write1), "Wrong write size");
+ fail_unless(ret == (int)strlen(write1), "Wrong write size");
snprintf(write2, 128, "%s %s", "/key_70", sysTimeBuffer);
/**
@@ -362,7 +363,7 @@ START_TEST(test_SetData)
* Resource ID: key_70
*/
ret = pclKeyWriteData(PCL_LDBID_LOCAL, "key_70", 1, 2, (unsigned char*)write2, strlen(write2));
- fail_unless(ret == strlen(write2), "Wrong write size");
+ fail_unless(ret == (int)strlen(write2), "Wrong write size");
/*******************************************************************************************************************************************/
@@ -376,7 +377,7 @@ START_TEST(test_SetData)
*/
//printf("Write data to trigger change notification\n");
ret = pclKeyWriteData(0x20, "links/last_link2", 2, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
- fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
+ fail_unless(ret == (int)strlen("Test notify shared data"), "Wrong write size");
/**
* Logical DB ID: 0x84 with user 2 and seat 1
@@ -386,7 +387,7 @@ START_TEST(test_SetData)
*/
//printf("Write data to trigger change notification\n");
ret = pclKeyWriteData(0x20, "links/last_link3", 3, 2, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
- fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
+ fail_unless(ret == (int)strlen("Test notify shared data"), "Wrong write size");
/**
* Logical DB ID: 0x84 with user 2 and seat 1
@@ -409,19 +410,19 @@ START_TEST(test_SetData)
ret = pclKeyReadData(PCL_LDBID_LOCAL, "69", 1, 2, buffer, READ_SIZE);
fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
- fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
+ fail_unless(ret == (int)strlen(sysTimeBuffer), "Wrong read size");
memset(buffer, 0, READ_SIZE);
ret = pclKeyReadData(PCL_LDBID_LOCAL, "70", 1, 2, buffer, READ_SIZE);
fail_unless(strncmp((char*)buffer, write1, strlen(write1)) == 0, "Buffer not correctly read");
- fail_unless(ret == strlen(write1), "Wrong read size");
+ fail_unless(ret == (int)strlen(write1), "Wrong read size");
memset(buffer, 0, READ_SIZE);
ret = pclKeyReadData(PCL_LDBID_LOCAL, "key_70", 1, 2, buffer, READ_SIZE);
fail_unless(strncmp((char*)buffer, write2, strlen(write2)) == 0, "Buffer not correctly read");
- fail_unless(ret == strlen(write2), "Wrong read size");
+ fail_unless(ret == (int)strlen(write2), "Wrong read size");
#endif
#endif
}
@@ -461,7 +462,7 @@ START_TEST(test_SetDataNoPRCT)
* ==> local USER value (user 1, seat 2)
*/
ret = pclKeyWriteData(PCL_LDBID_LOCAL, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
- fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
+ fail_unless(ret == (int)strlen(sysTimeBuffer), "Wrong write size");
//printf("Write Buffer : %s\n", sysTimeBuffer);
// read data again and and verify datat has been written correctly
@@ -469,7 +470,7 @@ START_TEST(test_SetDataNoPRCT)
ret = pclKeyReadData(PCL_LDBID_LOCAL, "NoPRCT", 1, 2, buffer, READ_SIZE);
fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
- fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
+ fail_unless(ret == (int)strlen(sysTimeBuffer), "Wrong read size");
//printf("read buffer : %s\n", buffer);
#endif
}
@@ -583,7 +584,7 @@ char gBackupInfo[] = {
int handle = open(backupBlacklist, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
ret = write(handle, gBackupInfo, strlen(gBackupInfo));
- if(ret != strlen(gBackupInfo))
+ if(ret != (int)strlen(gBackupInfo))
{
printf("data_setupBlacklist => Wrong size written: %d", ret);
}
@@ -651,7 +652,7 @@ START_TEST(test_DataFile)
size = pclFileReadData(fd, buffer, READ_SIZE);
//printf("pclFileReadData:\n ist : \"%s\"\n soll: \"%s\" ==> ret: %d => fd: %d\n", buffer, refBuffer, size, fd);
fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db");
- fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf
+ fail_unless(size == ((int)strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf
ret = pclFileClose(fd);
fail_unless(ret == 0, "Failed to close file");
@@ -661,7 +662,7 @@ START_TEST(test_DataFile)
fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db");
size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer));
- fail_unless(size == strlen(writeBuffer), "Failed to write data");
+ fail_unless(size == (int)strlen(writeBuffer), "Failed to write data");
ret = pclFileClose(fd);
fail_unless(ret == 0, "Failed to close file");
@@ -837,7 +838,7 @@ START_TEST(test_DataFileBackupCreation)
memset(rBuffer, 0, 1024);
rval = pclFileWriteData(fd_RW, wBuffer, strlen(wBuffer));
- fail_unless(rval == strlen(wBuffer), "Failed write data");
+ fail_unless(rval == (int)strlen(wBuffer), "Failed write data");
// verify the backup creation:
handle = open(path, O_RDWR);
@@ -1264,15 +1265,15 @@ START_TEST(test_WriteConfDefault)
// -- key-value interface ---
ret = pclKeyWriteData(PCL_LDBID_LOCAL, "statusHandle/writeconfdefault01", PCL_USER_DEFAULTDATA, 0, writeBuffer, strlen((char*)writeBuffer));
- fail_unless(ret == strlen((char*)writeBuffer), "Write Conf default data: write size does not match");
+ fail_unless(ret == (int)strlen((char*)writeBuffer), "Write Conf default data: write size does not match");
ret = pclKeyReadData(PCL_LDBID_LOCAL, "statusHandle/writeconfdefault01", 3, 2, readBuffer, READ_SIZE);
- fail_unless(ret == strlen((char*)writeBuffer), "Write Conf default data: read size does not match");
+ fail_unless(ret == (int)strlen((char*)writeBuffer), "Write Conf default data: read size does not match");
fail_unless(strncmp((char*)readBuffer, (char*)writeBuffer, strlen((char*)readBuffer)) == 0, "Buffer not correctly read");
//printf(" --- test_ReadConfDefault => statusHandle/writeconfdefault01: \"%s\" => \"%s\" \n retIst: %d retSoll: %d\n", readBuffer, writeBuffer, ret, strlen((char*)writeBuffer));
ret = pclKeyWriteData(PCL_LDBID_LOCAL, "statusHandle/writeconfdefault01", PCL_USER_DEFAULTDATA, 0, writeBuffer2, strlen((char*)writeBuffer2));
- fail_unless(ret == strlen((char*)writeBuffer2), "Write Conf default data 2: write size does not match");
+ fail_unless(ret == (int)strlen((char*)writeBuffer2), "Write Conf default data 2: write size does not match");
ret = pclKeyReadData(PCL_LDBID_LOCAL, "statusHandle/writeconfdefault01", 3, 2, readBuffer, READ_SIZE);
fail_unless(strncmp((char*)readBuffer, (char*)writeBuffer2, strlen((char*)readBuffer)) == 0, "Buffer2 not correctly read");
//printf(" --- test_ReadConfDefault => statusHandle/writeconfdefault01: \"%s\" => \"%s\" \n retIst: %d retSoll: %d\n", readBuffer, writeBuffer2, ret, strlen((char*)writeBuffer2));
@@ -1455,11 +1456,11 @@ START_TEST(test_utf8_string)
unsigned char buffer[128] = {0};
ret = pclKeyReadData(PCL_LDBID_LOCAL, "utf8String", 3, 2, buffer, READ_SIZE);
- fail_unless(ret == strlen(utf8StringBuffer), "Wrong read size");
+ fail_unless(ret == (int)strlen(utf8StringBuffer), "Wrong read size");
fail_unless(strncmp((char*)buffer, utf8StringBuffer, ret-1) == 0, "Buffer not correctly read => 1");
size = pclKeyGetSize(PCL_LDBID_LOCAL, "utf8String", 3, 2);
- fail_unless(size == strlen(utf8StringBuffer), "Invalid size");
+ fail_unless(size == (int)strlen(utf8StringBuffer), "Invalid size");
}
END_TEST
@@ -1776,6 +1777,8 @@ int main(int argc, char *argv[])
TestResult** tResult;
+ (void)argv;
+
// assign application name
strncpy(gTheAppId, "lt-persistence_client_library_test", MaxAppNameLen);
gTheAppId[MaxAppNameLen-1] = '\0';
diff --git a/test/persistence_lifeCycle_mockup.c b/test/persistence_lifeCycle_mockup.c
deleted file mode 100644
index eaab68d..0000000
--- a/test/persistence_lifeCycle_mockup.c
+++ /dev/null
@@ -1,609 +0,0 @@
-/******************************************************************************
- * Project Persistency
- * (c) copyright 2012
- * Company XS Embedded GmbH
- *****************************************************************************/
-/******************************************************************************
- * This Source Code Form is subject to the terms of the
- * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
- * with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
-******************************************************************************/
- /**
- * @file persistence_admin_service_mockup.c
- * @ingroup Persistence client library test
- * @author Ingo Huerner
- * @brief Persistence Administration Serivce mockup
- * @see
- */
-
-
-/*
- * N O T E
- *
- * To test the shutdown sequence the "./persistence_client_library_dbus_test" can be used.
- * Use the dbus-send command to send shutdown notification to registered client if the lifecycle mockup will be used.
- * To get the correct destionation (example is :1.11) see console when this application has been started.
- * You sould find something like:
- * "handleObjectPathMessageFallback Object: ':1.69' -> Interface: 'org.genivi.NodeStateManager.Consumer' -> Message: 'RegisterShutdownClient'"
- * when a client registeres itself to the lifecycle mockup.
- * Now use the the destination ":1.69" to communicate with the client library for dest in dbus-send command.
- *
-
- dbus-send --system --dest=:1.11 --type=method_call --print-reply /org/genivi/NodeStateManager/LifeCycleConsumer org.genivi.NodeStateManager.LifeCycleConsumer.LifecycleRequest uint32:1 uint32:22
-
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h> /* exit */
-#include <check.h>
-#include <time.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <dbus/dbus.h>
-#include <poll.h>
-#include <pthread.h>
-#include <sys/eventfd.h>
-
-
-/// command definitions for main loop
-typedef enum ECmd
-{
- CMD_NONE = 0, /// command none
- CMD_PAS_BLOCK_AND_WRITE_BACK, /// command block access and write data back
- CMD_LC_PREPARE_SHUTDOWN, /// command to prepare shutdown
- CMD_QUIT, /// quit command
- CMD_REQUEST_NAME
-} tCmd;
-
-
-/// pipe file descriptors
-int gEfds;
-
-
-
-pthread_mutex_t gDbusInitializedMtx = PTHREAD_MUTEX_INITIALIZER;
-pthread_cond_t gDbusInitializedCond = PTHREAD_COND_INITIALIZER;
-
-/// polling structure
-typedef struct SPollInfo
-{
- int nfds;
- struct pollfd fds[10];
- DBusWatch * watches[10];
-} tPollInfo;
-
-
-/// polling information
-static tPollInfo gPollInfo;
-
-
-/// dbus connection
-DBusConnection* gDbusConn = NULL;
-
-
-DBusConnection* get_dbus_connection(void)
-{
- return gDbusConn;
-}
-
-//------------------------------------------------------------------------
-// debugging only until "correct" exit of main loop is possible!!!!!
-//------------------------------------------------------------------------
-#include "signal.h"
-static int endLoop = 0;
-
-void sigHandler(int signo)
-{
- switch(signo)
- {
- case SIGHUP:
- // nothing to do
- printf("* * * * S I G H U P * * * *\n");
- break;
- default:
- endLoop = 1;
- break;
- }
-}
-//------------------------------------------------------------------------
-
-
-static int setupSignalHandler(const int nSignal, void (*pHandler)(int))
-{
- struct sigaction sa_old;
- int ret = sigaction(nSignal, NULL, &sa_old);
- if (0==ret)
- {
- if (pHandler!=sa_old.sa_handler)
- {
- /* setup own signal handler */
- struct sigaction sa_new;
- memset(&sa_new, 0, sizeof(sa_new));
- sa_new.sa_handler = pHandler;
- sa_new.sa_flags = 0;
- ret = sigaction(nSignal, &sa_new, 0);
- }
- }
-
- return ret;
-}
-
-
-#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
-
-
-
-int checkAdminMsg(DBusConnection *connection, DBusMessage *message, int reg)
-{
- char* busName = NULL;
- char* objName = NULL;
- int32_t notificationFlag = 0;
- uint32_t gTimeoutMs = 0;
- int msgReturn = 123321;
-
- DBusMessage *reply;
- DBusError error;
- dbus_error_init (&error);
-
- if(reg == 1)
- {
- if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &busName, // bus name
- DBUS_TYPE_STRING, &objName,
- DBUS_TYPE_UINT32, &notificationFlag,
- DBUS_TYPE_UINT32, &gTimeoutMs,
- DBUS_TYPE_INVALID))
- {
- reply = dbus_message_new_error(message, error.name, error.message);
-
- if (reply == 0)
- {
- //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
- printf("DBus No memory\n");
- }
-
- if (!dbus_connection_send(connection, reply, 0))
- {
- //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
- printf("DBus No memory\n");
- }
-
- dbus_message_unref(reply);
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
- }
- else if(reg == 0)
- {
- if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &busName, // bus name
- DBUS_TYPE_STRING, &objName,
- DBUS_TYPE_UINT32, &notificationFlag,
- DBUS_TYPE_INVALID))
- {
- reply = dbus_message_new_error(message, error.name, error.message);
-
- if (reply == 0)
- {
- //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
- printf("DBus No memory\n");
- }
-
- if (!dbus_connection_send(connection, reply, 0))
- {
- //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
- printf("DBus No memory\n");
- }
-
- dbus_message_unref(reply);
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
- }
-
-
- printf(" checkAdminMsg ==> busName: %s | objName: %s | notificationFlag: %d | gTimeoutMs: %u\n\n", busName, objName, notificationFlag, gTimeoutMs);
- reply = dbus_message_new_method_return(message);
-
- if (reply == 0)
- {
- //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
- printf("DBus No memory\n");
- }
-
- if (!dbus_message_append_args(reply, DBUS_TYPE_INT32, &msgReturn, DBUS_TYPE_INVALID))
- {
- //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
- printf("DBus No memory\n");
- }
-
- if (!dbus_connection_send(connection, reply, NULL))
- {
- //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
- printf("DBus No memory\n");
- }
-
- dbus_connection_flush(connection);
- dbus_message_unref(reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-
-
-DBusHandlerResult checkPersAdminMsg(DBusConnection * connection, DBusMessage * message, void * user_data)
-{
- DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- //printf("checkPersAdminMsg '%s' -> '%s'\n", dbus_message_get_interface(message), dbus_message_get_member(message));
- if((0==strcmp("org.genivi.NodeStateManager.LifeCycleConsumer", dbus_message_get_interface(message))))
- {
- if((0==strcmp("RegisterShutdownClient", dbus_message_get_member(message))))
- {
- printf(" ==> org.genivi.NodeStateManager.LifeCycleConsumer - received - ==> RegisterShutdownClient \n");
-
- result = checkAdminMsg(connection, message, 1);
- }
- else if((0==strcmp("UnRegisterShutdownClient", dbus_message_get_member(message))))
- {
- printf(" ==> org.genivi.NodeStateManager.LifeCycleConsumer - received - ==> UnRegisterShutdownClient \n");
-
- result = checkAdminMsg(connection, message, 0);
- }
- else if((0==strcmp("LifecycleRequestComplete", dbus_message_get_member(message))))
- {
- printf(" ==> org.genivi.NodeStateManager.LifeCycleConsumer - received - ==> LifecycleRequestComplete \n");
-
- result = checkAdminMsg(connection, message, 0);
- }
-
- else
- {
- printf(" ==> org.genivi.NodeStateManager.LifeCycleConsumer - received U N KN O W N-'%s'\n", dbus_message_get_interface(message));
- }
- }
- else
- {
- printf(" ==> org.genivi.NodeStateManager - received U N KN O W N-'%s'\n", dbus_message_get_interface(message));
- }
- return result;
-}
-
-
-/* function to unregister ojbect path message handler */
-static void unregisterMessageHandler(DBusConnection *connection, void *user_data)
-{
- printf("unregisterObjectPath\n");
-}
-
-/* catches messages not directed to any registered object path ("garbage collector") */
-static DBusHandlerResult handleObjectPathMessageFallback(DBusConnection * connection, DBusMessage * message, void * user_data)
-{
- DBusHandlerResult result = DBUS_HANDLER_RESULT_HANDLED;
-
- printf("handleObjectPathMessageFallback Object: '%s' -> Interface: '%s' -> Message: '%s'\n",
- dbus_message_get_sender(message), dbus_message_get_interface(message), dbus_message_get_member(message) );
-
- return result;
-}
-
-
-
-static void unregisterObjectPathFallback(DBusConnection *connection, void *user_data)
-{
- printf("unregisterObjectPathFallback\n");
-}
-
-
-
-
-
-
-static dbus_bool_t addWatch(DBusWatch *watch, void *data)
-{
- dbus_bool_t result = FALSE;
-
- //printf("addWatch called @%08x flags: %08x enabled: %c\n", (unsigned int)watch, dbus_watch_get_flags(watch), TRUE==dbus_watch_get_enabled(watch)?'x':'-');
-
- if (ARRAY_SIZE(gPollInfo.fds)>gPollInfo.nfds)
- {
- int flags = dbus_watch_get_flags(watch);
-
- gPollInfo.watches[gPollInfo.nfds] = watch;
-
- gPollInfo.fds[gPollInfo.nfds].fd = dbus_watch_get_unix_fd(watch);
-
- if (TRUE==dbus_watch_get_enabled(watch))
- {
- if (flags&DBUS_WATCH_READABLE)
- {
- gPollInfo.fds[gPollInfo.nfds].events |= POLLIN;
- }
- if (flags&DBUS_WATCH_WRITABLE)
- {
- gPollInfo.fds[gPollInfo.nfds].events |= POLLOUT;
- }
-
- ++gPollInfo.nfds;
- /* wakeup main-loop, just in case */
- static const uint64_t cmd = CMD_REQUEST_NAME;
- if (sizeof(uint64_t)!=write(gEfds, &cmd, sizeof(uint64_t)))
- {
- fprintf(stderr, "write failed w/ errno %d\n", errno);
- }
- }
-
- result = TRUE;
- }
-
- return result;
-}
-
-
-static void removeWatch(DBusWatch *watch, void *data)
-{
- void* w_data = dbus_watch_get_data(watch);
-
- printf("removeWatch called @0x%08x\n", (int)watch);
-
- if(w_data)
- free(w_data);
-
- dbus_watch_set_data(watch, NULL, NULL);
-}
-
-
-static void watchToggled(DBusWatch *watch, void *data)
-{
- printf("watchToggled called @0x%08x\n", (int)watch);
-
- if(dbus_watch_get_enabled(watch))
- addWatch(watch, data);
- else
- removeWatch(watch, data);
-}
-
-
-
-int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtableFallback, void* userData)
-{
- DBusError err;
- // lock mutex to make sure dbus main loop is running
- pthread_mutex_lock(&gDbusInitializedMtx);
-
- setupSignalHandler(SIGTERM, sigHandler);
- setupSignalHandler(SIGQUIT, sigHandler);
- setupSignalHandler(SIGINT, sigHandler);
- setupSignalHandler(SIGHUP, sigHandler);
-
- DBusConnection* conn = (DBusConnection*)userData;
- dbus_error_init(&err);
-
- if (dbus_error_is_set(&err))
- {
- printf("Connection Error (%s)\n", err.message);
- dbus_error_free(&err);
- }
- else if (NULL != conn)
- {
- dbus_connection_set_exit_on_disconnect (conn, FALSE);
- printf("connected as '%s'\n", dbus_bus_get_unique_name(conn));
- if (-1 == (gEfds = eventfd(0, 0)))
- {
- printf("eventfd() failed w/ errno %d\n", errno);
- }
- else
- {
- int ret;
- int bContinue = 0;
- memset(&gPollInfo, 0 , sizeof(gPollInfo));
-
- gPollInfo.nfds = 1;
- gPollInfo.fds[0].fd = gEfds;
- gPollInfo.fds[0].events = POLLIN;
-
- // register for messages
- if ( (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/NodeStateManager", &vtable, userData))
- && (TRUE==dbus_connection_register_fallback(conn, "/", &vtableFallback, userData)) )
- {
- if (TRUE!=dbus_connection_set_watch_functions(conn, addWatch, removeWatch, watchToggled, NULL, NULL))
- {
- printf("dbus_connection_set_watch_functions() failed\n");
- }
- else
- {
- uint16_t buf[64];
-
- pthread_cond_signal(&gDbusInitializedCond);
- pthread_mutex_unlock(&gDbusInitializedMtx);
- do
- {
- bContinue = 0; /* assume error */
-
- while(DBUS_DISPATCH_DATA_REMAINS==dbus_connection_dispatch(conn));
-
- while((-1==(ret=poll(gPollInfo.fds, gPollInfo.nfds, 500)))&&(EINTR==errno));
-
- if(0>ret)
- {
- printf("poll() failed w/ errno %d\n", errno);
- }
- else
- {
- int i;
- bContinue = 1;
-
- for (i=0; gPollInfo.nfds>i; ++i)
- {
- if (0!=gPollInfo.fds[i].revents)
- {
- if (gPollInfo.fds[i].fd==gEfds)
- {
- if (0!=(gPollInfo.fds[i].revents & POLLIN))
- {
- bContinue = TRUE;
- while ((-1==(ret=read(gPollInfo.fds[i].fd, buf, 64)))&&(EINTR==errno));
- if (0>ret)
- {
- printf("read() failed w/ errno %d | %s\n", errno, strerror(errno));
- }
- else if (ret != -1)
- {
- switch (buf[0])
- {
- case CMD_REQUEST_NAME:
- if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER !=dbus_bus_request_name(conn, "org.genivi.NodeStateManager", DBUS_NAME_FLAG_DO_NOT_QUEUE, &err))
- {
- fprintf(stderr, "Cannot acquire name 'org.genivi.NodeStateManager': \n \"(%s)\". Bailing out!\n", err.message);
- dbus_error_free(&err);
- bContinue = FALSE;
- }
- break;
- case CMD_QUIT:
- bContinue = FALSE;
- break;
- default:
- printf("command %d not handled!\n", buf[0]);
- break;
- }
- }
- }
- }
- else
- {
- int flags = 0;
- if (0!=(gPollInfo.fds[i].revents & POLLIN))
- {
- flags |= DBUS_WATCH_READABLE;
- }
- if (0!=(gPollInfo.fds[i].revents & POLLOUT))
- {
- flags |= DBUS_WATCH_WRITABLE;
- }
- if (0!=(gPollInfo.fds[i].revents & POLLERR))
- {
- flags |= DBUS_WATCH_ERROR;
- }
- if (0!=(gPollInfo.fds[i].revents & POLLHUP))
- {
- flags |= DBUS_WATCH_HANGUP;
- }
- //printf("handle watch @0x%08x flags: %04x\n", (int)gPollInfo.watches[i], flags);
- bContinue = dbus_watch_handle(gPollInfo.watches[i], flags);
- }
- }
- }
- }
- if(endLoop == 1)
- break;
- }
- while (0!=bContinue);
- }
- dbus_connection_unregister_object_path(conn, "/org/genivi/NodeStateManager");
- dbus_connection_unregister_object_path(conn, "/");
- }
- close(gEfds);
- }
- dbus_connection_close(conn);
- dbus_connection_unref(conn);
- dbus_shutdown();
- }
-
- pthread_cond_signal(&gDbusInitializedCond);
- pthread_mutex_unlock(&gDbusInitializedMtx);
- return 0;
-}
-
-
-void* run_mainloop(void* dataPtr)
-{
- // persistence admin message
- static const struct DBusObjectPathVTable vtablePersAdmin
- = {unregisterMessageHandler, checkPersAdminMsg, NULL, };
-
- // fallback
- static const struct DBusObjectPathVTable vtableFallback
- = {unregisterObjectPathFallback, handleObjectPathMessageFallback, NULL, };
-
- // setup the dbus
- mainLoop(vtablePersAdmin, vtableFallback, dataPtr);
-
- printf("Exit dbus main loop!!!!\n");
-
- return NULL;
-}
-
-
-int setup_dbus_mainloop(void)
-{
- int rval = 0;
- pthread_t thread;
- DBusError err;
- const char *pAddress = getenv("PERS_CLIENT_DBUS_ADDRESS");
- dbus_error_init(&err);
-
- // enable locking of data structures in the D-Bus library for multi threading.
- dbus_threads_init_default();
-
- // Connect to the bus and check for errors
- if(pAddress != NULL)
- {
- printf("Use specific dbus address: %s\n !", pAddress);
- gDbusConn = dbus_connection_open_private(pAddress, &err);
-
- if(gDbusConn != NULL)
- {
- if(!dbus_bus_register(gDbusConn, &err))
- {
- printf("dbus_bus_register() Error %s\n", err.message);
- dbus_error_free (&err);
- return -1;
- }
- else
- {
- printf("Registered connection successfully !\n");
- }
- }
- else
- {
- printf("dbus_connection_open() Error %s\n",err.message);
- dbus_error_free(&err);
- }
- }
- else
- {
- printf("Use default dbus bus!!!!!!\n");
- gDbusConn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
- }
-
- // wain until dbus main loop has been setup and running
- pthread_mutex_lock(&gDbusInitializedMtx);
-
- // create here the dbus connection and pass to main loop
- rval = pthread_create(&thread, NULL, run_mainloop, gDbusConn);
- if(rval)
- {
- fprintf(stderr, "Server: - ERROR! pthread_create( run_mainloop ) returned: %d\n", rval);
- }
-
- // wait for condition variable
- pthread_cond_wait(&gDbusInitializedCond, &gDbusInitializedMtx);
-
- pthread_mutex_unlock(&gDbusInitializedMtx);
- return rval;
-}
-
-
-
-int main(int argc, char *argv[])
-{
- setup_dbus_mainloop();
-
- printf("Wait, press enter to exit!!\n");
- getchar();
- printf("Exiting Persistence Lifecycle mockup!!\n");
-
- return 0;
-}
-
diff --git a/test/persistence_pfs_test.c b/test/persistence_pfs_test.c
index 8a3ef10..82290a0 100644
--- a/test/persistence_pfs_test.c
+++ b/test/persistence_pfs_test.c
@@ -29,7 +29,6 @@
* @see
*/
-
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
@@ -139,10 +138,9 @@ static const char* gDefaultFileResNames[] =
};
-pthread_cond_t gPowerDownMtxCond = PTHREAD_COND_INITIALIZER;
-pthread_mutex_t gPowerDownMtx = PTHREAD_MUTEX_INITIALIZER;
-
+// extdern declaration
+extern void pcl_test_send_shutdown_command();
// forward declaration
@@ -171,7 +169,7 @@ int setup_test_data(const char* postfix)
pclInitLibrary("pfs_test", shutdownReg); // register to persistence client library
// key/value data
- for(i=0; i<sizeof(gDefaultKeyValueTestData) / sizeof(char*); i++)
+ for(i=0; i < (int)sizeof(gDefaultKeyValueTestData) / (int)sizeof(char*); i++)
{
memset(databuffer, 0, 64);
snprintf(databuffer, 64, gDefaultKeyValueTestData[i], postfix);
@@ -208,7 +206,7 @@ void verify_test_setup()
pclInitLibrary("pfs_test", shutdownReg); // register to persistence client library
- for(i=0; i<sizeof(gDefaultKeyValueTestData) / sizeof(char*); i++)
+ for(i=0; i< (int)sizeof(gDefaultKeyValueTestData) / (int)sizeof(char*); i++)
{
ret = pclKeyReadData(PCL_LDBID_LOCAL, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)buffer, 64);
if(ret < 0)
@@ -226,63 +224,16 @@ void verify_test_setup()
-int setup_serial_con(const char* ttyConsole)
-{
- struct termios tty;
- int rval = -1;
-
- memset (&tty, 0, sizeof(tty));
- tty.c_iflag = IGNPAR;
- tty.c_oflag = 0;
- tty.c_cflag = CS8 | CREAD | CLOCAL; // 8n1, see termios.h for more information
- tty.c_lflag = 0;
- tty.c_cc[VMIN] = 1;
- tty.c_cc[VTIME] = 5;
-
- printf("Opening connection to %s\n", ttyConsole);
- rval = open(ttyConsole, O_RDWR | O_NOCTTY | O_SYNC);
- if(rval != -1)
- {
- if (cfsetospeed (&tty, B115200) == -1) // 115200 baud
- {
- printf("Failed to set cfsetospeed\n");
- }
- if(cfsetispeed (&tty, B115200)) // 115200 baud
- {
- printf("Failed to set cfsetispeed\n");
- }
-
- tcsetattr(rval, TCSANOW, &tty);
-
- printf("tty fd: %d\n", rval);
- }
- else
- {
- printf("Failed to open console: %s - %s\n", ttyConsole, strerror(errno));
- }
-
- return rval;
-}
-
-
-
/// after this function has been called the system reboots
-void send_serial_shutdown_cmd(int fd)
+void send_snmp_shutdown_cmd()
{
- // command for the computer controller power supply to power off and restart after 2.5 second again
- static const char data[] = { "USET 12.000; ISET 10.000; OUTPUT OFF; WAIT 0.500; OUTPUT ON\n" };
+ // command to power off the power supply
+ const char data[] = { "snmpset -v1 -c public 134.86.58.225 iso.3.6.1.4.1.1909.22.1.1.1.5.1 i 1" };
- if(write(fd, data, sizeof(data)) != -1)
- {
- fdatasync(fd);
- printf("Data: %s\n", data);
- }
- else
+ if(system(data) == -1)
{
- printf("Failed to write to tty - size: %d - error: %s\n", sizeof(data), strerror(errno));
+ printf("Failed to execute command: %s\n", data);
}
-
- close(fd);
}
@@ -365,28 +316,6 @@ void update_test_data(char* buffer, int lc_counter, int write_counter)
}
-void* power_supply_shutdown(void* dataPtr)
-{
- int fd = (int)(dataPtr);
- int secs = 100000;
- printf("Shutdown thread started fd: %d\n", fd);
-
- pthread_cond_wait(&gPowerDownMtxCond, &gPowerDownMtx);
- pthread_mutex_unlock(&gPowerDownMtx);
-
-# if 1
- printf(" Send pwrOff command!\n");
-#else
- printf(" Send pwrOff command but sleep first: %d !!!!\n", secs);
- usleep(secs);
- printf(" ==> no more sleeping!!!!\n");
-#endif
- send_serial_shutdown_cmd(fd);
- printf(" Cut pwr OFF => ByBy\n");
-
- return NULL;
-}
-
int get_lifecycle_count(char* buf)
{
@@ -398,17 +327,10 @@ int get_write_count(char* buf)
return atoi(&buf[WR_CNT_START]);
}
-
int main(int argc, char *argv[])
{
int rVal = EXIT_SUCCESS;
- int ttyfd = -1;
- int* retval;
- char ttydevice[24] = {0};
unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
- pthread_t powerShutdownThread;
- struct sched_param param;
- pthread_attr_t tattr;
printf("------------------\n");
printf("P F S - Test start\n");
@@ -419,22 +341,13 @@ int main(int argc, char *argv[])
//DLT_REGISTER_CONTEXT(gPFSDLTContext,"PFS","Context for PCL PFS test logging");
- if (argc < 2) {
- printf ("Please start with %s /dev/ttyS1 or /dev/ttyUSB0 (for example)\n", argv[0]);
- return EXIT_SUCCESS;
- }
-
- pthread_mutex_lock(&gPowerDownMtx); // lock power down mutex and release when powser should be cut off
-
-
- // default serial console
- strncpy(ttydevice, "/dev/ttyUSB0", 24);
#if 0
// mount persistence partitions
if(-1 != mount_persistence("/dev/sdb") )
{
#endif
+
int numLoops = 1000000, opt = 0;
while ((opt = getopt(argc, argv, "l:s:")) != -1)
@@ -444,20 +357,10 @@ int main(int argc, char *argv[])
case 'l':
numLoops = atoi(optarg);
break;
- case 's':
- memset(ttydevice, 0, 24);
- strncpy(ttydevice, optarg, 24);
- break;
}
}
- // setup the serial connection to the power supply
- ttyfd = setup_serial_con(ttydevice);
- if(ttyfd == -1)
- {
- printf("Failed to setup serial console: \"%s\"\n", ttydevice);
- return EXIT_SUCCESS;
- }
+
if(update_test_progress_flag(gTestInProgressFlag, &gLifecycleCounter) == 0)
{
@@ -477,17 +380,6 @@ int main(int argc, char *argv[])
DLT_LOG(gPFSDLTContext, DLT_LOG_INFO, DLT_STRING("PFS test - Lifecycle counter:"), DLT_INT(gLifecycleCounter),
DLT_STRING("- number of write loops:"), DLT_INT(numLoops));
*/
- pthread_attr_init(&tattr);
- param.sched_priority = 49;
- pthread_attr_setschedparam(&tattr, &param);
-
- // create here the dbus connection and pass to main loop
- if(pthread_create(&powerShutdownThread, &tattr, power_supply_shutdown, (void*)ttyfd) == -1)
- {
- //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("pthread_create( DBUS run_mainloop )") );
- return -1;
- }
-
pclInitLibrary("pfs_test", shutdownReg); // register to persistence client library
// verify the data form previous lifecycle
@@ -501,8 +393,6 @@ int main(int argc, char *argv[])
//write_data_file(numLoops);
- pthread_cond_signal(&gPowerDownMtxCond);
- pthread_mutex_unlock(&gPowerDownMtx);
printf("Deinit library\n");
pclDeinitLibrary(); // unregister from persistence client library
@@ -527,8 +417,6 @@ int main(int argc, char *argv[])
//dlt_free();
printf("Wait until shutdown thread has finished\n");
- // wait until the shutdown thread has ended
- pthread_join(powerShutdownThread, (void**)&retval);
return rVal;
}
@@ -541,7 +429,7 @@ void verify_data_key_value()
char buffer[64] = {0};
// read data from previous lifecycle - key/value
- for(i=0; i<sizeof(gDefaultKeyValueTestData) / sizeof(char*); i++)
+ for(i=0; i< (int)sizeof(gDefaultKeyValueTestData) / (int)sizeof(char*); i++)
{
memset(buffer, 0, 64);
ret = pclKeyReadData(PCL_LDBID_LOCAL, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)buffer, 64);
@@ -634,7 +522,7 @@ void write_data_key_value(int numLoops, int counter)
{
// write key/value data
- for(i=0; i<sizeof(gDefaultKeyValueTestData) / sizeof(char*); i++)
+ for(i=0; i< (int)sizeof(gDefaultKeyValueTestData) / (int)sizeof(char*); i++)
{
char buffer[64] = {0};
@@ -646,8 +534,8 @@ void write_data_key_value(int numLoops, int counter)
{
// unlock mutex
printf("Now POWER OFF => k: %d \n", k);
- pthread_cond_signal(&gPowerDownMtxCond);
- pthread_mutex_unlock(&gPowerDownMtx);
+ pcl_test_send_shutdown_command();
+ break;
}
ret = pclKeyWriteData(PCL_LDBID_LOCAL, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)buffer, strlen(buffer));
if(ret < 0)
@@ -673,13 +561,13 @@ void verify_data_file()
char buffer[64] = {0};
// open files
- for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++)
+ for(i=0; i< (int)sizeof(gDefaultFileAPITestData) / (int)sizeof(char*); i++)
{
handles[i] = pclFileOpen(PCL_LDBID_LOCAL, gDefaultFileResNames[i], 1, 0);
}
// read data from previous lifecycle - file
- for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++)
+ for(i=0; i< (int)sizeof(gDefaultFileAPITestData) / (int)sizeof(char*); i++)
{
memset(buffer, 0, 64);
ret = pclFileReadData(handles[i], buffer, 64);
@@ -695,7 +583,7 @@ void verify_data_file()
}
// close fd's
- for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++)
+ for(i=0; i< (int)sizeof(gDefaultFileAPITestData) / (int)sizeof(char*); i++)
{
ret = pclFileClose(handles[i]);
if(ret != 0)
@@ -712,7 +600,7 @@ void write_data_file(int numLoops)
int handles[128] = {0};
// open files
- for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++)
+ for(i=0; i< (int)sizeof(gDefaultFileAPITestData) / (int)sizeof(char*); i++)
{
handles[i] = pclFileOpen(PCL_LDBID_LOCAL, gDefaultFileResNames[i], 1, 1);
}
@@ -721,7 +609,7 @@ void write_data_file(int numLoops)
{
// write file data
- for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++)
+ for(i=0; i< (int)sizeof(gDefaultFileAPITestData) / (int)sizeof(char*); i++)
{
char buffer[64] = {0};
@@ -743,7 +631,7 @@ void write_data_file(int numLoops)
} // writes per lifecycle
// close fd's
- for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++)
+ for(i=0; i< (int)sizeof(gDefaultFileAPITestData) / (int)sizeof(char*); i++)
{
ret = pclFileClose(handles[i]);
if(ret != 0)
@@ -795,4 +683,3 @@ int mount_persistence(const char* deviceName)
return rval;
}
-
diff --git a/test/persistence_test_customlib.c b/test/persistence_test_customlib.c
index 5a5803a..9295df5 100644
--- a/test/persistence_test_customlib.c
+++ b/test/persistence_test_customlib.c
@@ -48,6 +48,8 @@ int plugin_handle_close(int handle)
{
int rval = 99;
+ (void)handle;
+
//printf("* * * * * plugin_close- handle: %d!\n", handle);
return rval;
@@ -65,6 +67,7 @@ int plugin_handle_close(int handle)
int plugin_delete_data(const char* path)
{
int rval = 13579;
+ (void)path;
//printf("* * * * * plugin_delete_data - path: %s!\n", path);
@@ -86,6 +89,7 @@ int plugin_handle_get_data(int handle, char* buffer, int size)
{
//int strSize = 99;
//printf("plugin_handle_get_data: %s\n", LIBIDENT);
+ (void)handle;
return snprintf(buffer, size, "Custom plugin -> plugin_get_data_handle: %s!", LIBIDENT);
}
@@ -103,6 +107,9 @@ int plugin_get_data(const char* path, char* buffer, int size)
//int strSize = 99;
//printf("Custom plugin -> plugin_get_data: %s!\n", LIBIDENT);
+ (void)path;
+ (void)buffer;
+ (void)size;
return snprintf(buffer, size, "Custom plugin -> plugin_get_data: %s!", LIBIDENT);
}
@@ -129,6 +136,7 @@ int plugin_init_async(plugin_callback_async_t pfInitCompletedCB)
//int rval = -1;
//printf("* * * * * plugin_init_async => %s!\n", LIBIDENT);
+ (void)pfInitCompletedCB;
return 1;
}
@@ -167,6 +175,9 @@ int plugin_handle_open(const char* path, int flag, int mode)
int rval = 100;
//printf("* * * * * plugin_open - path: %s | flag: %d | mode: %d | plugin: %s!\n", path, flag, mode, LIBIDENT);
+ (void)path;
+ (void)flag;
+ (void)mode;
return rval;
}
@@ -187,6 +198,9 @@ int plugin_handle_set_data(int handle, char* buffer, int size)
int rval = 123654;
//printf("* * * * * plugin_handle_set_data: %s!\n", LIBIDENT);
+ (void)handle;
+ (void)buffer;
+ (void)size;
return rval;
}
@@ -204,6 +218,9 @@ int plugin_set_data(const char* path, char* buffer, int size)
int rval = 321456;
//printf("* * * * * plugin_set_data: %s!\n", LIBIDENT);
+ (void)path;
+ (void)buffer;
+ (void)size;
return rval;
}
@@ -230,6 +247,7 @@ int plugin_get_status_notification_clbk(plugin_callback_t pFunct)
int rval = 99;
//printf("* * * * * plugin_get_status_notification_clbk: %s!\n", LIBIDENT);
+ (void)pFunct;
return rval;
}
@@ -240,6 +258,7 @@ int plugin_handle_get_size(int handle)
int rval = 11223344;
//printf("* * * * * plugin_get_size_handle: %d | %s!\n", handle, LIBIDENT);
+ (void)handle;
return rval;
}
@@ -250,6 +269,7 @@ int plugin_get_size(const char* path)
int rval = 44332211;
//printf("* * * * * plugin_get_size: %s | %s!\n", path, LIBIDENT);
+ (void)path;
return rval;
}
@@ -261,6 +281,7 @@ int plugin_create_backup(const char* backup_id)
int rval = -1;
printf("* * * * * plugin_create_backup: backup_id %s | %s!\n", backup_id, LIBIDENT);
+ (void)backup_id;
return rval;
}
@@ -271,6 +292,7 @@ int plugin_restore_backup(const char* backup_id)
int rval = -1;
printf("* * * * * plugin_restore_backup: backup_id %s | %s!\n", backup_id, LIBIDENT);
+ (void)backup_id;
return rval;
@@ -282,6 +304,8 @@ int plugin_get_backup(char* backup_id, int size)
int rval = -1;
printf("* * * * * plugin_get_backup: backup_id %s\n", backup_id);
+ (void)backup_id;
+ (void)size;
return rval;
}