Modified library for new test cases to corrupt data - related to the bug fix for...
authorChristian Muck <christian.muck@bmw.de>
Thu, 22 Mar 2012 07:33:17 +0000 (08:33 +0100)
committerChristian Muck <christian.muck@bmw.de>
Thu, 22 Mar 2012 07:33:17 +0000 (08:33 +0100)
Signed-off-by: Christian Muck <christian.muck@bmw.de>
CMakeLists.txt
include/dlt/dlt_user.h
src/examples/dlt-example-user.c
src/lib/dlt_user.c

index ae0bab6..539edd6 100755 (executable)
@@ -75,9 +75,10 @@ option(WITH_DLT_SHM_ENABLE    "Set to OFF to use FIFO as IPC from user to daemon
 option(WITH_DOC               "Set to ON to build documentation target"              OFF )\r
 option(WITH_MAN               "Set to OFF to skip building of man pages"             ON )\r
 option(WITH_CHECK_CONFIG_FILE "Set to ON to create a configure file of CheckIncludeFiles and CheckFunctionExists " OFF )\r
-option(WITH_TESTSCRIPTS       "Set to on to run CMakeLists.txt in testscripts"       OFF )\r
-option(WITH_SYSTEMD           "Set to on to run CMakeLists.txt in systemd"           OFF )\r
+option(WITH_TESTSCRIPTS       "Set to ON to run CMakeLists.txt in testscripts"       OFF )\r
+option(WITH_SYSTEMD           "Set to ON to run CMakeLists.txt in systemd"           OFF )\r
 option(WITH_GPROF             "Set -pg to compile flags"                             OFF )\r
+option(WITH_DLTTEST                      "Set to ON to build with modifications to test Uuser-Daemon communication with corrupt messages" OFF)\r
 \r
 # RPM settings\r
 set( GENIVI_RPM_RELEASE "1")#${DLT_REVISION}")\r
@@ -94,6 +95,10 @@ include_directories(
     ${CMAKE_SOURCE_DIR}/src/daemon/\r
 )\r
 \r
+if(WITH_DLTTEST)\r
+       add_definitions( -DDLT_TEST_ENABLE)\r
+endif(WITH_DLTTEST)\r
+\r
 if(WITH_DLT_SHM_ENABLE)\r
     add_definitions( -DDLT_SHM_ENABLE)\r
 endif(WITH_DLT_SHM_ENABLE)\r
@@ -116,6 +121,7 @@ message( STATUS "WITH_TESTSCRIPTS = ${WITH_TESTSCRIPTS}" )
 message( STATUS "WITH_SYSTEMD = ${WITH_SYSTEMD}" )\r
 message( STATUS "WITH_GPROF = ${WITH_GPROF}" )\r
 message( STATUS "WITH_MAN = ${WITH_MAN}" )\r
+message( STATUS "WITH_DLTTEST = ${WITH_DLTTEST}" )\r
 message( STATUS "BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}" )\r
 message( STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}" )\r
 message( STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}" )\r
index edfeef2..b6f2e39 100755 (executable)
@@ -246,6 +246,11 @@ typedef struct
 #ifdef DLT_SHM_ENABLE
     DltShm dlt_shm;
 #endif
+#ifdef DLT_TEST_ENABLE
+    int corrupt_user_header;
+    int corrupt_message_size;
+    int16_t corrupt_message_size_size;
+#endif
 } DltUser;
 
 /**************************************************************************************************
@@ -604,6 +609,11 @@ int dlt_user_check_buffer(int *total_size, int *used_size);
  */
 int dlt_user_atexit_blow_out_user_buffer(void);
 
+#ifdef DLT_TEST_ENABLE
+void dlt_user_test_corrupt_user_header(int enable);
+void dlt_user_test_corrupt_message_size(int enable,int16_t size);
+#endif /* DLT_TEST_ENABLE */
+
 #ifdef __cplusplus
 }
 #endif
index bdca2d5..a1a4b1e 100755 (executable)
@@ -112,6 +112,11 @@ void usage()
     printf("  -g            Switch to non-verbose mode (Default: verbose mode)\n");
     printf("  -a            Enable local printing of DLT messages (Default: disabled)\n");
     printf("  -m mode       Set log mode 0=off,1=external,2=internal,3=both\n");
