summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorIngo Huerner <ingo_huerner@mentor.com>2017-05-23 13:30:57 +0200
committerIngo Huerner <ingo_huerner@mentor.com>2017-05-23 13:30:57 +0200
commit1704723d0b5f43257dd556684229ffe4b996830c (patch)
tree50dabe32d956ce316fde141b222039aab280228e /test
parent6ce5be34c8bbbf2ed10081950493970ebaffa87c (diff)
downloadpersistence-client-library-1704723d0b5f43257dd556684229ffe4b996830c.tar.gz
Check return value when registering to PAS, pclInitLibrary returns now an error code if PAS register fails
Diffstat (limited to 'test')
-rw-r--r--test/data/PAS_data.tar.gzbin6843 -> 46914 bytes
-rw-r--r--test/persistence_client_library_test.c75
-rw-r--r--test/persistence_client_library_test_file.c83
3 files changed, 135 insertions, 23 deletions
diff --git a/test/data/PAS_data.tar.gz b/test/data/PAS_data.tar.gz
index 16a291b..e89be47 100644
--- a/test/data/PAS_data.tar.gz
+++ b/test/data/PAS_data.tar.gz
Binary files differ
diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c
index d9d1c03..116bc5a 100644
--- a/test/persistence_client_library_test.c
+++ b/test/persistence_client_library_test.c
@@ -1561,6 +1561,75 @@ START_TEST(test_NoPluginFunc)
END_TEST
+
+void* pasInstallThread(void* userData)
+{
+ // install data
+ printf("#### Start installation of data \n");
+ if(system("persadmin_tool install /usr/local/var/PAS_data.tar.gz") == -1)
+ {
+ printf("#### Failed to install data\n");
+ }
+ printf("#### Installation of data succeeded\n");
+
+ pthread_exit(0);
+}
+
+
+
+START_TEST(test_PclInitPasNotAllowed)
+{
+ pthread_t installThread;
+ int rval = -1;
+ int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
+ char* envVariable = "PERS_CLIENT_LIB_CUSTOM_LOAD";
+
+ setenv(envVariable, "/etc/pclCustomLibConfigFileTest.cfg", 1);
+
+ if(pthread_create(&installThread, NULL, pasInstallThread, NULL) == -1)
+ {
+ printf("#### Failed to create install thread\n");
+ }
+ else
+ {
+ rval = pclInitLibrary(gTheAppId, shutdownReg);
+ //printf("#### 1 pclInit: %d\n\n", rval);
+ fail_unless(rval == 1, "Should be allowed to register");
+ pclDeinitLibrary();
+
+ rval = pclInitLibrary(gTheAppId, shutdownReg);
+ printf("#### 2 pclInit: %d\n", rval);
+ //fail_unless(rval == EPERS_NO_REG_TO_PAS, "Should be not allowed to register");
+ pclDeinitLibrary();
+
+ rval = pclInitLibrary(gTheAppId, shutdownReg);
+ printf("#### 3 pclInit: %d\n", rval);
+ //fail_unless(rval == EPERS_NO_REG_TO_PAS, "Should be not allowed to register");
+ pclDeinitLibrary();
+
+ rval = pclInitLibrary(gTheAppId, shutdownReg);
+ printf("#### 4 pclInit: %d\n", rval);
+ //fail_unless(rval == EPERS_NO_REG_TO_PAS, "Should be not allowed to register");
+ pclDeinitLibrary();
+ }
+
+ //printf("#### wait for install thread to end\n");
+ if(pthread_join(installThread, NULL) != 0) // wait until thread has ended
+ printf("#### pthread_join - FAILED\n");
+
+
+ // printf("#### Install thread ended\n");
+ rval = pclInitLibrary(gTheAppId, shutdownReg);
+ //printf("#### 5 pclInit: %d\n\n", rval);
+ fail_unless(rval == 1, "Should be allowed to register");
+ pclDeinitLibrary();
+
+ (void)unsetenv(envVariable);
+}
+END_TEST
+
+
+
static Suite* persistenceClientLib_suite_multi()
{
const char* testSuiteName = "\n\nPersistence Client Library (Key-API) - Multi";
@@ -1695,6 +1764,9 @@ static Suite * persistenceClientLib_suite()
tcase_add_test(tc_SharedData, test_SharedData);
tcase_set_timeout(tc_SharedData, 10);
+ TCase * tc_PclInitPasNotAllowed = tcase_create("PclInitPasNotAllowed");
+ tcase_add_test(tc_PclInitPasNotAllowed, test_PclInitPasNotAllowed);
+ tcase_set_timeout(tc_PclInitPasNotAllowed, 20);
#if 1
suite_add_tcase(s, tc_NoPluginFunc);
@@ -1755,6 +1827,9 @@ static Suite * persistenceClientLib_suite()
suite_add_tcase(s, tc_SharedData);
tcase_add_checked_fixture(tc_SharedData, data_setup, data_teardown);
+
+
+ suite_add_tcase(s, tc_PclInitPasNotAllowed); // NOTE: make sure this test is run as the last test
#endif
#if USE_APPCHECK
diff --git a/test/persistence_client_library_test_file.c b/test/persistence_client_library_test_file.c
index 1f841a8..e57be0e 100644
--- a/test/persistence_client_library_test_file.c
+++ b/test/persistence_client_library_test_file.c
@@ -109,7 +109,6 @@ const char* gFileCsumNOKCsum = "/Data/mnt-backup/lt-persistence_client_library_
/// debug log and trace (DLT) setup
DLT_DECLARE_CONTEXT(gPcltDLTContext);
-
// function prototype
void run_concurrency_test();
int check_environment();
@@ -144,37 +143,60 @@ void setupRecoveryData(const char* originalFileName, const char* origData,
ssize_t written = 0;
// write data file
- fd = open(originalFileName, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
- written = write(fd, origData, strlen(origData));
- if(written != strlen(origData))
- printf("Failed to write file - %s\n", originalFileName);
- close(fd);
- fd = -1;
+ fd = open(originalFileName, O_CREAT|O_RDWR|O_TRUNC, 0744);
+ if(fd != -1)
+ {
+ written = write(fd, origData, strlen(origData));
+ if(written != strlen(origData))
+ printf("Failed to write file 1 - %s - %s\n", originalFileName, strerror(errno));
+ close(fd);
+ fd = -1;
+ }
+ else
+ {
+ printf("Failed to open file 1 - %s - %s\n", originalFileName, strerror(errno));
+ }
if(backupFileName != NULL)
{
// write backup file
- fd = open(backupFileName, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
- written = write(fd, backupData, strlen(backupData));
- if(written != strlen(backupData))
- printf("Failed to write file - %s\n", backupFileName);
- close(fd);
- fd = -1;
+ fd = open(backupFileName, O_CREAT|O_RDWR|O_TRUNC, 0744);
+ if(fd != -1)
+ {
+ written = write(fd, backupData, strlen(backupData));
+ if(written != strlen(backupData))
+ printf("Failed to write file 2 - %s - %s\n", backupFileName, strerror(errno));
+ close(fd);
+ fd = -1;
+ }
+ else
+ {
+ printf("Failed to open file 2 - %s - %s\n", originalFileName, strerror(errno));
+ }
}
+
if(csumFileName != NULL)
{
// write checksum file
- fd = open(csumFileName, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
- written = write(fd, csumBuffer, strlen(csumBuffer));
- if(written != strlen(csumBuffer))
- printf("Failed to write file - %s\n", csumFileName);
- close(fd);
- fd = -1;
+ fd = open(csumFileName, O_CREAT|O_RDWR|O_TRUNC, 0744);
+ if(fd != -1)
+ {
+ written = write(fd, csumBuffer, strlen(csumBuffer));
+ if(written != strlen(csumBuffer))
+ printf("Failed to write file 3 - %s - %s\n", csumFileName, strerror(errno));
+ close(fd);
+ fd = -1;
+ }
+ else
+ {
+ printf("Failed to open file 3 - %s - %s\n", originalFileName, strerror(errno));
+ }
}
}
+extern int pclCreateFile(const char* path, int chached);
void data_setupBandR(void)
{
@@ -184,6 +206,8 @@ void data_setupBandR(void)
const char* validCs2 = "2f7fb691"; // checksum for gWriteBuffer2
const char* validCs3 = "e6f52bda"; // checksum for gWriteBuffer3
+ (void)pclCreateFile("/Data/mnt-backup/lt-persistence_client_library_test/user/200/seat/100/media/dummy.dum", 0);
+
// create test data (original files only)
//
@@ -1241,7 +1265,7 @@ START_TEST(test_FileBackupAndRecovery)
(void)pclInitLibrary(gTheAppId, shutdownReg);
-#if 1
+
//
// test backup and checksum creation
//
@@ -1355,9 +1379,7 @@ START_TEST(test_FileBackupAndRecovery)
fail_unless(access(gFile2Backup, F_OK) != 0, "Backup 3 does exist, but should not\n");
fail_unless(access(gFile2Csum, F_OK) != 0, "Csum 3 does exist, but should not\n");
-#endif
-#if 1
//
// now the error cases
//
@@ -1415,7 +1437,7 @@ START_TEST(test_FileBackupAndRecovery)
sizeRead = pclFileReadData(fd, readBuffer, 8192);
fail_unless(sizeRead <= EPERS_COMMON, "Read succeeded, but should not => return: %dn", sizeRead);
pclFileClose(fd);
-#endif
+
// only backup file available, matches original data
// expected: keep original
@@ -1500,6 +1522,8 @@ static Suite * persistencyClientLib_suite()
tcase_add_test(tc_FileBackupAndRecovery, test_FileBackupAndRecovery);
tcase_set_timeout(tc_FileBackupAndRecovery, 30);
+#if 1
+
suite_add_tcase(s, tc_persDataFile);
tcase_add_checked_fixture(tc_persDataFile, data_setup, data_teardown);
@@ -1533,6 +1557,16 @@ static Suite * persistencyClientLib_suite()
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
+
+ printf("Do backup recovery test case now\n");
+ suite_add_tcase(s, tc_FileBackupAndRecovery);
+ tcase_add_checked_fixture(tc_FileBackupAndRecovery, data_setupBandR, data_teardownBandR);
+
+#endif
+
+
+
//suite_add_tcase(s, tc_MultiFileReadWrite);
//tcase_add_checked_fixture(tc_MultiFileReadWrite, data_setup, data_teardown);
@@ -2279,6 +2313,9 @@ int main(int argc, char *argv[])
}
+
+
+
const char* gWriteBuffer = "Pack my box with five dozen liquor jugs. - "
"Jackdaws love my big sphinx of quartz. - "
"The five boxing wizards jump quickly. - "