summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Huerner <ingo_huerner@mentor.com>2017-04-19 08:15:05 +0200
committerIngo Huerner <ingo_huerner@mentor.com>2017-04-19 08:15:05 +0200
commitb7ec5f42ff77e2bcdbdaf41d4d0e380b4e2d6975 (patch)
tree7d1df269047d56c19d1a14c635f64de274e65ac4
parent87281e7cb8e47cace208a1b0cf3109b37156418a (diff)
downloadpersistence-client-library-b7ec5f42ff77e2bcdbdaf41d4d0e380b4e2d6975.tar.gz
Added environment checker to tests in order to detect insufficient persistence setup
-rw-r--r--test/Makefile.am4
-rw-r--r--test/persistence_client_library_test.c19
-rw-r--r--test/persistence_client_library_test_file.c17
-rw-r--r--test/persistence_env_checker.c263
4 files changed, 294 insertions, 9 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 477532f..ff58198 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -17,11 +17,11 @@ persistence_client_library_dbus_test_SOURCES = persistence_client_library_dbus_t
persistence_client_library_dbus_test_LDADD = $(DEPS_LIBS) \
$(top_builddir)/src/libpersistence_client_library.la
-persistence_client_library_test_SOURCES = persistence_client_library_test.c
+persistence_client_library_test_SOURCES = persistence_client_library_test.c persistence_env_checker.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_SOURCES = persistence_client_library_test_file.c persistence_env_checker.c
persistence_client_library_test_file_LDADD = $(DEPS_LIBS) $(CHECK_LIBS) \
$(top_builddir)/src/libpersistence_client_library.la
diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c
index a89e940..0324cef 100644
--- a/test/persistence_client_library_test.c
+++ b/test/persistence_client_library_test.c
@@ -22,13 +22,16 @@
#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 <sys/mman.h>
+#include <sys/stat.h>
+
+#include <dbus/dbus.h>
+
#include <check.h>
#include "../include/persistence_client_library_key.h"
@@ -76,6 +79,8 @@ DLT_DECLARE_CONTEXT(gPcltDLTContext);
// function prototype
void run_concurrency_test();
+int check_environment();
+
void data_setup(void)
{
@@ -1778,6 +1783,14 @@ int main(int argc, char *argv[])
DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("Starting PCL test"));
+
+ if(check_environment() != 1)
+ {
+ printf("\nERROR: Environemnt not setup correclty, won't run tests!\n");
+ printf(" Please fix issues reported above.\n\n");
+ return EXIT_FAILURE;
+ }
+
if(argc >= 2)
{
printf("Running concurrency tests\n");
diff --git a/test/persistence_client_library_test_file.c b/test/persistence_client_library_test_file.c
index 51ebbfc..1f841a8 100644
--- a/test/persistence_client_library_test_file.c
+++ b/test/persistence_client_library_test_file.c
@@ -22,13 +22,14 @@
#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 <string.h>
+
+#include <sys/mman.h>
+#include <sys/stat.h>
+
+#include <dbus/dbus.h>
#include <check.h>
@@ -111,6 +112,7 @@ DLT_DECLARE_CONTEXT(gPcltDLTContext);
// function prototype
void run_concurrency_test();
+int check_environment();
void data_setup(void)
{
@@ -2223,6 +2225,13 @@ int main(int argc, char *argv[])
DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("Starting PCL test"));
+ if(check_environment() != 1)
+ {
+ printf("\nERROR: Environemnt not setup correclty, won't run tests!\n");
+ printf(" Please fix issues reported above.\n\n");
+ return EXIT_FAILURE;
+ }
+
data_setupBlacklist();
if(argc == 1)
diff --git a/test/persistence_env_checker.c b/test/persistence_env_checker.c
new file mode 100644
index 0000000..9c0b8cf
--- /dev/null
+++ b/test/persistence_env_checker.c
@@ -0,0 +1,263 @@
+/******************************************************************************
+ * Project Persistence
+ * (c) copyright 2017
+ * Company Mentor Graphics
+ *****************************************************************************/
+/******************************************************************************
+ * 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 <dirent.h>
+#include <sys/types.h>
+
+
+static const char* gProcCmdLineTemplate = "/proc/%ld/cmdline";
+static const char* gPersFolderCache = "/Data/mnt-c";
+static const char* gPersFolderWt = "/Data/mnt-wt";
+static const char* gConfigFilePathname = "/etc/pclCustomLibConfigFileTest.cfg";
+
+
+pid_t find_process_running(const char* processName)
+{
+ DIR* dir;
+ struct dirent* ent;
+ char* endptr;
+ char buf[256] = {0};
+
+ if (!(dir = opendir("/proc")))
+ {
+ printf("Failed to open /proc: %s\n", strerror(errno));
+ return -1;
+ }
+
+ while((ent = readdir(dir)) != NULL)
+ {
+ FILE* fp = NULL;
+ long lpid = strtol(ent->d_name, &endptr, 10);
+
+ if (*endptr != '\0')
+ {
+ continue;
+ }
+
+ memset(buf, 0, 256);
+ snprintf(buf, sizeof(buf), gProcCmdLineTemplate, lpid);
+
+ fp = fopen(buf, "r");
+ if(fp)
+ {
+ if(fgets(buf, sizeof(buf), fp) != NULL)
+ {
+ char* first = strtok(buf, " ");
+ if (!strcmp(first, processName))
+ {
+ fclose(fp);
+ closedir(dir);
+ return (pid_t)lpid;
+ }
+ }
+ fclose(fp);
+ }
+ }
+
+ closedir(dir);
+ return -1;
+}
+
+
+int check_NSM()
+{
+ if(find_process_running("NodeStateManager") == -1 )
+ {
+ printf(" \nFAILURE: GENIVI Node State Manager (NSM) is NOT running\n");
+ printf(" Start with \"NodeStateManager\" (needs ROOT privileges)\n");
+
+ return -1;
+ }
+
+ return 1;
+}
+
+
+int check_PAS()
+{
+ if(find_process_running("pers_admin_svc") == -1)
+ {
+ printf("\nFAILURE: GENIVI Persistence Administration Service (PAS) is NOT running\n");
+ printf(" Start with \"pers_admin_svc\" (needs ROOT privileges)\n");
+
+ return -1;
+ }
+
+ return 1;
+}
+
+
+int check_test_data()
+{
+ int rval = 1, doMoutcheck = 1;
+
+ if(access("/Data/mnt-c/lt-persistence_client_library_test/cached.itz", F_OK))
+ {
+ printf("\nFAILURE: Test data for cached data is not available\n");
+ printf(" Run \"persadmin_tool install /fullPathTofile/PAS_data.tar.gz\"\n");
+ printf(" Make sure persistence data partition is available and mounted to /Data/mnt-c\n");
+
+ rval = -1;
+ }
+
+ if(access("/Data/mnt-wt/lt-persistence_client_library_test/wt.itz", F_OK))
+ {
+ printf("\nFAILURE: Test data for write through is not available\n");
+ printf(" Run \"persadmin_tool install /fullPathTofile/PAS_data.tar.gz\"\n");
+ printf(" Make sure a persistence data partition is available and mounted to /Data/mnt-c\n");
+
+ rval = -1;
+ }
+
+ if(doMoutcheck)
+ {
+ char str1[24] = {0}, str2[24] = {0}, str3[24] = {0}, str4[96] = {0}, str5[12] = {0}, str6[12] = {0};
+ char deviceWt[24] = {0}, deviceC[24] = {0};
+
+ FILE * fp = fopen("/proc/mounts", "r");
+ if(fp != NULL)
+ {
+ memset(deviceWt, 0, 24);
+ deviceWt[23] = '\0';
+
+ memset(deviceC, 0, 24);
+ deviceC[23] = '\0';
+
+ while( fscanf(fp, "%s %s %s %s %s %s", str1, str2, str3, str4, str5, str6) != EOF )
+ {
+#if 0
+ printf("1. : |%s|\n", str1 );
+ printf("2. : |%s|\n", str2 );
+ printf("3. : |%s|\n", str3 );
+ printf("4. : |%s|\n", str4 );
+ printf("5. : |%s|\n", str5 );
+ printf("6. : |%s|\n\n", str6 );
+#endif
+
+ if(strncmp(gPersFolderCache, str2, strlen(gPersFolderCache)) == 0)
+ {
+ strncpy(deviceC, str1, strlen(str1));
+ }
+
+ if(strncmp(gPersFolderWt, str2, strlen(gPersFolderWt)) == 0)
+ {
+ strncpy(deviceWt, str1, strlen(str1));
+ }
+ }
+
+ if(strncmp(deviceC, deviceWt, strlen(deviceWt)) != 0)
+ {
+ printf("FAILURE: Same partition must be mounted to /Data/mnt-c AND /Data/mnt-wt\n");
+ printf(" The persistence partition: \"%s\" - \"%s\" \n", deviceWt, deviceC);
+
+ rval = -1;
+ }
+ }
+ }
+
+ if(rval == -1)
+ {
+ printf("\nNOTE: There must be ONE partition available for persistent data\n");
+ printf(" which must be mounted to /Data/mnt-c AND also to /Data/mnt-wt\n\n");
+ }
+
+ return rval;
+}
+
+
+int check_plugin_config()
+{
+ int rval = 1;
+
+ if(access(gConfigFilePathname, F_OK))
+ {
+ printf("\nFAILURE: Config file for plugins not available\n");
+ printf(" Please make sure the provided config file is available uner /etc/\n");
+ printf(" Config file \"pclCustomLibConfigFileTest.cfg\"is provided in the folder \"config\"\n");
+
+ rval = -1;
+ }
+ else
+ {
+ char plugType[10], libNameAndPath[64], str3[20], str4[20];
+
+ FILE * fp = fopen (gConfigFilePathname, "r");
+ if(fp != NULL)
+ {
+ while( fscanf(fp, "%s %s %s %s", plugType, libNameAndPath, str3, str4) != EOF )
+ {
+ if(strncmp("anInvalidEntry", plugType, strlen("anInvalidEntry"))) // ignore invalid test data entry
+ {
+ if(access(libNameAndPath, F_OK))
+ {
+ printf("\nFAILURE: plugin library not found: \"%s\"\n", libNameAndPath);
+ rval = -1;
+ }
+ }
+#if 0
+ else
+ {
+ printf("Found invalid test data: %s\n",plugType );
+ }
+
+ printf("Read type : |%s|\n", plugType );
+ printf("Read lib : |%s|\n", libNameAndPath );
+ printf("Read load type : |%s|\n", str3 );
+ printf("Read sync/async: |%s|\n\n", str4 );
+#endif
+ }
+ fclose(fp);
+ }
+ else
+ {
+ printf("Failed to open config file: %s\n", strerror(errno));
+ }
+ }
+
+ if(rval == -1)
+ {
+ printf("\nNOTE: Please check config file under \"/etc/pclCustomLibConfigFileTest.cfg\"\n");
+ printf(" and adjust config file or make sure requested pligin library is available under the correct path\n");
+ }
+ return rval;
+}
+
+
+int check_environment()
+{
+ int rval = 1;
+
+ if(check_NSM() != 1) // NSM running?
+ rval = -1;
+
+ if(check_PAS() != 1) // PAS running?
+ rval = -1;
+
+ if(check_test_data() != 1) // test data installed?
+ rval = -1;
+
+ if(check_plugin_config() != 1) // plugin libraries available?
+ rval = -1;
+
+ return rval;
+}