#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifdef __FUZIX__
+#include <unistd.h>
+#endif
#include "process_test.h"
#include "rassert.h"
+#ifdef __FUZIX__
+#define BLOCK_SIZE 0x10
+#define BLOCK_SHIFT 4
+#else
#define BLOCK_SIZE 0x1000
#define BLOCK_SHIFT 12
+#endif
int rand_int(int n) {
return (int)((long long)rand() * n / (RAND_MAX + 1LL));
int pool_used = 0;
for (int i = 0; i < n_events; ++i) {
struct process_test test;
+#ifdef __FUZIX__
+ memset(&test, 0, sizeof(test));
+#endif
test.process = rand_int(n_processes);
test.old_size = processes[test.process];
int blocks = (int)((test.size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
test.success = pool_used + blocks <= pool_blocks;
+#ifdef __FUZIX__
+ test.type = PROCESS_TEST_TYPE_ALLOC;
+ write(1, &test, sizeof(test));
+#else
printf(
"alloc %d %ld %s\n",
test.process,
test.size,
test.success ? "true" : "false"
);
+#endif
if (test.success) {
processes[test.process] = test.size;
else {
int old_blocks = (int)((test.old_size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
if (rand_int(64)) {
+#ifdef __FUZIX__
+ test.type = PROCESS_TEST_TYPE_RUN;
+ write(1, &test, sizeof(test));
+#else
printf("run %d\n", test.process);
+#endif
if (rand_int(8) == 0) {
test.size = rand_long(process_size + 1);
int blocks = (int)((test.size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
test.success = pool_used + blocks - old_blocks <= pool_blocks;
+#ifdef __FUZIX__
+ test.type = PROCESS_TEST_TYPE_REALLOC;
+ write(1, &test, sizeof(test));
+#else
printf(
"realloc %d %ld %ld %s\n",
test.process,
test.size,
test.success ? "true" : "false"
);
+#endif
if (test.success) {
processes[test.process] = test.size;
}
}
else {
+#ifdef __FUZIX__
+ test.type = PROCESS_TEST_TYPE_FREE;
+ write(1, &test, sizeof(test));
+#else
printf("free %d %ld\n", test.process, test.old_size);
+#endif
processes[test.process] = -1;
pool_used -= old_blocks;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifdef __FUZIX__
+#include <unistd.h>
+#endif
#include "core.h"
#include "process.h"
#include "process_test.h"
int i, j, k;
#endif /* INDIRECT_CORE */
struct process_test test;
+#ifndef __FUZIX__
char buf[256];
+#endif
bool result;
long actual_old_size;
int old_blocks, blocks, actual_old_blocks;
while (true) {
//printf("avail %d %d(%d) %d(%d)\n", process_avail, CORE_AVAIL, core_table.avail, SWAP_AVAIL, swap_table.avail);
+#ifdef __FUZIX__
+ if (read(0, &test, sizeof(test)) != sizeof(test))
+ break;
+#else
switch ((unsigned int)scanf("%s", buf)) { // cast because of ACK bug
case -1:
goto done;
rassert(false);
}
if (strcmp(buf, "alloc") == 0) {
- test.type = 0;
+ test.type = PROCESS_TEST_TYPE_ALLOC;
rassert(
scanf(
"%d %ld %s",
rassert(false);
}
else if (strcmp(buf, "realloc") == 0) {
- test.type = 1;
+ test.type = PROCESS_TEST_TYPE_REALLOC;
rassert(
scanf(
"%d %ld %ld %s",
rassert(false);
}
else if (strcmp(buf, "run") == 0) {
- test.type = 2;
+ test.type = PROCESS_TEST_TYPE_RUN;
rassert(scanf("%d", &test.process) == 1);
rassert(test.process >= 0 && test.process < n_processes);
}
else if (strcmp(buf, "free") == 0) {
- test.type = 3;
+ test.type = PROCESS_TEST_TYPE_FREE;
rassert(scanf("%d %ld", &test.process, &test.old_size) == 2);
rassert(test.process >= 0 && test.process < n_processes);
rassert(test.old_size >= 0);
}
else
rassert(false);
+#endif
switch (test.type) {
- case 0:
+ case PROCESS_TEST_TYPE_ALLOC:
printf(
"alloc %d %ld %s\n",
test.process,
}
}
break;
- case 1:
+ case PROCESS_TEST_TYPE_REALLOC:
printf(
"realloc %d %ld %ld %s\n",
test.process,
}
}
break;
- case 2:
+ case PROCESS_TEST_TYPE_RUN:
printf("run %d\n", test.process);
if (processes[test.process].size == -1L)
printf("... not allocated, ignore\n");
printf("... ok\n");
}
break;
- case 3:
+ case PROCESS_TEST_TYPE_FREE:
printf("free %d %ld\n", test.process, test.old_size);
if (processes[test.process].size == -1L)
printf("... not allocated, ignore\n");
}
}
+#ifndef __FUZIX__
done:
+#endif
printf("final state:\n");
for (i = 0; i < n_processes; ++i) {
if (processes[i].size == -1L)