diff options
27 files changed, 2623 insertions, 2207 deletions
diff --git a/configure.ac b/configure.ac index 85dbbcb..14d058b 100644 --- a/configure.ac +++ b/configure.ac @@ -30,7 +30,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) # Overwrite the build in defaults -CFLAGS="-Wall -Os -Wextra -fPIC -ffunction-sections" +CFLAGS="-Wall -O -Werror -fstack-protector -pthread -Wformat -Wformat-security -fexceptions -fstrict-aliasing -fno-omit-frame-pointer -Wconversion -D_FORTIFY_SOURCE=2" # Checks for programs. AC_PROG_CC @@ -89,7 +89,7 @@ AC_ARG_WITH([localcheck], if test "x$enable_tests" != "xno" ; then if test -z "$localcheck" ; then - PKG_CHECK_MODULES(CHECK, check) + PKG_CHECK_MODULES([CHECK], [check >= 0.9.6]) else CHECK_CFLAGS="-I$localcheck/include" CHECK_LIBS="-L$localcheck/lib -lcheck" diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c index 53aaacc..e0c7d9b 100644 --- a/src/persistence_client_library.c +++ b/src/persistence_client_library.c @@ -37,10 +37,11 @@ #include <dlfcn.h> #include <dbus/dbus.h> #include <pthread.h> +#include <dlt.h> /// debug log and trace (DLT) setup -DLT_DECLARE_CONTEXT(gPclDLTContext) +DLT_DECLARE_CONTEXT(gPclDLTContext); /// global variable to store lifecycle shutdown mode @@ -84,12 +85,12 @@ static void doInitAppcheck(const char* appName) if(access(rctFilename, F_OK) == 0) { gAppCheckFlag = 1; // "trusted" application - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("initLibrary - app check: "), DLT_STRING(appName), DLT_STRING("trusted app")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("initLibrary - app check: "), DLT_STRING(appName), DLT_STRING("trusted app")); } else { gAppCheckFlag = 0; // currently not a "trusted" application - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("initLibrary - app check: "), DLT_STRING(appName), DLT_STRING("NOT trusted app")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("initLibrary - app check: "), DLT_STRING(appName), DLT_STRING("NOT trusted app")); } } #endif @@ -126,16 +127,17 @@ int pclInitLibrary(const char* appName, int shutdownMode) pthread_mutex_lock(&gInitMutex); if(gPclInitCounter == 0) { - DLT_REGISTER_CONTEXT(gPclDLTContext,"PCL","Context for persistence client library logging"); - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclInitLibrary => INIT PCL - "), DLT_STRING(appName), - DLT_STRING("- init counter: "), DLT_INT(gPclInitCounter) ); + DLT_REGISTER_CONTEXT(gPclDLTContext,"PCL","Ctx for PCL Logging"); + + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => App:"), DLT_STRING(appName), + DLT_STRING("- init counter: "), DLT_UINT(gPclInitCounter) ); rval = private_pclInitLibrary(appName, shutdownMode); } else { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclInitLibrary - INIT PCL - "), DLT_STRING(gAppId), - DLT_STRING("- ONLY INCREMENT init counter: "), DLT_INT(gPclInitCounter) ); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary - App:"), DLT_STRING(gAppId), + DLT_STRING("- ONLY INCREMENT init counter: "), DLT_UINT(gPclInitCounter) ); } gPclInitCounter++; // increment after private init, otherwise atomic access is too early @@ -157,7 +159,7 @@ static int private_pclInitLibrary(const char* appName, int shutdownMode) #if USE_FILECACHE - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("Using the filecache!!!")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Using the filecache!!!")); pfcInitCache(appName); #endif @@ -168,7 +170,7 @@ static int private_pclInitLibrary(const char* appName, int shutdownMode) if(readBlacklistConfigFile(blacklistPath) == -1) { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("initLibrary - Err access blacklist:"), DLT_STRING(blacklistPath)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("initLibrary - Err access blacklist:"), DLT_STRING(blacklistPath)); } if(setup_dbus_mainloop() == -1) @@ -188,7 +190,7 @@ static int private_pclInitLibrary(const char* appName, int shutdownMode) } } #if USE_PASINTERFACE - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("PAS interface is enabled!!")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PAS interface is enabled!!")); if(register_pers_admin_service() == -1) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("initLibrary - Failed reg to PAS dbus interface")); @@ -197,10 +199,10 @@ static int private_pclInitLibrary(const char* appName, int shutdownMode) } else { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("initLibrary - Successfully established IPC protocol for PCL.")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("initLibrary - Successfully established IPC protocol for PCL.")); } #else - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("PAS interface not enabled, enable with \"./configure --enable-pasinterface\"")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PAS interface not enabled, enable with \"./configure --enable-pasinterface\"")); #endif if(load_custom_plugins(customAsyncInitClbk) < 0) // load custom plugins @@ -228,8 +230,8 @@ int pclDeinitLibrary(void) if(gPclInitCounter == 1) { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclDeinitLibrary - DEINIT client lib - "), DLT_STRING(gAppId), - DLT_STRING("- init counter: "), DLT_INT(gPclInitCounter)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary - DEINIT client lib - "), DLT_STRING(gAppId), + DLT_STRING("- init counter: "), DLT_UINT(gPclInitCounter)); rval = private_pclDeinitLibrary(); gPclInitCounter--; // decrement init counter @@ -237,8 +239,8 @@ int pclDeinitLibrary(void) } else if(gPclInitCounter > 1) { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclDeinitLibrary - DEINIT client lib - "), DLT_STRING(gAppId), - DLT_STRING("- ONLY DECREMENT init counter: "), DLT_INT(gPclInitCounter)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary - DEINIT client lib - "), DLT_STRING(gAppId), + DLT_STRING("- ONLY DECREMENT init counter: "), DLT_UINT(gPclInitCounter)); gPclInitCounter--; // decrement init counter } else @@ -275,7 +277,7 @@ static int private_pclDeinitLibrary(void) } else { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclDeinitLibrary - Succ de-initialized IPC protocol for PCL.")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary - Succ de-initialized IPC protocol for PCL.")); } #endif @@ -308,13 +310,13 @@ int pclLifecycleSet(int shutdown) { if(shutdown == PCL_SHUTDOWN) { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("lifecycleSet - PCL_SHUTDOWN -"), DLT_STRING(gAppId)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("lifecycleSet - PCL_SHUTDOWN -"), DLT_STRING(gAppId)); process_prepare_shutdown(Shutdown_Partial); gCancelCounter++; } else if(shutdown == PCL_SHUTDOWN_CANCEL) { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("lifecycleSet - PCL_SHUTDOWN_CANCEL -"), DLT_STRING(gAppId), DLT_STRING(" Cancel Counter - "), DLT_INT(gCancelCounter)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("lifecycleSet - PCL_SHUTDOWN_CANCEL -"), DLT_STRING(gAppId), DLT_STRING(" Cancel Counter - "), DLT_INT(gCancelCounter)); if(gCancelCounter < Shutdown_MaxCount) { pers_unlock_access(); diff --git a/src/persistence_client_library_backup_filelist.c b/src/persistence_client_library_backup_filelist.c index d5b6447..5a2b8f0 100644 --- a/src/persistence_client_library_backup_filelist.c +++ b/src/persistence_client_library_backup_filelist.c @@ -31,7 +31,9 @@ #include <errno.h> #include <stdlib.h> #include <sys/sendfile.h> +#include <dlt.h> +DLT_IMPORT_CONTEXT(gPclDLTContext); static char* gpTokenArray[TOKENARRAYSIZE] = {0}; @@ -143,7 +145,7 @@ int readBlacklistConfigFile(const char* filename) return EPERS_COMMON; } - configFileMap = (char*)mmap(0, buffer.st_size, PROT_WRITE, MAP_PRIVATE, fd, 0); // map the configuration file into memory + configFileMap = (char*)mmap(0, (size_t)buffer.st_size, PROT_WRITE, MAP_PRIVATE, fd, 0); // map the configuration file into memory if(configFileMap == MAP_FAILED) { @@ -153,11 +155,11 @@ int readBlacklistConfigFile(const char* filename) return EPERS_COMMON; } - fillFileBackupCharTokenArray(buffer.st_size, configFileMap); + fillFileBackupCharTokenArray((unsigned int)buffer.st_size, configFileMap); createAndStoreFileNames(); // create filenames and store them in the tree - (void)munmap(configFileMap, buffer.st_size); + (void)munmap(configFileMap, (size_t)buffer.st_size); close(fd); } @@ -169,7 +171,7 @@ int readBlacklistConfigFile(const char* filename) } else { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("blacklist - failed to stat() conf file:"), DLT_STRING(filename)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("blacklist - failed to stat() conf file:"), DLT_STRING(filename)); return EPERS_COMMON; } } @@ -221,7 +223,7 @@ static int pclBackupDoFileCopy(int srcFd, int dstFd) if(fstat(srcFd, &buf) != -1) { - rval = (int)sendfile(dstFd, srcFd, 0, buf.st_size); + rval = (int)sendfile(dstFd, srcFd, 0, (size_t)buf.st_size); // Reset file position pointer of destination file 'dstFd' lseek(dstFd, 0, SEEK_SET); } @@ -316,7 +318,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha // ************************************************* if((backupAvail == 0) && (csumAvail == 0) ) { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("verifyConsist- there is a backup file AND csum")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("verifyConsist- there is a backup file AND csum")); fdBackup = open(backupPath, O_RDONLY); // calculate checksum form backup file if(fdBackup != -1) @@ -326,7 +328,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha fdCsum = open(csumPath, O_RDONLY); if(fdCsum != -1) { - readSize = read(fdCsum, csumBuf, ChecksumBufSize); + readSize = (int)read(fdCsum, csumBuf, (size_t)ChecksumBufSize); if(readSize > 0) { if(strcmp(csumBuf, backCsumBuf) == 0) @@ -372,12 +374,12 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha // ************************************************* else if(csumAvail == 0) { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("verifyConsist - there is ONLY a csum file")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("verifyConsist - there is ONLY a csum file")); fdCsum = open(csumPath, O_RDONLY); if(fdCsum != -1) { - readSize = read(fdCsum, csumBuf, ChecksumBufSize); + readSize = (int)read(fdCsum, csumBuf, (size_t)ChecksumBufSize); if(readSize <= 0) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("verifyConsist - read csum: invalid readSize")); @@ -413,7 +415,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha // ************************************************* else if(backupAvail == 0) { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("verifyConsist - there is ONLY a backup file")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("verifyConsist - there is ONLY a backup file")); fdBackup = open(backupPath, O_RDONLY); // calculate checksum form backup file if(fdBackup != -1) @@ -495,7 +497,7 @@ int pclCreateBackup(const char* dstPath, int srcfd, const char* csumPath, const csfd = open(csumPath, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); if(csfd != -1) { - int csumSize = strlen(csumBuf); + size_t csumSize = strlen(csumBuf); if(write(csfd, csumBuf, csumSize) != csumSize) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("cBackup - failed write csum to file")); @@ -550,7 +552,7 @@ int pclCalcCrc32Csum(int fd, char crc32sum[]) if(fstat(fd, &statBuf) != -1) { - buf = malloc(statBuf.st_size); + buf = malloc((size_t)statBuf.st_size); if(buf != 0) { @@ -559,10 +561,10 @@ int pclCalcCrc32Csum(int fd, char crc32sum[]) if(curPos != 0) lseek(fd, 0, SEEK_SET); // set to beginning of the file - while((rval = read(fd, buf, statBuf.st_size)) > 0) + while((rval = (int)read(fd, buf, (size_t)statBuf.st_size)) > 0) { unsigned int crc = 0; - crc = pclCrc32(crc, (unsigned char*)buf, statBuf.st_size); + crc = pclCrc32(crc, (unsigned char*)buf, (size_t)statBuf.st_size); (void)snprintf(crc32sum, ChecksumBufSize-1, "%x", crc); } diff --git a/src/persistence_client_library_backup_filelist.h b/src/persistence_client_library_backup_filelist.h index cf7f2ee..fdb8bae 100644 --- a/src/persistence_client_library_backup_filelist.h +++ b/src/persistence_client_library_backup_filelist.h @@ -93,7 +93,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha * @return 1 if a backup will shall be created, * 0 if a backup shall be not created or -1 for an error */ -inline int pclBackupNeeded(const char* path); +int pclBackupNeeded(const char* path); /** diff --git a/src/persistence_client_library_custom_loader.c b/src/persistence_client_library_custom_loader.c index 9890a91..be07b40 100644 --- a/src/persistence_client_library_custom_loader.c +++ b/src/persistence_client_library_custom_loader.c @@ -23,7 +23,9 @@ #include <stdlib.h> #include <sys/stat.h> #include <dlfcn.h> +#include <dlt.h> +DLT_IMPORT_CONTEXT(gPclDLTContext); /// type definition of persistence custom library information typedef struct sPersCustomLibInfo @@ -252,7 +254,7 @@ int get_custom_libraries() int i = 0; int fd = open(filename, O_RDONLY); - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("load custom library config file ==> "), DLT_STRING(filename)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("load custom library config file ==> "), DLT_STRING(filename)); if (fd == -1) { @@ -262,7 +264,7 @@ int get_custom_libraries() } // map the config file into memory - customConfFileMap = (char*)mmap(0, buffer.st_size, PROT_WRITE, MAP_PRIVATE, fd, 0); + customConfFileMap = (char*)mmap(0, (size_t)buffer.st_size, PROT_WRITE, MAP_PRIVATE, fd, 0); if (customConfFileMap == MAP_FAILED) { @@ -271,7 +273,7 @@ int get_custom_libraries() return EPERS_COMMON; } - fillCustomCharTokenArray(buffer.st_size, customConfFileMap); + fillCustomCharTokenArray((unsigned int)buffer.st_size, customConfFileMap); while( i < (TOKENARRAYSIZE-3) ) { @@ -553,7 +555,7 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s { if( (gPersCustomFuncs[customLib].custom_plugin_init) != NULL) { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("load_custom_library => (sync) : "), DLT_STRING(get_custom_client_lib_name(customLib))); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("load_custom_library => (sync) : "), DLT_STRING(get_custom_client_lib_name(customLib))); gPersCustomFuncs[customLib].custom_plugin_init(); } else @@ -567,7 +569,7 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s { if( (gPersCustomFuncs[customLib].custom_plugin_init_async) != NULL) { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("load_custom_library => (async) : "), + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("load_custom_library => (async) : "), DLT_STRING(get_custom_client_lib_name(customLib))); gPersCustomFuncs[customLib].custom_plugin_init_async(gPlugin_callback_async_t); diff --git a/src/persistence_client_library_data_organization.c b/src/persistence_client_library_data_organization.c index 4a58a87..ef77d2f 100644 --- a/src/persistence_client_library_data_organization.c +++ b/src/persistence_client_library_data_organization.c @@ -27,9 +27,6 @@ char gAppId[PERS_RCT_MAX_LENGTH_RESPONSIBLE] = { [0 ... PERS_RCT_MAX_LENGTH_RESP /// flag to indicate if client library has been initialized unsigned int gPclInitCounter = 0; -/// the DLT context -DltContext gPclDLTContext; - int(* gChangeNotifyCallback)(pclNotification_s * notifyStruct); /// character lookup table used for parsing configuration files diff --git a/src/persistence_client_library_data_organization.h b/src/persistence_client_library_data_organization.h index cd87b6f..acb2c35 100644 --- a/src/persistence_client_library_data_organization.h +++ b/src/persistence_client_library_data_organization.h @@ -33,7 +33,6 @@ extern "C" { #include <persComDbAccess.h> #include <persComDataOrg.h> -#include <dlt.h> #include <string.h> @@ -51,7 +50,7 @@ typedef struct _PersistenceDbContext_s /// lofical database id unsigned int ldbid; /// user number - int user_no; + unsigned int user_no; /// seat number unsigned int seat_no; } PersistenceDbContext_s; @@ -273,8 +272,6 @@ const char* getLocalCacheFilePath(void); /// application id extern char gAppId[PERS_RCT_MAX_LENGTH_RESPONSIBLE] __attribute__ ((visibility ("hidden"))); -/// the DLT context -extern DltContext gPclDLTContext __attribute__ ((visibility ("hidden"))); /// flag to indicate if client library has been initialized extern unsigned int gPclInitCounter __attribute__ ((visibility ("hidden"))); diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c index e6980e9..6c40d3f 100644 --- a/src/persistence_client_library_db_access.c +++ b/src/persistence_client_library_db_access.c @@ -27,7 +27,9 @@ #include <persComErrors.h> #include <errno.h> +#include <dlt.h> +DLT_IMPORT_CONTEXT(gPclDLTContext); @@ -51,14 +53,15 @@ void deleteNotifyTree(void) static int database_get(PersistenceInfo_s* info, const char* dbPath, int dbType) { - int arrayIdx = 0, handleDB = -1; + unsigned int arrayIdx = 0; + int handleDB = -1; // create array index: index is a combination of resource configuration table type and group arrayIdx = info->configKey.storage + info->context.ldbid ; if(arrayIdx < DbTableSize) { - int openFlags = 0x01; // by default create file if not existing + unsigned char openFlags = 0x01; // by default create file if not existing if(gHandlesDBCreated[arrayIdx][dbType] == 0) { @@ -131,7 +134,7 @@ int pers_get_defaults(char* dbPath, char* key, PersistenceInfo_s* info, unsigned { if (PersGetDefault_Data == job) { - read_size = plugin_persComDbReadKey(handleDefaultDB, key, (char*)buffer, buffer_size); + read_size = plugin_persComDbReadKey(handleDefaultDB, key, (char*)buffer, (signed int)buffer_size); } else if (PersGetDefault_Size == job) { @@ -160,7 +163,7 @@ int pers_get_defaults(char* dbPath, char* key, PersistenceInfo_s* info, unsigned { snprintf(dltMessage, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s", dbPath, plugin_gLocalFactoryDefault); } - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("getDefaults - default data will be used for Key"), DLT_STRING(key), + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("getDefaults - default data will be used for Key"), DLT_STRING(key), DLT_STRING("from"), DLT_STRING(dltMessage)); break; } @@ -169,7 +172,7 @@ int pers_get_defaults(char* dbPath, char* key, PersistenceInfo_s* info, unsigned if (read_size < 0) { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("getDefaults - default data not available for Key"), DLT_STRING(key), + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("getDefaults - default data not available for Key"), DLT_STRING(key), DLT_STRING("Path:"), DLT_STRING(dbPath)); } @@ -204,7 +207,7 @@ void database_close_all() -int persistence_get_data(char* dbPath, char* key, const char* resourceID, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size) +int persistence_get_data(char* dbPath, char* key, const char* resourceID, PersistenceInfo_s* info, unsigned char* buffer, int buffer_size) { int read_size = -1, ret_defaults = -1; @@ -217,7 +220,7 @@ int persistence_get_data(char* dbPath, char* key, const char* resourceID, Persis read_size = plugin_persComDbReadKey(handleDB, key, (char*)buffer, buffer_size); if(read_size < 0) { - read_size = pers_get_defaults(dbPath, (char*)resourceID, info, buffer, buffer_size, PersGetDefault_Data); /* 0 ==> Get data */ + read_size = pers_get_defaults(dbPath, (char*)resourceID, info, buffer, (unsigned int)buffer_size, PersGetDefault_Data); /* 0 ==> Get data */ } } } @@ -253,7 +256,7 @@ int persistence_get_data(char* dbPath, char* key, const char* resourceID, Persis } else { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("getData - Plugin not avail, unknown loading type: "), + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("getData - Plugin not avail, unknown loading type: "), DLT_INT(getCustomLoadingType(idx))); read_size = EPERS_COMMON; } @@ -293,8 +296,8 @@ int persistence_get_data(char* dbPath, char* key, const char* resourceID, Persis (void)get_db_path_and_key(info, key, NULL, dbPath); - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("getData - Plugin data not available - get default data of key:"), DLT_STRING(key)); - ret_defaults = pers_get_defaults(dbPath, (char*)resourceID, info, buffer, buffer_size, PersGetDefault_Data); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("getData - Plugin data not available - get default data of key:"), DLT_STRING(key)); + ret_defaults = pers_get_defaults(dbPath, (char*)resourceID, info, buffer, (unsigned int)buffer_size, PersGetDefault_Data); if (0 < ret_defaults) { read_size = ret_defaults; @@ -306,7 +309,7 @@ int persistence_get_data(char* dbPath, char* key, const char* resourceID, Persis -int persistence_set_data(char* dbPath, char* key, const char* resource_id, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size) +int persistence_set_data(char* dbPath, char* key, const char* resource_id, PersistenceInfo_s* info, unsigned char* buffer, int buffer_size) { int write_size = -1; @@ -380,7 +383,7 @@ int persistence_set_data(char* dbPath, char* key, const char* resource_id, Persi } else { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("setData - Plugin not avail, unknown loading type: "), + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("setData - Plugin not avail, unknown loading type: "), DLT_INT(getCustomLoadingType(idx))); write_size = EPERS_COMMON; } @@ -475,7 +478,7 @@ int persistence_get_data_size(char* dbPath, char* key, const char* resourceID, P } else { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("getDataSize - Plugin not avail, unknown loading type: "), + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("getDataSize - Plugin not avail, unknown loading type: "), DLT_INT(getCustomLoadingType(idx))); read_size = EPERS_COMMON; } @@ -513,7 +516,7 @@ int persistence_get_data_size(char* dbPath, char* key, const char* resourceID, P info->configKey.policy = PersistencePolicy_wc; /* Set the policy */ info->configKey.type = PersistenceResourceType_key; /* Set the type */ (void)get_db_path_and_key(info, key, NULL, dbPath); - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("getDataSize - Plugin data not avail, get size of default data for key:"), + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("getDataSize - Plugin data not avail, get size of default data for key:"), DLT_STRING(key)); ret_defaults = pers_get_defaults(dbPath, (char*)resourceID, info, NULL, 0, PersGetDefault_Size); if (0 < ret_defaults) @@ -589,7 +592,7 @@ int persistence_delete_data(char* dbPath, char* key, const char* resource_id, Pe } else { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("deleteData - Plugin not available, unknown loading type: "), + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("deleteData - Plugin not available, unknown loading type: "), DLT_INT(getCustomLoadingType(idx))); ret = EPERS_COMMON; } diff --git a/src/persistence_client_library_db_access.h b/src/persistence_client_library_db_access.h index 75f6c68..5385dc3 100644 --- a/src/persistence_client_library_db_access.h +++ b/src/persistence_client_library_db_access.h @@ -102,7 +102,7 @@ int pers_get_defaults(char* dbPath, char* key, PersistenceInfo_s* info, unsigned * @return the number of bytes written or a negative value if an error occured with the following error codes: * EPERS_SETDTAFAILED EPERS_NOPRCTABLE EPERS_NOKEYDATA EPERS_NOKEY */ -int persistence_set_data(char* dbPath, char* key, const char* resource_id, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size); +int persistence_set_data(char* dbPath, char* key, const char* resource_id, PersistenceInfo_s* info, unsigned char* buffer, int buffer_size); @@ -119,7 +119,7 @@ int persistence_set_data(char* dbPath, char* key, const char* resource_id, Persi * @return the number of bytes read or a negative value if an error occured with the following error codes: * EPERS_NOPRCTABLE EPERS_NOKEYDATA EPERS_NOKEY */ -int persistence_get_data(char* dbPath, char* key, const char* resourceID, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size); +int persistence_get_data(char* dbPath, char* key, const char* resourceID, PersistenceInfo_s* info, unsigned char* buffer, int buffer_size); diff --git a/src/persistence_client_library_dbus_cmd.c b/src/persistence_client_library_dbus_cmd.c index d72d23c..1096896 100644 --- a/src/persistence_client_library_dbus_cmd.c +++ b/src/persistence_client_library_dbus_cmd.c @@ -39,6 +39,9 @@ #include <errno.h> #include <dlfcn.h> +#include <dlt.h> + +DLT_IMPORT_CONTEXT(gPclDLTContext); /// change signal string static const char* gChangeSignal = "PersistenceResChange"; @@ -190,7 +193,7 @@ void process_prepare_shutdown(int complete) { int i = 0, rval = 0; - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("prepShtdwn - writing all changed data / closing all handles")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("prepShtdwn - writing all changed data / closing all handles")); // block write pers_lock_access(); @@ -466,7 +469,7 @@ void msg_pending_func(DBusPendingCall *call, void *data) } else { - //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("msg_pending_func ==> UNlock mutex") ); + //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("msg_pending_func ==> UNlock mutex") ); dbus_message_get_args(message, &err, DBUS_TYPE_INT32, &replyArg, DBUS_TYPE_INVALID); } diff --git a/src/persistence_client_library_dbus_service.c b/src/persistence_client_library_dbus_service.c index 2e431a2..b9bcfdf 100644 --- a/src/persistence_client_library_dbus_service.c +++ b/src/persistence_client_library_dbus_service.c @@ -24,6 +24,9 @@ #include <errno.h> #include <stdlib.h> +#include <dlt.h> + +DLT_IMPORT_CONTEXT(gPclDLTContext); pthread_mutex_t gDbusPendingRegMtx = PTHREAD_MUTEX_INITIALIZER; @@ -79,7 +82,7 @@ typedef struct SObjectEntry /// polling structure typedef struct SPollInfo { - int nfds; /// number of polls + nfds_t nfds; /// number of polls struct pollfd fds[10]; /// poll file descriptors array tObjectEntry objects[10]; /// poll object } tPollInfo; @@ -96,7 +99,7 @@ static void unregisterMessageHandler(DBusConnection *connection, void *user_data { (void)connection; (void)user_data; - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("unregisterObjectPath\n")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("unregisterObjectPath\n")); } @@ -159,9 +162,9 @@ static DBusHandlerResult handleObjectPathMessageFallback(DBusConnection * connec } else { - notifyStruct.ldbid = atoi(ldbid); - notifyStruct.user_no = atoi(user_no); - notifyStruct.seat_no = atoi(seat_no); + notifyStruct.ldbid = (unsigned int)atoi(ldbid); + notifyStruct.user_no = (unsigned int)atoi(user_no); + notifyStruct.seat_no = (unsigned int)atoi(seat_no); if(gChangeNotifyCallback != NULL ) // call the registered callback function { @@ -186,7 +189,7 @@ static void unregisterObjectPathFallback(DBusConnection *connection, void *user { (void)connection; (void)user_data; - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("unregObjPathFback")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("unregObjPathFback")); } @@ -198,7 +201,7 @@ static dbus_bool_t addWatch(DBusWatch *watch, void *data) if (ARRAY_SIZE(gPollInfo.fds) > (unsigned int)(gPollInfo.nfds)) { - int flags = dbus_watch_get_flags(watch); + unsigned int flags = dbus_watch_get_flags(watch); tObjectEntry * const pEntry = &gPollInfo.objects[gPollInfo.nfds]; pEntry->objtype = OT_WATCH; @@ -233,7 +236,7 @@ static void removeWatch(DBusWatch *watch, void *data) (void)data; - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("removeWatch called "), DLT_INT( (long)watch) ); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("removeWatch called "), DLT_INT64( (long)watch) ); if(w_data) free(w_data); @@ -246,7 +249,7 @@ static void removeWatch(DBusWatch *watch, void *data) static void watchToggled(DBusWatch *watch, void *data) { (void)data; - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("watchToggled called "), DLT_INT( (long)watch) ); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("watchToggled called "), DLT_INT64( (long)watch) ); if(dbus_watch_get_enabled(watch)) addWatch(watch, data); @@ -302,8 +305,8 @@ static dbus_bool_t addTimeout(DBusTimeout *timeout, void *data) static void removeTimeout(DBusTimeout *timeout, void *data) { - int i = gPollInfo.nfds; - (void)data; + int i = (int)gPollInfo.nfds; + (void)data; while ((0<i--)&&(timeout!=gPollInfo.objects[i].timeout)); @@ -332,11 +335,11 @@ static void removeTimeout(DBusTimeout *timeout, void *data) // callback for libdbus' when timeout changed static void timeoutToggled(DBusTimeout *timeout, void *data) { - int i = gPollInfo.nfds; + int i = (int)gPollInfo.nfds; (void)data; while ((0<i--)&&(timeout!=gPollInfo.objects[i].timeout)); - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("timeoutToggled") ); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("timeoutToggled") ); if (0<i) { const int interval = (TRUE==dbus_timeout_get_enabled(timeout))?dbus_timeout_get_interval(timeout):0; @@ -368,7 +371,7 @@ int setup_dbus_mainloop(void) if(pAddress != NULL) // Connect to the bus and check for errors { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("setupMainLoop - specific dbus address:"), DLT_STRING(pAddress) ); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("setupMainLoop - specific dbus address:"), DLT_STRING(pAddress) ); conn = dbus_connection_open_private(pAddress, &err); @@ -390,7 +393,7 @@ int setup_dbus_mainloop(void) } else { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("setupMainLoop - Use def bus (DBUS_BUS_SYSTEM)")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("setupMainLoop - Use def bus (DBUS_BUS_SYSTEM)")); conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err); if(conn == NULL) @@ -492,39 +495,39 @@ int dispatchInternalCommand(DBusConnection* conn, MainLoopData_u* readData, int* { int rval = 1; - //DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("mainLoop - receive cmd:"), DLT_INT(readData.message.cmd)); + //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("mainLoop - receive cmd:"), DLT_INT(readData.message.cmd)); switch (readData->message.cmd) { case CMD_PAS_BLOCK_AND_WRITE_BACK: - process_block_and_write_data_back(readData->message.params[1] /*requestID*/, readData->message.params[0] /*status*/); - process_send_pas_request(conn, readData->message.params[1] /*request*/, readData->message.params[0] /*status*/); + process_block_and_write_data_back((unsigned int)readData->message.params[1] /*requestID*/, (unsigned int)readData->message.params[0] /*status*/); + process_send_pas_request(conn, (unsigned int)readData->message.params[1] /*request*/, (int)readData->message.params[0] /*status*/); break; case CMD_LC_PREPARE_SHUTDOWN: process_prepare_shutdown(Shutdown_Full); - process_send_lifecycle_request(conn, readData->message.params[1] /*requestID*/, readData->message.params[0] /*status*/); + process_send_lifecycle_request(conn, (unsigned int)readData->message.params[1] /*requestID*/, (unsigned int)readData->message.params[0] /*status*/); break; case CMD_SEND_NOTIFY_SIGNAL: - process_send_notification_signal(conn, readData->message.params[0] /*ldbid*/, readData->message.params[1], /*user*/ - readData->message.params[2] /*seat*/, readData->message.params[3], /*reason*/ + process_send_notification_signal(conn, (unsigned int)readData->message.params[0] /*ldbid*/, (unsigned int)readData->message.params[1], /*user*/ + (unsigned int)readData->message.params[2] /*seat*/, (unsigned int)readData->message.params[3], /*reason*/ readData->message.string); break; case CMD_REG_NOTIFY_SIGNAL: - process_reg_notification_signal(conn, readData->message.params[0] /*ldbid*/, readData->message.params[1], /*user*/ - readData->message.params[2] /*seat*/, readData->message.params[3], /*,policy*/ + process_reg_notification_signal(conn, (unsigned int)readData->message.params[0] /*ldbid*/, (unsigned int)readData->message.params[1], /*user*/ + (unsigned int)readData->message.params[2] /*seat*/, (unsigned int)readData->message.params[3], /*,policy*/ readData->message.string); break; case CMD_SEND_PAS_REGISTER: - process_send_pas_register(conn, readData->message.params[0] /*regType*/, readData->message.params[1] /*notifyFlag*/); + process_send_pas_register(conn, (int)readData->message.params[0] /*regType*/, (int)readData->message.params[1] /*notifyFlag*/); break; case CMD_SEND_LC_REGISTER: - process_send_lifecycle_register(conn, readData->message.params[0] /*regType*/, readData->message.params[1] /*mode*/); + process_send_lifecycle_register(conn, (int)readData->message.params[0] /*regType*/, (int)readData->message.params[1] /*mode*/); break; case CMD_QUIT: rval = 0; *quit = TRUE; break; default: - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop - cmd not handled"), DLT_INT(readData->message.cmd) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop - cmd not handled"), DLT_UINT32(readData->message.cmd) ); break; } @@ -583,7 +586,7 @@ void* mainLoop(void* userData) { MainLoopData_u readData; bContinue = TRUE; - while ((-1==(ret = read(gPollInfo.fds[i].fd, readData.payload, sizeof(struct message_))))&&(EINTR == errno)); + while ((-1==(ret = (int)read((int)(gPollInfo.fds[i].fd), readData.payload, (size_t)sizeof(struct message_))))&&(EINTR == errno)); if(ret < 0) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop - read() failed"), DLT_STRING(strerror(errno)) ); @@ -602,7 +605,7 @@ void* mainLoop(void* userData) } else { - int flags = 0; + unsigned int flags = 0; if (0!=(gPollInfo.fds[i].revents & POLLIN)) { @@ -620,7 +623,7 @@ void* mainLoop(void* userData) { flags |= DBUS_WATCH_HANGUP; } - bContinue = dbus_watch_handle(gPollInfo.objects[i].watch, flags); + bContinue = (int)dbus_watch_handle(gPollInfo.objects[i].watch, flags); } } } diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c index 92bbe84..4291d87 100644 --- a/src/persistence_client_library_file.c +++ b/src/persistence_client_library_file.c @@ -35,6 +35,10 @@ #include <sys/mman.h> #include <sys/stat.h> #include <sys/sendfile.h> +#include <dlt.h> + +DLT_IMPORT_CONTEXT(gPclDLTContext); + // path for the backup location static const char* gBackupPrefix = PERS_ORG_ROOT_PATH "/mnt-backup/"; @@ -47,6 +51,8 @@ static const int gCPathPrefixSize = sizeof(CACHEPREFIX)-1; // size of write through string static const int gWTPathPrefixSize = sizeof(WTPREFIX)-1; +static pthread_mutex_t gFileAccessMtx = PTHREAD_MUTEX_INITIALIZER; + // local function prototype static int pclFileGetDefaultData(int handle, const char* resource_id, int policy); static int pclFileOpenDefaultData(PersistenceInfo_s* dbContext, const char* resource_id); @@ -85,71 +91,79 @@ int pclFileClose(int fd) { int rval = EPERS_NOT_INITIALIZED; - //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclFileClose fd: "), DLT_INT(fd)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileClose - fd:"), DLT_INT(fd)); if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { -#if USE_APPCHECK - if(doAppcheck() == 1) + if(pthread_mutex_lock(&gFileAccessMtx) == 0) { +#if USE_APPCHECK + if(doAppcheck() == 1) + { #endif - int permission = get_file_permission(fd); + int permission = get_file_permission(fd); - if(permission != -1) // permission is here also used for range check - { - // check if a backup and checksum file needs to be deleted - if(permission != PersistencePermission_ReadOnly || permission != PersistencePermission_LastEntry) + if(permission != -1) // permission is here also used for range check { - // remove backup file - if(remove(get_file_backup_path(fd)) == -1) + // check if a backup and checksum file needs to be deleted + if(permission != PersistencePermission_ReadOnly || permission != PersistencePermission_LastEntry) { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileClose - backup remove failed!"), DLT_STRING(strerror(errno))); + // remove backup file + if(remove(get_file_backup_path(fd)) == -1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileClose - backup remove failed!"), DLT_STRING(strerror(errno))); + } + + // remove checksum file + if(remove(get_file_checksum_path(fd)) == -1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileClose - csum remove failed!"), DLT_STRING(strerror(errno)) ); + } + } + __sync_fetch_and_sub(&gOpenFdArray[fd], FileClosed); // set closed flag - // remove checksum file - if(remove(get_file_checksum_path(fd)) == -1) + // remove form file tree; + if(remove_file_handle_data(fd) != 1) { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileClose - csum remove failed!"), DLT_STRING(strerror(errno)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileClose - Failed to remove from tree!"), DLT_INT(fd) ); } - } - __sync_fetch_and_sub(&gOpenFdArray[fd], FileClosed); // set closed flag - - // remove form file tree; - if(remove_file_handle_data(fd) != 1) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileClose - Failed to remove from tree!"), DLT_INT(fd) ); - } - #if USE_FILECACHE - if(get_file_cache_status(fd) == 1) - { - rval = pfcCloseFile(fd); + if(get_file_cache_status(fd) == 1) + { + rval = pfcCloseFile(fd); + } + else + { + fsync(fd); + rval = close(fd); + } + #else + fsync(fd); + rval = close(fd); + #endif } else { - fsync(fd); - rval = close(fd); + rval = EPERS_MAXHANDLE; } - #else - fsync(fd); - rval = close(fd); - #endif - +#if USE_APPCHECK } else { - rval = EPERS_MAXHANDLE; + rval = EPERS_SHUTDOWN_NO_TRUSTED; } -#if USE_APPCHECK - } - else - { - rval = EPERS_SHUTDOWN_NO_TRUSTED; - } #endif + pthread_mutex_unlock(&gFileAccessMtx); + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileClose - not initialized")); } + return rval; } @@ -161,30 +175,38 @@ int pclFileGetSize(int fd) if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { - struct stat buf; + if(pthread_mutex_lock(&gFileAccessMtx) == 0) + { + struct stat buf; #if USE_FILECACHE - if(get_file_cache_status(fd) == 1) - { - size = pfcFileGetSize(fd); - } - else - { - size = fstat(fd, &buf); + if(get_file_cache_status(fd) == 1) + { + size = pfcFileGetSize(fd); + } + else + { + size = fstat(fd, &buf); - if(size != -1) - { - size = buf.st_size; - } - } + if(size != -1) + { + size = buf.st_size; + } + } #else - size = fstat(fd, &buf); + size = fstat(fd, &buf); - if(size != -1) - { - size = buf.st_size; - } + if(size != -1) + { + size = (int)buf.st_size; + } #endif + pthread_mutex_unlock(&gFileAccessMtx); + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileGetSize - not initialized")); } return size; } @@ -202,19 +224,27 @@ void* pclFileMapData(void* addr, long size, long offset, int fd) (void)fd; DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("fileMapData not supported when using file cache")); #else - //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclFileMapData fd: "), DLT_INT(fd)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileMapData fd: "), DLT_INT(fd)); if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + if(pthread_mutex_lock(&gFileAccessMtx) == 0) { - ptr = mmap(addr,size, PROT_WRITE | PROT_READ, MAP_SHARED, fd, offset); - } - else - { - ptr = EPERS_MAP_LOCKFS; + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + { + ptr = mmap(addr, (size_t)size, PROT_WRITE | PROT_READ, MAP_SHARED, fd, (off_t)offset); + } + else + { + ptr = EPERS_MAP_LOCKFS; + } + pthread_mutex_unlock(&gFileAccessMtx); } } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileMapData - not initialized")); + } #endif return ptr; @@ -230,6 +260,8 @@ int pclFileOpenRegular(PersistenceInfo_s* dbContext, const char* resource_id, ch char backupPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // backup file char csumPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // checksum file + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileOpenRegular - res:"), DLT_STRING(resource_id)); + if(dbContext->configKey.policy == PersistencePolicy_wc) { length = gCPathPrefixSize; @@ -265,9 +297,9 @@ int pclFileOpenRegular(PersistenceInfo_s* dbContext, const char* resource_id, ch else { if(dbContext->configKey.permission == PersistencePermission_ReadOnly) - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("fileOpen: NoBackup - file RONLY!"), DLT_STRING(dbKey)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("fileOpen: NoBackup - file RONLY!"), DLT_STRING(dbKey)); else - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("fileOpen: NoBackup - file in blacklist!"), DLT_STRING(dbKey)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("fileOpen: NoBackup - file in blacklist!"), DLT_STRING(dbKey)); } #if USE_FILECACHE @@ -378,6 +410,8 @@ int pclFileOpenDefaultData(PersistenceInfo_s* dbContext, const char* resource_id { int flags = pclGetPosixPermission(dbContext->configKey.permission); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileOpenDefaultData - res:"), DLT_STRING(resource_id)); + // check if there is default data available char pathPrefix[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = { [0 ... PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = 0}; char defaultPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = { [0 ... PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = 0}; @@ -403,44 +437,53 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n { int handle = EPERS_NOT_INITIALIZED; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileOpen - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res:"), DLT_STRING(resource_id)); + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { - PersistenceInfo_s dbContext; + if(pthread_mutex_lock(&gFileAccessMtx) == 0) + { + PersistenceInfo_s dbContext; - int shared_DB = 0; - char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key - char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location + int shared_DB = 0; + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location - //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclFileOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); + //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); - dbContext.context.ldbid = ldbid; - dbContext.context.seat_no = seat_no; - dbContext.context.user_no = user_no; + dbContext.context.ldbid = ldbid; + dbContext.context.seat_no = seat_no; + dbContext.context.user_no = user_no; - // get database context: database path and database key - shared_DB = get_db_context(&dbContext, resource_id, ResIsFile, dbKey, dbPath); + // get database context: database path and database key + shared_DB = get_db_context(&dbContext, resource_id, ResIsFile, dbKey, dbPath); - // check if the resource is marked as a file resource - if(dbContext.configKey.type == PersistenceResourceType_file) - { - if(user_no == (unsigned int)PCL_USER_DEFAULTDATA) + // check if the resource is marked as a file resource + if(dbContext.configKey.type == PersistenceResourceType_file) { - handle = pclFileOpenDefaultData(&dbContext, resource_id); - set_file_user_id(handle, PCL_USER_DEFAULTDATA); - // as default data will be opened, use read/write permission and we don't need backup and csum path so use an empty string. - set_file_handle_data(handle, PersistencePermission_ReadWrite, "", "", NULL); + if(user_no == (unsigned int)PCL_USER_DEFAULTDATA) + { + handle = pclFileOpenDefaultData(&dbContext, resource_id); + set_file_user_id(handle, (int)PCL_USER_DEFAULTDATA); + // as default data will be opened, use read/write permission and we don't need backup and csum path so use an empty string. + set_file_handle_data(handle, PersistencePermission_ReadWrite, "", "", NULL); + } + else + { + handle = pclFileOpenRegular(&dbContext, resource_id, dbKey, dbPath, shared_DB, user_no, seat_no); + } } else { - handle = pclFileOpenRegular(&dbContext, resource_id, dbKey, dbPath, shared_DB, user_no, seat_no); + handle = EPERS_RESOURCE_NO_FILE; // resource is not marked as file in RCT } - } - else - { - handle = EPERS_RESOURCE_NO_FILE; // resource is not marked as file in RCT + pthread_mutex_unlock(&gFileAccessMtx); } } // initialized - + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileOpen - not initialized")); + } return handle; } @@ -450,21 +493,31 @@ int pclFileReadData(int fd, void * buffer, int buffer_size) { int readSize = EPERS_NOT_INITIALIZED; - //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclFileReadData fd: "), DLT_INT(fd)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileReadData - fd:"), DLT_INT(fd)); + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { + if(pthread_mutex_lock(&gFileAccessMtx) == 0) + { + #if USE_FILECACHE - if(get_file_cache_status(fd) == 1 && get_file_user_id(fd) != (int)PCL_USER_DEFAULTDATA) - { - readSize = pfcReadFile(fd, buffer, buffer_size); - } - else - { - readSize = read(fd, buffer, buffer_size); - } + if(get_file_cache_status(fd) == 1 && get_file_user_id(fd) != (int)PCL_USER_DEFAULTDATA) + { + readSize = pfcReadFile(fd, buffer, buffer_size); + } + else + { + readSize = read(fd, buffer, buffer_size); + } #else - readSize = read(fd, buffer, buffer_size); + readSize = (int)read(fd, buffer, (size_t)buffer_size); #endif + pthread_mutex_unlock(&gFileAccessMtx); + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileReadData - not initialized")); } return readSize; } @@ -475,44 +528,52 @@ int pclFileRemove(unsigned int ldbid, const char* resource_id, unsigned int user { int rval = EPERS_NOT_INITIALIZED; - //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclFileReadData "), DLT_INT(ldbid), DLT_STRING(resource_id)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileRemove - ldbid"), DLT_UINT(ldbid), DLT_STRING(" res:"), DLT_STRING(resource_id)); if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + if(pthread_mutex_lock(&gFileAccessMtx) == 0) { - int shared_DB = 0; - PersistenceInfo_s dbContext; + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + { + int shared_DB = 0; + PersistenceInfo_s dbContext; - char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key - char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location - dbContext.context.ldbid = ldbid; - dbContext.context.seat_no = seat_no; - dbContext.context.user_no = user_no; + dbContext.context.ldbid = ldbid; + dbContext.context.seat_no = seat_no; + dbContext.context.user_no = user_no; - // get database context: database path and database key - shared_DB = get_db_context(&dbContext, resource_id, ResIsFile, dbKey, dbPath); + // get database context: database path and database key + shared_DB = get_db_context(&dbContext, resource_id, ResIsFile, dbKey, dbPath); - if( (shared_DB >= 0) // check valid database context - && (dbContext.configKey.type == PersistenceResourceType_file) ) // check if type matches - { - rval = remove(dbPath); - if(rval == -1) + if( (shared_DB >= 0) // check valid database context + && (dbContext.configKey.type == PersistenceResourceType_file) ) // check if type matches + { + rval = remove(dbPath); + if(rval == -1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("fileRemove - remove()"), DLT_STRING(resource_id), DLT_STRING(strerror(errno)) ); + } + } + else { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("fileRemove - remove()"), DLT_STRING(resource_id), DLT_STRING(strerror(errno)) ); + rval = shared_DB; + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("fileRemove - no valid db context or res not a file")); } } else { - rval = shared_DB; - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("fileRemove - no valid db context or res not a file")); + rval = EPERS_LOCKFS; } + pthread_mutex_unlock(&gFileAccessMtx); } - else - { - rval = EPERS_LOCKFS; - } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileRemove - not initialized")); } return rval; } @@ -523,30 +584,39 @@ int pclFileSeek(int fd, long int offset, int whence) { int rval = EPERS_NOT_INITIALIZED; - //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclFileSeek fd:"), DLT_INT(fd)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileSeek - fd"), DLT_INT(fd)); if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + if(pthread_mutex_lock(&gFileAccessMtx) == 0) { + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + { #if USE_FILECACHE - if(get_file_cache_status(fd) == 1) - { - rval = pfcFileSeek(fd, offset, whence); - } - else - { - rval = lseek(fd, offset, whence); - } + if(get_file_cache_status(fd) == 1) + { + rval = pfcFileSeek(fd, offset, whence); + } + else + { + rval = lseek(fd, offset, whence); + } #else - rval = lseek(fd, offset, whence); + rval = (int)lseek(fd, offset, whence); #endif + } + else + { + rval = EPERS_LOCKFS; + } + pthread_mutex_unlock(&gFileAccessMtx); } - else - { - rval = EPERS_LOCKFS; - } } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileSeek - not initialized")); + } + return rval; } @@ -556,19 +626,28 @@ int pclFileUnmapData(void* address, long size) { int rval = EPERS_NOT_INITIALIZED; - //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclFileUnmapData")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileUnmapData")); if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked - { - rval = munmap(address, size); - } - else + if(pthread_mutex_lock(&gFileAccessMtx) == 0) { - rval = EPERS_LOCKFS; + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + { + rval = munmap(address, (size_t)size); + } + else + { + rval = EPERS_LOCKFS; + } + pthread_mutex_unlock(&gFileAccessMtx); } } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileUnmapData - not initialized")); + } + return rval; } @@ -578,66 +657,74 @@ int pclFileWriteData(int fd, const void * buffer, int buffer_size) { int size = EPERS_NOT_INITIALIZED; - //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclFileWriteData fd:"), DLT_INT(fd)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileWriteData fd:"), DLT_INT(fd)); if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + if(pthread_mutex_lock(&gFileAccessMtx) == 0) { - int permission = get_file_permission(fd); - if(permission != -1) + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked { - if(permission != PersistencePermission_ReadOnly ) + int permission = get_file_permission(fd); + if(permission != -1) { - // check if a backup file has to be created - if( (get_file_backup_status(fd) == 0) && get_file_user_id(fd) != (int)PCL_USER_DEFAULTDATA) + if(permission != PersistencePermission_ReadOnly ) { - char csumBuf[ChecksumBufSize] = {0}; + // check if a backup file has to be created + if( (get_file_backup_status(fd) == 0) && get_file_user_id(fd) != (int)PCL_USER_DEFAULTDATA) + { + char csumBuf[ChecksumBufSize] = {0}; - pclCalcCrc32Csum(fd, csumBuf); // calculate checksum + pclCalcCrc32Csum(fd, csumBuf); // calculate checksum - pclCreateBackup(get_file_backup_path(fd), fd, get_file_checksum_path(fd), csumBuf); // create checksum and backup file + pclCreateBackup(get_file_backup_path(fd), fd, get_file_checksum_path(fd), csumBuf); // create checksum and backup file - set_file_backup_status(fd, 1); - } + set_file_backup_status(fd, 1); + } #if USE_FILECACHE - if(get_file_cache_status(fd) == 1 && get_file_user_id(fd) != (int)PCL_USER_DEFAULTDATA) - { - size = pfcWriteFile(fd, buffer, buffer_size); - } - else - { - size = write(fd, buffer, buffer_size); + if(get_file_cache_status(fd) == 1 && get_file_user_id(fd) != (int)PCL_USER_DEFAULTDATA) + { + size = pfcWriteFile(fd, buffer, buffer_size); + } + else + { + size = write(fd, buffer, buffer_size); - if(fsync(fd) == -1) - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("fileWriteData: Failed fsync ==>!"), DLT_STRING(strerror(errno))); - } + if(fsync(fd) == -1) + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("fileWriteData: Failed fsync ==>!"), DLT_STRING(strerror(errno))); + } #else - size = write(fd, buffer, buffer_size); - if(get_file_cache_status(fd) == 1) + size = (int)write(fd, buffer, (size_t)buffer_size); + if(get_file_cache_status(fd) == 1) + { + if(fsync(fd) == -1) + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("fileWriteData - Failed fsync ==>!"), DLT_STRING(strerror(errno))); + } +#endif + } + else { - if(fsync(fd) == -1) - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("fileWriteData - Failed fsync ==>!"), DLT_STRING(strerror(errno))); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("fileWriteData - Failed write ==> read only file!"), DLT_STRING(get_file_backup_path(fd))); + size = EPERS_RESOURCE_READ_ONLY; } -#endif } else { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("fileWriteData - Failed write ==> read only file!"), DLT_STRING(get_file_backup_path(fd))); - size = EPERS_RESOURCE_READ_ONLY; + size = EPERS_MAXHANDLE; } } - else - { - size = EPERS_MAXHANDLE; - } - } - else - { - size = EPERS_LOCKFS; + else + { + size = EPERS_LOCKFS; + } + pthread_mutex_unlock(&gFileAccessMtx); } } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileWriteData - not initialized")); + } return size; } @@ -647,143 +734,154 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int { int handle = EPERS_NOT_INITIALIZED; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileCreatePath - ldbid"), DLT_UINT(ldbid), DLT_STRING(" res:"), DLT_STRING(resource_id)); + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { - int shared_DB = 0; - PersistenceInfo_s dbContext; + if(pthread_mutex_lock(&gFileAccessMtx) == 0) + { + int shared_DB = 0; + PersistenceInfo_s dbContext; - char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key - char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location - char backupPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // backup file - char csumPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // checksum file + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location + char backupPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // backup file + char csumPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // checksum file - //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclFileOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); + //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); - dbContext.context.ldbid = ldbid; - dbContext.context.seat_no = seat_no; - dbContext.context.user_no = user_no; + dbContext.context.ldbid = ldbid; + dbContext.context.seat_no = seat_no; + dbContext.context.user_no = user_no; - // get database context: database path and database key - shared_DB = get_db_context(&dbContext, resource_id, ResIsFile, dbKey, dbPath); + // get database context: database path and database key + shared_DB = get_db_context(&dbContext, resource_id, ResIsFile, dbKey, dbPath); - if( dbContext.configKey.type == PersistenceResourceType_file) // check if type matches - { - if(shared_DB >= 0) // check valid database context + if( dbContext.configKey.type == PersistenceResourceType_file) // check if type matches { - int flags = pclGetPosixPermission(dbContext.configKey.permission); - - // file will be opened writable, so check about data consistency - if( dbContext.configKey.permission != PersistencePermission_ReadOnly - && pclBackupNeeded(get_raw_string(dbPath)) == CREATE_BACKUP) + if(shared_DB >= 0) // check valid database context { - snprintf(backupPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME-1, "%s%s", dbPath, gBackupPostfix); - snprintf(csumPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME-1, "%s%s", dbPath, gBackupCsPostfix); + int flags = pclGetPosixPermission(dbContext.configKey.permission); - if((handle = pclVerifyConsistency(dbPath, backupPath, csumPath, flags)) == -1) + // file will be opened writable, so check about data consistency + if( dbContext.configKey.permission != PersistencePermission_ReadOnly + && pclBackupNeeded(get_raw_string(dbPath)) == CREATE_BACKUP) { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("fileCreatePath - file inconsistent, recovery NOT possible!")); - return -1; + snprintf(backupPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME-1, "%s%s", dbPath, gBackupPostfix); + snprintf(csumPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME-1, "%s%s", dbPath, gBackupCsPostfix); + + if((handle = pclVerifyConsistency(dbPath, backupPath, csumPath, flags)) == -1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("fileCreatePath - file inconsistent, recovery NOT possible!")); + return -1; + } + // we don't need the file handle here + // the application calling this function must use the POSIX open() function to get an file descriptor + if(handle > 0) + close(handle); + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("fileCreatePath - No Backup, read only OR in blacklist!"), DLT_STRING(dbKey)); } - // we don't need the file handle here - // the application calling this function must use the POSIX open() function to get an file descriptor - if(handle > 0) - close(handle); - } - else - { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("fileCreatePath - No Backup, read only OR in blacklist!"), DLT_STRING(dbKey)); - } - handle = get_persistence_handle_idx(); + handle = get_persistence_handle_idx(); - if(handle != -1) - { - if(handle < MaxPersHandle) + if(handle != -1) { - *size = strlen(dbPath); - *path = malloc((*size)+1); // allocate 1 byte for the string termination - - if(NULL != (*path)) // Check if malloc was successful + if(handle < MaxPersHandle) { - memcpy(*path, dbPath, (*size)); - (*path)[(*size)] = '\0'; // terminate string + *size = (unsigned int)strlen(dbPath); + *path = malloc((*size)+1); // allocate 1 byte for the string termination - if(access(*path, F_OK) == -1) + if(NULL != (*path)) // Check if malloc was successful { - int handle = 0, cacheStatus = -1; - if(strstr(dbPath, WTPREFIX) != NULL) - { - cacheStatus = 0; - } - else - { - cacheStatus = 1; - } - - handle = pclCreateFile(*path, cacheStatus); // file does not exist, create it. - set_file_cache_status(handle, cacheStatus); - - if(handle == -1) - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("fileCreatePath - Err create file: "), DLT_STRING(*path)); - } - else - { - if(pclFileGetDefaultData(handle, resource_id, dbContext.configKey.policy) == -1) // try to get default data - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("fileCreatePath - no def data avail: "), DLT_STRING(resource_id)); - } - close(handle); // don't need the open file - } + memcpy(*path, dbPath, (*size)); + (*path)[(*size)] = '\0'; // terminate string + + if(access(*path, F_OK) == -1) + { + int handle = 0, cacheStatus = -1; + if(strstr(dbPath, WTPREFIX) != NULL) + { + cacheStatus = 0; + } + else + { + cacheStatus = 1; + } + + handle = pclCreateFile(*path, cacheStatus); // file does not exist, create it. + set_file_cache_status(handle, cacheStatus); + + if(handle == -1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("fileCreatePath - Err create file: "), DLT_STRING(*path)); + } + else + { + if(pclFileGetDefaultData(handle, resource_id, dbContext.configKey.policy) == -1) // try to get default data + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("fileCreatePath - no def data avail: "), DLT_STRING(resource_id)); + } + close(handle); // don't need the open file + } + } + __sync_fetch_and_add(&gOpenHandleArray[handle], FileOpen); // set open flag + + set_ossfile_handle_data(handle, dbContext.configKey.permission, 0/*backupCreated*/, backupPath, csumPath, *path); + } + else + { + handle = EPERS_DESER_ALLOCMEM; + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("fileCreatePath: malloc() failed for path:"), + DLT_STRING(dbPath), DLT_STRING("With size:"), DLT_UINT(*size)); } - __sync_fetch_and_add(&gOpenHandleArray[handle], FileOpen); // set open flag - - set_ossfile_handle_data(handle, dbContext.configKey.permission, 0/*backupCreated*/, backupPath, csumPath, *path); } - else + else { - handle = EPERS_DESER_ALLOCMEM; - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("fileCreatePath: malloc() failed for path:"), - DLT_STRING(dbPath), DLT_STRING("With size:"), DLT_UINT(*size)); + set_persistence_handle_close_idx(handle); + handle = EPERS_MAXHANDLE; } } - else - { - set_persistence_handle_close_idx(handle); - handle = EPERS_MAXHANDLE; - } } - } - else // requested resource is not in the RCT, so create resource as local/cached. - { - // assemble file string for local cached location - snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalCacheFilePath(), gAppId, user_no, seat_no, resource_id); - handle = get_persistence_handle_idx(); - - if(handle != -1) + else // requested resource is not in the RCT, so create resource as local/cached. { - if(handle < MaxPersHandle) + // assemble file string for local cached location + snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalCacheFilePath(), gAppId, user_no, seat_no, resource_id); + handle = get_persistence_handle_idx(); + + if(handle != -1) { - snprintf(backupPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s", dbPath, gBackupPostfix); - snprintf(csumPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s", dbPath, gBackupCsPostfix); + if(handle < MaxPersHandle) + { + snprintf(backupPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s", dbPath, gBackupPostfix); + snprintf(csumPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s", dbPath, gBackupCsPostfix); - __sync_fetch_and_add(&gOpenHandleArray[handle], FileOpen); // set open flag + __sync_fetch_and_add(&gOpenHandleArray[handle], FileOpen); // set open flag - set_ossfile_handle_data(handle, PersistencePermission_ReadWrite, 0/*backupCreated*/, backupPath, csumPath, NULL); - } - else - { - set_persistence_handle_close_idx(handle); - handle = EPERS_MAXHANDLE; + set_ossfile_handle_data(handle, PersistencePermission_ReadWrite, 0/*backupCreated*/, backupPath, csumPath, NULL); + } + else + { + set_persistence_handle_close_idx(handle); + handle = EPERS_MAXHANDLE; + } } } } - } - else - { - handle = EPERS_RESOURCE_NO_FILE; + else + { + handle = EPERS_RESOURCE_NO_FILE; + } + pthread_mutex_unlock(&gFileAccessMtx); } } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileCreatePath - not initialized")); + } + return handle; } @@ -793,48 +891,56 @@ int pclFileReleasePath(int pathHandle) { int rval = EPERS_NOT_INITIALIZED; - //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclFileClose fd: "), DLT_INT(fd)); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileClose fd: "), DLT_INT(pathHandle)); if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { - int permission = get_ossfile_permission(pathHandle); - if(permission != -1) // permission is here also used for range check + if(pthread_mutex_lock(&gFileAccessMtx) == 0) { - // check if a backup and checksum file needs to be deleted - if(permission != PersistencePermission_ReadOnly) + int permission = get_ossfile_permission(pathHandle); + if(permission != -1) // permission is here also used for range check { - // remove backup file - if(remove(get_ossfile_backup_path(pathHandle)) == -1) + // check if a backup and checksum file needs to be deleted + if(permission != PersistencePermission_ReadOnly) { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileClose - backup remove failed!")); - } + // remove backup file + if(remove(get_ossfile_backup_path(pathHandle)) == -1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileClose - backup remove failed!")); + } - // remove checksum file - if(remove(get_ossfile_checksum_path(pathHandle)) == -1) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileClose - backup remove failed!"), DLT_STRING(strerror(errno)) ); + // remove checksum file + if(remove(get_ossfile_checksum_path(pathHandle)) == -1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileClose - backup remove failed!"), DLT_STRING(strerror(errno)) ); + } } - } - free(get_ossfile_file_path(pathHandle)); + free(get_ossfile_file_path(pathHandle)); - __sync_fetch_and_sub(&gOpenHandleArray[pathHandle], FileClosed); // set closed flag + __sync_fetch_and_sub(&gOpenHandleArray[pathHandle], FileClosed); // set closed flag - set_persistence_handle_close_idx(pathHandle); + set_persistence_handle_close_idx(pathHandle); - set_ossfile_file_path(pathHandle, NULL); + set_ossfile_file_path(pathHandle, NULL); + + if(remove_ossfile_handle_data(pathHandle) != 1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileReleasePath - Failed to remove from tree!"), DLT_INT(pathHandle) ); + } - if(remove_ossfile_handle_data(pathHandle) != 1) + rval = 1; + } + else { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileReleasePath - Failed to remove from tree!"), DLT_INT(pathHandle) ); + rval = EPERS_MAXHANDLE; } - - rval = 1; - } - else - { - rval = EPERS_MAXHANDLE; + pthread_mutex_unlock(&gFileAccessMtx); } } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileReleasePath - not initialized")); + } return rval; } @@ -850,6 +956,8 @@ int pclFileGetDefaultData(int handle, const char* resource_id, int policy) char pathPrefix[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = { [0 ... PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = 0}; char defaultPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = { [0 ... PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = 0}; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileGetDefaultData fd: "), DLT_INT(handle), DLT_STRING(" res:"),DLT_STRING(resource_id)); + // create path to default data if(policy == PersistencePolicy_wc) { @@ -877,10 +985,10 @@ int pclFileGetDefaultData(int handle, const char* resource_id, int policy) if(fstat(defaultHandle, &buf) != -1) { - rval = sendfile(handle, defaultHandle, 0, buf.st_size); + rval = (int)sendfile(handle, defaultHandle, (off_t)0, (size_t)buf.st_size); if(rval != -1) { - rval = lseek(handle, 0, SEEK_SET); // set fd back to beginning of the file + rval = (int)lseek(handle, 0, SEEK_SET); // set fd back to beginning of the file } else { diff --git a/src/persistence_client_library_handle.c b/src/persistence_client_library_handle.c index e0c52d9..31624bf 100644 --- a/src/persistence_client_library_handle.c +++ b/src/persistence_client_library_handle.c @@ -21,6 +21,9 @@ #include "persistence_client_library_tree_helper.h" #include <pthread.h> +#include <dlt.h> + +DLT_IMPORT_CONTEXT(gPclDLTContext); pthread_mutex_t gKeyHandleAccessMtx = PTHREAD_MUTEX_INITIALIZER; @@ -81,7 +84,7 @@ int get_persistence_handle_idx() if(pthread_mutex_lock(&gMtx) == 0) { - if(gFreeHandleIdxHead > 0) // check if we have a free spot in the array before the current max + if(gFreeHandleIdxHead > 0 && gFreeHandleIdxHead < MaxPersHandle) // check if we have a free spot in the array before the current max { handle = gFreeHandleArray[--gFreeHandleIdxHead]; } @@ -107,7 +110,7 @@ void set_persistence_handle_close_idx(int handle) { if(pthread_mutex_lock(&gMtx) == 0) { - if(gFreeHandleIdxHead < MaxPersHandle) + if(gFreeHandleIdxHead >= 0 && gFreeHandleIdxHead < MaxPersHandle ) { gFreeHandleArray[gFreeHandleIdxHead++] = handle; } @@ -363,7 +366,6 @@ int get_file_permission(int idx) if(foundItem != NULL) { permission = foundItem->value.fileHandle.permission; - //debugFileItem("get_file_permission => foundItem", foundItem); } else { diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c index 5598e85..750200f 100644 --- a/src/persistence_client_library_key.c +++ b/src/persistence_client_library_key.c @@ -23,10 +23,15 @@ #include "persistence_client_library_prct_access.h" #include "persistence_client_library_db_access.h" +#include <dlt.h> + +DLT_IMPORT_CONTEXT(gPclDLTContext); /// max key value data size [default 16kB] static int gMaxKeyValDataSize = PERS_DB_MAX_SIZE_KEY_DATA; +static pthread_mutex_t gKeyAPIHandleAccessMtx = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t gKeyAPIAccessMtx = PTHREAD_MUTEX_INITIALIZER; // function declaration static int handleRegNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy); @@ -47,46 +52,57 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u { int rval = 0, handle = EPERS_NOT_INITIALIZED; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("keyHandleOpen - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res:"), DLT_STRING(resource_id)); + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { -#if USE_APPCHECK - if(doAppcheck() == 1) + if(pthread_mutex_lock(&gKeyAPIHandleAccessMtx) == 0) { + +#if USE_APPCHECK + if(doAppcheck() == 1) + { #endif - PersistenceInfo_s dbContext; + PersistenceInfo_s dbContext; - char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key - char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location - dbContext.context.ldbid = ldbid; - dbContext.context.seat_no = seat_no; - dbContext.context.user_no = user_no; + dbContext.context.ldbid = ldbid; + dbContext.context.seat_no = seat_no; + dbContext.context.user_no = user_no; - // get database context: database path and database key - rval = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); - if((rval >= 0) && (dbContext.configKey.type == PersistenceResourceType_key)) // check if type matches - { - if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid + // get database context: database path and database key + rval = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); + if((rval >= 0) && (dbContext.configKey.type == PersistenceResourceType_key)) // check if type matches { - // remember data in handle array - handle = set_key_handle_data(get_persistence_handle_idx(), resource_id, ldbid, user_no, seat_no); + if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid + { + // remember data in handle array + handle = set_key_handle_data(get_persistence_handle_idx(), resource_id, ldbid, user_no, seat_no); + } + else + { + handle = EPERS_BADPOL; + } } else { - handle = EPERS_BADPOL; + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("keyHandleOpen - no db context or res not a key ")); } +#if USE_APPCHECK } else { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("keyHandleOpen - no db context or res not a key ")); + handle = EPERS_SHUTDOWN_NO_TRUSTED; } -#if USE_APPCHECK - } - else - { - handle = EPERS_SHUTDOWN_NO_TRUSTED; - } #endif + pthread_mutex_unlock(&gKeyAPIHandleAccessMtx); + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("keyHandleOpen - not initialized")); } return handle; @@ -98,39 +114,49 @@ int pclKeyHandleClose(int key_handle) { int rval = EPERS_NOT_INITIALIZED; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleClose - key_handle:"), DLT_INT(key_handle)); + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { -#if USE_APPCHECK - if(doAppcheck() == 1) + if(pthread_mutex_lock(&gKeyAPIHandleAccessMtx) == 0) { +#if USE_APPCHECK + if(doAppcheck() == 1) + { #endif - PersistenceKeyHandle_s persHandle; + PersistenceKeyHandle_s persHandle; - if(get_key_handle_data(key_handle, &persHandle) != -1) - { - if ('\0' != persHandle.resource_id[0]) + if(get_key_handle_data(key_handle, &persHandle) != -1) { - /* Invalidate key handle data */ - set_persistence_handle_close_idx(key_handle); - clear_key_handle_array(key_handle); - rval = 1; + if ('\0' != persHandle.resource_id[0]) + { + /* Invalidate key handle data */ + set_persistence_handle_close_idx(key_handle); + clear_key_handle_array(key_handle); + rval = 1; + } + else + { + rval = EPERS_INVALID_HANDLE; + } } else { - rval = EPERS_INVALID_HANDLE; + rval = EPERS_MAXHANDLE; } +#if USE_APPCHECK } else { - rval = EPERS_MAXHANDLE; + rval = EPERS_SHUTDOWN_NO_TRUSTED; } -#if USE_APPCHECK - } - else - { - rval = EPERS_SHUTDOWN_NO_TRUSTED; - } #endif + pthread_mutex_unlock(&gKeyAPIHandleAccessMtx); + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclKeyHandleClose - not initialized")); } return rval; @@ -142,30 +168,34 @@ int pclKeyHandleGetSize(int key_handle) { int size = EPERS_NOT_INITIALIZED; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleGetSize - key_handle:"), DLT_INT(key_handle)); + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { -#if USE_APPCHECK - if(doAppcheck() == 1) + if(pthread_mutex_lock(&gKeyAPIHandleAccessMtx) == 0) { +#if USE_APPCHECK + if(doAppcheck() == 1) + { #endif - PersistenceKeyHandle_s persHandle; + PersistenceKeyHandle_s persHandle; - if(get_key_handle_data(key_handle, &persHandle) != -1) - { - if ('\0' != persHandle.resource_id[0]) + if(get_key_handle_data(key_handle, &persHandle) != -1) { - size = pclKeyGetSize(persHandle.ldbid, persHandle.resource_id, - persHandle.user_no, persHandle.seat_no); + if ('\0' != persHandle.resource_id[0]) + { + size = pclKeyGetSize(persHandle.ldbid, persHandle.resource_id, + persHandle.user_no, persHandle.seat_no); + } + else + { + size = EPERS_INVALID_HANDLE; + } } else { - size = EPERS_INVALID_HANDLE; + size = EPERS_MAXHANDLE; } - } - else - { - size = EPERS_MAXHANDLE; - } #if USE_APPCHECK } else @@ -173,6 +203,12 @@ int pclKeyHandleGetSize(int key_handle) size = EPERS_SHUTDOWN_NO_TRUSTED; } #endif + pthread_mutex_unlock(&gKeyAPIHandleAccessMtx); + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclKeyHandleGetSize - not initialized")); } return size; @@ -184,38 +220,48 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size) { int size = EPERS_NOT_INITIALIZED; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleReadData - key_handle:"), DLT_INT(key_handle)); + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { -#if USE_APPCHECK - if(doAppcheck() == 1) + if(pthread_mutex_lock(&gKeyAPIHandleAccessMtx) == 0) { +#if USE_APPCHECK + if(doAppcheck() == 1) + { #endif - PersistenceKeyHandle_s persHandle; + PersistenceKeyHandle_s persHandle; - if(get_key_handle_data(key_handle, &persHandle) != -1) - { - if ('\0' != persHandle.resource_id[0]) + if(get_key_handle_data(key_handle, &persHandle) != -1) { - size = pclKeyReadData(persHandle.ldbid, persHandle.resource_id, - persHandle.user_no, persHandle.seat_no, - buffer, buffer_size); + if ('\0' != persHandle.resource_id[0]) + { + size = pclKeyReadData(persHandle.ldbid, persHandle.resource_id, + persHandle.user_no, persHandle.seat_no, + buffer, buffer_size); + } + else + { + size = EPERS_INVALID_HANDLE; + } } else { - size = EPERS_INVALID_HANDLE; + size = EPERS_MAXHANDLE; } +#if USE_APPCHECK } else { - size = EPERS_MAXHANDLE; + size = EPERS_SHUTDOWN_NO_TRUSTED; } -#if USE_APPCHECK - } - else - { - size = EPERS_SHUTDOWN_NO_TRUSTED; - } #endif + pthread_mutex_unlock(&gKeyAPIHandleAccessMtx); + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclKeyHandleReadData - not initialized")); } return size; @@ -226,23 +272,41 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size) int pclKeyHandleRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback) { int rval = EPERS_COMMON; - //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclKeyHandleRegisterNotifyOnChange: "), - // DLT_INT(gKeyHandleArray[key_handle].info.context.ldbid), DLT_STRING(gKeyHandleArray[key_handle].resourceID) ); - if((gChangeNotifyCallback == callback) || (gChangeNotifyCallback == NULL)) - { - rval = handleRegNotifyOnChange(key_handle, callback, Notify_register); - } - else + + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleRegisterNotifyOnChange - key_handle:"), DLT_INT(key_handle)); + + if(pthread_mutex_lock(&gKeyAPIHandleAccessMtx) == 0) { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("keyHandleRegNotOnChange - Only one cBack allowed for ch notiy.")); - rval = EPERS_NOTIFY_NOT_ALLOWED; + //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleRegisterNotifyOnChange: "), + // DLT_INT(gKeyHandleArray[key_handle].info.context.ldbid), DLT_STRING(gKeyHandleArray[key_handle].resourceID) ); + if((gChangeNotifyCallback == callback) || (gChangeNotifyCallback == NULL)) + { + rval = handleRegNotifyOnChange(key_handle, callback, Notify_register); + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("keyHandleRegNotOnChange - Only one cBack allowed for ch notiy.")); + rval = EPERS_NOTIFY_NOT_ALLOWED; + } + pthread_mutex_unlock(&gKeyAPIHandleAccessMtx); } return rval; } int pclKeyHandleUnRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback) { - return handleRegNotifyOnChange(key_handle, callback, Notify_unregister); + int rval = EPERS_NOT_INITIALIZED; + + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleUnRegisterNotifyOnChange - key_handle:"), DLT_INT(key_handle)); + + if(pthread_mutex_lock(&gKeyAPIHandleAccessMtx) == 0) + { + rval = handleRegNotifyOnChange(key_handle, callback, Notify_unregister); + + pthread_mutex_unlock(&gKeyAPIHandleAccessMtx); + } + + return rval; } @@ -251,21 +315,23 @@ int handleRegNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback, { int rval = EPERS_NOT_INITIALIZED; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("handleRegNotifyOnChange - key_handle:"), DLT_INT(key_handle)); + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { - PersistenceKeyHandle_s persHandle; + PersistenceKeyHandle_s persHandle; if(get_key_handle_data(key_handle, &persHandle) != -1) { if ('\0' != persHandle.resource_id[0]) { rval = regNotifyOnChange(persHandle.ldbid, persHandle.resource_id, - persHandle.user_no, persHandle.seat_no, + persHandle.user_no, persHandle.seat_no, callback, regPolicy); } else { - rval = EPERS_INVALID_HANDLE; + rval = EPERS_INVALID_HANDLE; } } else @@ -273,6 +339,10 @@ int handleRegNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback, rval = EPERS_MAXHANDLE; } } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("handleRegNotifyOnChange - not initialized")); + } return rval; } @@ -282,37 +352,47 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size { int size = EPERS_NOT_INITIALIZED; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleWriteData - key_handle:"), DLT_INT(key_handle)); + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { -#if USE_APPCHECK - if(doAppcheck() == 1) + if(pthread_mutex_lock(&gKeyAPIHandleAccessMtx) == 0) { +#if USE_APPCHECK + if(doAppcheck() == 1) + { #endif - PersistenceKeyHandle_s persHandle; + PersistenceKeyHandle_s persHandle; - if(get_key_handle_data(key_handle, &persHandle) != -1) - { - if ('\0' != persHandle.resource_id[0]) + if(get_key_handle_data(key_handle, &persHandle) != -1) { - size = pclKeyWriteData(persHandle.ldbid, persHandle.resource_id, - persHandle.user_no, persHandle.seat_no, buffer, buffer_size); + if ('\0' != persHandle.resource_id[0]) + { + size = pclKeyWriteData(persHandle.ldbid, persHandle.resource_id, + persHandle.user_no, persHandle.seat_no, buffer, buffer_size); + } + else + { + size = EPERS_INVALID_HANDLE; + } } else { - size = EPERS_INVALID_HANDLE; + size = EPERS_MAXHANDLE; } +#if USE_APPCHECK } else { - size = EPERS_MAXHANDLE; + size = EPERS_SHUTDOWN_NO_TRUSTED; } -#if USE_APPCHECK - } - else - { - size = EPERS_SHUTDOWN_NO_TRUSTED; - } #endif + pthread_mutex_unlock(&gKeyAPIHandleAccessMtx); + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclKeyHandleWriteData - not initialized")); } return size; @@ -332,49 +412,59 @@ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_ { int rval = EPERS_NOT_INITIALIZED; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyDelete - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "),DLT_STRING(resource_id)); + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { -#if USE_APPCHECK - if(doAppcheck() == 1) + if(pthread_mutex_lock(&gKeyAPIAccessMtx) == 0) { -#endif - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked +#if USE_APPCHECK + if(doAppcheck() == 1) { - PersistenceInfo_s dbContext; +#endif + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + { + PersistenceInfo_s dbContext; - char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key - char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location - dbContext.context.ldbid = ldbid; - dbContext.context.seat_no = seat_no; - dbContext.context.user_no = user_no; + dbContext.context.ldbid = ldbid; + dbContext.context.seat_no = seat_no; + dbContext.context.user_no = user_no; - // get database context: database path and database key - rval = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); - if( (rval >= 0) - && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type is matching - { - if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid - { - rval = persistence_delete_data(dbPath, dbKey, resource_id, &dbContext); - } - else + // get database context: database path and database key + rval = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); + if( (rval >= 0) + && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type is matching { - rval = EPERS_BADPOL; + if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid + { + rval = persistence_delete_data(dbPath, dbKey, resource_id, &dbContext); + } + else + { + rval = EPERS_BADPOL; + } } - } + } + else + { + rval = EPERS_LOCKFS; + } +#if USE_APPCHECK } else { - rval = EPERS_LOCKFS; + rval = EPERS_SHUTDOWN_NO_TRUSTED; } -#if USE_APPCHECK - } - else - { - rval = EPERS_SHUTDOWN_NO_TRUSTED; - } #endif + pthread_mutex_unlock(&gKeyAPIAccessMtx); + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclKeyDelete - not initialized")); } return rval; @@ -386,46 +476,56 @@ int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user { int data_size = EPERS_NOT_INITIALIZED; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyGetSize - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "),DLT_STRING(resource_id)); + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { -#if USE_APPCHECK - if(doAppcheck() == 1) + if(pthread_mutex_lock(&gKeyAPIAccessMtx) == 0) { +#if USE_APPCHECK + if(doAppcheck() == 1) + { #endif - PersistenceInfo_s dbContext; + PersistenceInfo_s dbContext; - char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key - char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location - dbContext.context.ldbid = ldbid; - dbContext.context.seat_no = seat_no; - dbContext.context.user_no = user_no; + dbContext.context.ldbid = ldbid; + dbContext.context.seat_no = seat_no; + dbContext.context.user_no = user_no; - // get database context: database path and database key - data_size = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); - if( (data_size >= 0) - && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type matches - { - if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid + // get database context: database path and database key + data_size = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); + if( (data_size >= 0) + && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type matches { - data_size = persistence_get_data_size(dbPath, dbKey, resource_id, &dbContext); + if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid + { + data_size = persistence_get_data_size(dbPath, dbKey, resource_id, &dbContext); + } + else + { + data_size = EPERS_BADPOL; + } } else { data_size = EPERS_BADPOL; } +#if USE_APPCHECK } else { - data_size = EPERS_BADPOL; + data_size = EPERS_SHUTDOWN_NO_TRUSTED; } -#if USE_APPCHECK - } - else - { - data_size = EPERS_SHUTDOWN_NO_TRUSTED; - } #endif + pthread_mutex_unlock(&gKeyAPIAccessMtx); + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclKeyGetSize - not initialized")); } return data_size; @@ -438,54 +538,64 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use { int data_size = EPERS_NOT_INITIALIZED; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyReadData - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "),DLT_STRING(resource_id)); + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { -#if USE_APPCHECK - if(doAppcheck() == 1) + if(pthread_mutex_lock(&gKeyAPIAccessMtx) == 0) { -#endif - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked +#if USE_APPCHECK + if(doAppcheck() == 1) { - PersistenceInfo_s dbContext; - - char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key - char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location +#endif + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + { + PersistenceInfo_s dbContext; - dbContext.context.ldbid = ldbid; - dbContext.context.seat_no = seat_no; - dbContext.context.user_no = user_no; + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location - // get database context: database path and database key - data_size = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); - if( (data_size >= 0) - && (dbContext.configKey.type == PersistenceResourceType_key) ) - { + dbContext.context.ldbid = ldbid; + dbContext.context.seat_no = seat_no; + dbContext.context.user_no = user_no; - if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid + // get database context: database path and database key + data_size = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); + if( (data_size >= 0) + && (dbContext.configKey.type == PersistenceResourceType_key) ) { - data_size = persistence_get_data(dbPath, dbKey, resource_id, &dbContext, buffer, buffer_size); + + if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid + { + data_size = persistence_get_data(dbPath, dbKey, resource_id, &dbContext, buffer, buffer_size); + } + else + { + data_size = EPERS_BADPOL; + } } else { - data_size = EPERS_BADPOL; + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("keyReadData - no db context or res not a key")); } } else { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("keyReadData - no db context or res not a key")); + data_size = EPERS_LOCKFS; } +#if USE_APPCHECK } else { - data_size = EPERS_LOCKFS; + data_size = EPERS_SHUTDOWN_NO_TRUSTED; } -#if USE_APPCHECK - } - else - { - data_size = EPERS_SHUTDOWN_NO_TRUSTED; - } #endif + pthread_mutex_unlock(&gKeyAPIAccessMtx); + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("keyReadData - not initialized")); } return data_size; @@ -498,77 +608,88 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us { int data_size = EPERS_NOT_INITIALIZED; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyWriteData - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "),DLT_STRING(resource_id)); + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { -#if USE_APPCHECK - if(doAppcheck() == 1) + if(pthread_mutex_lock(&gKeyAPIAccessMtx) == 0) { -#endif - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + +#if USE_APPCHECK + if(doAppcheck() == 1) { - if(buffer_size <= gMaxKeyValDataSize) // check data size +#endif + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked { - PersistenceInfo_s dbContext; + if(buffer_size <= gMaxKeyValDataSize) // check data size + { + PersistenceInfo_s dbContext; - char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key - char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location + char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key + char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location - dbContext.context.ldbid = ldbid; - dbContext.context.seat_no = seat_no; - dbContext.context.user_no = user_no; + dbContext.context.ldbid = ldbid; + dbContext.context.seat_no = seat_no; + dbContext.context.user_no = user_no; - // get database context: database path and database key - data_size = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); - if( (data_size >= 0) - && (dbContext.configKey.type == PersistenceResourceType_key)) - { - if(dbContext.configKey.permission != PersistencePermission_ReadOnly) // don't write to a read only resource + // get database context: database path and database key + data_size = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); + if( (data_size >= 0) + && (dbContext.configKey.type == PersistenceResourceType_key)) { - // store data - if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid + if(dbContext.configKey.permission != PersistencePermission_ReadOnly) // don't write to a read only resource { - if( (dbContext.configKey.storage == PersistenceStorage_shared) - && (0 != strncmp(dbContext.configKey.reponsible, gAppId, PERS_RCT_MAX_LENGTH_RESPONSIBLE) ) ) + // store data + if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid { - data_size = EPERS_NOT_RESP_APP; + if( (dbContext.configKey.storage == PersistenceStorage_shared) + && (0 != strncmp(dbContext.configKey.reponsible, gAppId, PERS_RCT_MAX_LENGTH_RESPONSIBLE) ) ) + { + data_size = EPERS_NOT_RESP_APP; + } + else + { + data_size = persistence_set_data(dbPath, dbKey, resource_id, &dbContext, buffer, buffer_size); + } } else { - data_size = persistence_set_data(dbPath, dbKey, resource_id, &dbContext, buffer, buffer_size); + data_size = EPERS_BADPOL; } } else { - data_size = EPERS_BADPOL; + data_size = EPERS_RESOURCE_READ_ONLY; } } else { - data_size = EPERS_RESOURCE_READ_ONLY; + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("keyWriteData no db context or res is not a key")); } } else { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("keyWriteData no db context or res is not a key")); + data_size = EPERS_BUFLIMIT; + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("keyWriteData - buffer_size to big, limit is [bytes]:"), DLT_INT(gMaxKeyValDataSize)); } } else { - data_size = EPERS_BUFLIMIT; - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("keyWriteData - buffer_size to big, limit is [bytes]:"), DLT_INT(gMaxKeyValDataSize)); + data_size = EPERS_LOCKFS; } +#if USE_APPCHECK } else { - data_size = EPERS_LOCKFS; + data_size = EPERS_SHUTDOWN_NO_TRUSTED; } -#if USE_APPCHECK - } - else - { - data_size = EPERS_SHUTDOWN_NO_TRUSTED; - } #endif + pthread_mutex_unlock(&gKeyAPIAccessMtx); + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclKeyWriteData - not initialized")); } return data_size; } @@ -577,7 +698,17 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us int pclKeyUnRegisterNotifyOnChange( unsigned int ldbid, const char * resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback) { - return regNotifyOnChange(ldbid, resource_id, user_no, seat_no, callback, Notify_unregister); + int rval = EPERS_NOT_INITIALIZED; + + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyUnRegisterNotifyOnChange - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "),DLT_STRING(resource_id)); + + if(pthread_mutex_lock(&gKeyAPIAccessMtx) == 0) + { + rval = regNotifyOnChange(ldbid, resource_id, user_no, seat_no, callback, Notify_unregister); + + pthread_mutex_unlock(&gKeyAPIAccessMtx); + } + return rval; } @@ -585,16 +716,21 @@ int pclKeyUnRegisterNotifyOnChange( unsigned int ldbid, const char * resource_ int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback) { int rval = EPERS_COMMON; - //DLT_LOG(gDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclKeyRegisterNotifyOnChange: "), - // DLT_INT(ldbid), DLT_STRING(resource_id) ); - if((gChangeNotifyCallback == callback) || (gChangeNotifyCallback == NULL)) - { - rval = regNotifyOnChange(ldbid, resource_id, user_no, seat_no, callback, Notify_register); - } - else + + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyRegisterNotifyOnChange - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "), DLT_STRING(resource_id) ); + + if(pthread_mutex_lock(&gKeyAPIAccessMtx) == 0) { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("keyRegNotifyOnChange - Only one cBack is allowed for ch noti.")); - rval = EPERS_NOTIFY_NOT_ALLOWED; + if((gChangeNotifyCallback == callback) || (gChangeNotifyCallback == NULL)) + { + rval = regNotifyOnChange(ldbid, resource_id, user_no, seat_no, callback, Notify_register); + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("keyRegNotifyOnChange - Only one cBack is allowed for ch noti.")); + rval = EPERS_NOTIFY_NOT_ALLOWED; + } + pthread_mutex_unlock(&gKeyAPIAccessMtx); } return rval; } @@ -605,6 +741,8 @@ int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int { int rval = EPERS_NOT_INITIALIZED; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("regNotifyOnChange - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "), DLT_STRING(resource_id) ); + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { #if USE_APPCHECK @@ -653,6 +791,10 @@ int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int } #endif } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("regNotifyOnChange - not initialized")); + } return rval; } diff --git a/src/persistence_client_library_lc_interface.c b/src/persistence_client_library_lc_interface.c index 19942f2..06fae6a 100644 --- a/src/persistence_client_library_lc_interface.c +++ b/src/persistence_client_library_lc_interface.c @@ -20,6 +20,9 @@ #include "persistence_client_library_lc_interface.h" #include <errno.h> +#include <dlt.h> + +DLT_IMPORT_CONTEXT(gPclDLTContext); int check_lc_request(unsigned int request, unsigned int requestID) @@ -49,7 +52,7 @@ int check_lc_request(unsigned int request, unsigned int requestID) } default: { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("lcCechkReq - Unknown lcm message"), DLT_INT(request)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("lcCechkReq - Unknown lcm message"), DLT_UINT(request)); break; } } @@ -122,7 +125,7 @@ DBusHandlerResult checkLifecycleMsg(DBusConnection * connection, DBusMessage * m if((0==strncmp(gDbusLcConsterface, dbus_message_get_interface(message), 46))) { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("chLcMsg - Received dbus msg: "), DLT_STRING(dbus_message_get_member(message))); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("chLcMsg - Received dbus msg: "), DLT_STRING(dbus_message_get_member(message))); if((0==strncmp(gDbusLcConsMsg, dbus_message_get_member(message), 16))) { result = msg_lifecycleRequest(connection, message); @@ -143,7 +146,7 @@ int register_lifecycle(int shutdownMode) data.message.cmd = (uint32_t)CMD_SEND_LC_REGISTER; data.message.params[0] = 1; - data.message.params[1] = shutdownMode; + data.message.params[1] = (uint32_t)shutdownMode; data.message.string[0] = '\0'; // no string parameter, set to 0 return deliverToMainloop(&data); @@ -157,7 +160,7 @@ int unregister_lifecycle(int shutdownMode) data.message.cmd = (uint32_t)CMD_SEND_LC_REGISTER; data.message.params[0] = 0; - data.message.params[1] = shutdownMode; + data.message.params[1] = (uint32_t)shutdownMode; data.message.string[0] = '\0'; // no string parameter, set to 0 return deliverToMainloop(&data); diff --git a/src/persistence_client_library_pas_interface.c b/src/persistence_client_library_pas_interface.c index d40bb56..a24d7cf 100644 --- a/src/persistence_client_library_pas_interface.c +++ b/src/persistence_client_library_pas_interface.c @@ -20,6 +20,9 @@ #include "persistence_client_library_pas_interface.h" #include <errno.h> +#include <dlt.h> + +DLT_IMPORT_CONTEXT(gPclDLTContext); /// flag if access is locked static int gLockAccess = 0; @@ -60,7 +63,7 @@ int check_pas_request(unsigned int request, unsigned int requestID) data.message.params[1] = requestID; data.message.string[0] = '\0'; // no string parameter, set to 0 - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("chkPasReq - case PasMsg_Block o. PasMsg_WriteBack")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("chkPasReq - case PasMsg_Block o. PasMsg_WriteBack")); if(-1 == deliverToMainloop_NM(&data)) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("write failed w/ errno "), DLT_INT(errno), DLT_STRING(strerror(errno))); @@ -74,7 +77,7 @@ int check_pas_request(unsigned int request, unsigned int requestID) } case PasMsg_Unblock: { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("chkPasReq - case PasMsg_Unblock")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("chkPasReq - case PasMsg_Unblock")); pers_unlock_access(); rval = PasErrorStatus_OK; break; @@ -118,7 +121,7 @@ DBusHandlerResult msg_persAdminRequest(DBusConnection *connection, DBusMessage * return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - errorReturn = check_pas_request(request, requestID); + errorReturn = check_pas_request((unsigned int)request, (unsigned int)requestID); reply = dbus_message_new_method_return(message); @@ -153,7 +156,7 @@ DBusHandlerResult checkPersAdminMsg(DBusConnection * connection, DBusMessage * m if((0==strcmp(gDbusPersAdminConsInterface, dbus_message_get_interface(message)))) { - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("checkPasMsg - Received dbus msg: "), DLT_STRING(dbus_message_get_member(message))); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("checkPasMsg - Received dbus msg: "), DLT_STRING(dbus_message_get_member(message))); if((0==strcmp(gDbusPersAdminConsMsg, dbus_message_get_member(message)))) { diff --git a/src/persistence_client_library_prct_access.c b/src/persistence_client_library_prct_access.c index 405bc7c..db3860e 100644 --- a/src/persistence_client_library_prct_access.c +++ b/src/persistence_client_library_prct_access.c @@ -19,6 +19,9 @@ #include "persistence_client_library_prct_access.h" #include "persistence_client_library_custom_loader.h" +#include <dlt.h> + +DLT_IMPORT_CONTEXT(gPclDLTContext); /// pointer to resource table database @@ -42,7 +45,7 @@ typedef enum _PersistenceRCT_e } PersistenceRCT_e; -PersistenceRCT_e get_table_id(int ldbid, int* groupId) +PersistenceRCT_e get_table_id(unsigned int ldbid, int* groupId) { PersistenceRCT_e rctType = PersistenceRCT_LastEntry; @@ -52,7 +55,7 @@ PersistenceRCT_e get_table_id(int ldbid, int* groupId) if(ldbid != 0) { // shared G R O U P database * * * * * * * * * * * * * * * * * * * - *groupId = ldbid; // assign group ID + *groupId = (int)ldbid; // assign group ID rctType = PersistenceRCT_shared_group; } else @@ -96,10 +99,11 @@ void invalidate_resource_cfg_table(int i) int get_resource_cfg_table(PersistenceRCT_e rct, int group) { - int arrayIdx = 0, rval = -1; + unsigned int arrayIdx = 0; + int rval = -1; // create array index: index is a combination of resource config table type and group - arrayIdx = rct + group; + arrayIdx = (rct + (unsigned int)group); if(arrayIdx < PrctDbTableSize) { @@ -207,7 +211,7 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign memcpy(dbContext->configKey.reponsible, "default", strlen("default")); memcpy(dbContext->configKey.custom_name, "default", strlen("default")); - DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("gDBCtx - create res not in PRCT => key:"), DLT_STRING(resource_id) ); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("gDBCtx - create res not in PRCT => key:"), DLT_STRING(resource_id) ); rval = get_db_path_and_key(dbContext, resource_id, dbKey, dbPath); } diff --git a/src/persistence_client_library_tree_helper.c b/src/persistence_client_library_tree_helper.c index 393817e..68e6250 100644 --- a/src/persistence_client_library_tree_helper.c +++ b/src/persistence_client_library_tree_helper.c @@ -190,7 +190,7 @@ int key_val_cmp(const void *p1, const void *p2 ) /// duplicate function for key_value_s item void* key_val_dup(void *p) { - int value_size = 0; + size_t value_size = 0; key_value_s* src = NULL; key_value_s* dst = NULL; diff --git a/test/Makefile.am b/test/Makefile.am index 8a3fa87..d957dd2 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,7 +1,7 @@ AUTOMAKE_OPTIONS = foreign if DEBUG -AM_CFLAGS = $(DEPS_CFLAGS) $(CHECK_CFLAGS) -g +AM_CFLAGS = $(DEPS_CFLAGS) $(CHECK_CFLAGS) #AM_CFLAGS = -fprofile-arcs -ftest-coverage $(DEPS_CFLAGS) $(CHECK_CFLAGS) -g else AM_CFLAGS = $(DEPS_CFLAGS) $(CHECK_CFLAGS) @@ -9,6 +9,7 @@ AM_CFLAGS = $(DEPS_CFLAGS) $(CHECK_CFLAGS) endif noinst_PROGRAMS = persistence_client_library_test \ + persistence_client_library_test_file \ persistence_client_library_dbus_test persistence_client_library_dbus_test_SOURCES = persistence_client_library_dbus_test.c @@ -19,8 +20,11 @@ persistence_client_library_test_SOURCES = persistence_client_library_test.c persistence_client_library_test_LDADD = $(DEPS_LIBS) $(CHECK_LIBS) \ $(top_builddir)/src/libpersistence_client_library.la +persistence_client_library_test_file_SOURCES = persistence_client_library_test_file.c +persistence_client_library_test_file_LDADD = $(DEPS_LIBS) $(CHECK_LIBS) \ + $(top_builddir)/src/libpersistence_client_library.la -TESTS=persistence_client_library_test +TESTS=persistence_client_library_test persistence_client_library_test_file diff --git a/test/persCheck.h b/test/persCheck.h deleted file mode 100644 index 8769d6a..0000000 --- a/test/persCheck.h +++ /dev/null @@ -1,169 +0,0 @@ -/****************************************************************************** - * Project Persistency - * (c) copyright 2014 - * 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 persCheck.h - * @ingroup Persistence client library test - * @author awehrle - * @brief Test of persistence client library - * @see - */ - -#ifndef PERSCHECK_H_ -#define PERSCHECK_H_ - -#include "pers_test_base.h" -#include <check.h> - -#ifdef __cplusplus -extern "C" { -#endif - -enum X_TEST_REPORTS{ - X_TEST_REPORTED_RESULT -}; - -int _optTestsReported; -char _optTestID[256]; - -#define X_TEST_INIT() do { \ - _optTestID[0] = '\0'; \ - } while(0) - -#define ___FILE___ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) - -#define REPORT_WARNINGS(){ \ - if(0==(_optTestsReported & (1 << X_TEST_REPORTED_RESULT))) \ - X_TEST_REPORT_RESULT(PASSED); \ -} - -/** - * @brief: Report name of test. This has to be reported first. - * MANDATORY - */ -#define X_TEST_REPORT_TEST_NAME(...) do { \ - char buf[sizeof(_optTestID)]; \ - snprintf(buf,sizeof(buf), __VA_ARGS__); \ - snprintf (_optTestID, sizeof(_optTestID),"%s::%s", ___FILE___, buf); \ - X_TEST_REPORT_TEST_ID(_optTestID); \ - X_TEST_REPORT_TEST_NAME_ID(_optTestID, __VA_ARGS__); \ - } while(0) - -/** - * @brief: Path to root of source code directory under test - * MANDATORY - */ -#define X_TEST_REPORT_PATH(...) do { \ - X_TEST_REPORT_PATH_ID( _optTestID, __VA_ARGS__ ); \ - } while(0) - -/** - * @brief: Name of subcomponent under test, leave empty or set value NONE if not suitable for a COMPONENT test - * MANDATORY - */ -#define X_TEST_REPORT_COMP_NAME(...) do { \ - X_TEST_REPORT_COMP_NAME_ID( _optTestID, __VA_ARGS__ ); \ - } while(0) - -/** - * @brief: Name of class or file under test, leave empty or set value NONE for a COMPONENT test - * MANDATORY - */ -#define X_TEST_REPORT_FILE_NAME(...) do { \ - X_TEST_REPORT_FILE_NAME_ID( _optTestID, __VA_ARGS__ ); \ - } while(0) - -/** - * @brief: If information exists: Reference to a requirement, feature or bug ID. Else leave empty or set value NONE - * MANDATORY - */ -#define X_TEST_REPORT_REFERENCE(...) do { \ - X_TEST_REPORT_REFERENCE_ID( _optTestID, __VA_ARGS__ ); \ - } while(0) - -/** - * @brief: A short description of test case. - * Do not leave empty, can also be a internal department Test ID like CORE-OS-BOOT-0001 - * MANDATORY - */ -#define X_TEST_REPORT_DESCRIPTION(...) do { \ - X_TEST_REPORT_DESCRIPTION_ID( _optTestID, __VA_ARGS__ ); \ - } while(0) - -/** - * @brief: Reports weather this is a UNIT or a COMPONENT test - * MANDATORY - */ -#define X_TEST_REPORT_KIND(kind) do { \ - X_TEST_REPORT_KIND_ID( _optTestID, kind ); \ - } while(0) - -/** - * @brief: valid values: PASSED, FAILED or NONE. PASSED if test result is ok, FAILED if test result is not as expected, NONE if no test exists for whole file or class - * MANDATORY - */ -#define X_TEST_REPORT_RESULT(result) do { \ - X_TEST_REPORT_RESULT_ID( _optTestID, result); \ - _optTestsReported |= 1 << X_TEST_REPORTED_RESULT; \ - } while(0) - -/** - * @brief: Additional information, if test "just" checks common information flow inside structure (GOOD test case) or if structure is tested with invalid or border values(BORDER) - * OPTIONAL - */ -#define X_TEST_REPORT_TYPE(type) do { \ - X_TEST_REPORT_TYPE_ID( _optTestID, type ); \ - } while(0) - -#undef START_TEST -/* Start a unit test with START_TEST(unit_name), end with END_TEST - One must use braces within a START_/END_ pair to declare new variables -*/ -#define START_TEST(__testname)\ -static void __testname (int _i CK_ATTRIBUTE_UNUSED)\ -{\ - X_TEST_INIT(); \ - X_TEST_REPORT_TEST_NAME(""# __testname); \ - tcase_fn_start (""# __testname, __FILE__, __LINE__); - -#define x_fail_unless(exp, ...){\ - int result = exp; \ - if(!result){ \ - X_TEST_REPORT_RESULT(FAILED); \ - } \ - fail_unless(exp, ##__VA_ARGS__); \ -} while(0) - -#define x_fail_if(exp, ...) {\ - int result = exp; \ - if(result){ \ - X_TEST_REPORT_RESULT(FAILED); \ - } \ - fail_if(exp, ##__VA_ARGS__); \ -} while(0) - -/* Always fail */ -#define x_fail(...) {\ - X_TEST_REPORT_RESULT(FAILED); \ - fail(__VA_ARGS__); \ -} while(0) - -#undef END_TEST -/* End a unit test */ -#define END_TEST {\ - REPORT_WARNINGS(); \ - _optTestsReported = 0; }\ -} - -#ifdef __cplusplus -} -#endif - -#endif /* PERSCHECK_H_ */ diff --git a/test/pers_test_base.h b/test/pers_test_base.h deleted file mode 100644 index 83c7d95..0000000 --- a/test/pers_test_base.h +++ /dev/null @@ -1,140 +0,0 @@ -/****************************************************************************** - * Project Persistency - * (c) copyright 2013 - * 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 pers_test_base.h - * @ingroup Persistence client library test - * @author awehrle - * @brief Test of persistence client library - * @see - */ - - -#ifndef PERSBASETEST_H_ -#define PERSBASETEST_H_ - -#include <stdbool.h> -#include <string.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#define MAGIC_STRING "$$XS_TEST$$" - -#define FAILED 0 -#define PASSED 1 -#define NONE 2 - -#define BORDER 0 -#define GOOD 1 - -#define UNIT 0 -#define COMPONENT 1 - -/** -* @brief: Report name of test. This has to be reported first. -* MANDATORY -*/ -#define X_TEST_REPORT_TEST_ID(ID) do { \ -printf (MAGIC_STRING"%s", ID); \ -printf ("\n"); \ -} while(0) - -/** -* @brief: Report name of test. This has to be reported first. -* MANDATORY -*/ -#define X_TEST_REPORT_TEST_NAME_ID(ID, ...) do { \ -printf (MAGIC_STRING"%s$$", ID); \ -printf ("testName:%s", __VA_ARGS__); \ -printf ("\n"); \ -} while(0) - -/** -* @brief: Path to root of source code directory under test -* MANDATORY -*/ -#define X_TEST_REPORT_PATH_ID(ID, ...) do { \ -printf (MAGIC_STRING"%s$$", ID); \ -printf ("path:"__VA_ARGS__); \ -printf ("\n"); \ -} while(0) - -/** -* @brief: Name of subcomponent under test, leave empty or set value NONE if not suitable for a COMPONENT test -* MANDATORY -*/ -#define X_TEST_REPORT_COMP_NAME_ID(ID, ...) do { \ -printf (MAGIC_STRING"%s$$", ID); \ -printf ("compName:"__VA_ARGS__); \ -printf ("\n"); \ -} while(0) - -/** -* @brief: Name of class or file under test, leave empty or set value NONE for a COMPONENT test -* MANDATORY -*/ -#define X_TEST_REPORT_FILE_NAME_ID(ID, ...) do { \ -printf (MAGIC_STRING"%s$$", ID); \ -printf ("fileName:"__VA_ARGS__); \ -printf ("\n"); \ -} while(0) - -/** -* @brief: If information exists: Reference to a requirement, feature or bug ID. Else leave empty or set value NONE -* MANDATORY -*/ -#define X_TEST_REPORT_REFERENCE_ID(ID, ...) do { \ -printf (MAGIC_STRING"%s$$", ID); \ -printf ("ref:"__VA_ARGS__); \ -printf ("\n"); \ -} while(0) - -/** -* @brief: A short description of test case. -* Do not leave empty, can also be a internal department Test ID like CORE-OS-BOOT-0001 -* MANDATORY -*/ -#define X_TEST_REPORT_DESCRIPTION_ID(ID, ...) do { \ -printf (MAGIC_STRING"%s$$", ID); \ -printf ("desc:"__VA_ARGS__); \ -printf ("\n"); \ -} while(0) - -/** -* @brief: Reports weather this is a UNIT or a COMPONENT test -* MANDATORY -*/ -#define X_TEST_REPORT_KIND_ID(ID, kind) do { \ -printf (MAGIC_STRING"%s$$kind:%s\n", ID, kind==UNIT?"UNIT":kind==COMPONENT?"COMPONENT":"NONE"); \ -} while(0) - -/** -* @brief: valid values: PASSED, FAILED or NONE. PASSED if test result is ok, FAILED if test result is not as expected, NONE if no test exists for whole file or class -* MANDATORY -*/ -#define X_TEST_REPORT_RESULT_ID(ID, result) do { \ -printf (MAGIC_STRING"%s$$result:%s\n", ID, result==PASSED?"PASSED":result==FAILED?"FAILED":"NONE"); \ -} while(0) - -/** -* @brief: Additional information, if test "just" checks common information flow inside structure (GOOD test case) or if structure is tested with invalid or border values(BORDER) -* OPTIONAL -*/ -#define X_TEST_REPORT_TYPE_ID(ID, type) do { \ -printf (MAGIC_STRING"%s$$type:%s\n", ID, type==BORDER?"BORDER":"GOOD"); \ -} while(0) - -#ifdef __cplusplus -} -#endif - -#endif /* PERSBASETEST_H_ */ diff --git a/test/persistence_client_library_dbus_test.c b/test/persistence_client_library_dbus_test.c index a9222ef..bbaa19e 100644 --- a/test/persistence_client_library_dbus_test.c +++ b/test/persistence_client_library_dbus_test.c @@ -35,6 +35,8 @@ pthread_mutex_t gMtx = PTHREAD_MUTEX_INITIALIZER; +/// debug log and trace (DLT) setup +DLT_DECLARE_CONTEXT(gPcltDLTContext); int myChangeCallback(pclNotification_s * notifyStruct) @@ -58,10 +60,8 @@ int myChangeCallback(pclNotification_s * notifyStruct) int main(int argc, char *argv[]) { - int ret = 0, i = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - - unsigned char readBuffer[READ_BUFFER_SIZE] = {0}; + int ret = 0; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; const char* appID = "lt-persistence_client_library_dbus_test"; @@ -71,7 +71,10 @@ int main(int argc, char *argv[]) printf("Dbus interface test application\n"); /// debug log and trace (DLT) setup - DLT_REGISTER_APP("noty","tests the persistence client library"); + DLT_REGISTER_APP("NOTY","tests the persistence client library"); + + DLT_REGISTER_CONTEXT(gPcltDLTContext, "PCLt", "Context for PCL testing"); + ret = pclInitLibrary(appID, shutdownReg); printf("pclInitLibrary - %s - : %d\n", appID, ret); @@ -81,7 +84,6 @@ int main(int argc, char *argv[]) ret = pclKeyRegisterNotifyOnChange(0x20, "links/last_link2", 2/*user_no*/, 1/*seat_no*/, &myChangeCallback); -#if 0 ret = pclKeyRegisterNotifyOnChange(0x20, "links/last_link3", 3/*user_no*/, 2/*seat_no*/, &myChangeCallback); ret = pclKeyRegisterNotifyOnChange(0x20, "links/last_link4", 4/*user_no*/, 1/*seat_no*/, &myChangeCallback); @@ -118,33 +120,12 @@ int main(int argc, char *argv[]) printf("Press enter to end\n"); getchar(); - sleep(2); - -#else - - - - while(i<18) - { - memset(readBuffer, 0, READ_BUFFER_SIZE); - pthread_mutex_lock(&gMtx); - - pclKeyReadData(0x20, "links/last_link2", 2, 1, readBuffer, READ_BUFFER_SIZE); - printf("%d - Read value of resource \"links/last_link2\" = %s \n\n\n", i++, readBuffer); - } - -#endif - - pclDeinitLibrary(); - // unregister debug log and trace + DLT_UNREGISTER_CONTEXT(gPcltDLTContext); DLT_UNREGISTER_APP(); - dlt_free(); - - printf("By\n"); return ret; } diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c index a1b1d71..e475ae8 100644 --- a/test/persistence_client_library_test.c +++ b/test/persistence_client_library_test.c @@ -29,28 +29,31 @@ #include <dlt_common.h> #include <pthread.h> -//#include "persCheck.h" #include <check.h> -#include "../include/persistence_client_library_file.h" #include "../include/persistence_client_library_key.h" #include "../include/persistence_client_library.h" #include "../include/persistence_client_library_error_def.h" -#define BUF_SIZE 64 -#define NUM_OF_FILES 3 -#define READ_SIZE 1024 -#define MaxAppNameLen 256 +#define BUF_SIZE 64 +#define NUM_OF_FILES 3 +#define READ_SIZE 1024 +#define MaxAppNameLen 256 -#define NUM_THREADS 100 -#define NUM_OF_READS 100 -#define NUM_OF_WRITES 100 -#define NAME_LEN 24 +#define NUM_THREADS 20 +#define NUM_OF_READS 100 +#define NUM_OF_WRITES 100 +#define NAME_LEN 24 -static pthread_barrier_t barrier; +typedef struct s_threadData +{ + char threadName[NAME_LEN]; + int index; + int fd1; + int fd2; +} t_threadData; -static const char* gPathSegemnts[] = {"user/", "1/", "seat/", "1/", "media", NULL }; -static const char* gSourcePath = "/Data/mnt-c/lt-persistence_client_library_test/"; +static pthread_barrier_t gBarrierOne, gBarrierTwo; /// application id char gTheAppId[MaxAppNameLen] = {0}; @@ -59,28 +62,36 @@ char gTheAppId[MaxAppNameLen] = {0}; char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; char* gWriteBackupTestData = "This is the content of the file /Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db"; char* gWriteRecoveryTestData = "This is the data to recover: /Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db"; -char* gRecovChecksum = "608a3b5d"; // generated with http://www.tools4noobs.com/online_php_functions/crc32/ +char* gRecovChecksum = "608a3b5d"; // generated with http://www.tools4noobs.com/online_php_functions/crc32/ + +extern const char* gWriteBuffer; +extern const char* gWriteBuffer2; + + +/// debug log and trace (DLT) setup +DLT_DECLARE_CONTEXT(gPcltDLTContext); + // function prototype void run_concurrency_test(); void data_setup(void) { - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; (void)pclInitLibrary(gTheAppId, shutdownReg); } void data_setup_browser(void) { - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; (void)pclInitLibrary("browser", shutdownReg); } void data_setup_norct(void) { - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; (void)pclInitLibrary("norct", shutdownReg); } @@ -108,59 +119,27 @@ int myChangeCallback(pclNotification_s * notifyStruct) */ START_TEST(test_GetData) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test of get data"); - X_TEST_REPORT_TYPE(GOOD);*/ - int ret = 0; unsigned char buffer[READ_SIZE] = {0}; - -#if 1 /** * Logical DB ID: PCL_LDBID_LOCAL with user 0 and seat 0 * ==> local value accessible by all users (user 0, seat 0) */ ret = pclKeyReadData(PCL_LDBID_LOCAL, "pos/last_position", 1, 1, buffer, READ_SIZE); //printf("----test_GetData => pos/last_position: \"%s\" => ret: %d \nReference: %s => size: %d\n", buffer, ret, "CACHE_ +48 10' 38.95, +8 44' 39.06", strlen("CACHE_ +48 10' 38.95, +8 44' 39.06")); - fail_unless(strncmp((char*)buffer, "CACHE_ +48 10' 38.95, +8 44' 39.06", - strlen((char*)buffer)) == 0, "Buffer not correctly read - pos/last_position"); - fail_unless(ret == strlen("CACHE_ +48 10' 38.95, +8 44' 39.06")); + ck_assert_str_eq( (char*)buffer, "CACHE_ +48 10' 38.95, +8 44' 39.06"); + ck_assert_int_eq( ret, (int)strlen("CACHE_ +48 10' 38.95, +8 44' 39.06") ); memset(buffer, 0, READ_SIZE); /** - * Logical DB ID: PCL_LDBID_LOCAL with user 0 and seat 0 - * ==> local value accessible by all users (user 0, seat 0) - */ - /* - ret = pclKeyReadData(PCL_LDBID_LOCAL, "language/country_code", 0, 0, buffer, READ_SIZE); - x_fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data: secure!", - strlen((char*)buffer)) == 0, "Buffer not correctly read"); - x_fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle")); - memset(buffer, 0, READ_SIZE); - */ - - - /** - * Logical DB ID: 0 with user 3 and seat 0 - * ==> public shared user value (user 3, seat 0) - */ - //ret = pclKeyReadData(0, "language/current_language", 0, 0, buffer, READ_SIZE); - //printf("----test_GetData => language/current_language \"%s\" => ret: %d \n", buffer, ret); - //x_fail_unless(strncmp((char*)buffer, "CACHE_ Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read"); - //memset(buffer, 0, READ_SIZE); - - /** * Logical DB ID: PCL_LDBID_LOCAL with user 3 and seat 2 * ==> local USER value (user 3, seat 2) */ ret = pclKeyReadData(PCL_LDBID_LOCAL, "status/open_document", 3, 2, buffer, READ_SIZE); //printf("----test_GetData => status/open_document \"%s\" => ret: %d \n", buffer, ret); - fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, - "Buffer not correctly read - status/open_document"); - fail_unless(ret == strlen("WT_ /var/opt/user_manual_climateControl.pdf")); + ck_assert_str_eq( (char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf"); + ck_assert_int_eq(ret, (int)strlen("WT_ /var/opt/user_manual_climateControl.pdf")); memset(buffer, 0, READ_SIZE); /** @@ -169,9 +148,8 @@ START_TEST(test_GetData) */ ret = pclKeyReadData(0x20, "address/home_address", 4, 0, buffer, READ_SIZE); //printf("----test_GetData => address/home_address \"%s\" => ret: %d \n", buffer, ret); - fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0, - "Buffer not correctly read - address/home_address"); - fail_unless(ret == strlen("WT_ 55327 Heimatstadt, Wohnstrasse 31")); + ck_assert_str_eq( (char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31"); + ck_assert_int_eq(ret, (int)strlen("WT_ 55327 Heimatstadt, Wohnstrasse 31")); memset(buffer, 0, READ_SIZE); /** @@ -180,9 +158,8 @@ START_TEST(test_GetData) */ ret = pclKeyReadData(PCL_LDBID_LOCAL, "pos/last_satellites", 0, 0, buffer, READ_SIZE); //printf("----test_GetData => pos/last_satellites \"%s\" => ret: %d \n", buffer, ret); - fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0, - "Buffer not correctly read - pos/last_satellites"); - fail_unless(ret == strlen("WT_ 17")); + ck_assert_str_eq( (char*)buffer, "WT_ 17"); + ck_assert_int_eq(ret, (int)strlen("WT_ 17")); memset(buffer, 0, READ_SIZE); /** @@ -191,20 +168,13 @@ START_TEST(test_GetData) */ ret = pclKeyReadData(0x20, "links/last_link", 2, 0, buffer, READ_SIZE); //printf("----test_GetData => links/last_link \"%s\" => ret: %d \n", buffer, ret); - fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0, - "Buffer not correctly read - links/last_link"); - fail_unless(ret == strlen("CACHE_ /last_exit/queens")); + ck_assert_str_eq( (char*)buffer, "CACHE_ /last_exit/queens"); + ck_assert_int_eq(ret, (int)strlen("CACHE_ /last_exit/queens")); memset(buffer, 0, READ_SIZE); - - - -#endif - } END_TEST - /** * Test the key value h a n d l e interface using different logicalDB id's, users and seats * Each resource below has an entry in the resource configuration table where @@ -212,12 +182,6 @@ END_TEST */ START_TEST (test_GetDataHandle) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test of get data handle"); - X_TEST_REPORT_TYPE(GOOD); */ - int ret = 0, handle = 0, handle2 = 0, handle3 = 0, handle4 = 0, size = 0; unsigned char buffer[READ_SIZE] = {0}; @@ -225,33 +189,29 @@ START_TEST (test_GetDataHandle) char sysTimeBuffer[128]; -#if 1 time_t t = time(0); locTime = localtime(&t); snprintf(sysTimeBuffer, 128, "TimeAndData: \"%s %d.%d.%d - %d:%.2d:%.2d Uhr\"", dayOfWeek[locTime->tm_wday], locTime->tm_mday, locTime->tm_mon+1, (locTime->tm_year+1900), locTime->tm_hour, locTime->tm_min, locTime->tm_sec); - - // open handle --------------------------------------------------- /** * Logical DB ID: PCL_LDBID_LOCAL with user 0 and seat 0 * ==> local value accessible by ALL USERS (user 0, seat 0) */ handle = pclKeyHandleOpen(PCL_LDBID_LOCAL, "posHandle/last_position", 0, 0); - fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position"); + ck_assert_int_gt(handle, 0); ret = pclKeyHandleReadData(handle, buffer, READ_SIZE); //printf("pclKeyHandleReadData: \nsoll: %s \nist : %s => ret: %d | strlen: %d\n", "WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", buffer, ret, strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"")); - fail_unless(strncmp((char*)buffer, "WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", ret) == 0, "Buffer not correctly read => 1"); + fail_unless(strncmp((char*)buffer, "WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", (size_t)ret) == 0, "Buffer not correctly read => 1"); size = pclKeyHandleGetSize(handle); //printf("pclKeyHandleGetSize => size: %d\n", size); - fail_unless(size == strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"")); + ck_assert_int_eq(size, (int)strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"")); // --------------------------------------------------------------------------------------------- - // open handle --------------------------------------------------- /** * Logical DB ID: PCL_LDBID_LOCAL with user 3 and seat 2 @@ -260,34 +220,12 @@ START_TEST (test_GetDataHandle) handle2 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "statusHandle/open_document", 3, 2); fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document"); - size = pclKeyHandleWriteData(handle2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer)); + size = pclKeyHandleWriteData(handle2, (unsigned char*)sysTimeBuffer, (int)strlen(sysTimeBuffer)); fail_unless(size == (int)strlen(sysTimeBuffer)); // close ret = pclKeyHandleClose(handle2); // --------------------------------------------------------------------------------------------- - - // open handle --------------------------------------------------- - /** - * Logical DB ID: PCL_LDBID_LOCAL with user 0 and seat 0 - * ==> local value accessible by ALL USERS (user 0, seat 0) - */ -#if 0 // plugin test case - memset(buffer, 0, READ_SIZE); - handle4 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "language/country_code", 0, 0); - fail_unless(handle4 >= 0, "Failed to open handle /language/country_code"); - - ret = pclKeyHandleReadData(handle4, buffer, READ_SIZE); - fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle: secure!", -1) == 0, "Buffer not correctly read => 2"); - - size = pclKeyHandleGetSize(handle4); - fail_unless(size = strlen("Custom plugin -> plugin_get_data_handle")); - - ret = pclKeyHandleWriteData(handle4, (unsigned char*)"Only dummy implementation behind custom library", READ_SIZE); -#endif - // --------------------------------------------------------------------------------------------- - - // open handle --------------------------------------------------- /** * Logical DB ID: PCL_LDBID_LOCAL with user 3 and seat 2 @@ -300,15 +238,13 @@ START_TEST (test_GetDataHandle) fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read => 3"); size = pclKeyHandleGetSize(handle3); - fail_unless(size = strlen(sysTimeBuffer)); + fail_unless(size = (int)strlen(sysTimeBuffer)); // --------------------------------------------------------------------------------------------- - // close handle ret = pclKeyHandleClose(handle); ret = pclKeyHandleClose(handle3); ret = pclKeyHandleClose(handle4); -#endif } END_TEST @@ -320,12 +256,6 @@ END_TEST */ START_TEST(test_SetData) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test of set data"); - X_TEST_REPORT_TYPE(GOOD); */ - int ret = 0; unsigned char buffer[READ_SIZE] = {0}; char write1[READ_SIZE] = {0}; @@ -334,7 +264,6 @@ START_TEST(test_SetData) struct tm *locTime; -#if 1 /** * Logical DB ID: PCL_LDBID_LOCAL with user 3 and seat 2 * ==> local USER value (user 3, seat 2) @@ -348,9 +277,7 @@ START_TEST(test_SetData) ret = pclKeyWriteData(PCL_LDBID_LOCAL, "posHandle/last_position", 0, 0, (unsigned char*)"WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"")); fail_unless(ret == strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""), "Wrong write size"); -#endif -#if 1 time_t t = time(0); locTime = localtime(&t); @@ -363,16 +290,16 @@ START_TEST(test_SetData) * ==> local USER value (user 1, seat 2) * Resource ID: 69 */ - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "69", 1, 2, (unsigned char*)sysTimeBuffer, (int)strlen(sysTimeBuffer)); fail_unless(ret == (int)strlen(sysTimeBuffer), "Wrong write size"); -#if 1 + snprintf(write1, 128, "%s %s", "/70", sysTimeBuffer); /** * Logical DB ID: PCL_LDBID_LOCAL with user 1 and seat 2 * ==> local USER value (user 1, seat 2) * Resource ID: 70 */ - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "70", 1, 2, (unsigned char*)write1, strlen(write1)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "70", 1, 2, (unsigned char*)write1, (int)strlen(write1)); fail_unless(ret == (int)strlen(write1), "Wrong write size"); snprintf(write2, 128, "%s %s", "/key_70", sysTimeBuffer); @@ -381,7 +308,7 @@ START_TEST(test_SetData) * ==> local USER value (user 1, seat 2) * Resource ID: key_70 */ - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "key_70", 1, 2, (unsigned char*)write2, strlen(write2)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "key_70", 1, 2, (unsigned char*)write2, (int)strlen(write2)); fail_unless(ret == (int)strlen(write2), "Wrong write size"); @@ -442,8 +369,6 @@ START_TEST(test_SetData) 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 == (int)strlen(write2), "Wrong read size"); -#endif -#endif } END_TEST @@ -456,17 +381,10 @@ END_TEST */ START_TEST(test_SetDataNoPRCT) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test of set data no PRCT"); - X_TEST_REPORT_TYPE(GOOD);*/ - int ret = 0; unsigned char buffer[READ_SIZE] = {0}; struct tm *locTime; -#if 1 time_t t = time(0); char sysTimeBuffer[128]; @@ -480,7 +398,7 @@ START_TEST(test_SetDataNoPRCT) * Logical DB ID: PCL_LDBID_LOCAL with user 1 and seat 2 * ==> local USER value (user 1, seat 2) */ - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, (int)strlen(sysTimeBuffer)); fail_unless(ret == (int)strlen(sysTimeBuffer), "Wrong write size"); //printf("Write Buffer : %s\n", sysTimeBuffer); @@ -491,7 +409,6 @@ START_TEST(test_SetDataNoPRCT) fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read"); fail_unless(ret == (int)strlen(sysTimeBuffer), "Wrong read size"); //printf("read buffer : %s\n", buffer); -#endif } END_TEST @@ -503,14 +420,7 @@ END_TEST */ START_TEST(test_GetDataSize) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test of get data size"); - X_TEST_REPORT_TYPE(GOOD); */ - int size = 0; -#if 1 /** * Logical DB ID: PCL_LDBID_LOCAL with user 3 and seat 2 * ==> local USER value (user 3, seat 2) @@ -518,14 +428,12 @@ START_TEST(test_GetDataSize) size = pclKeyGetSize(PCL_LDBID_LOCAL, "status/open_document", 3, 2); fail_unless(size == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Invalid size"); - /** * Logical DB ID: 0x84 with user 2 and seat 1 * ==> shared user value accessible by A GROUP (user 2 and seat 1) */ size = pclKeyGetSize(0x84, "links/last_link", 2, 1); fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size"); -#endif } END_TEST @@ -537,15 +445,9 @@ END_TEST */ START_TEST(test_DeleteData) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test of delete data"); - X_TEST_REPORT_TYPE(GOOD); */ - int rval = 0; unsigned char buffer[READ_SIZE]; -#if 1 + // read data from key rval = pclKeyReadData(PCL_LDBID_LOCAL, "key_70", 1, 2, buffer, READ_SIZE); fail_unless(rval != EPERS_NOKEY, "Read form key key_70 fails"); @@ -571,244 +473,6 @@ START_TEST(test_DeleteData) // after deleting the key, reading from key must fail now! rval = pclKeyReadData(PCL_LDBID_LOCAL, "70", 1, 2, buffer, READ_SIZE); fail_unless(rval == EPERS_NOKEY, "Read form key 70 works, but should fail"); -#endif -} -END_TEST - - - -// creat blacklist file, if this does not exist -void data_setupBlacklist(void) -{ - -/// backup info -char gBackupInfo[] = { -"/media/doNotBackupMe.txt_START\n\ -/media/doNotBackupMe_01.txt\n\ -/media/doNotBackupMe_02.txt\n\ -/media/doNotBackupMe_03.txt\n\ -/media/doNotBackupMe_04.txt\n\ -/media/iDontWantDoBeBackuped_01.txt\n\ -/media/iDontWantDoBeBackuped_02.txt\n\ -/media/iDontWantDoBeBackuped_03.txt\n\ -/media/iDontWantDoBeBackuped_04.txt\n\ -/media/iDontWantDoBeBackuped_05.txt_END\n" -}; - - const char* backupBlacklist = "/Data/mnt-c/lt-persistence_client_library_test/BackupFileList.info"; - - if(access(backupBlacklist, F_OK) == -1) - { - int ret = 0; - 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 != (int)strlen(gBackupInfo)) - { - printf("data_setupBlacklist => Wrong size written: %d", ret); - } - close(handle); - } -} - - -/* - * Test the file interface: - * - open file - * - read / write - * - remove file - * - map file - * - get size - */ -START_TEST(test_DataFile) -{ - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test of data file"); - X_TEST_REPORT_TYPE(GOOD); */ - - int fd = 0, i = 0, idx = 0; - int size = 0, ret = 0, avail = 100; - int writeSize = 16*1024; - int fdArray[10] = {0}; - - unsigned char buffer[READ_SIZE] = {0}; - unsigned char wBuffer[READ_SIZE] = {0}; - const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media"; - char* writeBuffer; - char* fileMap = NULL; - -#if 1 - writeBuffer = malloc(writeSize); - - // fill buffer a sequence - for(i = 0; i<(writeSize/8); i++) - { - writeBuffer[idx++] = 'A'; - writeBuffer[idx++] = 'B'; - writeBuffer[idx++] = 'C'; - writeBuffer[idx++] = ' '; - writeBuffer[idx++] = 'D'; - writeBuffer[idx++] = 'E'; - writeBuffer[idx++] = 'F'; - writeBuffer[idx++] = ' '; - } - // create file - fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db", - O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); - close(fd); - - // open ------------------------------------------------------------ - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); - fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db"); - - - size = pclFileGetSize(fd); - fail_unless(size == 68, "Wrong file size"); - - - 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 == ((int)strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf - - ret = pclFileClose(fd); - fail_unless(ret == 0, "Failed to close file"); - - // open ------------------------------------------------------------ - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDBWrite.db", 1, 1); - fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db"); - - size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer)); - fail_unless(size == (int)strlen(writeBuffer), "Failed to write data"); - ret = pclFileClose(fd); - fail_unless(ret == 0, "Failed to close file"); - - // remove ---------------------------------------------------------- - ret = pclFileRemove(PCL_LDBID_LOCAL, "media/mediaDBWrite.db", 1, 1); - fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db"); - - fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR); - fail_unless(fd == -1, "Failed to remove file, file still exists"); - close(fd); - - // map file -------------------------------------------------------- - - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); - - size = pclFileGetSize(fd); - pclFileMapData(fileMap, size, 0, fd); - fail_unless(fileMap != MAP_FAILED, "Failed to map file"); - - ret = pclFileUnmapData(fileMap, size); - fail_unless(ret != -1, "Failed to unmap file"); - - // file seek - ret = pclFileSeek(fd, 0, SEEK_CUR); - fail_unless(ret == 0, "Failed to seek file - pos 0"); - - ret = pclFileSeek(fd, 8, SEEK_CUR); - fail_unless(ret == 8, "Failed to seek file - pos 8"); - - // negative test - size = pclFileGetSize(1024); - fail_unless(size < 0 , "Got size, but should not"); - - ret = pclFileClose(fd); - fail_unless(ret == 0, "Failed to close file"); - - // test backup blacklist functionality - fdArray[0] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 1, 1); - fdArray[1] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 1, 2); - fdArray[2] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 20, 10); - fdArray[3] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 200, 100); - - fdArray[4] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_01.txt", 2, 1); - fdArray[5] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_02.txt", 2, 1); - fdArray[6] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_03.txt", 2, 1); - fdArray[7] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_04.txt", 2, 1); - - fdArray[8] = pclFileOpen(PCL_LDBID_LOCAL, "media/iDontWantDoBeBackuped_04.txt", 2, 1); - fdArray[9] = pclFileOpen(PCL_LDBID_LOCAL, "media/iDontWantDoBeBackuped_05.txt_END", 2, 1); - - for(i=0; i<10; i++) - { - snprintf( (char*)wBuffer, 1024, "Test - %d", i); - pclFileWriteData(fdArray[i], wBuffer, strlen( (char*)wBuffer)); - } - - // - // test if backup blacklist works correctly - // - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/doNotBackupMe.txt_START~", F_OK); - fail_unless(avail == -1, "1. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/2/media/doNotBackupMe.txt_START~", F_OK); - fail_unless(avail == -1, "2. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/20/seat/10/media/doNotBackupMe.txt_START~", F_OK); - fail_unless(avail == -1, "3. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/200/seat/100/media/doNotBackupMe.txt_START~", F_OK); - fail_unless(avail == -1, "4. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_01.txt~", F_OK); - fail_unless(avail == -1, "5. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_02.txt~", F_OK); - fail_unless(avail == -1, "6. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_03.txt~", F_OK); - fail_unless(avail == -1, "7. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_04.txt~", F_OK); - fail_unless(avail == -1, "8. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/iDontWantDoBeBackuped_04.txt~", F_OK); - fail_unless(avail == -1, "9. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/iDontWantDoBeBackuped_05.txt_END~", F_OK); - fail_unless(avail == -1, "10. Failed backup => backup available, but should not"); - - for(i=0; i<10; i++) - { - pclFileClose(fdArray[i]); - } - - // write to file not in RCT - fd = pclFileOpen(PCL_LDBID_LOCAL, "nonRCT/aNonRctFile.db", 1, 1); - size = pclFileGetSize(fd); - size = pclFileWriteData(fd, "nonRCT/mediaDB.db", strlen("nonRCT/mediaDB.db")); - - - free(writeBuffer); -#endif -} -END_TEST - - - -START_TEST(test_DataFileConfDefault) -{ - int fd = 0; - char readBuffer[READ_SIZE] = {0}; - char* refBuffer01 = "Some default file content: 01 Configurable default data 01."; - char* refBuffer02 = "Some default file content: 02 Configurable default data 02."; - - // -- file interface --- - memset(readBuffer, 0, READ_SIZE); - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData_01.configurable", 99, 99); - (void)pclFileReadData(fd, readBuffer, READ_SIZE); - fail_unless(strncmp(readBuffer, refBuffer01, strlen(refBuffer01)) == 0, "Buffer not correctly read => mediaData_01.configurable"); - (void)pclFileClose(fd); - - - memset(readBuffer, 0, READ_SIZE); - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData_02.configurable", 99, 99); - (void)pclFileReadData(fd, readBuffer, READ_SIZE); - fail_unless(strncmp(readBuffer, refBuffer02, strlen(refBuffer02)) == 0, "Buffer not correctly read => mediaData_01.configurable"); - (void)pclFileClose(fd); } END_TEST @@ -816,10 +480,10 @@ END_TEST void data_setupBackup(void) { - int handle = -1; - const char* path = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db"; + int handle = -1; + const char* path = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db"; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; (void)pclInitLibrary(gTheAppId, shutdownReg); handle = open(path, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); @@ -829,224 +493,9 @@ void data_setupBackup(void) } } -START_TEST(test_DataFileBackupCreation) -{ - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test of file backup creation"); - X_TEST_REPORT_TYPE(GOOD); */ - - int fd_RW = 0, fd_RO = 0, rval = -1, handle = -1; - char* wBuffer = " ==> Appended: Test Data - test_DataFileRecovery! "; - const char* path = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db~"; - char rBuffer[1024] = {0}; - -#if 1 - - fd_RO = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_ReadOnly.db", 1, 1); - fail_unless(fd_RO != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db"); - - fd_RW = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_ReadWrite.db", 1, 1); - fail_unless(fd_RW != -1, "Could not open file ==> /media/mediaDB_ReadWrite.db"); - - rval = pclFileReadData(fd_RW, rBuffer, 10); - fail_unless(rval == 10, "Failed read 10 bytes"); - memset(rBuffer, 0, 1024); - - rval = pclFileReadData(fd_RW, rBuffer, 15); - fail_unless(rval == 15, "Failed read 15 bytes"); - memset(rBuffer, 0, 1024); - - rval = pclFileReadData(fd_RW, rBuffer, 20); - fail_unless(rval == 20, "Failed read 20 bytes"); - memset(rBuffer, 0, 1024); - - rval = pclFileWriteData(fd_RW, wBuffer, strlen(wBuffer)); - fail_unless(rval == (int)strlen(wBuffer), "Failed write data"); - - // verify the backup creation: - handle = open(path, O_RDWR); - fail_unless(handle != -1, "Could not open file ==> failed to access backup file"); - - rval = read(handle, rBuffer, 1024); - //printf(" * * * Backup: \nIst : %s \nSoll: %s\n", rBuffer, gWriteBackupTestData); - fail_unless(strncmp((char*)rBuffer, gWriteBackupTestData, strlen(gWriteBackupTestData)) == 0, "Backup not correctly read"); - - - (void)close(handle); - (void)pclFileClose(fd_RW); - (void)pclFileClose(fd_RO); - -#endif -} -END_TEST - - - -void data_setupRecovery(void) -{ - int i = 0; - char createPath[128] = {0}; - - int handleRecov = -1, handleToBackup = -1, handleToCs = -1; - char* corruptData = "Some corrupted data .. )=§?=34=/%&$%&()Ö:ÄNJH/)("; - const char* pathToRecover = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db"; - const char* pathToBackup = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db~"; - const char* pathToChecksum = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db~.crc"; - - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - (void)pclInitLibrary(gTheAppId, shutdownReg); - - // create directory, even if exist - snprintf(createPath, 128, "%s", gSourcePath ); - while(gPathSegemnts[i] != NULL) - { - strncat(createPath, gPathSegemnts[i++], 128-1); - mkdir(createPath, 0744); - } - - handleRecov = open(pathToRecover, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); - if(write(handleRecov, corruptData, strlen(corruptData)) == -1) - { - printf("setup test: failed to write test data: %s\n", pathToRecover); - } - - handleToBackup = open(pathToBackup, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); - if(write(handleToBackup, gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)) == -1) - { - printf("setup test: failed to write test data: %s\n", pathToBackup); - } - - handleToCs = open(pathToChecksum, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); - if(write(handleToCs, gRecovChecksum, strlen(gRecovChecksum)) == -1) - { - printf("setup test: failed to write test data: %s\n", pathToChecksum); - } - - close(handleRecov); - close(handleToBackup); - close(handleToCs); - -} - -START_TEST(test_DataFileRecovery) -{ - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test file recovery form backup"); - X_TEST_REPORT_TYPE(GOOD); */ - - int handle = 0; - unsigned char buffer[READ_SIZE] = {0}; - - handle = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_DataRecovery.db", 1, 1); - //printf("pclFileOpen => handle: %d\n", handle); - fail_unless(handle != -1, "Could not open file ==> /media/mediaDB_DataRecovery.db"); - - - /*ret = */(void)pclFileReadData(handle, buffer, READ_SIZE); - //printf(" ** pclFileReadData => ist-buffer : %s | size: %d\n", buffer, ret); - //printf(" ** pclFileReadData => soll-buffer: %s | size: %d\n", gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)); - fail_unless(strncmp((char*)buffer, gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)) == 0, "Recovery failed"); - - (void)pclFileClose(handle); -} -END_TEST - - - -/* - * The the handle function of the key and file interface. - */ -START_TEST(test_DataHandle) -{ - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test of data handle"); - X_TEST_REPORT_TYPE(GOOD); */ - - int handle1 = 0, handle2 = 0; - int handleArray[4] = {0}; - int ret = 0; - unsigned char buffer[READ_SIZE] = {0}; - -#if 1 - // test multiple handles - handleArray[0] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_01.db", 1, 1); - fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_01.db"); - - handleArray[1] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_02.db", 1, 1); - fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_02.db"); - - handleArray[2] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_03.db", 1, 1); - fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_03.db"); - - handleArray[3] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_04.db", 1, 1); - fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_04.db"); - - memset(buffer, 0, READ_SIZE); - ret = pclFileReadData(handleArray[0], buffer, READ_SIZE); - fail_unless(ret >= 0, "Failed to read handle idx \"0\"!!"); - fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_01.db", - strlen("/user/1/seat/1/media/mediaDB_write_01.db")) - == 0, "Buffer not correctly read => mediaDB_write_01.db"); - - memset(buffer, 0, READ_SIZE); - ret = pclFileReadData(handleArray[1], buffer, READ_SIZE); - fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_02.db", - strlen("/user/1/seat/1/media/mediaDB_write_02.db")) - == 0, "Buffer not correctly read => mediaDB_write_02.db"); - - memset(buffer, 0, READ_SIZE); - ret = pclFileReadData(handleArray[2], buffer, READ_SIZE); - fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_03.db", - strlen("/user/1/seat/1/media/mediaDB_write_03.db")) - == 0, "Buffer not correctly read => mediaDB_write_03.db"); - - memset(buffer, 0, READ_SIZE); - (void)pclFileReadData(handleArray[3], buffer, READ_SIZE); - fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_04.db", - strlen("/user/1/seat/1/media/mediaDB_write_04.db")) - == 0, "Buffer not correctly read => mediaDB_write_04.db"); - - ret = pclKeyHandleClose(handleArray[0]); - fail_unless(ret != -1, "Failed to close handle idx \"0\"!!"); - - ret = pclKeyHandleClose(handleArray[1]); - fail_unless(ret != -1, "Failed to close handle idx \"1\"!!"); - - ret = pclKeyHandleClose(handleArray[2]); - fail_unless(ret != -1, "Failed to close handle idx \"2\"!!"); - - ret = pclKeyHandleClose(handleArray[3]); - fail_unless(ret != -1, "Failed to close handle idx \"3\"!!"); - - // test key handles - handle2 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "statusHandle/open_document", 3, 2); - fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document"); - - ret = pclKeyHandleClose(handle2); - fail_unless(ret != -1, "Failed to close handle!!"); - - ret = pclKeyHandleClose(1024); - fail_unless(ret == EPERS_MAXHANDLE, "Max handle!!"); - - // test file handles - handle1 = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); - fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db"); - ret = pclFileClose(handle1); - fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db"); - ret = pclFileClose(1024); - fail_unless(ret == EPERS_MAXHANDLE, "1. Could close file, but should not!!"); -#endif -} -END_TEST @@ -1056,14 +505,7 @@ END_TEST */ START_TEST(test_DataHandleOpen) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test of data handle open"); - X_TEST_REPORT_TYPE(GOOD); */ - int hd1 = -2, hd2 = -2, hd3 = -2, hd4 = -2, hd5 = -2, hd6 = -2, hd7 = -2, hd8 = -2, hd9 = -2, ret = 0; -#if 1 // open handles ---------------------------------------------------- hd1 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "posHandle/last_position1", 0, 0); fail_unless(hd1 == 1, "Failed to open handle ==> /posHandle/last_position1"); @@ -1121,7 +563,6 @@ START_TEST(test_DataHandleOpen) ret = pclKeyHandleClose(hd9); fail_unless(ret != -1, "Failed to close handle!!"); -#endif } END_TEST @@ -1129,44 +570,36 @@ END_TEST START_TEST(test_Plugin) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test of plugins"); - X_TEST_REPORT_TYPE(GOOD); */ - - int ret = 0; - unsigned char buffer[READ_SIZE] = {0}; - -#if 1 + int ret = 0; + unsigned char buffer[READ_SIZE] = {0}; - ret = pclKeyReadData(PCL_LDBID_LOCAL, "secured", 0, 0, buffer, READ_SIZE); - //printf("B U F F E R - secure: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: secure!")); - fail_unless(ret == strlen("Custom plugin -> plugin_get_data: secure!") ); + ret = pclKeyReadData(PCL_LDBID_LOCAL, "secured", 0, 0, buffer, READ_SIZE); + //printf("B U F F E R - secure: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: secure!")); + fail_unless(ret == strlen("Custom plugin -> plugin_get_data: secure!") ); fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: secure!", strlen((char*)buffer)) == 0, "Buffer SECURE not correctly read"); - memset(buffer, 0, READ_SIZE); + memset(buffer, 0, READ_SIZE); - ret = pclKeyReadData(PCL_LDBID_LOCAL, "early", 0, 0, buffer, READ_SIZE); - //printf("B U F F E R - early: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: early!")); - fail_unless(ret == strlen("Custom plugin -> plugin_get_data: early!")); + ret = pclKeyReadData(PCL_LDBID_LOCAL, "early", 0, 0, buffer, READ_SIZE); + //printf("B U F F E R - early: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: early!")); + fail_unless(ret == strlen("Custom plugin -> plugin_get_data: early!")); fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: early!", strlen((char*)buffer)) == 0, "Buffer EARLY not correctly read"); - memset(buffer, 0, READ_SIZE); + memset(buffer, 0, READ_SIZE); - ret = pclKeyReadData(PCL_LDBID_LOCAL, "emergency", 0, 0, buffer, READ_SIZE); - //printf("B U F F E R - emergency: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: emergency!")); - fail_unless(ret == strlen("Custom plugin -> plugin_get_data: emergency!")); + ret = pclKeyReadData(PCL_LDBID_LOCAL, "emergency", 0, 0, buffer, READ_SIZE); + //printf("B U F F E R - emergency: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: emergency!")); + fail_unless(ret == strlen("Custom plugin -> plugin_get_data: emergency!")); fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: emergency!", strlen((char*)buffer)) == 0, "Buffer EMERGENCY not correctly read"); - memset(buffer, 0, READ_SIZE); + memset(buffer, 0, READ_SIZE); - ret = pclKeyReadData(PCL_LDBID_LOCAL, "hwinfo", 0, 0, buffer, READ_SIZE); - //printf("B U F F E R - hwinfo: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: hwinfo!")); - fail_unless(ret != EPERS_NOT_INITIALIZED); + ret = pclKeyReadData(PCL_LDBID_LOCAL, "hwinfo", 0, 0, buffer, READ_SIZE); + //printf("B U F F E R - hwinfo: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: hwinfo!")); + fail_unless(ret != EPERS_NOT_INITIALIZED); fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: hwinfo!", strlen((char*)buffer)) == 0, "Buffer HWINFO not correctly read"); - memset(buffer, 0, READ_SIZE); + memset(buffer, 0, READ_SIZE); ret = pclKeyReadData(PCL_LDBID_LOCAL, "custom2", 0, 0, buffer, READ_SIZE); //printf("B U F F E R - custom2: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: custom2!")); @@ -1183,17 +616,15 @@ START_TEST(test_Plugin) memset(buffer, 0, READ_SIZE); ret = pclKeyWriteData(PCL_LDBID_LOCAL, "custom3", 0, 0, (unsigned char*)"This is a message to write", READ_SIZE); - fail_unless(ret == 321456, "Failed to write custom data"); // plugin should return 321456 + fail_unless(ret == 321456, "Failed to write custom data"); // plugin should return 321456 ret = pclKeyGetSize(PCL_LDBID_LOCAL, "custom3", 0, 0); - fail_unless(ret == 44332211, "Failed query custom data size"); // plugin should return 44332211 + fail_unless(ret == 44332211, "Failed query custom data size"); // plugin should return 44332211 ret = pclKeyDelete(PCL_LDBID_LOCAL, "custom3", 0, 0); - fail_unless(ret == 13579, "Failed query custom data size"); // plugin should return 13579 - -#endif + fail_unless(ret == 13579, "Failed query custom data size"); // plugin should return 13579 } END_TEST @@ -1203,16 +634,9 @@ END_TEST START_TEST(test_ReadDefault) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test of read default"); - X_TEST_REPORT_TYPE(GOOD); */ - int ret = 0; unsigned char buffer[READ_SIZE] = {0}; -#if 1 ret = pclKeyReadData(PCL_LDBID_LOCAL, "statusHandle/default01", 3, 2, buffer, READ_SIZE); //printf(" --- test_ReadConfDefault => statusHandle/default01: %s => retIst: %d retSoll: %d\n", buffer, ret, strlen("DEFAULT_01!")); fail_unless(ret == strlen("DEFAULT_01!")); @@ -1225,8 +649,6 @@ START_TEST(test_ReadDefault) ret = pclKeyGetSize(PCL_LDBID_LOCAL, "statusHandle/default01", 3, 2); fail_unless(ret == strlen("DEFAULT_01!"), "Invalid size"); - -#endif } END_TEST @@ -1234,12 +656,6 @@ END_TEST START_TEST(test_ReadConfDefault) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test of configurable default data"); - X_TEST_REPORT_TYPE(GOOD); */ - int ret = 0; unsigned char buffer[READ_SIZE] = {0}; #if 1 @@ -1264,20 +680,14 @@ END_TEST START_TEST(test_WriteConfDefault) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Write configurable default data"); - X_TEST_REPORT_TYPE(GOOD); */ - - int ret = 0, fd = 0; + int ret = 0; unsigned char writeBuffer[] = "This is a test string"; unsigned char writeBuffer2[] = "And this is a test string which is different form previous test string"; unsigned char readBuffer[READ_SIZE] = {0}; // -- key-value interface --- - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "statusHandle/writeconfdefault01", PCL_USER_DEFAULTDATA, 0, writeBuffer, strlen((char*)writeBuffer)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "statusHandle/writeconfdefault01", PCL_USER_DEFAULTDATA, 0, writeBuffer, (int)strlen((char*)writeBuffer)); 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 == (int)strlen((char*)writeBuffer), "Write Conf default data: read size does not match"); @@ -1285,87 +695,38 @@ START_TEST(test_WriteConfDefault) //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)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "statusHandle/writeconfdefault01", PCL_USER_DEFAULTDATA, 0, writeBuffer2, (int)strlen((char*)writeBuffer2)); 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)); - - // -- file interface --- - memset(readBuffer, 0, READ_SIZE); - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData.configurable", PCL_USER_DEFAULTDATA, 99); - ret = pclFileWriteData(fd, writeBuffer, strlen((char*)writeBuffer)); - pclFileSeek(fd, 0, SEEK_SET); - ret = pclFileReadData(fd, readBuffer, READ_SIZE); - fail_unless(strncmp((char*)readBuffer, (char*)writeBuffer, strlen((char*)writeBuffer)) == 0, "Buffer not correctly read"); - (void)pclFileClose(fd); - - memset(readBuffer, 0, READ_SIZE); - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData.configurable", PCL_USER_DEFAULTDATA, 99); - ret = pclFileWriteData(fd, writeBuffer2, strlen((char*)writeBuffer2)); - pclFileSeek(fd, 0, SEEK_SET); - ret = pclFileReadData(fd, readBuffer, READ_SIZE); - fail_unless(strncmp((char*)readBuffer, (char*)writeBuffer2, strlen((char*)writeBuffer2)) == 0, "Buffer2 not correctly read"); - (void)pclFileClose(fd); - } END_TEST -START_TEST(test_GetPath) -{ - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test of get path"); - X_TEST_REPORT_TYPE(GOOD); */ - - int ret = 0; - char* path = NULL; - const char* thePath = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_create.db"; - unsigned int pathSize = 0; - -#if 1 - ret = pclFileCreatePath(PCL_LDBID_LOCAL, "media/mediaDB_create.db", 1, 1, &path, &pathSize); - - fail_unless(strncmp((char*)path, thePath, strlen((char*)path)) == 0, "Path not correct"); - fail_unless(pathSize == strlen((char*)path), "Path size not correct"); - - pclFileReleasePath(ret); -#endif -} -END_TEST - - START_TEST(test_InitDeinit) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Init and deinit library"); - X_TEST_REPORT_TYPE(GOOD); */ - int i = 0, rval = -1, handle = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; for(i=0; i<5; i++) { - // initialize and deinitialize 1. time - (void)pclInitLibrary(gTheAppId, shutdownReg); - pclDeinitLibrary(); + // initialize and deinitialize 1. time + (void)pclInitLibrary(gTheAppId, shutdownReg); + pclDeinitLibrary(); - // initialize and deinitialize 2. time - (void)pclInitLibrary(gTheAppId, shutdownReg); - pclDeinitLibrary(); + // initialize and deinitialize 2. time + (void)pclInitLibrary(gTheAppId, shutdownReg); + pclDeinitLibrary(); - // initialize and deinitialize 3. time - (void)pclInitLibrary(gTheAppId, shutdownReg); - pclDeinitLibrary(); + // initialize and deinitialize 3. time + (void)pclInitLibrary(gTheAppId, shutdownReg); + pclDeinitLibrary(); } @@ -1386,11 +747,6 @@ START_TEST(test_InitDeinit) pclInitLibrary(gTheAppId, PCL_SHUTDOWN_TYPE_NONE); - handle = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); - //printf("pclFileOpen: %d\n", handle); - fail_unless(handle >= 0, "Could not open file ==> /media/mediaDB.db"); - (void)pclFileClose(handle); - handle = pclKeyHandleOpen(PCL_LDBID_LOCAL, "posHandle/last_position", 0, 0); //printf("pclKeyHandleOpen: %d\n", handle); fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position"); @@ -1406,7 +762,6 @@ START_TEST(test_InitDeinit) rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); - //EPERS_COMMON pclDeinitLibrary(); @@ -1417,12 +772,6 @@ END_TEST START_TEST(test_NegHandle) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test negative handle"); - X_TEST_REPORT_TYPE(GOOD); */ - int handle = -1, ret = 0; int negativeHandle = -17; unsigned char buffer[128] = {0}; @@ -1461,19 +810,13 @@ END_TEST START_TEST(test_utf8_string) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test UTF8 String"); - X_TEST_REPORT_TYPE(GOOD); */ - - int ret = 0, size = 0; + int ret = 0, size = 0; const char* utf8StringBuffer = "String °^° Ñ text"; unsigned char buffer[128] = {0}; ret = pclKeyReadData(PCL_LDBID_LOCAL, "utf8String", 3, 2, buffer, 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"); + fail_unless(strncmp((char*)buffer, utf8StringBuffer, (size_t)ret-1) == 0, "Buffer not correctly read => 1"); size = pclKeyGetSize(PCL_LDBID_LOCAL, "utf8String", 3, 2); fail_unless(size == (int)strlen(utf8StringBuffer), "Invalid size"); @@ -1484,14 +827,21 @@ END_TEST START_TEST(test_Notifications) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test notifications"); - X_TEST_REPORT_TYPE(GOOD); */ - - pclKeyRegisterNotifyOnChange(0x20, "address/home_address", 1, 1, myChangeCallback); - pclKeyUnRegisterNotifyOnChange(0x20, "address/home_address", 1, 1, myChangeCallback); + int ret = 0; + ret = pclKeyRegisterNotifyOnChange(0x20, "address/home_address", 1, 1, myChangeCallback); + fail_unless(ret == 0, "Failed to register"); + + ret = pclKeyUnRegisterNotifyOnChange(0x20, "address/home_address", 1, 1, myChangeCallback); + fail_unless(ret == 0, "Failed to register"); + + ret = pclKeyUnRegisterNotifyOnChange(PCL_LDBID_PUBLIC, "aSharedResource", 1, 1, myChangeCallback); + fail_unless(ret == 0, "Failed to register"); + + ret = pclKeyUnRegisterNotifyOnChange(PCL_LDBID_LOCAL, "status/open_document", 1, 1, myChangeCallback); + fail_unless(ret == EPERS_NOTIFY_NOT_ALLOWED, "Possible to register, but should not - is local variable"); + + ret = pclKeyUnRegisterNotifyOnChange(0x20, "notInRCT", 1, 1, myChangeCallback); + fail_unless(ret == EPERS_NOKEYDATA, "Possible to register, but should not - not in rct"); } END_TEST @@ -1499,14 +849,8 @@ END_TEST #if USE_APPCHECK START_TEST(test_ValidApplication) { - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test valid applications"); - X_TEST_REPORT_TYPE(GOOD); */ - - int ret = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int ret = 0; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; unsigned char buffer[128] = {0}; ret = pclInitLibrary("InvalidAppID", shutdownReg); @@ -1545,44 +889,6 @@ END_TEST #endif - -START_TEST(test_VerifyROnly) -{ - /* X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); - X_TEST_REPORT_COMP_NAME("libpersistence_client_library"); - X_TEST_REPORT_REFERENCE("NONE"); - X_TEST_REPORT_DESCRIPTION("Test read only file"); - X_TEST_REPORT_TYPE(GOOD); */ - - int fd = 0; - int rval = 0; - char* wBuffer = "This is a test string"; - - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_ReadOnly.db", 1, 1); - fail_unless(fd != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db"); - - rval = pclFileWriteData(fd, wBuffer, strlen(wBuffer)); - fail_unless(rval == EPERS_RESOURCE_READ_ONLY, "Write to read only file is possible, but should not ==> /media/mediaDB_ReadOnly.db"); - - rval = pclFileClose(fd); - fail_unless(rval == 0, "Failed to close file: media/mediaDB_ReadOnly.db"); - - /* - char* path = NULL; - unsigned int pathSize = 0; - const char* thePath = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadOnly.db"; - rval = pclFileCreatePath(PCL_LDBID_LOCAL, "media/mediaDB_ReadOnly.db", 1, 1, &path, &pathSize); - printf("pclFileCreatePath: %d | %s \n ", rval, path); - x_fail_unless(strncmp((char*)path, thePath, strlen((char*)path)) == 0, "Path not correct"); - - pclFileReleasePath(rval); - */ -} -END_TEST - - - - START_TEST(test_PAS_DbusInterface) { // let the administration servis generate a message to the PCL @@ -1657,7 +963,7 @@ END_TEST START_TEST(test_SharedAccess) { int ret = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; unsigned char buffer[256] = {0}; char sysTimeBuffer[256]; struct tm *locTime; @@ -1671,7 +977,7 @@ START_TEST(test_SharedAccess) (void)pclInitLibrary(gTheAppId, shutdownReg); // use the app id, the resource is registered for - ret = pclKeyWriteData(PCL_LDBID_PUBLIC, "aSharedResource", 1, 1, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer)); + ret = pclKeyWriteData(PCL_LDBID_PUBLIC, "aSharedResource", 1, 1, (unsigned char*)sysTimeBuffer, (int)strlen(sysTimeBuffer)); fail_unless(ret == (int)strlen(sysTimeBuffer), "Failed to write shared data "); ret = pclKeyReadData(PCL_LDBID_PUBLIC, "aSharedResource", 1, 1, buffer, 256); @@ -1683,7 +989,7 @@ START_TEST(test_SharedAccess) (void)pclInitLibrary("node-health-monitor", shutdownReg); // now use a different app id, which is not able to write this resource - ret = pclKeyWriteData(PCL_LDBID_PUBLIC, "aSharedResource", 1, 1, (unsigned char*)"This is a test Buffer", strlen("This is a test Buffer")); + ret = pclKeyWriteData(PCL_LDBID_PUBLIC, "aSharedResource", 1, 1, (unsigned char*)"This is a test Buffer", (int)strlen("This is a test Buffer")); fail_unless(ret == EPERS_NOT_RESP_APP, "Able to write shared data, but should not!!"); ret = pclKeyReadData(PCL_LDBID_PUBLIC, "aSharedResource", 1, 1, buffer, 256); @@ -1699,7 +1005,7 @@ END_TEST START_TEST(test_VO722) { int ret = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; unsigned char buffer[256] = {0}; char* writeBuffer[] = {"VO722 - TestString One", @@ -1711,7 +1017,7 @@ START_TEST(test_VO722) "2 - VO722 - Test - String Three -", }; (void)pclInitLibrary(gTheAppId, shutdownReg); // use the app id, the resource is registered for - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 1, 2, (unsigned char*)writeBuffer[0], strlen(writeBuffer[0])); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 1, 2, (unsigned char*)writeBuffer[0], (int)strlen(writeBuffer[0])); fail_unless(ret == (int)strlen(writeBuffer[0]), "Wrong write size"); memset(buffer, 0, 256); @@ -1720,7 +1026,7 @@ START_TEST(test_VO722) fail_unless(ret == (int)strlen(writeBuffer[0]), "Failed to read shared data "); fail_unless(strncmp((char*)buffer, writeBuffer[0], strlen((char*)writeBuffer[0])) == 0, "Buffer not correctly read - 1.1"); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 1, 2, (unsigned char*)writeBuffer[1], strlen(writeBuffer[1])); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 1, 2, (unsigned char*)writeBuffer[1], (int)strlen(writeBuffer[1])); fail_unless(ret == (int)strlen(writeBuffer[1]), "Wrong write size"); memset(buffer, 0, 256); @@ -1729,7 +1035,7 @@ START_TEST(test_VO722) fail_unless(ret == (int)strlen(writeBuffer[1]), "Failed to read shared data "); fail_unless(strncmp((char*)buffer, writeBuffer[1], strlen((char*)writeBuffer[1])) == 0, "Buffer not correctly read - 1.2"); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 1, 2, (unsigned char*)writeBuffer[2], strlen(writeBuffer[2])); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 1, 2, (unsigned char*)writeBuffer[2], (int)strlen(writeBuffer[2])); fail_unless(ret == (int)strlen(writeBuffer[2]), "Wrong write size"); pclDeinitLibrary(); @@ -1751,7 +1057,7 @@ START_TEST(test_VO722) (void)pclInitLibrary(gTheAppId, shutdownReg); // use the app id, the resource is registered for - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 0, 0, (unsigned char*)writeBuffer2[0], strlen(writeBuffer2[0])); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 0, 0, (unsigned char*)writeBuffer2[0], (int)strlen(writeBuffer2[0])); fail_unless(ret == (int)strlen(writeBuffer2[0]), "Wrong write size"); memset(buffer, 0, 256); @@ -1761,7 +1067,7 @@ START_TEST(test_VO722) fail_unless(strncmp((char*)buffer, writeBuffer2[0], strlen((char*)writeBuffer2[0])) == 0, "Buffer not correctly read - 2.1"); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 0, 0, (unsigned char*)writeBuffer2[1], strlen(writeBuffer2[1])); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 0, 0, (unsigned char*)writeBuffer2[1], (int)strlen(writeBuffer2[1])); fail_unless(ret == (int)strlen(writeBuffer2[1]), "Wrong write size"); memset(buffer, 0, 256); @@ -1770,7 +1076,7 @@ START_TEST(test_VO722) fail_unless(ret == (int)strlen(writeBuffer2[1]), "Failed to read shared data "); fail_unless(strncmp((char*)buffer, writeBuffer2[1], strlen((char*)writeBuffer2[1])) == 0, "Buffer not correctly read - 2.2"); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 0, 0, (unsigned char*)writeBuffer2[2], strlen(writeBuffer2[2])); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 0, 0, (unsigned char*)writeBuffer2[2], (int)strlen(writeBuffer2[2])); fail_unless(ret == (int)strlen(writeBuffer2[2]), "Wrong write size"); pclDeinitLibrary(); @@ -1790,115 +1096,12 @@ END_TEST - -void runTestSequence(const char* resourceID) -{ - int fd1 = 0, fd2 = 0, rval = 0; - unsigned char buffer[READ_SIZE] = {0}; - unsigned char writebuffer[] = {" _Updates file_ "}; - unsigned char writebuffer2[] = {" _New Data_ "}; - - // part one: write to file - // ------------------------------------------ - fd1 = pclFileOpen(PCL_LDBID_LOCAL, resourceID, 1, 1); - fail_unless(fd1 != -1, "Could not open file ==> dataLoc/file.txt"); - - (void)pclFileReadData(fd1, buffer, READ_SIZE); - (void)pclFileWriteData(fd1, writebuffer, strlen((char*)writebuffer)); - - #if 1 - rval = pclFileClose(fd1); - fail_unless(rval == 0, "Could not close file ==> dataLoc/file.txt"); - #else - printf("\nN O C L O S E\n\n"); - #endif - - // part two: remove file - // ------------------------------------------ - rval = pclFileRemove(PCL_LDBID_LOCAL, resourceID, 1, 1); - fail_unless(rval == 0, "Could not remove file ==> dataLoc/file.txt"); - - - // part three: open file again, and write to it - // ------------------------------------------ - fd2 = pclFileOpen(PCL_LDBID_LOCAL, resourceID, 1, 1); - fail_unless(fd1 != -1, "Could not open file ==> dataLoc/file.txt"); - - (void)pclFileWriteData(fd2, writebuffer2, strlen((char*)writebuffer2)); - - rval = pclFileClose(fd2); - fail_unless(rval == 0, "Could not close file ==> dataLoc/file.txt"); -} - - -START_TEST(test_FileTest) -{ - int i = 0; - const char* resourceID_01 = "dataLoc/fileB.txt"; - const char* resourceID_02 = "dataLoc/fileA.txt"; - int fdArray[10] = {0}; - - const char* resourceIDArray[] = {"dataLoc/fileC.txt", - "dataLoc/fileD.txt", - "dataLoc/fileE.txt", - "dataLoc/fileF.txt", - "dataLoc/fileG.txt"}; -#if 1 - const char* testStringsFirst[] = {"FIRST - - Test Data START - dataLoc/fileC.txt - Test Data END ", - "FIRST - - Test Data START - dataLoc/fileD.txt - Test Data END ", - "FIRST - - Test Data START - dataLoc/fileE.txt - Test Data END ", - "FIRST - - Test Data START - dataLoc/fileF.txt - Test Data END ", - "FIRST - - Test Data START - dataLoc/fileG.txt - Test Data END "}; - - const char* testStringsSecond[] = {"Second - - Test Data START - dataLoc/fileC.txt - Test Data END ", - "Second - - Test Data START - dataLoc/fileD.txt - Test Data END ", - "Second - - Test Data START - dataLoc/fileE.txt - Test Data END ", - "Second - - Test Data START - dataLoc/fileF.txt - Test Data END ", - "Second - - Test Data START - dataLoc/fileG.txt - Test Data END "}; -#endif - // open files - - for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) - { - fdArray[i] = pclFileOpen(PCL_LDBID_LOCAL, resourceIDArray[i], 1, 1); - //printf("******** test_FileTest => pclFileOpen: %s -- %d\n", resourceIDArray[i], fdArray[i] ); - fail_unless(fdArray[i] != -1, "Could not open file ==> file: %s", resourceIDArray[i]); - } - - // write to files - for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) - { - (void)pclFileWriteData(fdArray[i], testStringsFirst[i], strlen((char*)testStringsFirst[i])); - } - - runTestSequence(resourceID_01); - runTestSequence(resourceID_02); - - - // write to files again - for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) - { - (void)pclFileWriteData(fdArray[i], testStringsSecond[i], strlen((char*)testStringsSecond[i])); - } - - - // close files - for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) - { - fdArray[i] = pclFileClose(fdArray[i]); - fail_unless(fdArray[i] == 0, "Could not close file ==> file: %s - %d", resourceIDArray[i], fdArray[i]); - } -} -END_TEST - - - START_TEST(test_NoRct) { int ret = 0; const char writeBuffer[] = "This is a test string"; - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "someResourceId", 0, 0, (unsigned char*)writeBuffer, strlen(writeBuffer)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "someResourceId", 0, 0, (unsigned char*)writeBuffer, (int)strlen(writeBuffer)); fail_unless(ret == EPERS_NOPRCTABLE, "RCT available, but should not"); } END_TEST @@ -1907,7 +1110,7 @@ END_TEST START_TEST(test_InvalidPluginfConf) { - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; const char* envVariable = "PERS_CLIENT_LIB_CUSTOM_LOAD"; // change to an invalid plugin configuration file using environment variable @@ -1966,11 +1169,16 @@ void* readThread(void* userData) { int ret = 0, i = 0; unsigned char buffer[READ_SIZE] = {0}; + char threadName[64] = {0}; + char* uData = NULL; + uData = (char*)userData; - pthread_barrier_wait(&barrier); - usleep(10000); + memset(threadName, 0, 64-1); + memcpy(threadName, uData, 64-1); + threadName[64-1] = '\0'; - (void)userData; + pthread_barrier_wait(&gBarrierOne); + usleep(5000); for(i=0; i<NUM_OF_READS; i++) { @@ -1983,6 +1191,7 @@ void* readThread(void* userData) fail_unless(strncmp((char*)buffer, "CACHE_ +48 10' 38.95, +8 44' 39.06", strlen((char*)buffer)) == 0, "Buffer not correctly read - pos/last_position"); fail_unless(ret == strlen("CACHE_ +48 10' 38.95, +8 44' 39.06")); + usleep(3000); /** * Logical DB ID: PCL_LDBID_LOCAL with user 3 and seat 2 @@ -1993,6 +1202,7 @@ void* readThread(void* userData) fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, "Buffer not correctly read - status/open_document"); fail_unless(ret == strlen("WT_ /var/opt/user_manual_climateControl.pdf")); + usleep(2000); /** * Logical DB ID: 0x20 with user 4 and seat 0 @@ -2003,6 +1213,7 @@ void* readThread(void* userData) fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0, "Buffer not correctly read - address/home_address"); fail_unless(ret == strlen("WT_ 55327 Heimatstadt, Wohnstrasse 31")); + usleep(5000); /** * Logical DB ID: PCL_LDBID_LOCAL with user 0 and seat 0 @@ -2010,9 +1221,11 @@ void* readThread(void* userData) */ memset(buffer, 0, READ_SIZE); ret = pclKeyReadData(PCL_LDBID_LOCAL, "pos/last_satellites", 0, 0, buffer, READ_SIZE); + fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0, "Buffer not correctly read - pos/last_satellites"); fail_unless(ret == strlen("WT_ 17")); + usleep(2000); /** * Logical DB ID: 0x20 with user 4 and seat 0 @@ -2023,20 +1236,21 @@ void* readThread(void* userData) fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0, "Buffer not correctly read - links/last_link"); fail_unless(ret == strlen("CACHE_ /last_exit/queens")); + usleep(3000); } - return NULL; + pthread_exit(0); } + + START_TEST(test_MultiThreadedRead) { - pthread_t threads[NUM_THREADS]; - int* retval; + pthread_t gReadthreads[NUM_THREADS]; int i=0; - int success[NUM_THREADS] = {0}; char threadName[NUM_THREADS][NAME_LEN]; - if(pthread_barrier_init(&barrier, NULL, NUM_THREADS) == 0) + if(pthread_barrier_init(&gBarrierOne, NULL, NUM_THREADS) == 0) { for(i=0; i<NUM_THREADS; i++) { @@ -2044,21 +1258,19 @@ START_TEST(test_MultiThreadedRead) sprintf(threadName[i], "R-Thread -%3d-", i); threadName[i][NAME_LEN-1] = '\0'; - if(pthread_create(&threads[i], NULL, readThread, threadName[i]) != -1) + if(pthread_create(&gReadthreads[i], NULL, readThread, threadName[i]) != -1) { - (void)pthread_setname_np(threads[i], threadName[i]); - success[i] = 1; + (void)pthread_setname_np(gReadthreads[i], threadName[i]); } } - // wait for(i=0; i<NUM_THREADS; i++) { - if(success[i] == 1) - pthread_join(threads[i], (void**)&retval); // wait until thread has ended + if(pthread_join(gReadthreads[i], NULL) != 0) // wait until thread has ended + printf("pthread_join - FAILED [%d]\n", i); } - if(pthread_barrier_destroy(&barrier) != 0) + if(pthread_barrier_destroy(&gBarrierOne) != 0) printf("Failed to destroy barrier\n"); } else @@ -2070,13 +1282,6 @@ END_TEST - -typedef struct s_threadData -{ - char threadName[NAME_LEN]; - int index; -} t_threadData; - void* writeThread(void* userData) { int ret = 0, i = 0; @@ -2092,7 +1297,7 @@ void* writeThread(void* userData) strncpy(payload, threadData->threadName, NAME_LEN); payload[NAME_LEN-1] = '\0'; // string end termination - pthread_barrier_wait(&barrier); + pthread_barrier_wait(&gBarrierTwo); usleep(5000); for(i=0; i<NUM_OF_WRITES; i++) @@ -2101,91 +1306,90 @@ void* writeThread(void* userData) locTime = localtime(&t); clock_gettime(CLOCK_MONOTONIC, &curTime); memset(sysTimeBuffer, 0, 128); - snprintf(sysTimeBuffer, 128, "\"%s %d.%d.%d - %d:%.2d:%.2d::%.4d:%.8ld Uhr\"", dayOfWeek[locTime->tm_wday], locTime->tm_mday, locTime->tm_mon+1, (locTime->tm_year+1900), - locTime->tm_hour, locTime->tm_min, locTime->tm_sec, (int)(curTime.tv_nsec / 1.0e6), curTime.tv_nsec ); + snprintf(sysTimeBuffer, 128, "\"%s %d.%d.%d - %d:%.2d:%.2d::%.4d:%.8ld Uhr\"", dayOfWeek[locTime->tm_wday], (int)locTime->tm_mday, (int)locTime->tm_mon+1, (int)(locTime->tm_year+1900), + (int)locTime->tm_hour, (int)locTime->tm_min, (int)locTime->tm_sec, (int)((int)curTime.tv_nsec / 1.0e6), curTime.tv_nsec ); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "69", threadData->index, 2, (unsigned char*)payload, strlen(payload)); + ret = pclKeyWriteData((unsigned int)PCL_LDBID_LOCAL, "69", (unsigned int)threadData->index, 2, (unsigned char*)payload, (int)strlen(payload)); fail_unless(ret == (int)strlen(payload), "Wrong write size"); + usleep(2000); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, payload, 1, threadData->index, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, payload, 1, (unsigned int)threadData->index, (unsigned char*)sysTimeBuffer, (int)strlen(sysTimeBuffer)); fail_unless(ret == (int)strlen(sysTimeBuffer), "Wrong write size"); + usleep(3000); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "70", 1, 2, (unsigned char*)staticString, strlen(staticString)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "70", 1, 2, (unsigned char*)staticString, (int)strlen(staticString)); fail_unless(ret == (int)strlen(staticString), "Wrong write size"); - + usleep(3000); memset(buffer, 0, READ_SIZE); - ret = pclKeyReadData(PCL_LDBID_LOCAL, "69", threadData->index, 2, buffer, READ_SIZE); + ret = pclKeyReadData(PCL_LDBID_LOCAL, "69", (unsigned int)threadData->index, 2, buffer, READ_SIZE); fail_unless(strncmp((char*)buffer, payload, strlen(payload)) == 0, "2: Buffer not correctly read"); fail_unless(ret == (int)strlen(payload), "Wrong read size"); + usleep(5000); memset(buffer, 0, READ_SIZE); - ret = pclKeyReadData(PCL_LDBID_LOCAL, payload, 1, threadData->index, buffer, READ_SIZE); + ret = pclKeyReadData(PCL_LDBID_LOCAL, payload, 1, (unsigned int)threadData->index, buffer, READ_SIZE); fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "1: Buffer not correctly read"); fail_unless(ret == (int)strlen(sysTimeBuffer), "Wrong read size"); + usleep(2000); memset(buffer, 0, READ_SIZE); ret = pclKeyReadData(PCL_LDBID_LOCAL, "70", 1, 2, buffer, READ_SIZE); fail_unless(strncmp((char*)buffer, staticString, strlen(staticString)) == 0, "3: Buffer not correctly read"); fail_unless(ret == (int)strlen(staticString), "Wrong read size"); + usleep(3000); } - return NULL; + pthread_exit(0); } + START_TEST(test_MultiThreadedWrite) { - pthread_t threads[NUM_THREADS]; - int* retval; int i=0; - int success[NUM_THREADS] = {0}; + pthread_t gWritethreads[NUM_THREADS]; t_threadData threadData[NUM_THREADS]; - if(pthread_barrier_init(&barrier, NULL, NUM_THREADS) == 0) + if(pthread_barrier_init(&gBarrierTwo, NULL, NUM_THREADS) == 0) { for(i=0; i<NUM_THREADS; i++) { - memset(threadData[i].threadName, 0, NAME_LEN); + memset(threadData[i].threadName, 0, NAME_LEN); sprintf(threadData[i].threadName, "-%3d-W-Key-%3d-", i, i); threadData[i].threadName[NAME_LEN-1] = '\0'; threadData[i].index = i; - if(pthread_create(&threads[i], NULL, writeThread, &(threadData[i])) != -1) + if(pthread_create(&gWritethreads[i], NULL, writeThread, &(threadData[i])) != -1) { - (void)pthread_setname_np(threads[i], threadData[i].threadName); - success[i] = 1; + (void)pthread_setname_np(gWritethreads[i], threadData[i].threadName); } } - // wait for(i=0; i<NUM_THREADS; i++) { - if(success[i] == 1) - pthread_join(threads[i], (void**)&retval); // wait until thread has ended + if(pthread_join(gWritethreads[i], NULL) != 0) // wait until thread has ended + printf("pthread_join - FAILED [%d]\n", i); } - if(pthread_barrier_destroy(&barrier) != 0) + if(pthread_barrier_destroy(&gBarrierTwo) != 0) printf("Failed to destroy barrier\n"); } else { printf("Failed to init barrier\n"); } - - printf("MultiWriteEnd\n"); } END_TEST + static Suite * persistencyClientLib_suite() { - const char* testSuiteName = "Persistency_client_library"; + const char* testSuiteName = "Persistency Client Library (Key-API)"; Suite * s = suite_create(testSuiteName); - //setenv("CK_RUN_SUITE", testSuiteName, 1); - TCase * tc_persGetData = tcase_create("GetData"); tcase_add_test(tc_persGetData, test_GetData); tcase_set_timeout(tc_persGetData, 3); @@ -2210,29 +1414,10 @@ static Suite * persistencyClientLib_suite() tcase_add_test(tc_persGetDataHandle, test_GetDataHandle); tcase_set_timeout(tc_persGetDataHandle, 3); - TCase * tc_persDataHandle = tcase_create("DataHandle"); - tcase_add_test(tc_persDataHandle, test_DataHandle); - tcase_set_timeout(tc_persGetData, 3); - TCase * tc_persDataHandleOpen = tcase_create("DataHandleOpen"); tcase_add_test(tc_persDataHandleOpen, test_DataHandleOpen); tcase_set_timeout(tc_persDataHandleOpen, 3); - TCase * tc_persDataFile = tcase_create("DataFile"); - tcase_add_test(tc_persDataFile, test_DataFile); - tcase_set_timeout(tc_persDataFile, 3); - - TCase * tc_DataFileConfDefault = tcase_create("DataFileConfDefault"); - tcase_add_test(tc_DataFileConfDefault, test_DataFileConfDefault); - tcase_set_timeout(tc_DataFileConfDefault, 3); - - TCase * tc_persDataFileBackupCreation = tcase_create("DataFileBackupCreation"); - tcase_add_test(tc_persDataFileBackupCreation, test_DataFileBackupCreation); - tcase_set_timeout(tc_persDataFileBackupCreation, 3); - - TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery"); - tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery); - tcase_set_timeout(tc_persDataFileRecovery, 3); TCase * tc_Plugin = tcase_create("Plugin"); tcase_add_test(tc_Plugin, test_Plugin); @@ -2250,10 +1435,6 @@ static Suite * persistencyClientLib_suite() tcase_add_test(tc_WriteConfDefault, test_WriteConfDefault); tcase_set_timeout(tc_WriteConfDefault, 3); - TCase * tc_GetPath = tcase_create("GetPath"); - tcase_add_test(tc_GetPath, test_GetPath); - tcase_set_timeout(tc_GetPath, 3); - TCase * tc_InitDeinit = tcase_create("InitDeinit"); tcase_add_test(tc_InitDeinit, test_InitDeinit); tcase_set_timeout(tc_InitDeinit, 3); @@ -2284,10 +1465,6 @@ static Suite * persistencyClientLib_suite() tcase_add_test(tc_LC_DbusInterface, test_LC_DbusInterface); tcase_set_timeout(tc_LC_DbusInterface, 3); - TCase * tc_VerifyROnly = tcase_create("VerifyROnly"); - tcase_add_test(tc_VerifyROnly, test_VerifyROnly); - tcase_set_timeout(tc_VerifyROnly, 3); - TCase * tc_SharedAccess = tcase_create("SharedAccess"); tcase_add_test(tc_SharedAccess, test_SharedAccess); tcase_set_timeout(tc_SharedAccess, 3); @@ -2296,10 +1473,6 @@ static Suite * persistencyClientLib_suite() tcase_add_test(tc_VO722, test_VO722); tcase_set_timeout(tc_VO722, 5); - TCase * tc_FileTest = tcase_create("FileTest"); - tcase_add_test(tc_FileTest, test_FileTest); - tcase_set_timeout(tc_FileTest, 3); - TCase * tc_NoRct = tcase_create("NoRct"); tcase_add_test(tc_NoRct, test_NoRct); tcase_set_timeout(tc_NoRct, 3); @@ -2319,13 +1492,12 @@ static Suite * persistencyClientLib_suite() tcase_add_test(tc_MultiThreadedWrite, test_MultiThreadedWrite); tcase_set_timeout(tc_MultiThreadedWrite, 20); + suite_add_tcase(s, tc_persGetData); + tcase_add_checked_fixture(tc_persGetData, data_setup, data_teardown); suite_add_tcase(s, tc_persSetData); tcase_add_checked_fixture(tc_persSetData, data_setup, data_teardown); - suite_add_tcase(s, tc_persGetData); - tcase_add_checked_fixture(tc_persGetData, data_setup, data_teardown); - suite_add_tcase(s, tc_persGetDataHandle); tcase_add_checked_fixture(tc_persGetDataHandle, data_setup, data_teardown); @@ -2338,9 +1510,6 @@ static Suite * persistencyClientLib_suite() suite_add_tcase(s, tc_persDeleteData); tcase_add_checked_fixture(tc_persDeleteData, data_setup, data_teardown); - suite_add_tcase(s, tc_persDataHandle); - tcase_add_checked_fixture(tc_persDataHandle, data_setup, data_teardown); - suite_add_tcase(s, tc_persDataHandleOpen); tcase_add_checked_fixture(tc_persDataHandleOpen, data_setup, data_teardown); @@ -2353,17 +1522,6 @@ static Suite * persistencyClientLib_suite() suite_add_tcase(s, tc_WriteConfDefault); tcase_add_checked_fixture(tc_WriteConfDefault, data_setup, data_teardown); - suite_add_tcase(s, tc_persDataFile); - tcase_add_checked_fixture(tc_persDataFile, data_setup, data_teardown); - - suite_add_tcase(s, tc_persDataFileBackupCreation); - tcase_add_checked_fixture(tc_persDataFileBackupCreation, data_setupBackup, data_teardown); - - suite_add_tcase(s, tc_persDataFileRecovery); - tcase_add_checked_fixture(tc_persDataFileRecovery, data_setupRecovery, data_teardown); - suite_add_tcase(s, tc_GetPath); - tcase_add_checked_fixture(tc_GetPath, data_setup, data_teardown); - suite_add_tcase(s, tc_NegHandle); tcase_add_checked_fixture(tc_NegHandle, data_setup, data_teardown); @@ -2376,23 +1534,23 @@ static Suite * persistencyClientLib_suite() suite_add_tcase(s, tc_Plugin); tcase_add_checked_fixture(tc_Plugin, data_setup, data_teardown); - suite_add_tcase(s, tc_VerifyROnly); - tcase_add_checked_fixture(tc_VerifyROnly, data_setup, data_teardown); - - suite_add_tcase(s, tc_DataFileConfDefault); - tcase_add_checked_fixture(tc_DataFileConfDefault, data_setup, data_teardown); - suite_add_tcase(s, tc_SharedAccess); suite_add_tcase(s, tc_VO722); - suite_add_tcase(s, tc_FileTest); - tcase_add_checked_fixture(tc_FileTest, data_setup_browser, data_teardown); - suite_add_tcase(s, tc_InvalidPluginfConf); suite_add_tcase(s, tc_InitDeinit); + suite_add_tcase(s, tc_SharedData); + tcase_add_checked_fixture(tc_SharedData, data_setup, data_teardown); + + suite_add_tcase(s, tc_MultiThreadedRead); + tcase_add_checked_fixture(tc_MultiThreadedRead, data_setup, data_teardown); + + suite_add_tcase(s, tc_MultiThreadedWrite); + tcase_add_checked_fixture(tc_MultiThreadedWrite, data_setup, data_teardown); + #if USE_APPCHECK suite_add_tcase(s, tc_ValidApplication); #else @@ -2405,35 +1563,18 @@ static Suite * persistencyClientLib_suite() tcase_add_checked_fixture(tc_PAS_DbusInterface, data_setup, data_teardown); tcase_set_timeout(tc_PAS_DbusInterface, 10); - suite_add_tcase(s, tc_LC_DbusInterface); tcase_add_checked_fixture(tc_LC_DbusInterface, data_setup, data_teardown); tcase_set_timeout(tc_LC_DbusInterface, 8); #endif - suite_add_tcase(s, tc_SharedData); - tcase_add_checked_fixture(tc_SharedData, data_setup, data_teardown); - - - suite_add_tcase(s, tc_MultiThreadedRead); - tcase_add_checked_fixture(tc_MultiThreadedRead, data_setup, data_teardown); - - suite_add_tcase(s, tc_MultiThreadedWrite); - tcase_add_checked_fixture(tc_MultiThreadedWrite, data_setup, data_teardown); - return s; } int main(int argc, char *argv[]) { - int nr_failed = 0, - nr_run = 0, - i = 0; - //int fail = 0; - - TestResult** tResult; - + int nr_failed = 0; (void)argv; // assign application name @@ -2441,133 +1582,40 @@ int main(int argc, char *argv[]) gTheAppId[MaxAppNameLen-1] = '\0'; /// debug log and trace (DLT) setup - DLT_REGISTER_APP("PCLt","tests the persistence client library"); - - DLT_ENABLE_LOCAL_PRINT(); - - -#if 0 - //Manual test of concurrent access - // start 2 instances of persistence-client_library_test - // persistence-client_library_test -w 5 - // persistence-client_library_test -r 5 - // press any key to proceed in the test - - int opt = 0; - int write = 0; - int read = 0; - int numloops = 0; - - while ((opt = getopt(argc, argv, "w:r:")) != -1) - { - switch (opt) - { - case 'w': - write = 1; - numloops = atoi(optarg); - break; - case 'r': - read = 1; - numloops = atoi(optarg); - break; - } - } - - - const char* appId_one = "lt-persistence_client_library_test"; - const char* appId_two = "concurrency_test"; - if (write) - { - int ret = 0, i = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - unsigned char buffer[READ_SIZE] = { 0 }; - - (void) pclInitLibrary(appId_one, shutdownReg); + DLT_REGISTER_APP("PCLT", "PCL test"); - for (i = 0; i < numloops; i++) - { - getchar(); - printf("write: [%d] \n", i); + DLT_REGISTER_CONTEXT(gPcltDLTContext, "PCLt", "Context for PCL testing"); - ret = pclKeyWriteData(0x20, "links/last_link2", 2, 1, (unsigned char*) "Test notify shared data", - strlen("Test notify shared data")); - if (ret < 0) - printf("Failed to write data: %d\n", ret); - } - pclDeinitLibrary(); - sleep(1); - _exit(EXIT_SUCCESS); - - } - - - - if(read) - { - int ret = 0, i = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - unsigned char buffer[READ_SIZE] = { 0 }; - - (void) pclInitLibrary(appId_two, shutdownReg); - - for (i = 0; i < numloops; i++) - { - getchar(); - printf("read: [%d] \n", i); - - - memset(buffer, 0, READ_SIZE); - ret = pclKeyReadData(0x20, "links/last_link2", 2, 1, buffer, READ_SIZE); - if (ret < 0) - printf("Failed to read data: %d\n", ret); - } - - pclDeinitLibrary(); - sleep(1); - _exit(EXIT_SUCCESS); - } - #endif - - data_setupBlacklist(); + DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("Starting PCL test")); if(argc >= 2) { - printf("Running concurrency tests\n"); + printf("Running concurrency tests\n"); - run_concurrency_test(); + run_concurrency_test(); } else { -#if 1 - Suite * s = persistencyClientLib_suite(); - SRunner * sr = srunner_create(s); - srunner_set_xml(sr, "/tmp/persistenceClientLibraryTest.xml"); - srunner_set_log(sr, "/tmp/persistenceClientLibraryTest.log"); - srunner_run_all(sr, CK_VERBOSE /*CK_NORMAL CK_VERBOSE*/); - - printf("Running automated tests\n"); - nr_failed = srunner_ntests_failed(sr); - nr_run = srunner_ntests_run(sr); - - tResult = srunner_results(sr); - for(i = 0; i< nr_run; i++) - { - (void)tr_rtype(tResult[i]); // get status of each test - //fail = tr_rtype(tResult[i]); // get status of each test - //printf("[%d] Fail: %d \n", i, fail); - } - - srunner_free(sr); + Suite * s = persistencyClientLib_suite(); + SRunner * sr = srunner_create(s); + srunner_set_fork_status(sr, CK_NOFORK); + srunner_set_xml(sr, "/tmp/persistenceClientLibraryTest.xml"); + srunner_set_log(sr, "/tmp/persistenceClientLibraryTest.log"); + + srunner_run_all(sr, CK_VERBOSE /*CK_NORMAL CK_VERBOSE CK_SUBUNIT*/); + + nr_failed = srunner_ntests_failed(sr); + srunner_ntests_run(sr); + + srunner_free(sr); } -#endif - pclDeinitLibrary(); + DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("End of PCL test")); // unregister debug log and trace + DLT_UNREGISTER_CONTEXT(gPcltDLTContext); DLT_UNREGISTER_APP(); - dlt_free(); - return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE; } @@ -2575,65 +1623,285 @@ int main(int argc, char *argv[]) void do_pcl_concurrency_access(const char* applicationID, const char* resourceID, int operation) { - int ret = 0, i = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - unsigned char buffer[READ_SIZE] = {0}; - - (void)pclInitLibrary(applicationID, shutdownReg); - - for(i=0; i< 10; i++) - { - printf("[%d] - i: %d \n", operation, i); - if(operation == 0 ) - { - ret = pclKeyWriteData(0x20, resourceID, 2, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data")); - if(ret < 0) - printf("Failed to write data: %d\n", ret); - } - else if(operation == 1) - { - memset(buffer, 0, READ_SIZE); - ret = pclKeyReadData(0x20, resourceID, 2, 1, buffer, READ_SIZE); - if(ret < 0) - printf("Failed to read data: %d\n", ret); - } - else - { - printf("invalid operation - end!! \n"); - break; - } - } - - pclDeinitLibrary(); + int ret = 0, i = 0; + size_t bufferSize = 0; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + unsigned char* buffer = NULL; + + char* writeBuffer = "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß"; + + bufferSize = strlen(writeBuffer); + + buffer = malloc(bufferSize); + + if(buffer != NULL) + { + (void)pclInitLibrary(applicationID, shutdownReg); + + for(i=0; i< 10000; i++) + { + memset(buffer, 0, bufferSize); + + //printf("[%d] - i: %d \n", operation, i); + if(operation == 0 ) + { + ret = pclKeyWriteData(0x20, resourceID, 2, 1,(unsigned char* )writeBuffer, (int)bufferSize); + if(ret < 0) + printf("Failed to write data: %d\n", ret); + + ret = pclKeyReadData(0x20, resourceID, 2, 1, buffer, (int)bufferSize); + if(ret < 0) + { + printf("Failed to read data: %d\n", ret); + } + else + { + if(strncmp((char*)buffer, writeBuffer, (size_t)ret) != 0) + printf("Wrong buffer\n"); + } + } + else if(operation == 1) + { + ret = pclKeyReadData(0x20, resourceID, 2, 1, buffer, (int)bufferSize); + if(ret < 0) + { + printf("Failed to read data: %d\n", ret); + } + else + { + if(strncmp((char*)buffer, writeBuffer, (size_t)ret) != 0) + printf("Wrong buffer\n"); + } + } + else + { + printf("invalid operation - end!! \n"); + break; + } + + if(operation == 0) + usleep(1500); + else + usleep(1000); + } + + free(buffer); + + pclDeinitLibrary(); + } + } void run_concurrency_test() { - const char* appId_one = "lt-persistence_client_library_test"; - const char* appId_two = "concurrency_test"; + const char* appId_one = "lt-persistence_client_library_test"; + const char* appId_two = "concurrency_test"; - int pid = fork(); + int pid = fork(); - if (pid == 0) - { /*child*/ - printf("Started child process with PID: [%d] \n", pid); + if (pid == 0) + { /*child*/ + printf("Started child process with PID: [%d] \n", pid); - do_pcl_concurrency_access(appId_one, "links/last_link2", 0); //write + do_pcl_concurrency_access(appId_one, "links/last_link2", 0); //write - printf("CHILD exits! \n"); + printf("CHILD exits! \n"); - _exit(EXIT_SUCCESS); - } - else if (pid > 0) - { /*parent*/ - printf("Started father process with PID: [%d] \n", pid); + _exit(EXIT_SUCCESS); + } + else if (pid > 0) + { /*parent*/ + printf("Started father process with PID: [%d] \n", pid); - do_pcl_concurrency_access(appId_two, "links/last_link2", 1); //read + do_pcl_concurrency_access(appId_two, "links/last_link2", 1); //read - printf("PARENT exits! \n"); + printf("PARENT exits! \n"); - _exit(EXIT_SUCCESS); - } + _exit(EXIT_SUCCESS); + } } + +const char* gWriteBuffer = "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste""Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste"; + +const char* gWriteBuffer2 = "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste""Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - "; + diff --git a/test/persistence_client_library_test_file.c b/test/persistence_client_library_test_file.c new file mode 100644 index 0000000..c336c45 --- /dev/null +++ b/test/persistence_client_library_test_file.c @@ -0,0 +1,1201 @@ +/****************************************************************************** + * 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_client_library_test.c + * @author Ingo Huerner + * @brief Test of persistence client library + * @see + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> /* exit */ +#include <time.h> +#include <fcntl.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <dbus/dbus.h> +#include <dlt.h> +#include <dlt_common.h> +#include <pthread.h> + +#include <check.h> + +#include "../include/persistence_client_library_file.h" +#include "../include/persistence_client_library_key.h" +#include "../include/persistence_client_library.h" +#include "../include/persistence_client_library_error_def.h" + + +#define READ_SIZE 1024 +#define MaxAppNameLen 256 + +#define NUM_THREADS 100 +#define NUM_OF_WRITES 350 +#define NAME_LEN 24 + +typedef struct s_threadData +{ + char threadName[NAME_LEN]; + int index; + int fd1; + int fd2; +} t_threadData; + +static pthread_barrier_t gBarrierOne; + +static const char* gPathSegemnts[] = {"user/", "1/", "seat/", "1/", "media", NULL }; +static const char* gSourcePath = "/Data/mnt-c/lt-persistence_client_library_test/"; + +/// application id +char gTheAppId[MaxAppNameLen] = {0}; + +// definition of weekday +char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; +char* gWriteBackupTestData = "This is the content of the file /Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db"; +char* gWriteRecoveryTestData = "This is the data to recover: /Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db"; +char* gRecovChecksum = "608a3b5d"; // generated with http://www.tools4noobs.com/online_php_functions/crc32/ + +extern const char* gWriteBuffer; +extern const char* gWriteBuffer2; + + +/// debug log and trace (DLT) setup +DLT_DECLARE_CONTEXT(gPcltDLTContext); + + +// function prototype +void run_concurrency_test(); + +void data_setup(void) +{ + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + (void)pclInitLibrary(gTheAppId, shutdownReg); +} + + +void data_setup_browser(void) +{ + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + (void)pclInitLibrary("browser", shutdownReg); +} + + +void data_setup_norct(void) +{ + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + + (void)pclInitLibrary("norct", shutdownReg); +} + + +void data_teardown(void) +{ + pclDeinitLibrary(); +} + + +int myChangeCallback(pclNotification_s * notifyStruct) +{ + printf(" ==> * - * myChangeCallback * - *\n"); + (void)notifyStruct; + return 1; +} + + +// creat blacklist file, if this does not exist +void data_setupBlacklist(void) +{ + +/// backup info +char gBackupInfo[] = { +"/media/doNotBackupMe.txt_START\n\ +/media/doNotBackupMe_01.txt\n\ +/media/doNotBackupMe_02.txt\n\ +/media/doNotBackupMe_03.txt\n\ +/media/doNotBackupMe_04.txt\n\ +/media/iDontWantDoBeBackuped_01.txt\n\ +/media/iDontWantDoBeBackuped_02.txt\n\ +/media/iDontWantDoBeBackuped_03.txt\n\ +/media/iDontWantDoBeBackuped_04.txt\n\ +/media/iDontWantDoBeBackuped_05.txt_END\n" +}; + + const char* backupBlacklist = "/Data/mnt-c/lt-persistence_client_library_test/BackupFileList.info"; + + if(access(backupBlacklist, F_OK) == -1) + { + ssize_t ret = 0; + 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 != (int)strlen(gBackupInfo)) + { + printf("data_setupBlacklist => Wrong size written: %d", (int)ret); + } + close(handle); + } +} + + +/* + * Test the file interface: + * - open file + * - read / write + * - remove file + * - map file + * - get size + */ +START_TEST(test_DataFile) +{ + int fd = 0, i = 0, idx = 0; + int size = 0, ret = 0, avail = 100; + int writeSize = 16*1024; + int fdArray[10] = {0}; + + unsigned char buffer[READ_SIZE] = {0}; + unsigned char wBuffer[READ_SIZE] = {0}; + const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media"; + char* writeBuffer; + char* fileMap = NULL; + + writeBuffer = malloc((size_t)writeSize); + + // fill buffer a sequence + for(i = 0; i<(writeSize/8); i++) + { + writeBuffer[idx++] = 'A'; + writeBuffer[idx++] = 'B'; + writeBuffer[idx++] = 'C'; + writeBuffer[idx++] = ' '; + writeBuffer[idx++] = 'D'; + writeBuffer[idx++] = 'E'; + writeBuffer[idx++] = 'F'; + writeBuffer[idx++] = ' '; + } + // create file + fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db", + O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + close(fd); + + // open ------------------------------------------------------------ + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); + fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db"); + + + size = pclFileGetSize(fd); + fail_unless(size == 68, "Wrong file size"); + + + 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 == ((int)strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf + + ret = pclFileClose(fd); + fail_unless(ret == 0, "Failed to close file"); + + // open ------------------------------------------------------------ + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDBWrite.db", 1, 1); + fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db"); + + size = pclFileWriteData(fd, writeBuffer, (int)strlen(writeBuffer)); + fail_unless(size == (int)strlen(writeBuffer), "Failed to write data"); + ret = pclFileClose(fd); + fail_unless(ret == 0, "Failed to close file"); + + // remove ---------------------------------------------------------- + ret = pclFileRemove(PCL_LDBID_LOCAL, "media/mediaDBWrite.db", 1, 1); + fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db"); + + fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR); + fail_unless(fd == -1, "Failed to remove file, file still exists"); + close(fd); + + // map file -------------------------------------------------------- + + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); + + size = pclFileGetSize(fd); + pclFileMapData(fileMap, size, 0, fd); + fail_unless(fileMap != MAP_FAILED, "Failed to map file"); + + ret = pclFileUnmapData(fileMap, size); + fail_unless(ret != -1, "Failed to unmap file"); + + // file seek + ret = pclFileSeek(fd, 0, SEEK_CUR); + fail_unless(ret == 0, "Failed to seek file - pos 0"); + + ret = pclFileSeek(fd, 8, SEEK_CUR); + fail_unless(ret == 8, "Failed to seek file - pos 8"); + + // negative test + size = pclFileGetSize(1024); + fail_unless(size < 0 , "Got size, but should not"); + + ret = pclFileClose(fd); + fail_unless(ret == 0, "Failed to close file"); + + // test backup blacklist functionality + fdArray[0] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 1, 1); + fdArray[1] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 1, 2); + fdArray[2] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 20, 10); + fdArray[3] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 200, 100); + + fdArray[4] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_01.txt", 2, 1); + fdArray[5] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_02.txt", 2, 1); + fdArray[6] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_03.txt", 2, 1); + fdArray[7] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_04.txt", 2, 1); + + fdArray[8] = pclFileOpen(PCL_LDBID_LOCAL, "media/iDontWantDoBeBackuped_04.txt", 2, 1); + fdArray[9] = pclFileOpen(PCL_LDBID_LOCAL, "media/iDontWantDoBeBackuped_05.txt_END", 2, 1); + + for(i=0; i<10; i++) + { + snprintf( (char*)wBuffer, 1024, "Test - %d", i); + pclFileWriteData(fdArray[i], wBuffer, (int)strlen((char*)wBuffer)); + } + + // + // test if backup blacklist works correctly + // + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/doNotBackupMe.txt_START~", F_OK); + fail_unless(avail == -1, "1. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/2/media/doNotBackupMe.txt_START~", F_OK); + fail_unless(avail == -1, "2. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/20/seat/10/media/doNotBackupMe.txt_START~", F_OK); + fail_unless(avail == -1, "3. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/200/seat/100/media/doNotBackupMe.txt_START~", F_OK); + fail_unless(avail == -1, "4. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_01.txt~", F_OK); + fail_unless(avail == -1, "5. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_02.txt~", F_OK); + fail_unless(avail == -1, "6. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_03.txt~", F_OK); + fail_unless(avail == -1, "7. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_04.txt~", F_OK); + fail_unless(avail == -1, "8. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/iDontWantDoBeBackuped_04.txt~", F_OK); + fail_unless(avail == -1, "9. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/iDontWantDoBeBackuped_05.txt_END~", F_OK); + fail_unless(avail == -1, "10. Failed backup => backup available, but should not"); + + for(i=0; i<10; i++) + { + pclFileClose(fdArray[i]); + } + + // write to file not in RCT + fd = pclFileOpen(PCL_LDBID_LOCAL, "nonRCT/aNonRctFile.db", 1, 1); + size = pclFileGetSize(fd); + size = pclFileWriteData(fd, "nonRCT/mediaDB.db", strlen("nonRCT/mediaDB.db")); + + free(writeBuffer); +} +END_TEST + + + +START_TEST(test_DataFileConfDefault) +{ + int fd = 0; + char readBuffer[READ_SIZE] = {0}; + char* refBuffer01 = "Some default file content: 01 Configurable default data 01."; + char* refBuffer02 = "Some default file content: 02 Configurable default data 02."; + + // -- file interface --- + memset(readBuffer, 0, READ_SIZE); + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData_01.configurable", 99, 99); + (void)pclFileReadData(fd, readBuffer, READ_SIZE); + fail_unless(strncmp(readBuffer, refBuffer01, strlen(refBuffer01)) == 0, "Buffer not correctly read => mediaData_01.configurable"); + (void)pclFileClose(fd); + + + memset(readBuffer, 0, READ_SIZE); + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData_02.configurable", 99, 99); + (void)pclFileReadData(fd, readBuffer, READ_SIZE); + fail_unless(strncmp(readBuffer, refBuffer02, strlen(refBuffer02)) == 0, "Buffer not correctly read => mediaData_01.configurable"); + (void)pclFileClose(fd); +} +END_TEST + + + +void data_setupBackup(void) +{ + int handle = -1; + const char* path = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db"; + + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + (void)pclInitLibrary(gTheAppId, shutdownReg); + + handle = open(path, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + if(write(handle, gWriteBackupTestData, strlen(gWriteBackupTestData)) == -1) + { + printf("setup test: failed to write test data: %s\n", path); + } +} + +START_TEST(test_DataFileBackupCreation) +{ + int fd_RW = 0, fd_RO = 0, rval = -1, handle = -1; + char* wBuffer = " ==> Appended: Test Data - test_DataFileRecovery! "; + const char* path = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db~"; + char rBuffer[1024] = {0}; + +#if 1 + + fd_RO = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_ReadOnly.db", 1, 1); + fail_unless(fd_RO != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db"); + + fd_RW = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_ReadWrite.db", 1, 1); + fail_unless(fd_RW != -1, "Could not open file ==> /media/mediaDB_ReadWrite.db"); + + rval = pclFileReadData(fd_RW, rBuffer, 10); + fail_unless(rval == 10, "Failed read 10 bytes"); + memset(rBuffer, 0, 1024); + + rval = pclFileReadData(fd_RW, rBuffer, 15); + fail_unless(rval == 15, "Failed read 15 bytes"); + memset(rBuffer, 0, 1024); + + rval = pclFileReadData(fd_RW, rBuffer, 20); + fail_unless(rval == 20, "Failed read 20 bytes"); + memset(rBuffer, 0, 1024); + + rval = pclFileWriteData(fd_RW, wBuffer, (int)strlen(wBuffer)); + fail_unless(rval == (int)strlen(wBuffer), "Failed write data"); + + // verify the backup creation: + handle = open(path, O_RDWR); + fail_unless(handle != -1, "Could not open file ==> failed to access backup file"); + + rval = (int)read(handle, rBuffer, 1024); + //printf(" * * * Backup: \nIst : %s \nSoll: %s\n", rBuffer, gWriteBackupTestData); + fail_unless(strncmp((char*)rBuffer, gWriteBackupTestData, strlen(gWriteBackupTestData)) == 0, "Backup not correctly read"); + + + (void)close(handle); + (void)pclFileClose(fd_RW); + (void)pclFileClose(fd_RO); + +#endif +} +END_TEST + + + +void data_setupRecovery(void) +{ + int i = 0; + char createPath[128] = {0}; + + int handleRecov = -1, handleToBackup = -1, handleToCs = -1; + char* corruptData = "Some corrupted data .. )=§?=34=/%&$%&()Ö:ÄNJH/)("; + const char* pathToRecover = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db"; + const char* pathToBackup = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db~"; + const char* pathToChecksum = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db~.crc"; + + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + (void)pclInitLibrary(gTheAppId, shutdownReg); + + // create directory, even if exist + snprintf(createPath, 128, "%s", gSourcePath ); + while(gPathSegemnts[i] != NULL) + { + strncat(createPath, gPathSegemnts[i++], 128-1); + mkdir(createPath, 0744); + } + + handleRecov = open(pathToRecover, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + if(write(handleRecov, corruptData, strlen(corruptData)) == -1) + { + printf("setup test: failed to write test data: %s\n", pathToRecover); + } + + handleToBackup = open(pathToBackup, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + if(write(handleToBackup, gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)) == -1) + { + printf("setup test: failed to write test data: %s\n", pathToBackup); + } + + handleToCs = open(pathToChecksum, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + if(write(handleToCs, gRecovChecksum, strlen(gRecovChecksum)) == -1) + { + printf("setup test: failed to write test data: %s\n", pathToChecksum); + } + + close(handleRecov); + close(handleToBackup); + close(handleToCs); + +} + +START_TEST(test_DataFileRecovery) +{ + int handle = 0; + unsigned char buffer[READ_SIZE] = {0}; + + handle = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_DataRecovery.db", 1, 1); + //printf("pclFileOpen => handle: %d\n", handle); + fail_unless(handle != -1, "Could not open file ==> /media/mediaDB_DataRecovery.db"); + + + /*ret = */(void)pclFileReadData(handle, buffer, READ_SIZE); + //printf(" ** pclFileReadData => ist-buffer : %s | size: %d\n", buffer, ret); + //printf(" ** pclFileReadData => soll-buffer: %s | size: %d\n", gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)); + fail_unless(strncmp((char*)buffer, gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)) == 0, "Recovery failed"); + + (void)pclFileClose(handle); +} +END_TEST + + + +/* + * The the handle function of the key and file interface. + */ +START_TEST(test_DataHandle) +{ + int handle1 = 0, handle2 = 0; + int handleArray[4] = {0}; + int ret = 0; + unsigned char buffer[READ_SIZE] = {0}; + + // test multiple handles + handleArray[0] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_01.db", 1, 1); + fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_01.db"); + + handleArray[1] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_02.db", 1, 1); + fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_02.db"); + + handleArray[2] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_03.db", 1, 1); + fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_03.db"); + + handleArray[3] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_04.db", 1, 1); + fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_04.db"); + + memset(buffer, 0, READ_SIZE); + ret = pclFileReadData(handleArray[0], buffer, READ_SIZE); + fail_unless(ret >= 0, "Failed to read handle idx \"0\"!!"); + fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_01.db", + strlen("/user/1/seat/1/media/mediaDB_write_01.db")) + == 0, "Buffer not correctly read => mediaDB_write_01.db"); + + memset(buffer, 0, READ_SIZE); + ret = pclFileReadData(handleArray[1], buffer, READ_SIZE); + fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_02.db", + strlen("/user/1/seat/1/media/mediaDB_write_02.db")) + == 0, "Buffer not correctly read => mediaDB_write_02.db"); + + memset(buffer, 0, READ_SIZE); + ret = pclFileReadData(handleArray[2], buffer, READ_SIZE); + fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_03.db", + strlen("/user/1/seat/1/media/mediaDB_write_03.db")) + == 0, "Buffer not correctly read => mediaDB_write_03.db"); + + memset(buffer, 0, READ_SIZE); + (void)pclFileReadData(handleArray[3], buffer, READ_SIZE); + fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_04.db", + strlen("/user/1/seat/1/media/mediaDB_write_04.db")) + == 0, "Buffer not correctly read => mediaDB_write_04.db"); + + ret = pclKeyHandleClose(handleArray[0]); + fail_unless(ret != -1, "Failed to close handle idx \"0\"!!"); + + ret = pclKeyHandleClose(handleArray[1]); + fail_unless(ret != -1, "Failed to close handle idx \"1\"!!"); + + ret = pclKeyHandleClose(handleArray[2]); + fail_unless(ret != -1, "Failed to close handle idx \"2\"!!"); + + ret = pclKeyHandleClose(handleArray[3]); + fail_unless(ret != -1, "Failed to close handle idx \"3\"!!"); + + // test key handles + handle2 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "statusHandle/open_document", 3, 2); + fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document"); + + ret = pclKeyHandleClose(handle2); + fail_unless(ret != -1, "Failed to close handle!!"); + + ret = pclKeyHandleClose(1024); + fail_unless(ret == EPERS_MAXHANDLE, "Max handle!!"); + + + // test file handles + handle1 = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); + fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db"); + + ret = pclFileClose(handle1); + fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db"); + + ret = pclFileClose(1024); + fail_unless(ret == EPERS_MAXHANDLE, "1. Could close file, but should not!!"); +} +END_TEST + + +START_TEST(test_WriteConfDefault) +{ + int ret = 0, fd = 0; + unsigned char writeBuffer[] = "This is a test string"; + unsigned char writeBuffer2[] = "And this is a test string which is different form previous test string"; + unsigned char readBuffer[READ_SIZE] = {0}; + + // -- file interface --- + memset(readBuffer, 0, READ_SIZE); + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData.configurable", PCL_USER_DEFAULTDATA, 99); + ret = pclFileWriteData(fd, writeBuffer, (int)strlen((char*)writeBuffer)); + fail_unless(ret >= 0, "Failed pclFileWriteData"); + pclFileSeek(fd, 0, SEEK_SET); + ret = pclFileReadData(fd, readBuffer, READ_SIZE); + fail_unless(strncmp((char*)readBuffer, (char*)writeBuffer, strlen((char*)writeBuffer)) == 0, "Buffer not correctly read"); + (void)pclFileClose(fd); + + memset(readBuffer, 0, READ_SIZE); + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData.configurable", PCL_USER_DEFAULTDATA, 99); + ret = pclFileWriteData(fd, writeBuffer2, (int)strlen((char*)writeBuffer2)); + fail_unless(ret >= 0, "Failed pclFileWriteData"); + pclFileSeek(fd, 0, SEEK_SET); + ret = pclFileReadData(fd, readBuffer, READ_SIZE); + fail_unless(strncmp((char*)readBuffer, (char*)writeBuffer2, strlen((char*)writeBuffer2)) == 0, "Buffer2 not correctly read"); + (void)pclFileClose(fd); +} +END_TEST + + + +START_TEST(test_GetPath) +{ + int ret = 0; + char* path = NULL; + const char* thePath = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_create.db"; + unsigned int pathSize = 0; + + ret = pclFileCreatePath(PCL_LDBID_LOCAL, "media/mediaDB_create.db", 1, 1, &path, &pathSize); + + fail_unless(strncmp((char*)path, thePath, strlen((char*)path)) == 0, "Path not correct"); + fail_unless(pathSize == strlen((char*)path), "Path size not correct"); + + pclFileReleasePath(ret); +} +END_TEST + + + +START_TEST(test_InitDeinit) +{ + int i = 0, rval = -1, handle = 0; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + + for(i=0; i<5; i++) + { + // initialize and deinitialize 1. time + (void)pclInitLibrary(gTheAppId, shutdownReg); + pclDeinitLibrary(); + + + // initialize and deinitialize 2. time + (void)pclInitLibrary(gTheAppId, shutdownReg); + pclDeinitLibrary(); + + + // initialize and deinitialize 3. time + (void)pclInitLibrary(gTheAppId, shutdownReg); + pclDeinitLibrary(); + } + + // test multiple init/deinit + pclInitLibrary(gTheAppId, shutdownReg); + pclInitLibrary(gTheAppId, shutdownReg); + + pclDeinitLibrary(); + pclDeinitLibrary(); + pclDeinitLibrary(); + + // test lifecycle set + pclInitLibrary(gTheAppId, shutdownReg); + rval = pclLifecycleSet(PCL_SHUTDOWN); + fail_unless(rval == EPERS_SHUTDOWN_NO_PERMIT, "Lifecycle set allowed, but should not"); + pclDeinitLibrary(); + + + pclInitLibrary(gTheAppId, PCL_SHUTDOWN_TYPE_NONE); + + handle = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); + //printf("pclFileOpen: %d\n", handle); + fail_unless(handle >= 0, "Could not open file ==> /media/mediaDB.db"); + (void)pclFileClose(handle); + + handle = pclKeyHandleOpen(PCL_LDBID_LOCAL, "posHandle/last_position", 0, 0); + //printf("pclKeyHandleOpen: %d\n", handle); + fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position"); + (void)pclKeyHandleClose(handle); + + rval = pclLifecycleSet(PCL_SHUTDOWN); + fail_unless(rval != EPERS_SHUTDOWN_NO_PERMIT, "Lifecycle set NOT allowed, but should"); + + + rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); + rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); + rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); + rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); + rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); + rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); + + pclDeinitLibrary(); +} +END_TEST + + + +START_TEST(test_VerifyROnly) +{ + int fd = 0; + int rval = 0; + char* wBuffer = "This is a test string"; + + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_ReadOnly.db", 1, 1); + fail_unless(fd != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db"); + + rval = pclFileWriteData(fd, wBuffer, (int)strlen(wBuffer)); + fail_unless(rval == EPERS_RESOURCE_READ_ONLY, "Write to read only file is possible, but should not ==> /media/mediaDB_ReadOnly.db"); + + rval = pclFileClose(fd); + fail_unless(rval == 0, "Failed to close file: media/mediaDB_ReadOnly.db"); +} +END_TEST + + + +void runTestSequence(const char* resourceID) +{ + int fd1 = 0, fd2 = 0, rval = 0; + unsigned char buffer[READ_SIZE] = {0}; + unsigned char writebuffer[] = {" _Updates file_ "}; + unsigned char writebuffer2[] = {" _New Data_ "}; + + // part one: write to file + // ------------------------------------------ + fd1 = pclFileOpen(PCL_LDBID_LOCAL, resourceID, 1, 1); + fail_unless(fd1 != -1, "Could not open file ==> dataLoc/file.txt"); + + (void)pclFileReadData(fd1, buffer, READ_SIZE); + (void)pclFileWriteData(fd1, writebuffer, (int)strlen((char*)writebuffer)); + + #if 1 + rval = pclFileClose(fd1); + fail_unless(rval == 0, "Could not close file ==> dataLoc/file.txt"); + #else + printf("\nN O C L O S E\n\n"); + #endif + + // part two: remove file + // ------------------------------------------ + rval = pclFileRemove(PCL_LDBID_LOCAL, resourceID, 1, 1); + fail_unless(rval == 0, "Could not remove file ==> dataLoc/file.txt"); + + + // part three: open file again, and write to it + // ------------------------------------------ + fd2 = pclFileOpen(PCL_LDBID_LOCAL, resourceID, 1, 1); + fail_unless(fd1 != -1, "Could not open file ==> dataLoc/file.txt"); + + (void)pclFileWriteData(fd2, writebuffer2, (int)strlen((char*)writebuffer2)); + + rval = pclFileClose(fd2); + fail_unless(rval == 0, "Could not close file ==> dataLoc/file.txt"); +} + + +START_TEST(test_FileTest) +{ + int i = 0; + const char* resourceID_01 = "dataLoc/fileB.txt"; + const char* resourceID_02 = "dataLoc/fileA.txt"; + int fdArray[10] = {0}; + + const char* resourceIDArray[] = {"dataLoc/fileC.txt", + "dataLoc/fileD.txt", + "dataLoc/fileE.txt", + "dataLoc/fileF.txt", + "dataLoc/fileG.txt"}; +#if 1 + const char* testStringsFirst[] = {"FIRST - - Test Data START - dataLoc/fileC.txt - Test Data END ", + "FIRST - - Test Data START - dataLoc/fileD.txt - Test Data END ", + "FIRST - - Test Data START - dataLoc/fileE.txt - Test Data END ", + "FIRST - - Test Data START - dataLoc/fileF.txt - Test Data END ", + "FIRST - - Test Data START - dataLoc/fileG.txt - Test Data END "}; + + const char* testStringsSecond[] = {"Second - - Test Data START - dataLoc/fileC.txt - Test Data END ", + "Second - - Test Data START - dataLoc/fileD.txt - Test Data END ", + "Second - - Test Data START - dataLoc/fileE.txt - Test Data END ", + "Second - - Test Data START - dataLoc/fileF.txt - Test Data END ", + "Second - - Test Data START - dataLoc/fileG.txt - Test Data END "}; +#endif + // open files + + for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) + { + fdArray[i] = pclFileOpen(PCL_LDBID_LOCAL, resourceIDArray[i], 1, 1); + //printf("******** test_FileTest => pclFileOpen: %s -- %d\n", resourceIDArray[i], fdArray[i] ); + fail_unless(fdArray[i] != -1, "Could not open file ==> file: %s", resourceIDArray[i]); + } + + // write to files + for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) + { + (void)pclFileWriteData(fdArray[i], testStringsFirst[i], (int)strlen((char*)testStringsFirst[i])); + } + + runTestSequence(resourceID_01); + runTestSequence(resourceID_02); + + + // write to files again + for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) + { + (void)pclFileWriteData(fdArray[i], testStringsSecond[i], (int)strlen((char*)testStringsSecond[i])); + } + + + // close files + for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) + { + fdArray[i] = pclFileClose(fdArray[i]); + fail_unless(fdArray[i] == 0, "Could not close file ==> file: %s - %d", resourceIDArray[i], fdArray[i]); + } +} +END_TEST + +void* fileWriteThread(void* userData) +{ + t_threadData* threadData = (t_threadData*)userData; + + static int i = 0; + + size_t bufferSize = strlen(gWriteBuffer); + size_t bufferSize2 = strlen(gWriteBuffer2); + + unsigned char* readbuffer = malloc(bufferSize); + unsigned char* readbuffer2 = malloc(bufferSize2); + + if(readbuffer != NULL && readbuffer2 != NULL) + { + pthread_barrier_wait(&gBarrierOne); + usleep(5000); + + for(i=0; i<NUM_OF_WRITES; i++) + { + int wsize = 0, rsize = 0; + int wsize2 = 0, rsize2 = 0; + + memset(readbuffer, 0, bufferSize); + + wsize = pclFileWriteData(threadData->fd1, gWriteBuffer, (int)bufferSize); + ck_assert_int_ge(wsize, 0); + pclFileSeek(threadData->fd1, 0, SEEK_SET); + + rsize = pclFileReadData(threadData->fd1, readbuffer, (int)bufferSize); + ck_assert_int_eq(rsize, (int)bufferSize); + + usleep( (useconds_t)(50 * i * threadData->index)); // do some "random" sleep + + memset(readbuffer2, 0, bufferSize2); + + wsize2 = pclFileWriteData(threadData->fd2, gWriteBuffer2, (int)bufferSize2); + ck_assert_int_ge(wsize2, 0); + pclFileSeek(threadData->fd2, 0, SEEK_SET); + + rsize2 = pclFileReadData(threadData->fd2, readbuffer2, (int)bufferSize2); + ck_assert_int_eq(rsize2, (int)bufferSize2); + } + + free(readbuffer); + free(readbuffer2); + } + + return NULL; +} + + +START_TEST(test_MultFileReadWrite) +{ + int fd1 = -1; + int fd2 = -1; + + fd1 = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDBWrite.db", 1, 1); + fd2 = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDBWrite.db", 2, 1); + + if(fd1 != -1 && fd2 != 0) + { + pthread_t threads[NUM_THREADS]; + int* retval; + int i=0; + int success[NUM_THREADS] = {0}; + t_threadData threadData[NUM_THREADS]; + + if(pthread_barrier_init(&gBarrierOne, NULL, NUM_THREADS) == 0) + { + for(i=0; i<NUM_THREADS; i++) + { + memset(threadData[i].threadName, 0, NAME_LEN); + sprintf(threadData[i].threadName, "-MultWritefile-%3d-", i); + threadData[i].threadName[NAME_LEN-1] = '\0'; + threadData[i].index = i; + threadData[i].fd1 = fd1; + threadData[i].fd2 = fd2; + + if(pthread_create(&threads[i], NULL, fileWriteThread, &(threadData[i])) != -1) + { + (void)pthread_setname_np(threads[i], threadData[i].threadName); + success[i] = 1; + } + } + // wait + for(i=0; i<NUM_THREADS; i++) + { + if(success[i] == 1) + pthread_join(threads[i], (void**)&retval); // wait until thread has ended + } + + if(pthread_barrier_destroy(&gBarrierOne) != 0) + printf("Failed to destroy barrier\n"); + } + else + { + printf("Failed to init barrier\n"); + } + + (void)pclFileClose(fd1); + (void)pclFileClose(fd2); + } + else + { + printf("Could not open file ==> /media/mediaDBWrite.db\n"); + } +} +END_TEST + + + + +static Suite * persistencyClientLib_suite() +{ + const char* testSuiteName = "Persistency Client Library (File-API)"; + + Suite * s = suite_create(testSuiteName); + + TCase * tc_persDataFile = tcase_create("DataFile"); + tcase_add_test(tc_persDataFile, test_DataFile); + tcase_set_timeout(tc_persDataFile, 3); + + TCase * tc_DataFileConfDefault = tcase_create("DataFileConfDefault"); + tcase_add_test(tc_DataFileConfDefault, test_DataFileConfDefault); + tcase_set_timeout(tc_DataFileConfDefault, 3); + + TCase * tc_persDataFileBackupCreation = tcase_create("DataFileBackupCreation"); + tcase_add_test(tc_persDataFileBackupCreation, test_DataFileBackupCreation); + tcase_set_timeout(tc_persDataFileBackupCreation, 3); + + TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery"); + tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery); + tcase_set_timeout(tc_persDataFileRecovery, 3); + + TCase * tc_WriteConfDefault = tcase_create("WriteConfDefault"); + tcase_add_test(tc_WriteConfDefault, test_WriteConfDefault); + tcase_set_timeout(tc_WriteConfDefault, 3); + + TCase * tc_GetPath = tcase_create("GetPath"); + tcase_add_test(tc_GetPath, test_GetPath); + tcase_set_timeout(tc_GetPath, 3); + + TCase * tc_InitDeinit = tcase_create("InitDeinit"); + tcase_add_test(tc_InitDeinit, test_InitDeinit); + tcase_set_timeout(tc_InitDeinit, 3); + + TCase * tc_VerifyROnly = tcase_create("VerifyROnly"); + tcase_add_test(tc_VerifyROnly, test_VerifyROnly); + tcase_set_timeout(tc_VerifyROnly, 3); + + TCase * tc_FileTest = tcase_create("FileTest"); + tcase_add_test(tc_FileTest, test_FileTest); + tcase_set_timeout(tc_FileTest, 3); + + TCase * tc_DataHandle= tcase_create("DataHandle"); + tcase_add_test(tc_DataHandle, test_DataHandle); + tcase_set_timeout(tc_DataHandle, 3); + + TCase * tc_MultiFileReadWrite = tcase_create("MultFileReadWrite"); + tcase_add_test(tc_MultiFileReadWrite, test_MultFileReadWrite); + tcase_set_timeout(tc_MultiFileReadWrite, 20); + + + suite_add_tcase(s, tc_WriteConfDefault); + tcase_add_checked_fixture(tc_WriteConfDefault, data_setup, data_teardown); + + suite_add_tcase(s, tc_persDataFile); + tcase_add_checked_fixture(tc_persDataFile, data_setup, data_teardown); + + suite_add_tcase(s, tc_persDataFileBackupCreation); + tcase_add_checked_fixture(tc_persDataFileBackupCreation, data_setupBackup, data_teardown); + + suite_add_tcase(s, tc_persDataFileRecovery); + tcase_add_checked_fixture(tc_persDataFileRecovery, data_setupRecovery, data_teardown); + + suite_add_tcase(s, tc_GetPath); + tcase_add_checked_fixture(tc_GetPath, data_setup, data_teardown); + + suite_add_tcase(s, tc_VerifyROnly); + tcase_add_checked_fixture(tc_VerifyROnly, data_setup, data_teardown); + + suite_add_tcase(s, tc_DataFileConfDefault); + tcase_add_checked_fixture(tc_DataFileConfDefault, data_setup, data_teardown); + + 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_MultiFileReadWrite); + tcase_add_checked_fixture(tc_MultiFileReadWrite, data_setup, data_teardown); + + return s; +} + + +int main(int argc, char *argv[]) +{ + int nr_failed = 0; + (void)argv; + (void)argc; + + // assign application name + strncpy(gTheAppId, "lt-persistence_client_library_test", MaxAppNameLen); + gTheAppId[MaxAppNameLen-1] = '\0'; + + /// debug log and trace (DLT) setup + DLT_REGISTER_APP("PCLT", "PCL tests"); + + DLT_REGISTER_CONTEXT(gPcltDLTContext, "PCLt", "Context for PCL testing"); + + DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("Starting PCL test")); + + data_setupBlacklist(); + + Suite * s = persistencyClientLib_suite(); + SRunner * sr = srunner_create(s); + 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); + srunner_free(sr); + + DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("End of PCL test")); + + // unregister debug log and trace + DLT_UNREGISTER_CONTEXT(gPcltDLTContext); + DLT_UNREGISTER_APP(); + + return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE; + +} + +const char* gWriteBuffer = "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste""Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste"; + +const char* gWriteBuffer2 = "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste""Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - "; + diff --git a/test/persistence_test_customlib.c b/test/persistence_test_customlib.c index 9295df5..93cc80a 100644 --- a/test/persistence_test_customlib.c +++ b/test/persistence_test_customlib.c @@ -91,7 +91,7 @@ int plugin_handle_get_data(int handle, char* buffer, int size) //printf("plugin_handle_get_data: %s\n", LIBIDENT); (void)handle; - return snprintf(buffer, size, "Custom plugin -> plugin_get_data_handle: %s!", LIBIDENT); + return snprintf(buffer, (size_t)size, "Custom plugin -> plugin_get_data_handle: %s!", LIBIDENT); } /** * @brief get data @@ -111,7 +111,7 @@ int plugin_get_data(const char* path, char* buffer, int size) (void)buffer; (void)size; - return snprintf(buffer, size, "Custom plugin -> plugin_get_data: %s!", LIBIDENT); + return snprintf(buffer, (size_t)size, "Custom plugin -> plugin_get_data: %s!", LIBIDENT); } diff --git a/tools/persistence_client_tool.c b/tools/persistence_client_tool.c index 93a0d22..fdd2562 100644 --- a/tools/persistence_client_tool.c +++ b/tools/persistence_client_tool.c @@ -76,7 +76,7 @@ void printHexDump(unsigned char* buffer, int formatNumPerRow) -int readKey(char * resource_id, unsigned int user, unsigned int seat, unsigned int ldbid, unsigned int doHexdump, unsigned char* buffer, unsigned int size) +int readKey(const char * resource_id, unsigned int user, unsigned int seat, unsigned int ldbid, unsigned int doHexdump, unsigned char* buffer, int size) { int rval = 0; int numPerRow = 8; @@ -103,7 +103,7 @@ int readKey(char * resource_id, unsigned int user, unsigned int seat, unsigned i -int writeKey(char * resource_id, unsigned int user, unsigned int seat, unsigned int ldbid, unsigned char* buffer, unsigned int doHexdump) +int writeKey(const char * resource_id, unsigned int user, unsigned int seat, unsigned int ldbid, unsigned char* buffer, unsigned int doHexdump) { int rval = 0, size = 0; int numPerRow = 8; @@ -112,7 +112,7 @@ int writeKey(char * resource_id, unsigned int user, unsigned int seat, unsigned printf(" ResourceID: \"%s\" \n", resource_id); printf(" Data : \"%s \"\n", buffer); - size = pclKeyWriteData(ldbid, resource_id, user, seat, buffer, strlen((char*)buffer)); + size = pclKeyWriteData(ldbid, resource_id, user, seat, buffer, (int)strlen((char*)buffer)); if(doHexdump == 1) { @@ -169,7 +169,7 @@ int writeDataToFile(char* fileName, unsigned char* buffer, int size) rval = ftruncate(fd, size); if(rval != -1) { - rval = write(fd, buffer, size); + rval = (int)write(fd, buffer, (size_t)size); if(rval == -1) { @@ -202,14 +202,14 @@ unsigned char* readDataFromFile(char* fileName) int fd = open(fileName, O_RDONLY); if(fd != -1) { - int readSize = 0; - writeBuffer = malloc(buffer.st_size ); + ssize_t readSize = 0; + writeBuffer = malloc((size_t)buffer.st_size ); if(writeBuffer != NULL) { - readSize = read(fd, writeBuffer, buffer.st_size-1); //-1 - just read content, not line endings + readSize = read(fd, writeBuffer, (size_t)(buffer.st_size-1)); //-1 - just read content, not line endings if(readSize < 0) { - printf("Failed to read data: %d\n", readSize); + printf("Failed to read data: %d\n", (int)readSize); } } else @@ -362,7 +362,7 @@ int main(int argc, char *argv[]) { printf("Application name: %s\n", appName); - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; (void)pclInitLibrary(appName, shutdownReg); switch(opMode) @@ -374,10 +374,10 @@ int main(int argc, char *argv[]) if(keysize > 0) { - buffer = malloc(keysize); + buffer = malloc((size_t)keysize); if(buffer != NULL) { - memset(buffer, 0, keysize-1); + memset(buffer, 0, (size_t)(keysize-1)); readKey(resourceID, user_no, seat_no, ldbid, doHexdump, buffer, keysize); if(fileName != NULL) diff --git a/tools/persistence_db_viewer.c b/tools/persistence_db_viewer.c index bff8007..15f20df 100644 --- a/tools/persistence_db_viewer.c +++ b/tools/persistence_db_viewer.c @@ -146,8 +146,8 @@ void printDBcontent(const char* appname, dbType type) listSize = persComDbGetSizeKeysList(handle); if(listSize > 0 && listSize < 2048) { - resourceList = (char*)malloc(listSize+4); - memset(resourceList, 0, listSize+4-1); + resourceList = (char*)malloc((size_t)listSize+4); + memset(resourceList, 0, (size_t)listSize+4-1); if(resourceList != NULL) { @@ -222,8 +222,8 @@ void printRCTcontent(const char* appname, int full) listSize = persComRctGetSizeResourcesList(handle); if(listSize > 0 && listSize < 2048) { - resourceList = (char*)malloc(listSize+4); - memset(resourceList, 0, listSize+4-1); + resourceList = (char*)malloc((size_t)listSize+4); + memset(resourceList, 0, (size_t)listSize+4-1); if(resourceList != NULL) { @@ -319,7 +319,7 @@ void printSingleApplicationDBs(const char* appname, const char* thePath, unsigne if(databaseTypes != dbTypeNone) { - int i = 0; + int i = 0; for(i=1; i<=5; i++) { if(databaseTypes & gDbMaskArray[i]) // check if db content needs to be printed |