From aa9865f9781a58e09c28b9e48ca6332f207e15f5 Mon Sep 17 00:00:00 2001 From: Christian Muck Date: Thu, 22 Mar 2012 08:33:17 +0100 Subject: Modified library for new test cases to corrupt data - related to the bug fix for testing signed and unsigned integer Signed-off-by: Christian Muck --- CMakeLists.txt | 10 +++++++-- include/dlt/dlt_user.h | 10 +++++++++ src/examples/dlt-example-user.c | 49 ++++++++++++++++++++++++++++++++++++++++- src/lib/dlt_user.c | 30 +++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae0bab6..539edd6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ) option(WITH_MAN "Set to OFF to skip building of man pages" ON ) option(WITH_CHECK_CONFIG_FILE "Set to ON to create a configure file of CheckIncludeFiles and CheckFunctionExists " OFF ) -option(WITH_TESTSCRIPTS "Set to on to run CMakeLists.txt in testscripts" OFF ) -option(WITH_SYSTEMD "Set to on to run CMakeLists.txt in systemd" OFF ) +option(WITH_TESTSCRIPTS "Set to ON to run CMakeLists.txt in testscripts" OFF ) +option(WITH_SYSTEMD "Set to ON to run CMakeLists.txt in systemd" OFF ) option(WITH_GPROF "Set -pg to compile flags" OFF ) +option(WITH_DLTTEST "Set to ON to build with modifications to test Uuser-Daemon communication with corrupt messages" OFF) # RPM settings set( GENIVI_RPM_RELEASE "1")#${DLT_REVISION}") @@ -94,6 +95,10 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/daemon/ ) +if(WITH_DLTTEST) + add_definitions( -DDLT_TEST_ENABLE) +endif(WITH_DLTTEST) + if(WITH_DLT_SHM_ENABLE) add_definitions( -DDLT_SHM_ENABLE) endif(WITH_DLT_SHM_ENABLE) @@ -116,6 +121,7 @@ message( STATUS "WITH_TESTSCRIPTS = ${WITH_TESTSCRIPTS}" ) message( STATUS "WITH_SYSTEMD = ${WITH_SYSTEMD}" ) message( STATUS "WITH_GPROF = ${WITH_GPROF}" ) message( STATUS "WITH_MAN = ${WITH_MAN}" ) +message( STATUS "WITH_DLTTEST = ${WITH_DLTTEST}" ) message( STATUS "BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}" ) message( STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}" ) message( STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}" ) diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h index edfeef2..b6f2e39 100755 --- a/include/dlt/dlt_user.h +++ b/include/dlt/dlt_user.h @@ -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 diff --git a/src/examples/dlt-example-user.c b/src/examples/dlt-example-user.c index bdca2d5..a1a4b1e 100755 --- a/src/examples/dlt-example-user.c +++ b/src/examples/dlt-example-user.c @@ -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;numlen = 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 + + -- cgit v1.2.1