flow/storage: use fail/pass api in unit tests

pull/15119/head
Jason Ish 4 months ago committed by Victor Julien
parent e4e5413478
commit 31a4381d30

@ -86,212 +86,127 @@ static void StorageTestFree(void *x)
static int FlowStorageTest01(void) static int FlowStorageTest01(void)
{ {
Flow *f = NULL;
StorageCleanup(); StorageCleanup();
StorageInit(); StorageInit();
FlowStorageId id1 = FlowStorageRegister("test", 8, StorageTestAlloc, StorageTestFree); FlowStorageId id1 = FlowStorageRegister("test", 8, StorageTestAlloc, StorageTestFree);
if (id1.id < 0) FAIL_IF(id1.id < 0);
goto error;
FlowStorageId id2 = FlowStorageRegister("variable", 24, StorageTestAlloc, StorageTestFree); FlowStorageId id2 = FlowStorageRegister("variable", 24, StorageTestAlloc, StorageTestFree);
if (id2.id < 0) FAIL_IF(id2.id < 0);
goto error;
FlowStorageId id3 = FlowStorageId id3 =
FlowStorageRegister("store", sizeof(void *), StorageTestAlloc, StorageTestFree); FlowStorageRegister("store", sizeof(void *), StorageTestAlloc, StorageTestFree);
if (id3.id < 0) FAIL_IF(id3.id < 0);
goto error;
if (StorageFinalize() < 0) FAIL_IF(StorageFinalize() < 0);
goto error;
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
f = FlowAlloc(); Flow *f = FlowAlloc();
if (f == NULL) { FAIL_IF_NULL(f);
goto error;
}
void *ptr = FlowGetStorageById(f, id1); void *ptr = FlowGetStorageById(f, id1);
if (ptr != NULL) { FAIL_IF_NOT_NULL(ptr);
goto error;
}
ptr = FlowGetStorageById(f, id2); ptr = FlowGetStorageById(f, id2);
if (ptr != NULL) { FAIL_IF_NOT_NULL(ptr);
goto error;
}
ptr = FlowGetStorageById(f, id3); ptr = FlowGetStorageById(f, id3);
if (ptr != NULL) { FAIL_IF_NOT_NULL(ptr);
goto error;
}
void *ptr1a = FlowAllocStorageById(f, id1); void *ptr1a = FlowAllocStorageById(f, id1);
if (ptr1a == NULL) { FAIL_IF_NULL(ptr1a);
goto error;
}
void *ptr2a = FlowAllocStorageById(f, id2); void *ptr2a = FlowAllocStorageById(f, id2);
if (ptr2a == NULL) { FAIL_IF_NULL(ptr2a);
goto error;
}
void *ptr3a = FlowAllocStorageById(f, id3); void *ptr3a = FlowAllocStorageById(f, id3);
if (ptr3a == NULL) { FAIL_IF_NULL(ptr3a);
goto error;
}
void *ptr1b = FlowGetStorageById(f, id1); void *ptr1b = FlowGetStorageById(f, id1);
if (ptr1a != ptr1b) { FAIL_IF(ptr1a != ptr1b);
goto error;
}
void *ptr2b = FlowGetStorageById(f, id2); void *ptr2b = FlowGetStorageById(f, id2);
if (ptr2a != ptr2b) { FAIL_IF(ptr2a != ptr2b);
goto error;
}
void *ptr3b = FlowGetStorageById(f, id3); void *ptr3b = FlowGetStorageById(f, id3);
if (ptr3a != ptr3b) { FAIL_IF(ptr3a != ptr3b);
goto error;
}
FlowClearMemory(f, 0); FlowClearMemory(f, 0);
FlowFree(f); FlowFree(f);
FlowShutdown(); FlowShutdown();
StorageCleanup(); StorageCleanup();
return 1; PASS;
error:
if (f != NULL) {
FlowClearMemory(f, 0);
FlowFree(f);
}
FlowShutdown();
StorageCleanup();
return 0;
} }
static int FlowStorageTest02(void) static int FlowStorageTest02(void)
{ {
Flow *f = NULL;
StorageCleanup(); StorageCleanup();
StorageInit(); StorageInit();
FlowStorageId id1 = FlowStorageRegister("test", sizeof(void *), NULL, StorageTestFree); FlowStorageId id1 = FlowStorageRegister("test", sizeof(void *), NULL, StorageTestFree);
if (id1.id < 0) FAIL_IF(id1.id < 0);
goto error;
if (StorageFinalize() < 0) FAIL_IF(StorageFinalize() < 0);
goto error;
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
f = FlowAlloc(); Flow *f = FlowAlloc();
if (f == NULL) { FAIL_IF_NULL(f);
goto error;
}
void *ptr = FlowGetStorageById(f, id1); void *ptr = FlowGetStorageById(f, id1);
if (ptr != NULL) { FAIL_IF_NOT_NULL(ptr);
goto error;
}
void *ptr1a = SCMalloc(128); void *ptr1a = SCMalloc(128);
if (unlikely(ptr1a == NULL)) { FAIL_IF_NULL(ptr1a);
goto error;
}
FlowSetStorageById(f, id1, ptr1a); FlowSetStorageById(f, id1, ptr1a);
void *ptr1b = FlowGetStorageById(f, id1); void *ptr1b = FlowGetStorageById(f, id1);
if (ptr1a != ptr1b) { FAIL_IF(ptr1a != ptr1b);
goto error;
}
FlowClearMemory(f, 0); FlowClearMemory(f, 0);
FlowFree(f); FlowFree(f);
FlowShutdown(); FlowShutdown();
StorageCleanup(); StorageCleanup();
return 1; PASS;
error:
if (f != NULL) {
FlowClearMemory(f, 0);
FlowFree(f);
}
FlowShutdown();
StorageCleanup();
return 0;
} }
static int FlowStorageTest03(void) static int FlowStorageTest03(void)
{ {
Flow *f = NULL;
StorageCleanup(); StorageCleanup();
StorageInit(); StorageInit();
FlowStorageId id1 = FlowStorageRegister("test1", sizeof(void *), NULL, StorageTestFree); FlowStorageId id1 = FlowStorageRegister("test1", sizeof(void *), NULL, StorageTestFree);
if (id1.id < 0) FAIL_IF(id1.id < 0);
goto error;
FlowStorageId id2 = FlowStorageRegister("test2", sizeof(void *), NULL, StorageTestFree); FlowStorageId id2 = FlowStorageRegister("test2", sizeof(void *), NULL, StorageTestFree);
if (id2.id < 0) FAIL_IF(id2.id < 0);
goto error;
FlowStorageId id3 = FlowStorageRegister("test3", 32, StorageTestAlloc, StorageTestFree); FlowStorageId id3 = FlowStorageRegister("test3", 32, StorageTestAlloc, StorageTestFree);
if (id3.id < 0) FAIL_IF(id3.id < 0);
goto error;
if (StorageFinalize() < 0) FAIL_IF(StorageFinalize() < 0);
goto error;
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
f = FlowAlloc(); Flow *f = FlowAlloc();
if (f == NULL) { FAIL_IF_NULL(f);
goto error;
}
void *ptr = FlowGetStorageById(f, id1); void *ptr = FlowGetStorageById(f, id1);
if (ptr != NULL) { FAIL_IF_NOT_NULL(ptr);
goto error;
}
void *ptr1a = SCMalloc(128); void *ptr1a = SCMalloc(128);
if (unlikely(ptr1a == NULL)) { FAIL_IF_NULL(ptr1a);
goto error;
}
FlowSetStorageById(f, id1, ptr1a); FlowSetStorageById(f, id1, ptr1a);
void *ptr2a = SCMalloc(256); void *ptr2a = SCMalloc(256);
if (unlikely(ptr2a == NULL)) { FAIL_IF_NULL(ptr2a);
goto error;
}
FlowSetStorageById(f, id2, ptr2a); FlowSetStorageById(f, id2, ptr2a);
void *ptr3a = FlowAllocStorageById(f, id3); void *ptr3a = FlowAllocStorageById(f, id3);
if (ptr3a == NULL) { FAIL_IF_NULL(ptr3a);
goto error;
}
void *ptr1b = FlowGetStorageById(f, id1); void *ptr1b = FlowGetStorageById(f, id1);
if (ptr1a != ptr1b) { FAIL_IF(ptr1a != ptr1b);
goto error;
}
void *ptr2b = FlowGetStorageById(f, id2); void *ptr2b = FlowGetStorageById(f, id2);
if (ptr2a != ptr2b) { FAIL_IF(ptr2a != ptr2b);
goto error;
}
void *ptr3b = FlowGetStorageById(f, id3); void *ptr3b = FlowGetStorageById(f, id3);
if (ptr3a != ptr3b) { FAIL_IF(ptr3a != ptr3b);
goto error;
}
FlowClearMemory(f, 0); FlowClearMemory(f, 0);
FlowFree(f); FlowFree(f);
FlowShutdown(); FlowShutdown();
StorageCleanup(); StorageCleanup();
return 1; PASS;
error:
if (f != NULL) {
FlowClearMemory(f, 0);
FlowFree(f);
}
FlowShutdown();
StorageCleanup();
return 0;
} }
#endif #endif

Loading…
Cancel
Save