+#ifdef DLT_TEST_ENABLE
+    printf("  -c                       Corrupt user header\n");
+    printf("  -s size       Corrupt message size\n");
+    printf("  -z size          Size of message\n");
+#endif /* DLT_TEST_ENABLE */
 }
 
 /**
@@ -122,6 +127,11 @@ int main(int argc, char* argv[])
     int vflag = 0;
     int gflag = 0;
     int aflag = 0;
+#ifdef DLT_TEST_ENABLE
+    int cflag = 0;    
+    char *svalue = 0;
+    char *zvalue = 0;
+#endif /* DLT_TEST_ENABLE */
     char *dvalue = 0;
     char *fvalue = 0;
     char *nvalue = 0;
@@ -138,8 +148,11 @@ int main(int argc, char* argv[])
        int state=-1,newstate;
 
     opterr = 0;
-
+#ifdef DLT_TEST_ENABLE
+    while ((c = getopt (argc, argv, "vgacd:f:n:m:z:s:")) != -1)
+#else
     while ((c = getopt (argc, argv, "vgad:f:n:m:")) != -1)
+#endif /* DLT_TEST_ENABLE */
     {
         switch (c)
         {
@@ -158,6 +171,23 @@ int main(int argc, char* argv[])
             aflag = 1;
             break;
         }
+#ifdef DLT_TEST_ENABLE
+        case 'c':
+        {
+            cflag = 1;
+            break;
+        }
+        case 's':
+        {
+            svalue = optarg;
+            break;
+        }
+        case 'z':
+        {
+            zvalue = optarg;
+            break;
+        }
+#endif /* DLT_TEST_ENABLE */
         case 'd':
         {
             dvalue = optarg;
@@ -278,6 +308,23 @@ int main(int argc, char* argv[])
         DLT_LOG_ID(mycontext,DLT_LOG_INFO,14,DLT_STRING("DEAD BEEF"));
     }
 
+#ifdef DLT_TEST_ENABLE
+    if (cflag)
+    {
+               dlt_user_test_corrupt_user_header(1);
+    }
+    if (svalue)
+    {
+               dlt_user_test_corrupt_message_size(1,atoi(svalue));
+    }
+       if (zvalue)
+       {
+               char* buffer = malloc(atoi(zvalue));
+        DLT_LOG(mycontext,DLT_LOG_WARN,DLT_STRING(text),DLT_RAW(buffer,atoi(zvalue)));         
+               free(buffer);
+       }
+#endif /* DLT_TEST_ENABLE */
+
     for (num=0;num<maxnum;num++)
     {
         printf("Send %d %s\n",num,text);
index 6ed45a6..62e6fa5 100755 (executable)
@@ -326,6 +326,12 @@ int dlt_init_common(void)
 
     atexit(dlt_user_atexit_handler);
 
+#ifdef DLT_TEST_ENABLE
+    dlt_user.corrupt_user_header = 0;
+    dlt_user.corrupt_message_size = 0;
+    dlt_user.corrupt_message_size_size = 0;
+#endif
+
     return 0;
 }
 
@@ -2249,6 +2255,17 @@ int dlt_user_log_send_log(DltContextData *log, int mtype)
                                                                        0, 0);
 #else
                        /* log to FIFO */
+#ifdef DLT_TEST_ENABLE
+                       if(dlt_user.corrupt_user_header) {
+                               userheader.pattern[0]=0xff;
+                               userheader.pattern[1]=0xff;
+                               userheader.pattern[2]=0xff;
+                               userheader.pattern[3]=0xff;
+                       }
+                       if(dlt_user.corrupt_message_size) {
+                               msg.standardheader->len = DLT_HTOBE_16(dlt_user.corrupt_message_size_size);
+                       }
+#endif
                        ret = dlt_user_log_out3(dlt_user.dlt_log_handle,
                                                                        &(userheader), sizeof(DltUserHeader),
                                                                        msg.headerbuffer+sizeof(DltStorageHeader), msg.headersize-sizeof(DltStorageHeader),
@@ -2983,3 +3000,16 @@ int dlt_user_check_buffer(int *total_size, int *used_size)
        return 0; /* ok */
 }
 
+#ifdef DLT_TEST_ENABLE
+void dlt_user_test_corrupt_user_header(int enable)
+{
+    dlt_user.corrupt_user_header = enable;
+}
+void dlt_user_test_corrupt_message_size(int enable,int16_t size)
+{
+    dlt_user.corrupt_message_size = enable;
+    dlt_user.corrupt_message_size_size = size;
+}
+#endif
+
+