Fix some defines and conditional compiles that got lost in the ifdef-generation
authorNick Downing <nick@ndcode.org>
Fri, 31 May 2019 15:19:25 +0000 (01:19 +1000)
committerNick Downing <nick@ndcode.org>
Fri, 31 May 2019 15:19:25 +0000 (01:19 +1000)
cpp.sh
process_test.h
process_test_gen.c
process_test_run.c

diff --git a/cpp.sh b/cpp.sh
index e76d81d..e0304fe 100755 (executable)
--- a/cpp.sh
+++ b/cpp.sh
@@ -2,7 +2,7 @@
 dir=$1
 shift
 mkdir --parents $dir
-sed -e 's/^#include </$include </; s/^#include "rassert\.h"/$include "rassert.h"/; s/^#define DISK_/$define DISK_/; s/^#define BLOCK_/$define BLOCK_/; s/^#define UCP/$define UCP/; s/^#define TRANSFER_/$define TRANSFER_/; s/^#define POOL_ALLOC_MODE_/$define POOL_ALLOC_MODE_/' -i *.[ch]
+sed -e 's/^#include </$include </; s/^#include "rassert\.h"/$include "rassert.h"/; s/^#define DISK_/$define DISK_/; s/^#define BLOCK_/$define BLOCK_/; s/^#define UCP/$define UCP/; s/^#define TRANSFER_/$define TRANSFER_/; s/^#define POOL_ALLOC_MODE_/$define POOL_ALLOC_MODE_/; s/^#define PROCESS_TEST_TYPE_/$define PROCESS_TEST_TYPE_/' -i *.[ch]
 for i in \
 block_pool.c \
 block_pool.h \
index 0f62080..5adbfd1 100644 (file)
@@ -3,6 +3,11 @@
 
 #include <stdbool.h>
 
+#define PROCESS_TEST_TYPE_ALLOC 0
+#define PROCESS_TEST_TYPE_REALLOC 1
+#define PROCESS_TEST_TYPE_RUN 2
+#define PROCESS_TEST_TYPE_FREE 3
+
 struct process_test {
   int type;
   int process;
index 9b04ed7..ea3baaa 100644 (file)
@@ -2,11 +2,19 @@
 #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));
@@ -37,6 +45,9 @@ int main(int argc, char **argv) {
   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];
@@ -45,12 +56,17 @@ int main(int argc, char **argv) {
       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;
@@ -60,13 +76,22 @@ int main(int argc, char **argv) {
     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,
@@ -74,6 +99,7 @@ int main(int argc, char **argv) {
             test.size,
             test.success ? "true" : "false"
           );
+#endif
 
           if (test.success) {
             processes[test.process] = test.size;
@@ -82,7 +108,12 @@ int main(int argc, char **argv) {
         }
       }
       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;
       }
index 638d121..e688d8f 100644 (file)
@@ -3,6 +3,9 @@
 #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"
@@ -167,7 +170,9 @@ int main(int argc, char **argv) {
   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;
@@ -236,6 +241,10 @@ int main(int argc, char **argv) {
 
   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;
@@ -245,7 +254,7 @@ int main(int argc, char **argv) {
       rassert(false);
     }
     if (strcmp(buf, "alloc") == 0) {
-      test.type = 0;
+      test.type = PROCESS_TEST_TYPE_ALLOC;
       rassert(
         scanf(
           "%d %ld %s",
@@ -264,7 +273,7 @@ int main(int argc, char **argv) {
         rassert(false);
     }
     else if (strcmp(buf, "realloc") == 0) {
-      test.type = 1;
+      test.type = PROCESS_TEST_TYPE_REALLOC;
       rassert(
         scanf(
           "%d %ld %ld %s",
@@ -285,20 +294,21 @@ int main(int argc, char **argv) {
         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,
@@ -337,7 +347,7 @@ int main(int argc, char **argv) {
         }
       }
       break;
-    case 1:
+    case PROCESS_TEST_TYPE_REALLOC:
       printf(
         "realloc %d %ld %ld %s\n",
         test.process,
@@ -402,7 +412,7 @@ int main(int argc, char **argv) {
         }
       }
       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");
@@ -411,7 +421,7 @@ int main(int argc, char **argv) {
         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");
@@ -482,7 +492,9 @@ int main(int argc, char **argv) {
     }
   }
 
+#ifndef __FUZIX__
 done:
+#endif
   printf("final state:\n");
   for (i = 0; i < n_processes; ++i) {
     if (processes[i].size == -1L)