More defspace tests.

This commit is contained in:
Bill Currie 2018-10-09 12:45:26 +09:00
parent 6f28ab2a68
commit d95c01be1a
4 changed files with 63 additions and 2 deletions

View file

@ -211,5 +211,5 @@ voidfor.run: Makefile build-run
include ./$(DEPDIR)/voidfor.Qo
EXTRA_DIST= test-bi.h build-run
EXTRA_DIST= test-bi.h build-run test-defspace.h
CLEANFILES= *.dat *.sym *.qfo *.run *.frame

View file

@ -5,13 +5,14 @@
#include <stdlib.h>
#include "class.h"
#include "defspace.h"
#include "expr.h"
#include "function.h"
#include "options.h"
#include "strpool.h"
#include "qfcc.h"
#include "test-defspace.h"
options_t options;
pr_info_t pr;
function_t *current_func;

View file

@ -0,0 +1,6 @@
#include "def.h"
#include "defspace.h"
int def_list_is_empty (const defspace_t *space);
int def_list_is_valid (const defspace_t *space);
int free_locs_is_valid (const defspace_t *space);

View file

@ -1 +1,55 @@
#include "../source/defspace.c"
#include "test-defspace.h"
__attribute__((pure)) int
def_list_is_empty (const defspace_t *space)
{
return (!space->defs && space->def_tail == &space->defs);
}
__attribute__((pure)) int
def_list_is_valid (const defspace_t *space)
{
def_t *const *d = &space->defs;
while (*d) {
d = &(*d)->next;
}
return d == space->def_tail;
}
int
free_locs_is_valid (const defspace_t *space)
{
int free_space = 0;
const locref_t *loc;
for (loc = space->free_locs; loc; loc = loc->next) {
if (loc->ofs < 0) {
printf ("negative offset in free_locs\n");
return 0;
}
if (loc->size <= 0) {
printf ("zero or negative size in free_locs\n");
return 0;
}
if (loc->next && loc->ofs > loc->next->ofs) {
printf ("free_locs not in ascending order\n");
return 0;
}
if (loc->next && loc->ofs + loc->size > loc->next->ofs) {
printf ("overlap in free_locs\n");
return 0;
}
if (loc->next && loc->ofs + loc->size == loc->next->ofs) {
printf ("adjoining nodes in free_locs\n");
return 0;
}
free_space += loc->size;
}
if (free_space > space->size) {
printf ("free_locs describes too much free space\n");
return 0;
}
return 1;
}