pool/thread: clean up tests

pull/3898/head
Victor Julien 6 years ago
parent 025cc64f55
commit 597ff3c8e3

@ -231,12 +231,11 @@ void PoolThreadTestFree(void *data)
static int PoolThreadTestInit01(void) static int PoolThreadTestInit01(void)
{ {
PoolThread *pt = PoolThreadInit(4, /* threads */ PoolThread *pt = PoolThreadInit(4, /* threads */
10, 5, 10, PoolThreadTestAlloc, NULL, NULL, NULL, NULL); 10, 5, 10, PoolThreadTestAlloc,
if (pt == NULL) NULL, NULL, NULL, NULL);
return 0; FAIL_IF(pt == NULL);
PoolThreadFree(pt); PoolThreadFree(pt);
return 1; PASS;
} }
static int PoolThreadTestInit02(void) static int PoolThreadTestInit02(void)
@ -244,135 +243,89 @@ static int PoolThreadTestInit02(void)
int i = 123; int i = 123;
PoolThread *pt = PoolThreadInit(4, /* threads */ PoolThread *pt = PoolThreadInit(4, /* threads */
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, &i, PoolThreadTestFree, NULL); 10, 5, 10,
if (pt == NULL) PoolThreadTestAlloc, PoolThreadTestInit,
return 0; &i, PoolThreadTestFree, NULL);
FAIL_IF(pt == NULL);
PoolThreadFree(pt); PoolThreadFree(pt);
return 1; PASS;
} }
static int PoolThreadTestGet01(void) static int PoolThreadTestGet01(void)
{ {
int result = 0;
PoolThread *pt = PoolThreadInit(4, /* threads */ PoolThread *pt = PoolThreadInit(4, /* threads */
10, 5, 10, PoolThreadTestAlloc, NULL, NULL, NULL, NULL); 10, 5, 10, PoolThreadTestAlloc,
if (pt == NULL) NULL, NULL, NULL, NULL);
return 0; FAIL_IF(pt == NULL);
void *data = PoolThreadGetById(pt, 3); void *data = PoolThreadGetById(pt, 3);
if (data == NULL) { FAIL_IF_NULL(data);
printf("data == NULL: ");
goto end;
}
struct PoolThreadTestData *pdata = data; struct PoolThreadTestData *pdata = data;
if (pdata->res != 3) { FAIL_IF(pdata->res != 3);
printf("res != 3, but %d: ", pdata->res);
goto end;
}
result = 1;
end:
PoolThreadFree(pt); PoolThreadFree(pt);
return result; PASS;
} }
static int PoolThreadTestGet02(void) static int PoolThreadTestGet02(void)
{ {
int i = 123; int i = 123;
int result = 0;
PoolThread *pt = PoolThreadInit(4, /* threads */ PoolThread *pt = PoolThreadInit(4, /* threads */
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, &i, PoolThreadTestFree, NULL); 10, 5, 10, PoolThreadTestAlloc,
if (pt == NULL) PoolThreadTestInit, &i, PoolThreadTestFree, NULL);
return 0; FAIL_IF_NULL(pt);
void *data = PoolThreadGetById(pt, 3); void *data = PoolThreadGetById(pt, 3);
if (data == NULL) { FAIL_IF_NULL(data);
printf("data == NULL: ");
goto end;
}
struct PoolThreadTestData *pdata = data; struct PoolThreadTestData *pdata = data;
if (pdata->res != 3) { FAIL_IF_NOT (pdata->res == 3);
printf("res != 3, but %d: ", pdata->res);
goto end;
}
if (pdata->abc != 123) { FAIL_IF_NOT (pdata->abc == 123);
printf("abc != 123, but %d: ", pdata->abc);
goto end;
}
result = 1;
end:
PoolThreadFree(pt); PoolThreadFree(pt);
return result; PASS;
} }
static int PoolThreadTestReturn01(void) static int PoolThreadTestReturn01(void)
{ {
int i = 123; int i = 123;
int result = 0;
PoolThread *pt = PoolThreadInit(4, /* threads */ PoolThread *pt = PoolThreadInit(4, /* threads */
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, &i, PoolThreadTestFree, NULL); 10, 5, 10, PoolThreadTestAlloc,
if (pt == NULL) PoolThreadTestInit, &i, PoolThreadTestFree, NULL);
return 0; FAIL_IF_NULL(pt);
void *data = PoolThreadGetById(pt, 3); void *data = PoolThreadGetById(pt, 3);
if (data == NULL) { FAIL_IF_NULL(data);
printf("data == NULL: ");
goto end;
}
struct PoolThreadTestData *pdata = data; struct PoolThreadTestData *pdata = data;
if (pdata->res != 3) { FAIL_IF_NOT (pdata->res == 3);
printf("res != 3, but %d: ", pdata->res);
goto end;
}
if (pdata->abc != 123) { FAIL_IF_NOT (pdata->abc == 123);
printf("abc != 123, but %d: ", pdata->abc);
goto end;
}
if (pt->array[3].pool->outstanding != 1) { FAIL_IF_NOT (pt->array[3].pool->outstanding == 1);
printf("pool outstanding count wrong %u: ",
pt->array[3].pool->outstanding);
goto end;
}
PoolThreadReturn(pt, data); PoolThreadReturn(pt, data);
if (pt->array[3].pool->outstanding != 0) { FAIL_IF_NOT (pt->array[3].pool->outstanding == 0);
printf("pool outstanding count wrong %u: ",
pt->array[3].pool->outstanding);
goto end;
}
result = 1;
end:
PoolThreadFree(pt); PoolThreadFree(pt);
return result; PASS;
} }
static int PoolThreadTestGrow01(void) static int PoolThreadTestGrow01(void)
{ {
PoolThread *pt = PoolThreadInit(4, /* threads */ PoolThread *pt = PoolThreadInit(4, /* threads */
10, 5, 10, PoolThreadTestAlloc, NULL, NULL, NULL, NULL); 10, 5, 10, PoolThreadTestAlloc,
if (pt == NULL) NULL, NULL, NULL, NULL);
return 0; FAIL_IF_NULL(pt);
FAIL_IF(PoolThreadExpand(pt) < 0);
if (PoolThreadExpand(pt) < 0) {
PoolThreadFree(pt); PoolThreadFree(pt);
return 0; PASS;
}
PoolThreadFree(pt);
return 1;
} }
static int PoolThreadTestGrow02(void) static int PoolThreadTestGrow02(void)
@ -380,70 +333,41 @@ static int PoolThreadTestGrow02(void)
int i = 123; int i = 123;
PoolThread *pt = PoolThreadInit(4, /* threads */ PoolThread *pt = PoolThreadInit(4, /* threads */
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, &i, PoolThreadTestFree, NULL); 10, 5, 10, PoolThreadTestAlloc,
if (pt == NULL) PoolThreadTestInit, &i, PoolThreadTestFree, NULL);
return 0; FAIL_IF_NULL(pt);
FAIL_IF(PoolThreadExpand(pt) < 0);
if (PoolThreadExpand(pt) < 0) {
PoolThreadFree(pt);
return 0;
}
PoolThreadFree(pt); PoolThreadFree(pt);
return 1; PASS;
} }
static int PoolThreadTestGrow03(void) static int PoolThreadTestGrow03(void)
{ {
int i = 123; int i = 123;
int result = 0;
PoolThread *pt = PoolThreadInit(4, /* threads */ PoolThread *pt = PoolThreadInit(4, /* threads */
10, 5, 10, PoolThreadTestAlloc, PoolThreadTestInit, &i, PoolThreadTestFree, NULL); 10, 5, 10, PoolThreadTestAlloc,
if (pt == NULL) PoolThreadTestInit, &i, PoolThreadTestFree, NULL);
return 0; FAIL_IF_NULL(pt);
FAIL_IF(PoolThreadExpand(pt) < 0);
if (PoolThreadExpand(pt) < 0) {
PoolThreadFree(pt);
return 0;
}
void *data = PoolThreadGetById(pt, 4); void *data = PoolThreadGetById(pt, 4);
if (data == NULL) { FAIL_IF_NULL(data);
printf("data == NULL: ");
goto end;
}
struct PoolThreadTestData *pdata = data; struct PoolThreadTestData *pdata = data;
if (pdata->res != 4) { FAIL_IF_NOT(pdata->res == 4);
printf("res != 5, but %d: ", pdata->res);
goto end;
}
if (pdata->abc != 123) { FAIL_IF_NOT(pdata->abc == 123);
printf("abc != 123, but %d: ", pdata->abc);
goto end;
}
if (pt->array[4].pool->outstanding != 1) { FAIL_IF_NOT(pt->array[4].pool->outstanding == 1);
printf("pool outstanding count wrong %u: ",
pt->array[4].pool->outstanding);
goto end;
}
PoolThreadReturn(pt, data); PoolThreadReturn(pt, data);
if (pt->array[4].pool->outstanding != 0) { FAIL_IF_NOT(pt->array[4].pool->outstanding == 0);
printf("pool outstanding count wrong %u: ",
pt->array[4].pool->outstanding);
goto end;
}
result = 1;
end:
PoolThreadFree(pt); PoolThreadFree(pt);
return result; PASS;
} }
#endif #endif

Loading…
Cancel
Save