summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorSaya Sugiura <ssugiura@jp.adit-jv.com>2019-01-08 16:45:04 +0900
committerSaya Sugiura <ssugiura@jp.adit-jv.com>2019-05-06 15:55:01 +0900
commitdf6fc2a1ce9f3a1778e9c8e14c800cd2ad96e96e (patch)
tree6356575d4f9e6461769f7b40b72829366feb37b4 /src/tests
parent4fe69b0927f4c5d0cb3b3ae4fa64500db22b13d0 (diff)
downloadDLT-daemon-df6fc2a1ce9f3a1778e9c8e14c800cd2ad96e96e.tar.gz
POSIX: Replace usleep with nanosleep
Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/dlt-test-multi-process.c12
-rw-r--r--src/tests/dlt-test-stress-user.c5
-rw-r--r--src/tests/dlt-test-stress.c24
3 files changed, 31 insertions, 10 deletions
diff --git a/src/tests/dlt-test-multi-process.c b/src/tests/dlt-test-multi-process.c
index 5b508f3..c5da2a6 100644
--- a/src/tests/dlt-test-multi-process.c
+++ b/src/tests/dlt-test-multi-process.c
@@ -292,9 +292,9 @@ void cleanup()
time_t mksleep_time(int delay, int fudge)
{
if (!fudge)
- return delay * 1000;
+ return delay*1000000;
else
- return (delay + rand() % fudge) * 1000;
+ return (delay+rand()%fudge)*1000000;
}
/**
@@ -305,7 +305,8 @@ void do_logging(s_thread_data *data)
DltContext mycontext;
char ctid[5];
char ctid_name[256];
-
+ struct timespec ts;
+ time_t sleep_time;
snprintf(ctid, 5, "%.2x", rand() & 0x0000ffff);
snprintf(ctid_name, 256, "Child %s in dlt-test-multi-process", ctid);
@@ -315,7 +316,10 @@ void do_logging(s_thread_data *data)
while (msgs_left-- > 0) {
DLT_LOG(mycontext, DLT_LOG_INFO, DLT_STRING(PAYLOAD_DATA));
- usleep(mksleep_time(data->params.delay, data->params.delay_fudge));
+ sleep_time = mksleep_time(data->params.delay, data->params.delay_fudge);
+ ts.tv_sec = sleep_time / 1000000000;
+ ts.tv_nsec = sleep_time % 1000000000;
+ nanosleep(&ts, NULL);
}
DLT_UNREGISTER_CONTEXT(mycontext);
diff --git a/src/tests/dlt-test-stress-user.c b/src/tests/dlt-test-stress-user.c
index 5cd3a65..5b7047b 100644
--- a/src/tests/dlt-test-stress-user.c
+++ b/src/tests/dlt-test-stress-user.c
@@ -232,6 +232,7 @@ int testall(int count, int repeat, int delay, int size)
{
char buffer[size];
int num, rnum;
+ struct timespec ts;
for (num = 0; num < size; num++)
buffer[num] = num;
@@ -243,7 +244,9 @@ int testall(int count, int repeat, int delay, int size)
for (rnum = 0; rnum < repeat; rnum++)
for (num = 1; num <= count; num++) {
DLT_LOG(context_info, DLT_LOG_INFO, DLT_INT(num), DLT_RAW(buffer, size));
- usleep(delay);
+ ts.tv_sec = (delay * 1000) / 1000000000;
+ ts.tv_nsec = (delay * 1000) % 1000000000;
+ nanosleep(&ts, NULL);
}
/* wait 5 seconds after test */
diff --git a/src/tests/dlt-test-stress.c b/src/tests/dlt-test-stress.c
index ddfe937..bb986da 100644
--- a/src/tests/dlt-test-stress.c
+++ b/src/tests/dlt-test-stress.c
@@ -227,6 +227,7 @@ void stress1(void)
{
int i, c;
char ctid[5];
+ struct timespec ts;
printf("Starting stress test1... (press \"Enter\" to terminate test) \n");
@@ -240,7 +241,9 @@ void stress1(void)
/*printf("%i: '%s' \n",i,ctid); */
dlt_register_context(&(mycontext[i]), ctid, ctid);
- usleep(500);
+ ts.tv_sec = 0;
+ ts.tv_nsec = 500 * 1000;
+ nanosleep(&ts, NULL);
}
while (1) {
@@ -255,7 +258,9 @@ void stress1(void)
for (i = 0; i < STRESS1_NUM_CONTEXTS; i++) {
DLT_UNREGISTER_CONTEXT(mycontext[i]);
- usleep(500);
+ ts.tv_sec = 0;
+ ts.tv_nsec = 500 * 1000;
+ nanosleep(&ts, NULL);
}
printf("Finished stress test1 \n\n");
@@ -264,6 +269,7 @@ void stress1(void)
void stress2(void)
{
int ret, index;
+ struct timespec ts;
pthread_t thread[STRESS2_MAX_NUM_THREADS];
thread_data_t thread_data[STRESS2_MAX_NUM_THREADS];
@@ -282,7 +288,9 @@ void stress2(void)
if (ret != 0)
printf("Error creating thread %d: %s \n", index, strerror(errno));
- usleep(1000);
+ ts.tv_sec = 0;
+ ts.tv_nsec = 1000 * 1000;
+ nanosleep(&ts, NULL);
}
for (index = 0; index < STRESS2_MAX_NUM_THREADS; index++)
@@ -296,6 +304,7 @@ void thread_function(void)
/*thread_data_t *data; */
DLT_DECLARE_CONTEXT(context_thread1);
char ctid[5];
+ struct timespec ts;
/*data = (thread_data_t *) ptr; */
@@ -304,7 +313,9 @@ void thread_function(void)
/* Create random context id */
snprintf(ctid, 5, "%.2x", rand() & 0x0000ffff);
- usleep(rand() / 1000);
+ ts.tv_sec = 0;
+ ts.tv_nsec = rand();
+ nanosleep(&ts, NULL);
DLT_REGISTER_CONTEXT(context_thread1, ctid, ctid);
@@ -318,6 +329,7 @@ void stress3(void)
DLT_DECLARE_CONTEXT(context_stress3);
char buffer[STRESS3_MAX_NUM_MESSAGES];
int num;
+ struct timespec ts;
/* Performance test */
DLT_REGISTER_CONTEXT(context_stress3, "TST3", "Stress Test 3 - Performance");
@@ -328,7 +340,9 @@ void stress3(void)
for (num = 0; num < STRESS3_MAX_NUM_MESSAGES; num++) {
buffer[num] = num;
DLT_LOG(context_stress3, DLT_LOG_INFO, DLT_INT(num), DLT_RAW(buffer, num));
- usleep(10000);
+ ts.tv_sec = 0;
+ ts.tv_nsec = 10000 * 1000;
+ nanosleep(&ts, NULL);
}
printf("Finished stress test3 \n\n");