summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Huerner <ingo_huerner@mentor.com>2017-02-17 14:43:55 +0100
committerIngo Huerner <ingo_huerner@mentor.com>2017-02-17 14:43:55 +0100
commit4ac02336cb4b71893355211491a54cb3d715839a (patch)
tree3c597d8346f44eb188b2b8f64243b5d4d27f45f0
parent89568bfd604dc309357496b2a194f5e5122dc90a (diff)
downloadpersistence-client-library-4ac02336cb4b71893355211491a54cb3d715839a.tar.gz
Moved closing of open handles from pclDeinit function into mainloop.
Deinit function just sends a message to mailoop to close handles.
-rw-r--r--src/persistence_client_library.c32
-rw-r--r--src/persistence_client_library_backup_filelist.c1
-rw-r--r--src/persistence_client_library_dbus_cmd.c10
-rw-r--r--src/persistence_client_library_dbus_cmd.h2
-rw-r--r--src/persistence_client_library_dbus_service.c18
-rw-r--r--test/persistence_client_library_test_file.c199
6 files changed, 163 insertions, 99 deletions
diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c
index 7266376..1739e5c 100644
--- a/src/persistence_client_library.c
+++ b/src/persistence_client_library.c
@@ -363,10 +363,6 @@ static int private_pclDeinitLibrary(void)
MainLoopData_u data;
- memset(&data, 0, sizeof(MainLoopData_u));
- data.cmd = (uint32_t)CMD_QUIT;
- data.string[0] = '\0'; // no string parameter, set to 0
-
if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE) // unregister for lifecycle dbus messages
{
rval = unregister_lifecycle(gShutdownMode);
@@ -384,16 +380,26 @@ static int private_pclDeinitLibrary(void)
}
#endif
- process_prepare_shutdown(Shutdown_Full); // close all db's and fd's and block access
+ memset(&data, 0, sizeof(MainLoopData_u));
+ data.cmd = (uint32_t)CMD_LC_PREPARE_SHUTDOWN;
+ data.params[0] = Shutdown_Full; // shutdown full
+ data.params[1] = 0; // internal prepare shutdown
+ data.string[0] = '\0'; // no string parameter, set to 0
+ deliverToMainloop_NM(&data); // send quit command to dbus mainloop
+
+
+ memset(&data, 0, sizeof(MainLoopData_u));
+ data.cmd = (uint32_t)CMD_QUIT;
+ data.string[0] = '\0'; // no string parameter, set to 0
deliverToMainloop_NM(&data); // send quit command to dbus mainloop
+ pthread_join(gMainLoopThread, (void**)&retval); // wait until the dbus mainloop has ended
+
deleteHandleTrees(); // delete allocated trees
deleteBackupTree();
deleteNotifyTree();
- pthread_join(gMainLoopThread, (void**)&retval); // wait until the dbus mainloop has ended
-
pthread_mutex_unlock(&gDbusPendingRegMtx);
#if USE_FILECACHE
@@ -413,8 +419,17 @@ int pclLifecycleSet(int shutdown)
{
if(shutdown == PCL_SHUTDOWN)
{
+ MainLoopData_u data;
+
DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("lifecycleSet - PCL_SHUTDOWN -"), DLT_STRING(gAppId));
- process_prepare_shutdown(Shutdown_Partial);
+
+ memset(&data, 0, sizeof(MainLoopData_u));
+ data.cmd = (uint32_t)CMD_LC_PREPARE_SHUTDOWN;
+ data.params[0] = Shutdown_Partial; // shutdown partial
+ data.params[1] = 0; // internal prepare shutdown
+ data.string[0] = '\0'; // no string parameter, set to 0
+ deliverToMainloop_NM(&data); // send quit command to dbus mainloop
+
gCancelCounter++;
}
else if(shutdown == PCL_SHUTDOWN_CANCEL)
@@ -436,6 +451,7 @@ int pclLifecycleSet(int shutdown)
}
else
{
+ DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("lifecycleSet - not allowed, type not PCL_SHUTDOWN_TYPE_NONE"));
rval = EPERS_SHUTDOWN_NO_PERMIT;
}
diff --git a/src/persistence_client_library_backup_filelist.c b/src/persistence_client_library_backup_filelist.c
index 5a2b8f0..0896dc5 100644
--- a/src/persistence_client_library_backup_filelist.c
+++ b/src/persistence_client_library_backup_filelist.c
@@ -451,6 +451,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha
if(handle == -1) // if we are in an inconsistent state: delete file, backup and checksum
{
+ DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("verifyConsist - no recovery possible"));
(void)remove(origPath);
(void)remove(backupPath);
(void)remove(csumPath);
diff --git a/src/persistence_client_library_dbus_cmd.c b/src/persistence_client_library_dbus_cmd.c
index 21e2ba7..0f17bd4 100644
--- a/src/persistence_client_library_dbus_cmd.c
+++ b/src/persistence_client_library_dbus_cmd.c
@@ -66,6 +66,9 @@ void process_reg_notification_signal(DBusConnection* conn, unsigned int notifyLd
char ruleDeleted[DbusMatchRuleSize] = {[0 ... DbusMatchRuleSize-1] = 0};
char ruleCreated[DbusMatchRuleSize] = {[0 ... DbusMatchRuleSize-1] = 0};
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("process notification - User:"), DLT_UINT(notifyUserNo), DLT_STRING("- Seat:"), DLT_UINT(notifySeatNo));
+
+
// add match for c h a n g e
snprintf(ruleChanged, DbusMatchRuleSize,
"type='signal',interface='org.genivi.persistence.adminconsumer',member='PersistenceResChange',path='/org/genivi/persistence/adminconsumer',arg0='%s',arg1='%u',arg2='%u',arg3='%u'",
@@ -107,6 +110,7 @@ void process_send_notification_signal(DBusConnection* conn, unsigned int notifyL
dbus_bool_t ret;
DBusMessage* message;
const char* notifyReasonString = NULL;
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("send notification - User:"), DLT_UINT(notifyUserNo), DLT_STRING("- Seat:"), DLT_UINT(notifySeatNo));
char ldbidArray[DbusSubMatchSize] = {[0 ... DbusSubMatchSize-1] = 0};
char userArray[DbusSubMatchSize] = {[0 ... DbusSubMatchSize-1] = 0};
@@ -190,7 +194,7 @@ void process_block_and_write_data_back(unsigned int requestID, unsigned int stat
-void process_prepare_shutdown(int complete)
+void process_prepare_shutdown(unsigned int complete)
{
int i = 0;
@@ -295,6 +299,8 @@ void process_send_pas_register(DBusConnection* conn, int regType, int notificati
char* method = NULL;
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("sendPasReg - Type:"), DLT_INT(regType) );
+
if(regType == 0)
method = "UnRegisterPersAdminNotification";
else if(regType == 1)
@@ -357,6 +363,8 @@ void process_send_lifecycle_register(DBusConnection* conn, int regType, int shut
char* method = NULL;
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("sendLcmReg - Type:"), DLT_INT(regType) );
+
if(regType == 1)
method = "RegisterShutdownClient";
else if(regType == 0)
diff --git a/src/persistence_client_library_dbus_cmd.h b/src/persistence_client_library_dbus_cmd.h
index 9efcf52..50cbcb4 100644
--- a/src/persistence_client_library_dbus_cmd.h
+++ b/src/persistence_client_library_dbus_cmd.h
@@ -28,7 +28,7 @@
*
* @param complete The mode: Shutdown_Partial=0; Shutdown_Full=1
*/
-void process_prepare_shutdown(int complete);
+void process_prepare_shutdown(unsigned int complete);
/**
diff --git a/src/persistence_client_library_dbus_service.c b/src/persistence_client_library_dbus_service.c
index 68fe56e..b19d607 100644
--- a/src/persistence_client_library_dbus_service.c
+++ b/src/persistence_client_library_dbus_service.c
@@ -495,7 +495,7 @@ int dispatchInternalCommand(DBusConnection* conn, MainLoopData_u* readData, int*
{
int rval = 1;
- //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("mainLoop - receive cmd:"), DLT_INT(readData.message.cmd));
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("mainLoop - receive cmd:"), DLT_UINT(readData->cmd));
switch (readData->cmd)
{
case CMD_PAS_BLOCK_AND_WRITE_BACK:
@@ -503,9 +503,21 @@ int dispatchInternalCommand(DBusConnection* conn, MainLoopData_u* readData, int*
process_send_pas_request(conn, (unsigned int)readData->params[1] /*request*/, (int)readData->params[0] /*status*/);
break;
case CMD_LC_PREPARE_SHUTDOWN:
- process_prepare_shutdown(Shutdown_Full);
- process_send_lifecycle_request(conn, (unsigned int)readData->params[1] /*requestID*/, (unsigned int)readData->params[0] /*status*/);
+ {
+
+ if(readData->params[1] == 0) // if params[1] == 0, internal shutdown; no need to send lifecycle notification
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("mainLoop internal shutdown"), DLT_UINT(readData->cmd));
+ process_prepare_shutdown(readData->params[0]);
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("mainLoop external shutdown"), DLT_UINT(readData->cmd));
+ process_prepare_shutdown(Shutdown_Full);
+ process_send_lifecycle_request(conn, (unsigned int)readData->params[1] /*requestID*/, (unsigned int)readData->params[0] /*status*/);
+ }
break;
+ }
case CMD_SEND_NOTIFY_SIGNAL:
process_send_notification_signal(conn, (unsigned int)readData->params[0] /*ldbid*/, (unsigned int)readData->params[1], /*user*/
(unsigned int)readData->params[2] /*seat*/, (unsigned int)readData->params[3], /*reason*/
diff --git a/test/persistence_client_library_test_file.c b/test/persistence_client_library_test_file.c
index 83edbe9..27a3bba 100644
--- a/test/persistence_client_library_test_file.c
+++ b/test/persistence_client_library_test_file.c
@@ -563,16 +563,16 @@ START_TEST(test_DataHandle)
memset(handleArray, -1, 1024);
- for(i=0; i<1024; i++)
+ for(i=0; i<512; i++)
{
memset(fileNameBuf,0,1024);
snprintf(fileNameBuf, 1024, "media/threeAnotherFileTestData.db_%d", i);
//printf("\n\nOpen - %d\n", i);
- handleArray[i] = pclFileOpen(PCL_LDBID_LOCAL, fileNameBuf, 4, 12);
+ handleArray[i] = pclFileOpen(PCL_LDBID_LOCAL, fileNameBuf, 4, 77);
}
// now write data
- for(i=0; i<1024; i++)
+ for(i=0; i<512; i++)
{
if(handleArray[i] >=0 )
{
@@ -586,7 +586,7 @@ START_TEST(test_DataHandle)
}
// now read data
- for(i=0; i<1024; i++)
+ for(i=0; i<512; i++)
{
if(handleArray[i] >=0 )
{
@@ -596,6 +596,7 @@ START_TEST(test_DataHandle)
pclFileSeek(handleArray[i], 0, SEEK_SET);
size = pclFileReadData(handleArray[i], buffer, READ_SIZE);
fail_unless(size != 256);
+ //printf("\n%s - \n%s\n", buffer, writeBuffer);
fail_unless(strncmp((const char*)buffer, (const char*)writeBuffer, 256) == 0);
}
}
@@ -660,9 +661,86 @@ END_TEST
+
+void do_shutdown_sequence(int shutdownReg, unsigned int numOfFiles)
+{
+ char writeBuffer[1024] = {0};
+ char fileNameBuf[1024] = {0};
+ int* handleArray;
+ int size = 0, i =0;
+ size_t arraySize = (numOfFiles*sizeof(int));
+
+ handleArray = (int*)malloc(arraySize);
+ memset(handleArray, -1, arraySize);
+
+
+ DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("# pclInitLibrary ->"));
+ pclInitLibrary(gTheAppId, shutdownReg);
+ DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("# pclInitLibrary <-"));
+
+ for(i=0; i<numOfFiles; i++)
+ {
+ memset(fileNameBuf,0,1024);
+ snprintf(fileNameBuf, 1024, "media/threeAnotherFileTestData.db_%d", i);
+ handleArray[i] = pclFileOpen(PCL_LDBID_LOCAL, fileNameBuf, 4, 12);
+ }
+
+
+ for(i=0; i<numOfFiles; i++)
+ {
+ if(handleArray[i] >=0 )
+ {
+ memset(writeBuffer,0,1024);
+ snprintf(writeBuffer, 1024, "START_TEST(test_DataHandle)_media/some_test_data_to_show_read and write is working_%d_%s", i, gWriteBuffer);
+
+ pclFileSeek(handleArray[i], 0, SEEK_SET);
+ size = pclFileWriteData(handleArray[i], writeBuffer, (int)strlen(writeBuffer));
+ fail_unless(size == (int)strlen(writeBuffer), "Wrong size written - %d", i);
+
+ size = pclFileWriteData(handleArray[i], writeBuffer, (int)strlen(writeBuffer));
+ fail_unless(size == (int)strlen(writeBuffer), "Wrong size written - %d", i);
+
+ size = pclFileWriteData(handleArray[i], writeBuffer, (int)strlen(writeBuffer));
+ fail_unless(size == (int)strlen(writeBuffer), "Wrong size written - %d", i);
+ }
+ }
+
+ DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("# pclLifecycleSet ->"));
+ (void)pclLifecycleSet(PCL_SHUTDOWN);
+ DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("# pclLifecycleSet <-"));
+
+ if(shutdownReg != PCL_SHUTDOWN_TYPE_NONE)
+ {
+ // make the NSM to send shutdown notification to registered clients
+ const char* theDbusCommand =
+ "dbus-send --system --print-reply \
+ --dest=org.genivi.NodeStateManager \
+ /org/genivi/NodeStateManager/LifecycleControl \
+ \"org.genivi.NodeStateManager.LifecycleControl.SetNodeState\" \
+ int32:6";
+
+ // notify the NSM to shutdown the system
+ DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("# dbus-send: make NSM send shutdown notification"));
+ if(system(theDbusCommand) == -1)
+ {
+ printf("Failed to execute command -> NSM!!\n");
+ }
+ }
+
+ DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("# pclDeinitLibrary ->"));
+ pclDeinitLibrary();
+ DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("# pclDeinitLibrary <-"));
+
+ free(handleArray);
+}
+
+
+
START_TEST(test_InitDeinit)
{
- int i = 0, rval = -1, handle = 0;
+
+ int i = 0;
+ int handle = 0, rval = -1;
int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
for(i=0; i<5; i++)
@@ -721,6 +799,15 @@ START_TEST(test_InitDeinit)
rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL);
pclDeinitLibrary();
+
+
+ DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("# do_shutdown_sequence - PCL_SHUTDOWN_TYPE_NONE ->"));
+ do_shutdown_sequence(PCL_SHUTDOWN_TYPE_NONE, 100);
+ DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("# do_shutdown_sequence <-"));
+
+ DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("# do_shutdown_sequence - PCL_SHUTDOWN_TYPE_NORMAL ->"));
+ do_shutdown_sequence(PCL_SHUTDOWN_TYPE_NORMAL, 400);
+ DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("# do_shutdown_sequence <-"));
}
END_TEST
@@ -1069,13 +1156,16 @@ static Suite * persistencyClientLib_suite()
suite_add_tcase(s, tc_FileTest);
tcase_add_checked_fixture(tc_FileTest, data_setup_browser, data_teardown);
- suite_add_tcase(s, tc_InitDeinit);
-
suite_add_tcase(s, tc_DataHandle);
tcase_add_checked_fixture(tc_DataHandle, data_setup, data_teardown);
+
+
+ suite_add_tcase(s, tc_InitDeinit); // I M P O R T A N T: this needs to be the last test, as this tests ends NSM
+
#else
+
//suite_add_tcase(s, tc_MultiFileReadWrite);
//tcase_add_checked_fixture(tc_MultiFileReadWrite, data_setup, data_teardown);
@@ -1500,76 +1590,6 @@ void doMultithreadedReadWrite()
}
-#define NUM_OF_FILES 20
-
-
-void fdTest()
-{
- int i = 0;
- int handle[2000] = {0};
- char fileBuffer[1024] = {0};
- memset(handle, -1, sizeof(handle));
-
-
-
- printf("\nOpen and close every second file right away\n");
- for(i=0; i < NUM_OF_FILES; i++)
- {
- memset(fileBuffer,0,1024);
- snprintf(fileBuffer, 1024, "/tmp/fd_testFiles/file_%d.txt", i);
- handle[i] = open(fileBuffer, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
- printf("1 o -> fd[%d]: %d\n", i, handle[i]);
-
- if(i%2)
- {
- close(handle[i]);
- handle[i] = -1;
- }
- }
-
- printf("\nClose remaining open files\n");
- for(i=0; i < NUM_OF_FILES; i++)
- {
- if(handle[i] > 0)
- {
- printf("1 c -> fd[%d]: %d\n", i, handle[i]);
- close(handle[i]);
- handle[i] = -1;
- }
- }
-
- printf("\nOpen files \n");
- for(i=0; i < NUM_OF_FILES; i++)
- {
- memset(fileBuffer,0,1024);
- snprintf(fileBuffer, 1024, "/tmp/fd_testFiles/file_%d.txt", i);
- handle[i] = open(fileBuffer, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
- printf("2 o -> fd[%d]: %d\n", i, handle[i]);
- }
-
-
- printf("\nClose open files\n");
- for(i=0; i < NUM_OF_FILES; i++)
- {
- if(handle[i] > 0)
- {
- printf("2 c -> fd[%d]: %d\n", i, handle[i]);
- close(handle[i]);
- handle[i] = -1;
- }
- }
-
-}
-
-
-
-
-
-
-
-
-
-
int doPrintf(int fd)
{
return printf(" value: %d\n", fd);
@@ -1835,27 +1855,34 @@ int main(int argc, char *argv[])
if(argc == 1)
{
+ printf("R U N T E S T S\n");
Suite * s = persistencyClientLib_suite();
SRunner * sr = srunner_create(s);
- srunner_set_fork_status(sr, CK_NOFORK);
-
srunner_set_xml(sr, "/tmp/persistenceClientLibraryTestFile.xml");
srunner_set_log(sr, "/tmp/persistenceClientLibraryTestFile.log");
+ srunner_set_fork_status(sr, CK_NOFORK);
srunner_run_all(sr, CK_VERBOSE /*CK_NORMAL CK_VERBOSE CK_SUBUNIT*/);
- nr_failed = srunner_ntests_failed(sr);
- srunner_ntests_run(sr);
+ //nr_failed = srunner_ntests_failed(sr);
+ //srunner_ntests_run(sr);
srunner_free(sr);
}
else
{
- doMultithreadedReadWrite();
-
- //fdTest();
-
- //doListTest();
+ switch(atoi(argv[1]))
+ {
+ case 0:
+ doMultithreadedReadWrite();
+ break;
+ case 1:
+ doListTest();
+ break;
+ default:
+ printf("invalid parameter\n");
+ break;
+ }
}
DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("End of PCL test"));