Allow mutability if in testing

This commit is contained in:
Peter Evans 2018-02-06 23:37:20 -06:00
parent 4e0892dc86
commit 5e7492abdf
1 changed files with 13 additions and 2 deletions

View File

@ -10,6 +10,7 @@
* a value for a DI entry, it cannot be changed.
*/
#include <stdbool.h>
#include <stdlib.h>
#include "log.h"
@ -22,15 +23,25 @@
*/
static void *di_table[VM_DI_SIZE];
#ifdef TESTING
static bool di_mutable = true;
#else
static bool di_mutable = false;
#endif
/*
* Set the di table entry `ent` to `val`. If there is a _previous_
* value assigned to ent, then this returns ERR_INVALID, and no
* further assignment is allowed.
* further assignment is allowed.
*
* NOTE: in testing, we _do_ allow multiple assignments to entries, so
* as to make it easier to tear down and rebuild machines/cpus/etc.
* between tests.
*/
int
vm_di_set(int ent, void *val)
{
if (di_table[ent] != NULL) {
if (di_table[ent] != NULL && !di_mutable) {
return ERR_INVALID;
}