mirror of https://github.com/tailix/libkernaux.git
Main: include/kernaux/memmap.h: Test assertions
This commit is contained in:
parent
82dcb74824
commit
9cab961d46
|
@ -29,7 +29,7 @@ typedef struct KernAux_MemMap {
|
||||||
struct KernAux_MemMap KernAux_MemMap_create(size_t memory_size);
|
struct KernAux_MemMap KernAux_MemMap_create(size_t memory_size);
|
||||||
void KernAux_MemMap_init(KernAux_MemMap memmap, size_t memory_size);
|
void KernAux_MemMap_init(KernAux_MemMap memmap, size_t memory_size);
|
||||||
|
|
||||||
/// @warning Must only be called with unfinished memmap, otherwise panics.
|
/// @warning Must only be called with NOT finished memmap, otherwise panics.
|
||||||
bool KernAux_MemMap_add_entry(
|
bool KernAux_MemMap_add_entry(
|
||||||
KernAux_MemMap memmap,
|
KernAux_MemMap memmap,
|
||||||
bool is_available,
|
bool is_available,
|
||||||
|
@ -38,7 +38,7 @@ bool KernAux_MemMap_add_entry(
|
||||||
size_t size
|
size_t size
|
||||||
);
|
);
|
||||||
|
|
||||||
/// @warning Must only be called with unfinished memmap, otherwise panics.
|
/// @warning Must only be called with NOT finished memmap, otherwise panics.
|
||||||
bool KernAux_MemMap_finish(KernAux_MemMap memmap);
|
bool KernAux_MemMap_finish(KernAux_MemMap memmap);
|
||||||
|
|
||||||
/// @warning Must only be called with finished memmap, otherwise panics.
|
/// @warning Must only be called with finished memmap, otherwise panics.
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <kernaux/assert.h>
|
||||||
#include <kernaux/memmap.h>
|
#include <kernaux/memmap.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -11,11 +12,27 @@
|
||||||
|
|
||||||
static KernAux_MemMap memmap;
|
static KernAux_MemMap memmap;
|
||||||
|
|
||||||
|
static unsigned int assert_count_exp = 0;
|
||||||
|
static unsigned int assert_count_ctr = 0;
|
||||||
|
|
||||||
|
static const char *assert_last_file = NULL;
|
||||||
|
|
||||||
|
static void assert_cb(
|
||||||
|
const char *const file,
|
||||||
|
__attribute__((unused)) const int line,
|
||||||
|
__attribute__((unused)) const char *const msg
|
||||||
|
) {
|
||||||
|
++assert_count_ctr;
|
||||||
|
assert_last_file = file;
|
||||||
|
}
|
||||||
|
|
||||||
#define MEMSET memset(memmap, 0xff, sizeof(memmap))
|
#define MEMSET memset(memmap, 0xff, sizeof(memmap))
|
||||||
#define MEMMAP (*memmap)
|
#define MEMMAP (*memmap)
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
kernaux_assert_cb = assert_cb;
|
||||||
|
|
||||||
{
|
{
|
||||||
MEMSET;
|
MEMSET;
|
||||||
KernAux_MemMap_init(memmap, 0);
|
KernAux_MemMap_init(memmap, 0);
|
||||||
|
@ -31,6 +48,12 @@ int main()
|
||||||
assert(MEMMAP.entries_count == 0);
|
assert(MEMMAP.entries_count == 0);
|
||||||
|
|
||||||
assert(KernAux_MemMap_entry_by_index(memmap, 0) == NULL);
|
assert(KernAux_MemMap_entry_by_index(memmap, 0) == NULL);
|
||||||
|
|
||||||
|
assert(assert_count_ctr == assert_count_exp);
|
||||||
|
assert(!KernAux_MemMap_finish(memmap));
|
||||||
|
assert(assert_count_ctr == ++assert_count_exp);
|
||||||
|
assert(strstr(assert_last_file, "src/memmap.c") != NULL);
|
||||||
|
assert_last_file = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -140,7 +163,11 @@ int main()
|
||||||
assert(MEMMAP.entries[0].end == 1);
|
assert(MEMMAP.entries[0].end == 1);
|
||||||
assert(MEMMAP.entries[0].limit == 2);
|
assert(MEMMAP.entries[0].limit == 2);
|
||||||
|
|
||||||
|
assert(assert_count_ctr == assert_count_exp);
|
||||||
assert(KernAux_MemMap_entry_by_index(memmap, 0) == NULL);
|
assert(KernAux_MemMap_entry_by_index(memmap, 0) == NULL);
|
||||||
|
assert(assert_count_ctr == ++assert_count_exp);
|
||||||
|
assert(strstr(assert_last_file, "src/memmap.c") != NULL);
|
||||||
|
assert_last_file = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -185,5 +212,7 @@ int main()
|
||||||
assert(KernAux_MemMap_entry_by_index(memmap, 1) == &MEMMAP.entries[1]);
|
assert(KernAux_MemMap_entry_by_index(memmap, 1) == &MEMMAP.entries[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(assert_count_ctr == assert_count_exp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue