Improve test coverage
This commit is contained in:
1 parent
ff778528f8
commit
100c0f22fe
2 files changed
+35
-5
No files matched your search
+27
-4
@@ -32,10 +32,18 @@ typedef struct test_s {
|
|||||||
ILIST_INTERFACE (ilist_free, struct test_s);
|
ILIST_INTERFACE (ilist_free, struct test_s);
|
||||||
} test_t;
|
} test_t;
|
||||||
|
|
||||||
|
static inline int test_cmp(const test_t *i1, const test_t *i2)
|
||||||
|
{
|
||||||
|
return i1->n < i2->n ? -1 : i1->n > i2->n;
|
||||||
|
}
|
||||||
|
static inline bool test_equal_p(const test_t *i1, const test_t *i2)
|
||||||
|
{
|
||||||
|
return i1->n == i2->n;
|
||||||
|
}
|
||||||
|
|
||||||
#include "coverage.h"
|
#include "coverage.h"
|
||||||
START_COVERAGE
|
START_COVERAGE
|
||||||
ILIST_DEF(ilist_tname, test_t, M_POD_OPLIST)
|
ILIST_DEF(ilist_tname, test_t, M_OPEXTEND(M_POD_OPLIST, CMP(API_6(test_cmp)), EQUAL(API_6(test_equal_p))))
|
||||||
END_COVERAGE
|
END_COVERAGE
|
||||||
|
|
||||||
ILIST_DEF(ilist_free, test_t, (DEL(free)))
|
ILIST_DEF(ilist_free, test_t, (DEL(free)))
|
||||||
@@ -88,6 +96,7 @@ static void test(void)
|
|||||||
assert (ilist_tname_end_p(it2));
|
assert (ilist_tname_end_p(it2));
|
||||||
assert (ilist_tname_last_p(it2));
|
assert (ilist_tname_last_p(it2));
|
||||||
assert (!ilist_tname_it_equal_p(it1, it2));
|
assert (!ilist_tname_it_equal_p(it1, it2));
|
||||||
|
assert (ilist_tname_it_equal_p(it1, it1));
|
||||||
for(ilist_tname_it_set(it2, it1) ; !ilist_tname_end_p(it2) ; ilist_tname_previous(it2)) {
|
for(ilist_tname_it_set(it2, it1) ; !ilist_tname_end_p(it2) ; ilist_tname_previous(it2)) {
|
||||||
const test_t *item = ilist_tname_cref(it2);
|
const test_t *item = ilist_tname_cref(it2);
|
||||||
n--;
|
n--;
|
||||||
@@ -117,7 +126,9 @@ static void test(void)
|
|||||||
|
|
||||||
for M_EACH(item, list, ILIST_OPLIST(ilist_tname)) {
|
for M_EACH(item, list, ILIST_OPLIST(ilist_tname)) {
|
||||||
(void)item;
|
(void)item;
|
||||||
assert(false);
|
if (M_UNLIKELY_NOMEM(1)) {
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ilist_tname_push_back (list, &x3);
|
ilist_tname_push_back (list, &x3);
|
||||||
@@ -142,7 +153,7 @@ static void test(void)
|
|||||||
ilist_tname_clear(list);
|
ilist_tname_clear(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NUM 10
|
#define NUM 100
|
||||||
static void test2(void)
|
static void test2(void)
|
||||||
{
|
{
|
||||||
test_t x[NUM];
|
test_t x[NUM];
|
||||||
@@ -155,6 +166,7 @@ static void test2(void)
|
|||||||
assert (ilist_tname_size(list1) == NUM);
|
assert (ilist_tname_size(list1) == NUM);
|
||||||
assert (ilist_tname_size(list2) == 0);
|
assert (ilist_tname_size(list2) == 0);
|
||||||
assert (ilist_tname_equal_p(list1, list2) == false);
|
assert (ilist_tname_equal_p(list1, list2) == false);
|
||||||
|
assert (ilist_tname_equal_p(list1, list1) == true);
|
||||||
ilist_tname_it_t it;
|
ilist_tname_it_t it;
|
||||||
ilist_tname_it (it, list1);
|
ilist_tname_it (it, list1);
|
||||||
for(int i = 0; i < NUM; i++) {
|
for(int i = 0; i < NUM; i++) {
|
||||||
@@ -193,7 +205,6 @@ static void test2(void)
|
|||||||
assert (n == item->n);
|
assert (n == item->n);
|
||||||
}
|
}
|
||||||
assert (n == 0);
|
assert (n == 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
M_LET(list1, list2, ILIST_OPLIST(ilist_tname)) {
|
M_LET(list1, list2, ILIST_OPLIST(ilist_tname)) {
|
||||||
for(int i = 0; i < NUM; i++)
|
for(int i = 0; i < NUM; i++)
|
||||||
@@ -204,6 +215,7 @@ static void test2(void)
|
|||||||
for(int i = NUM/2; i < NUM; i++) {
|
for(int i = NUM/2; i < NUM; i++) {
|
||||||
ilist_tname_push_back(list2, &x[i]);
|
ilist_tname_push_back(list2, &x[i]);
|
||||||
}
|
}
|
||||||
|
assert (ilist_tname_equal_p(list1, list2) == false);
|
||||||
ilist_tname_splice(list1, list2);
|
ilist_tname_splice(list1, list2);
|
||||||
assert (ilist_tname_size(list1) == NUM);
|
assert (ilist_tname_size(list1) == NUM);
|
||||||
assert (ilist_tname_size(list2) == 0);
|
assert (ilist_tname_size(list2) == 0);
|
||||||
@@ -224,6 +236,17 @@ static void test2(void)
|
|||||||
}
|
}
|
||||||
assert (n == NUM);
|
assert (n == NUM);
|
||||||
}
|
}
|
||||||
|
M_LET(list1, list2, ILIST_OPLIST(ilist_tname)) {
|
||||||
|
for(int i = 0; i < NUM/2; i++) {
|
||||||
|
x[i].n = i;
|
||||||
|
x[i+NUM/2].n = i;
|
||||||
|
}
|
||||||
|
for(int i = 0; i < NUM/2; i++) {
|
||||||
|
ilist_tname_push_back(list1, &x[i]);
|
||||||
|
ilist_tname_push_back(list2, &x[i+NUM/2]);
|
||||||
|
}
|
||||||
|
assert (ilist_tname_equal_p(list1, list2) == true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_free(void)
|
static void test_free(void)
|
||||||
|
|||||||
@@ -34,10 +34,16 @@ typedef struct ishared_s {
|
|||||||
int data[100];
|
int data[100];
|
||||||
} ishared_t[1];
|
} ishared_t[1];
|
||||||
|
|
||||||
|
static bool ishared_init_sleep = false;
|
||||||
|
|
||||||
static void ishared_init_data(struct ishared_s *x)
|
static void ishared_init_data(struct ishared_s *x)
|
||||||
{
|
{
|
||||||
for(int i = 0 ; i < 100; i++)
|
for(int i = 0 ; i < 100; i++)
|
||||||
x->data[i] = i * i;
|
x->data[i] = i * i;
|
||||||
|
if (ishared_init_sleep) {
|
||||||
|
// Slow down init
|
||||||
|
m_thread_sleep(100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ishared_test(struct ishared_s *x)
|
static void ishared_test(struct ishared_s *x)
|
||||||
@@ -94,7 +100,6 @@ static struct ishared_s g_var = {
|
|||||||
static void test_static(void)
|
static void test_static(void)
|
||||||
{
|
{
|
||||||
ishared2_t p1, p2;
|
ishared2_t p1, p2;
|
||||||
|
|
||||||
p1 = ishared2_init_once(NULL);
|
p1 = ishared2_init_once(NULL);
|
||||||
assert(p1 == NULL);
|
assert(p1 == NULL);
|
||||||
p1 = ishared2_init_once(&g_var);
|
p1 = ishared2_init_once(&g_var);
|
||||||
@@ -129,12 +134,14 @@ static void test_shared(void)
|
|||||||
{
|
{
|
||||||
m_thread_t id[MAX_THREAD];
|
m_thread_t id[MAX_THREAD];
|
||||||
|
|
||||||
|
ishared_init_sleep = true;
|
||||||
for(int i = 0; i < MAX_THREAD; i++) {
|
for(int i = 0; i < MAX_THREAD; i++) {
|
||||||
m_thread_create(id[i], func, (void*) (intptr_t) i);
|
m_thread_create(id[i], func, (void*) (intptr_t) i);
|
||||||
}
|
}
|
||||||
for(int i = 0; i < MAX_THREAD; i++) {
|
for(int i = 0; i < MAX_THREAD; i++) {
|
||||||
m_thread_join(id[i]);
|
m_thread_join(id[i]);
|
||||||
}
|
}
|
||||||
|
ishared_init_sleep = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
|||||||
Reference in new issue
Block a user