diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/dlt_test_receiver.c | 124 | ||||
-rwxr-xr-x[-rw-r--r--] | tests/start_filetransfer_test.sh | 2 | ||||
-rwxr-xr-x | tests/start_systemd_journal_test.sh | 34 |
3 files changed, 116 insertions, 44 deletions
diff --git a/tests/dlt_test_receiver.c b/tests/dlt_test_receiver.c index 437c169..46b194b 100644 --- a/tests/dlt_test_receiver.c +++ b/tests/dlt_test_receiver.c @@ -77,6 +77,7 @@ #include <fcntl.h> /* for open() */ #include <sys/uio.h> /* for writev() */ #include <string.h> +#include <syslog.h> #include "dlt_client.h" #include <zlib.h> @@ -94,6 +95,8 @@ typedef struct { char *ovalue; char *evalue; int bvalue; + int filetransfervalue; + int systemjournalvalue; char ecuid[4]; int ohandle; DltFile file; @@ -101,6 +104,7 @@ typedef struct { } DltReceiveData; FILE *fp; +int result = 0; /** * Print usage information of tool. @@ -119,6 +123,8 @@ void usage() printf(" -v Verbose mode\n"); printf(" -h Usage\n"); printf(" -y Serial device mode\n"); + printf(" -f Activate filetransfer test case\n"); + printf(" -s Activate systemd journal test case\n"); printf(" -b baudrate Serial device baudrate (Default: 115200)\n"); printf(" -e ecuid Set ECU ID (Default: RECV)\n"); printf(" -o filename Output messages in new DLT file\n"); @@ -141,11 +147,13 @@ int main(int argc, char* argv[]) dltdata.evalue = 0; dltdata.bvalue = 0; dltdata.ohandle=-1; + dltdata.filetransfervalue = 0; + dltdata.systemjournalvalue = 0; /* Fetch command line arguments */ opterr = 0; - while ((c = getopt (argc, argv, "vhy:o:e:b:")) != -1) + while ((c = getopt (argc, argv, "vshyfa:o:e:b:")) != -1) switch (c) { case 'v': @@ -163,6 +171,16 @@ int main(int argc, char* argv[]) dltdata.yflag = 1; break; } + case 'f': + { + dltdata.filetransfervalue = 1; + break; + } + case 's': + { + dltdata.systemjournalvalue = 1; + break; + } case 'o': { dltdata.ovalue = optarg; @@ -312,59 +330,79 @@ int dlt_receive_filetransfer_callback(DltMessage *message, void *data) } dltdata = (DltReceiveData*)data; - - dlt_message_print_ascii(message, text, DLT_RECEIVE_TEXTBUFSIZE, dltdata->vflag); - // 1st find starting point of tranfering data packages - if( strncmp(text, "FLST", 4) == 0) + if(dltdata->filetransfervalue) { - char *tmpFilename; - tmpFilename = strrchr(text, '/') + 1; - unsigned int i; - for(i=0; i<strlen(tmpFilename);i++) + dlt_message_print_ascii(message, text, DLT_RECEIVE_TEXTBUFSIZE, dltdata->vflag); + + // 1st find starting point of tranfering data packages + if( strncmp(text, "FLST", 4) == 0) { - if(isspace(tmpFilename[i])) + char *tmpFilename; + tmpFilename = strrchr(text, '/') + 1; + unsigned int i; + for(i=0; i<strlen(tmpFilename);i++) { - tmpFilename[i] ='\0'; - break; + if(isspace(tmpFilename[i])) + { + tmpFilename[i] ='\0'; + break; + } } + // create file for each received file, as named as crc value + snprintf(filename, 255, "/tmp/%s", tmpFilename); + fp = fopen(filename, "w+"); } - // create file for each received file, as named as crc value - snprintf(filename, 255, "/tmp/%s", tmpFilename); - fp = fopen(filename, "w+"); - } - // 3rd close fp - if( strncmp(text, "FLFI", 4) == 0) - { - printf("TEST FILETRANSFER PASSED\n"); - fclose(fp); + // 3rd close fp + if( strncmp(text, "FLFI", 4) == 0) + { + printf("TEST FILETRANSFER PASSED\n"); + fclose(fp); + } + + // 2nd check if incomming data are filetransfer data + if( strncmp(text, "FLDA", 4) == 0) + { + // truncate beginning of data stream ( FLDA, File identifier and package number) + char *position = strchr(text, 32); // search for space + snprintf(text, DLT_RECEIVE_TEXTBUFSIZE, position+1); + position = strchr(text, 32); + snprintf(text, DLT_RECEIVE_TEXTBUFSIZE, position+1); + position = strchr(text, 32); + snprintf(text, DLT_RECEIVE_TEXTBUFSIZE, position+1); + + // truncate ending of data stream ( FLDA ) + int len = strlen(text); + text[len - 4] = '\0'; + // hex to ascii and store at /tmp + char tmp[3]; + int i; + for(i = 0;i< (int) strlen(text); i = i+3) + { + tmp[0] = text[i]; + tmp[1] = text[i+1]; + tmp[2] = '\0'; + unsigned long h = strtoul(tmp, NULL, 16); + fprintf(fp, "%c", (int) h); + } + } } - // 2nd check if incomming data are filetransfer data - if( strncmp(text, "FLDA", 4) == 0) + if(dltdata->systemjournalvalue) { - // truncate beginning of data stream ( FLDA, File identifier and package number) - char *position = strchr(text, 32); // search for space - snprintf(text, DLT_RECEIVE_TEXTBUFSIZE, position+1); - position = strchr(text, 32); - snprintf(text, DLT_RECEIVE_TEXTBUFSIZE, position+1); - position = strchr(text, 32); - snprintf(text, DLT_RECEIVE_TEXTBUFSIZE, position+1); - - // truncate ending of data stream ( FLDA ) - int len = strlen(text); - text[len - 4] = '\0'; - // hex to ascii and store at /tmp - char tmp[3]; - int i; - for(i = 0;i< (int) strlen(text); i = i+3) + dlt_message_print_ascii(message, text, DLT_RECEIVE_TEXTBUFSIZE, dltdata->vflag); + // 1st find the relevant packages + char * tmp = message->extendedheader->ctid; + tmp[4] = '\0'; + if( strcmp( tmp , (const char *) "JOUR") == 0) { - tmp[0] = text[i]; - tmp[1] = text[i+1]; - tmp[2] = '\0'; - unsigned long h = strtoul(tmp, NULL, 16); - fprintf(fp, "%c", (int) h); + if(strstr(text,"DLT SYSTEM JOURNAL TEST")) + { + result ++; + if( result == 1000) + exit(159); + } } } diff --git a/tests/start_filetransfer_test.sh b/tests/start_filetransfer_test.sh index cd44332..c139fb1 100644..100755 --- a/tests/start_filetransfer_test.sh +++ b/tests/start_filetransfer_test.sh @@ -5,7 +5,7 @@ fullpath="$(pwd)/testfile_filetransfer.txt" #start dlt-daemon dlt-daemon & #start dlt-test-receiver -./../build/tests/dlt_test_receiver localhost & +./../build/tests/dlt_test_receiver -f localhost & #send file to daemon dlt-example-filetransfer $fullpath & diff --git a/tests/start_systemd_journal_test.sh b/tests/start_systemd_journal_test.sh new file mode 100755 index 0000000..bdac21c --- /dev/null +++ b/tests/start_systemd_journal_test.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +#build and install with SYSTEMD_JOURNAL=ON +mkdir ../build +cd ../build/ +cmake -DWITH_SYSTEMD_JOURNAL=ON .. +make && sudo make install +#enable SYSTEMD_JOURNAL in config file +sudo vim -esnc '%s/JournalEnable = 0/JournalEnable = 1/g|:wq' /usr/local/etc/dlt-system.conf +#start dlt-daemon +dlt-daemon & +#start dlt_system +dlt-system & +#send 10 times "DLT SYSTEM JOURNAL TEST" +for i in {1..1000} +do + logger DLT SYSTEM JOURNAL TEST +done +#start receiver +./../build/tests/dlt_test_receiver -s localhost & +pid=$! +wait $pid +exitcode=$? +# kill processes, receiver automatically killed with daemon +pkill dlt-daemon +pkill dlt-system +# if exit code == 159 , test successfull +tput setaf 1 +if [ $exitcode == 159 ]; then + echo "Systemd Journal tests successfull." +else + echo "Systemd Journal tests failed." +fi +tput setaf 7 |