summaryrefslogtreecommitdiff
path: root/src/lib/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/tests')
-rw-r--r--src/lib/tests/shm_du_map_test_du_buff_create.c6
-rw-r--r--src/lib/tests/shm_du_map_test_prod_cons.c58
2 files changed, 20 insertions, 44 deletions
diff --git a/src/lib/tests/shm_du_map_test_du_buff_create.c b/src/lib/tests/shm_du_map_test_du_buff_create.c
index 9f66b20c..6787a1bc 100644
--- a/src/lib/tests/shm_du_map_test_du_buff_create.c
+++ b/src/lib/tests/shm_du_map_test_du_buff_create.c
@@ -54,7 +54,9 @@ int shm_du_map_test_du_buff_create(int argc, char ** argv)
j_inc = MAX(1, SHM_DU_BLOCK_DATA_SIZE / 8);
k_inc = MAX(1, SHM_DU_BLOCK_DATA_SIZE / 16);
- for (i = SHM_DU_BUFF_BLOCK_SIZE / 4; i <= TEST_BUFF_SIZE; i += i_inc) {
+ for (i = SHM_DU_BLOCK_DATA_SIZE / 4;
+ i <= TEST_BUFF_SIZE;
+ i += i_inc) {
for (j = 0; j < i; j += j_inc) {
for (k = 0; k < i - j; k += k_inc) {
if (k > SHM_DU_BLOCK_DATA_SIZE)
@@ -73,7 +75,7 @@ int shm_du_map_test_du_buff_create(int argc, char ** argv)
shm_du_map_close(dum);
return -1;
}
- shm_release_du_buff(dum, dub);
+ shm_release_du_buff(dum);
}
}
}
diff --git a/src/lib/tests/shm_du_map_test_prod_cons.c b/src/lib/tests/shm_du_map_test_prod_cons.c
index 945104c1..ff9dfb0a 100644
--- a/src/lib/tests/shm_du_map_test_prod_cons.c
+++ b/src/lib/tests/shm_du_map_test_prod_cons.c
@@ -27,12 +27,12 @@
#include <pthread.h>
#include "shm_du_map.c"
-#define TEST_BUFF_SIZE (3 * SHM_DU_BLOCK_DATA_SIZE)
+#define TEST_BUFF_SIZE (SHM_DU_BLOCK_DATA_SIZE)
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
-int * sync;
+int sync;
void * produce()
{
@@ -46,31 +46,26 @@ void * produce()
struct timespec starttime;
struct timespec stoptime;
double elapsed;
- long overruns = 0;
dum = shm_du_map_open();
if (dum == NULL)
return (void *)-1;
srand(time(NULL));
- clock_gettime(CLOCK_MONOTONIC, &starttime);
test_values = malloc (sizeof *test_values * TEST_BUFF_SIZE);
for (i = 0; i < TEST_BUFF_SIZE; i++)
test_values[i] = 170;
- for (i = 0; i < 4 * SHM_BLOCKS_IN_MAP; i++) {
+ clock_gettime(CLOCK_MONOTONIC, &starttime);
+ for (i = 0; i < SHM_BLOCKS_IN_MAP; i++) {
struct shm_du_buff * sdb;
size_t len;
- struct timespec ts;
-
- test_buf_size = rand() % (TEST_BUFF_SIZE - 512) + 512;
- headspace = MAX(4, rand() % 64);
- tailspace = MAX(1, rand() % 24);
+ test_buf_size = TEST_BUFF_SIZE;
- ts.tv_sec = 0;
- ts.tv_nsec = rand() % 90000;
+ headspace = 32;
+ tailspace = 8;
len = test_buf_size - (headspace + tailspace);
@@ -81,23 +76,12 @@ void * produce()
len);
if (sdb != NULL) {
- sync[i] = du_buff_ptr_to_idx(dum, sdb);
bytes_written += len;
}
else {
- i--;
- ++overruns;
- ts.tv_nsec = 10000;
- nanosleep(&ts, NULL);
- }
- nanosleep(&ts, NULL);
-
- if (overruns > 100) {
- LOG_INFO("Bugging out due to overruns.");
- sync[i+1] = -2;
+ sync = -2;
break;
}
-
}
clock_gettime(CLOCK_MONOTONIC, &stoptime);
@@ -110,6 +94,9 @@ void * produce()
free(test_values);
shm_du_map_close(dum);
+
+ sync = -1;
+
return 0;
}
@@ -117,24 +104,19 @@ void * consume()
{
struct shm_du_map * dum;
- long i;
-
struct timespec ts;
ts.tv_sec = 0;
- ts.tv_nsec = 5000;
+ ts.tv_nsec = 1000;
dum = shm_du_map_open();
if (dum == NULL)
pthread_exit((void *) -1);
- for (i = 0; i < 4 * SHM_BLOCKS_IN_MAP; i++) {
- while (sync[i] == -1)
- nanosleep(&ts, NULL); /* wait for the producer */
- if (sync[i] == -2)
- break;
- shm_release_du_buff(dum, idx_to_du_buff_ptr(dum, sync[i]));
+ while (!sync) {
+ while (!shm_release_du_buff(dum));
+ nanosleep(&ts, NULL);
}
shm_du_map_close(dum);
@@ -148,11 +130,8 @@ int shm_du_map_test_prod_cons(int argc, char ** argv)
int res1;
- int i;
-
pthread_t producer;
pthread_t consumer;
-
shm_unlink(SHM_DU_MAP_FILENAME);
dum = shm_du_map_create();
@@ -160,10 +139,7 @@ int shm_du_map_test_prod_cons(int argc, char ** argv)
if (dum == NULL)
return -1;
- sync = malloc(sizeof *sync * 4 * SHM_BLOCKS_IN_MAP);
-
- for (i = 0; i < 4 * SHM_BLOCKS_IN_MAP; i++)
- sync[i] = -1;
+ sync = 0;
res1 = (int) pthread_create(&producer, NULL, produce, NULL);
pthread_create(&consumer, NULL, consume, NULL);
@@ -171,8 +147,6 @@ int shm_du_map_test_prod_cons(int argc, char ** argv)
pthread_join(producer, NULL);
pthread_join(consumer, NULL);
- free(sync);
-
shm_du_map_close(dum);
return res1;