diff options
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/dlt-test-filetransfer.c | 4 | ||||
-rw-r--r-- | src/tests/dlt-test-init-free.c | 33 | ||||
-rw-r--r-- | src/tests/dlt-test-stress-user.c | 6 | ||||
-rw-r--r-- | src/tests/dlt-test-user.c | 6 |
4 files changed, 23 insertions, 26 deletions
diff --git a/src/tests/dlt-test-filetransfer.c b/src/tests/dlt-test-filetransfer.c index 5ec4114..591714a 100644 --- a/src/tests/dlt-test-filetransfer.c +++ b/src/tests/dlt-test-filetransfer.c @@ -59,10 +59,10 @@ #include <dlt.h> /*Needed for dlt logging*/ //!Declare some context for the main program. It's a must have to do this, when you want to log with dlt. -DLT_DECLARE_CONTEXT(mainContext); +DLT_DECLARE_CONTEXT(mainContext) //!Declare some context for the file transfer. It's not a must have to do this, but later you can set a filter on this context in the dlt viewer. -DLT_DECLARE_CONTEXT(fileContext); +DLT_DECLARE_CONTEXT(fileContext) //!Textfile which will be transferred. char *file1; diff --git a/src/tests/dlt-test-init-free.c b/src/tests/dlt-test-init-free.c index d299938..81083e3 100644 --- a/src/tests/dlt-test-init-free.c +++ b/src/tests/dlt-test-init-free.c @@ -27,11 +27,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <stdbool.h> #include "dlt_common.h" #include "dlt_user.h" -char* exec(const char* cmd); +void exec(const char* cmd, char *buffer, size_t length); void printMemoryUsage(); char* occupyMemory(uint size); void do_example_test(); @@ -110,32 +111,28 @@ void do_dlt_test() } } -char* exec(const char* cmd) +void exec(const char* cmd, char *buffer, size_t length) { - FILE* pipe = popen(cmd, "r"); - if (!pipe) - return "ERROR"; + FILE* pipe = NULL; + strncpy(buffer, "ERROR", length); - char* buffer = (char*)malloc(128); - while (!feof(pipe)) - { - fgets(buffer, 128, pipe); - } - pclose(pipe); + if ( (pipe = popen(cmd, "r")) == NULL ) + return; + + while (fgets(buffer, length, pipe) != NULL); - return buffer; + if(pipe != NULL) + pclose(pipe); } void printMemoryUsage() { - char command[128] = "pmap "; + char result[128] = { 0 }; + char command[128] = { 0 }; - char buf[128]; - snprintf(buf, sizeof(command), "%d", getpid()); - strcat(command, buf); - strcat(command, " | grep total"); + snprintf(command, sizeof(command), "pmap %d | grep total", getpid()); - char* result = exec(command); + exec(command, result, sizeof(result)); printf("%s", result); } diff --git a/src/tests/dlt-test-stress-user.c b/src/tests/dlt-test-stress-user.c index dcd7555..6fe73d9 100644 --- a/src/tests/dlt-test-stress-user.c +++ b/src/tests/dlt-test-stress-user.c @@ -83,11 +83,11 @@ int testall(int count,int repeat,int delay,int size); /* Context declaration.. */ -DLT_DECLARE_CONTEXT(context_info); +DLT_DECLARE_CONTEXT(context_info) /* for macro interface */ -DLT_DECLARE_CONTEXT(context_macro_callback); -DLT_DECLARE_CONTEXT(context_macro_test[DLT_TEST_NUM_CONTEXT]); +DLT_DECLARE_CONTEXT(context_macro_callback) +DLT_DECLARE_CONTEXT(context_macro_test[DLT_TEST_NUM_CONTEXT]) /* for function interface */ DltContext context_function_callback; diff --git a/src/tests/dlt-test-user.c b/src/tests/dlt-test-user.c index 3abe9d8..80614e0 100644 --- a/src/tests/dlt-test-user.c +++ b/src/tests/dlt-test-user.c @@ -107,11 +107,11 @@ int test_injection_macro_callback(uint32_t service_id, void *data, uint32_t leng int test_injection_function_callback(uint32_t service_id, void *data, uint32_t length); /* Context declaration.. */ -DLT_DECLARE_CONTEXT(context_info); +DLT_DECLARE_CONTEXT(context_info) /* for macro interface */ -DLT_DECLARE_CONTEXT(context_macro_callback); -DLT_DECLARE_CONTEXT(context_macro_test[DLT_TEST_NUM_CONTEXT]); +DLT_DECLARE_CONTEXT(context_macro_callback) +DLT_DECLARE_CONTEXT(context_macro_test[DLT_TEST_NUM_CONTEXT]) /* for function interface */ DltContext context_function_callback; |