move socket code out of runtime.c
authorbdemsky <bdemsky>
Thu, 2 Nov 2006 07:51:47 +0000 (07:51 +0000)
committerbdemsky <bdemsky>
Thu, 2 Nov 2006 07:51:47 +0000 (07:51 +0000)
add more error injection options

Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/State.java
Robust/src/Main/Main.java
Robust/src/Runtime/runtime.c
Robust/src/Runtime/runtime.h
Robust/src/Runtime/socket.c [new file with mode: 0644]
Robust/src/buildscriptrepair
Robust/src/buildscripttask

index c3b05d5c84089fdc8ee9e2a6f33a4fa4052b43b4..7a123a216750f79bbdefe2b8a8f66ef6634e2da0 100644 (file)
@@ -867,6 +867,9 @@ public class BuildCode {
            visited.add(current_node);
            if (nodetolabel.containsKey(current_node))
                output.println("L"+nodetolabel.get(current_node)+":");
+           if (state.INSTRUCTIONFAILURE) {
+               output.println("if ((--instructioncount)==0) injectinstructionfailure();");
+           }
            if (current_node.numNext()==0) {
                output.print("   ");
                generateFlatNode(fm, current_node, output);
index a40ed70d3b675d649db6dff2b39baa82d6000fbd..b4326130b8422b91f10866b47b6fa41d00a08c4b 100644 (file)
@@ -22,6 +22,7 @@ public class State {
     /** Boolean flag which indicates whether compiler is compiling a task-based
      * program. */
     public boolean TASK;
+    public boolean INSTRUCTIONFAILURE=false;
     public String structfile;
     public String main;
     public boolean CONSCHECK=false;
index 75487a3f315006a66b1bdb6df308c07343eebae5..8e7f88508629cb74a6c418d5c4462ef855e5a8ed 100644 (file)
@@ -33,6 +33,8 @@ public class Main {
              state.CONSCHECK=true;
          else if (option.equals("-task"))
              state.TASK=true;
+         else if (option.equals("-instructionfailures"))
+             state.INSTRUCTIONFAILURE=true;
          else if (option.equals("-help")) {
              System.out.println("-classlibrary classlibrarydirectory -- directory where classlibrary is located");
              System.out.println("-dir outputdirectory -- output code in outputdirectory");
@@ -41,6 +43,8 @@ public class Main {
              System.out.println("-precise -- use precise garbage collection");
 
              System.out.println("-conscheck -- turn on consistency checking");
+             System.out.println("-task -- compiler for tasks");
+             System.out.println("-instructionfailures -- insert code for instruction level failures");
              System.out.println("-help -- print out help");
              System.exit(0);
          } else {
index 86d4e0717e580052f46abd8d0bfbdd217748deb8..1ad9651b2f210598ab8975bb4f87475a1e0fd7f0 100644 (file)
@@ -12,6 +12,7 @@
 
 extern int classsize[];
 jmp_buf error_handler;
+int instructioncount;
 
 #ifdef TASK
 #include "checkpoint.h"
@@ -19,9 +20,6 @@ jmp_buf error_handler;
 #include "SimpleHash.h"
 #include "GenericHashtable.h"
 #include <sys/select.h>
-#include <sys/socket.h>
-#include <fcntl.h>
-#include <arpa/inet.h>
 
 #ifdef CONSCHECK
 #include "instrument.h"
@@ -30,48 +28,71 @@ jmp_buf error_handler;
 struct Queue * activetasks;
 struct parameterwrapper * objectqueues[NUMCLASSES];
 struct genhashtable * failedtasks;
+/*struct genhashtable * failedobjects;*/
 extern char ** environ;
 char *options;
 int injectfailures=0;
 float failurechance=0;
 int debugtask=0;
+int injectinstructionfailures;
+int failurecount;
+float instfailurechance=0;
 
-int main(int argc, char **argv) {
-  GC_init();
-#ifdef CONSCHECK
-  initializemmap();
-#endif
-  {
-    int i;
-    options=NULL;
-    for(i=0;environ[i]!=0;i++) {
-      if (strncmp(environ[i],"BRISTLECONE=",12)==0) {
-       options=environ[i]+12;
-       break;
-      }
+void processOptions() {
+  int i;
+  options=NULL;
+  for(i=0;environ[i]!=0;i++) {
+    if (strncmp(environ[i],"BRISTLECONE=",12)==0) {
+      options=environ[i]+12;
+      break;
     }
-
-    while(options!=NULL) {
-      if (strncmp(options,"-injectfailures",sizeof("-injectfailures")-1)==0) {
-       options=strchr(options,' ');
-       if (options!=NULL) options++;
-       if (options==NULL)
-         break;
-       sscanf(options, "%f", &failurechance);
-       injectfailures=1;
-       printf("Injecting errors with chance=%f\n",failurechance);
-       options=strchr(options,' ');
-       if (options!=NULL) options++;
-      } else if (strncmp(options, "-debugtask",sizeof("-debugtask")-1)==0) {
-       options=strchr(options,' ');
-       if (options!=NULL) options++;
-       debugtask=1;
-       printf("Debug task option on\n");
-      } else
+  }
+  
+  while(options!=NULL) {
+    if (strncmp(options,"-injectfailures",sizeof("-injectfailures")-1)==0) {
+      options=strchr(options,' ');
+      if (options!=NULL) options++;
+      if (options==NULL)
        break;
-    }
+      sscanf(options, "%f", &failurechance);
+      injectfailures=1;
+      printf("Injecting errors with chance=%f\n",failurechance);
+      options=strchr(options,' ');
+      if (options!=NULL) options++;
+    } else if (strncmp(options,"-injectinstructionfailures",sizeof("-injectinstructionfailures")-1)==0) {
+      options=strchr(options,' ');
+      if (options!=NULL) options++;
+      if (options==NULL)
+       break;
+      sscanf(options, "%d", &failurecount);
+      options=strchr(options,' ');
+      if (options!=NULL) options++;
+      if (options==NULL)
+       break;
+      sscanf(options, "%f", &instfailurechance);
+      options=strchr(options,' ');
+      if (options!=NULL) options++;
+      instructioncount=failurecount;
+      injectinstructionfailures=1;
+      printf("Injecting errors with count=%d\n",failurecount);
+      printf("Injecting errors with chance=%f\n",instfailurechance);
+
+    } else if (strncmp(options, "-debugtask",sizeof("-debugtask")-1)==0) {
+      options=strchr(options,' ');
+      if (options!=NULL) options++;
+      debugtask=1;
+      printf("Debug task option on.\n");
+    } else
+      break;
   }
+}
 
+int main(int argc, char **argv) {
+  GC_init(); // Initialize the garbage collector
+#ifdef CONSCHECK
+  initializemmap();
+#endif
+  processOptions();
 
   {
   int i;
@@ -80,6 +101,7 @@ int main(int argc, char **argv) {
   struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1); 
   failedtasks=genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd, 
                                   (int (*)(void *,void *)) &comparetpd);
+  /*  failedobjects=genallocatehashtable(NULL,NULL);*/
   
   activetasks=createQueue();
 
@@ -240,6 +262,40 @@ void removereadfd(int fd) {
   }
 }
 
+/*
+void restoreObject(void * obj) {
+  if (gencontains(failedobjects, obj)) {
+    struct tpdlist *tpd=gengettable(failedobjects, obj);
+    genfreekey(failedobjects, obj);
+    while(tpd!=NULL) {
+      int i;
+      struct taskparamdescriptor *task=tpd->task;
+      genfreekey(failedtasks, task);
+      for(i=0;i<task->numParameters;i++) {
+       void *objother=task->parameterArray[i];
+       struct tpdlist *tpdother=gengettable(failedobjects, objother);
+       struct tpdlist *tmpptr;
+       genfreekey(failedobjects, objother);
+       struct tpdlist **tpdptr=&tpdother;
+       while((*tpdptr)->task!=task)
+         tpdptr=&((*tpdptr)->next);
+       tmpptr=*tpdptr;
+       (*tpdptr)=(*tpdptr)->next;
+       RUNFREE(tmpptr);
+       if (tpdother!=NULL)
+         genputtable(failedobjects, objother, tpdother);
+      }
+      RUNFREE(task);
+      {
+       struct tpdlist *old=tpd;
+       tpd=tpd->next;
+       RUNFREE(old);
+      }
+    }
+  }
+}
+*/
+
 void executetasks() {
   void * taskpointerarray[MAXTASKPARAMS];
 
@@ -313,6 +369,22 @@ void executetasks() {
          printf("Fatal Error=%d, Recovering!\n",x);
 #endif
          genputtable(failedtasks,tpd,tpd);
+       /* for(i=0;i<tpd->task->numParameters;i++) {
+           void *parameter=tpd->parameterArray[i];
+           {
+             // Create mapping from object -> failed tasks 
+             struct tpdlist * tpnew=RUNMALLOC(sizeof(struct tpdlist));
+             tpnew->task=tpd;
+             if (gencontains(failedobjects, parameter)) {
+               struct tpdlist * tpdptr=gengettable(failedobjects, parameter);
+               tpnew->next=tpdptr->next;
+               tpdptr->next=tpnew;
+             } else {
+               tpnew->next=NULL;
+               genputtable(failedobjects, parameter, tpnew);
+             }
+           }
+         }  */
          restorecheckpoint(tpd->task->numParameters, taskpointerarray, checkpoint, forward, reverse);
        } else {
          if (injectfailures) {
@@ -358,123 +430,22 @@ void processtasks() {
   }
 }
 
-
-
-int ___ServerSocket______createSocket____I(struct ___ServerSocket___ * sock, int port) {
-  int fd;
-
-  int n=1;
-  struct sockaddr_in sin;
-
-  bzero (&sin, sizeof (sin));
-  sin.sin_family = AF_INET;
-  sin.sin_port = htons (port);
-  sin.sin_addr.s_addr = htonl (INADDR_ANY);
-  fd=socket(AF_INET, SOCK_STREAM, 0);
-  if (fd<0) {
-#ifdef DEBUG
-    perror(NULL);
-    printf("createSocket error #1\n");
 #endif
-    longjmp(error_handler,5);
-  }
 
-  if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof (n)) < 0) {
-    close(fd);
-#ifdef DEBUG
-    perror(NULL);
-    printf("createSocket error #2\n");
-#endif
-    longjmp(error_handler, 6);
-  }
-  fcntl(fd, F_SETFD, 1);
-  fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK);
 
-  /* bind to port */
-  if (bind(fd, (struct sockaddr *) &sin, sizeof(sin))<0) { 
-    close (fd);
-#ifdef DEBUG
-    perror(NULL);
-    printf("createSocket error #3\n");
-#endif
-    longjmp(error_handler, 7);
-  }
-
-  /* listen */
-  if (listen(fd, 5)<0) { 
-    close (fd);
-#ifdef DEBUG
-    perror(NULL);
-    printf("createSocket error #4\n");
-#endif
-    longjmp(error_handler, 8);
+void injectinstructionfailure() {
+#ifdef TASK
+  if (injectinstructionfailures) {
+    instructioncount=failurecount;    
+    if ((((double)random())/RAND_MAX)<instfailurechance) {
+      printf("FAILURE!!!\n");
+      longjmp(error_handler,11);
+    }
   }
-
-  /* Store the fd/socket object mapping */
-  RuntimeHashadd(fdtoobject, fd, (int) sock);
-  addreadfd(fd);
-  return fd;
-}
-
-int ___ServerSocket______nativeaccept____L___Socket___(struct ___ServerSocket___ * serversock, struct ___Socket___ * sock) {
-  struct sockaddr_in sin;
-  unsigned int sinlen=sizeof(sin);
-  int fd=serversock->___fd___;
-  int newfd;
-  newfd=accept(fd, (struct sockaddr *)&sin, &sinlen);
-
-
-  if (newfd<0) { 
-#ifdef DEBUG
-    perror(NULL);
-    printf("acceptSocket error #1\n");
+#else
 #endif
-    longjmp(error_handler, 9);
-  }
-  fcntl(newfd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK);
-
-  RuntimeHashadd(fdtoobject, newfd, (int) sock);
-  addreadfd(newfd);
-  flagorand(serversock,0,0xFFFFFFFE);
-  return newfd;
 }
 
-
-void ___Socket______nativeWrite_____AR_B(struct ___Socket___ * sock, struct ArrayObject * ao) {
-  int fd=sock->___fd___;
-  int length=ao->___length___;
-  char * charstr=((char *)& ao->___length___)+sizeof(int);
-  int bytewritten=write(fd, charstr, length);
-  if (bytewritten!=length) {
-    printf("ERROR IN NATIVEWRITE\n");
-  }
-  flagorand(sock,0,0xFFFFFFFE);
-}
-
-int ___Socket______nativeRead_____AR_B(struct ___Socket___ * sock, struct ArrayObject * ao) {
-  int fd=sock->___fd___;
-  int length=ao->___length___;
-  char * charstr=((char *)& ao->___length___)+sizeof(int);
-  int byteread=read(fd, charstr, length);
-  
-  if (byteread<0) {
-    printf("ERROR IN NATIVEREAD\n");
-  }
-  flagorand(sock,0,0xFFFFFFFE);
-  return byteread;
-}
-
-void ___Socket______nativeClose____(struct ___Socket___ * sock) {
-  int fd=sock->___fd___;
-  int data;
-  RuntimeHashget(fdtoobject, fd, &data);
-  RuntimeHashremove(fdtoobject, fd, data);
-  removereadfd(fd);
-  close(fd);
-  flagorand(sock,0,0xFFFFFFFE);
-}
-#endif
-
 int ___Object______hashcode____(struct ___Object___ * ___this___) {
   return (int) ___this___;
 }
index c20578a8264bd83cfc60d7f0534741c273b8b67d..7f90aa69360a683e24f9b8d0c4f08e708fb0d3a7 100644 (file)
@@ -2,6 +2,7 @@
 #define RUNTIME
 #include <setjmp.h>
 extern jmp_buf error_handler;
+extern int instructioncount;
 
 void * allocate_new(int type);
 struct ArrayObject * allocate_newarray(int type, int length);
@@ -10,6 +11,7 @@ struct ___String___ * NewString(const char *str,int length);
 void failedboundschk();
 void failednullptr();
 void abort_task();
+void injectinstructionfailure();
 
 #ifdef TASK
 #include "SimpleHash.h"
@@ -32,6 +34,11 @@ struct taskparamdescriptor {
   void ** parameterArray;
 };
 
+struct tpdlist {
+  struct taskparamdescriptor * task;
+  struct tpdlist * next;
+};
+
 int hashCodetpd(struct taskparamdescriptor *);
 int comparetpd(struct taskparamdescriptor *, struct taskparamdescriptor *);
 #endif
diff --git a/Robust/src/Runtime/socket.c b/Robust/src/Runtime/socket.c
new file mode 100644 (file)
index 0000000..190aae5
--- /dev/null
@@ -0,0 +1,123 @@
+#include "runtime.h"
+#include "structdefs.h"
+#include <sys/socket.h>
+#include <fcntl.h>
+#include <arpa/inet.h>
+#include <strings.h>
+#include "SimpleHash.h"
+#include "GenericHashtable.h"
+extern struct RuntimeHash *fdtoobject;
+
+int ___ServerSocket______createSocket____I(struct ___ServerSocket___ * sock, int port) {
+  int fd;
+
+  int n=1;
+  struct sockaddr_in sin;
+
+  bzero (&sin, sizeof (sin));
+  sin.sin_family = AF_INET;
+  sin.sin_port = htons (port);
+  sin.sin_addr.s_addr = htonl (INADDR_ANY);
+  fd=socket(AF_INET, SOCK_STREAM, 0);
+  if (fd<0) {
+#ifdef DEBUG
+    perror(NULL);
+    printf("createSocket error #1\n");
+#endif
+    longjmp(error_handler,5);
+  }
+
+  if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof (n)) < 0) {
+    close(fd);
+#ifdef DEBUG
+    perror(NULL);
+    printf("createSocket error #2\n");
+#endif
+    longjmp(error_handler, 6);
+  }
+  fcntl(fd, F_SETFD, 1);
+  fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK);
+
+  /* bind to port */
+  if (bind(fd, (struct sockaddr *) &sin, sizeof(sin))<0) { 
+    close (fd);
+#ifdef DEBUG
+    perror(NULL);
+    printf("createSocket error #3\n");
+#endif
+    longjmp(error_handler, 7);
+  }
+
+  /* listen */
+  if (listen(fd, 5)<0) { 
+    close (fd);
+#ifdef DEBUG
+    perror(NULL);
+    printf("createSocket error #4\n");
+#endif
+    longjmp(error_handler, 8);
+  }
+
+  /* Store the fd/socket object mapping */
+  RuntimeHashadd(fdtoobject, fd, (int) sock);
+  addreadfd(fd);
+  return fd;
+}
+
+int ___ServerSocket______nativeaccept____L___Socket___(struct ___ServerSocket___ * serversock, struct ___Socket___ * sock) {
+  struct sockaddr_in sin;
+  unsigned int sinlen=sizeof(sin);
+  int fd=serversock->___fd___;
+  int newfd;
+  newfd=accept(fd, (struct sockaddr *)&sin, &sinlen);
+
+
+  if (newfd<0) { 
+#ifdef DEBUG
+    perror(NULL);
+    printf("acceptSocket error #1\n");
+#endif
+    longjmp(error_handler, 9);
+  }
+  fcntl(newfd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK);
+
+  RuntimeHashadd(fdtoobject, newfd, (int) sock);
+  addreadfd(newfd);
+  flagorand(serversock,0,0xFFFFFFFE);
+  return newfd;
+}
+
+
+void ___Socket______nativeWrite_____AR_B(struct ___Socket___ * sock, struct ArrayObject * ao) {
+  int fd=sock->___fd___;
+  int length=ao->___length___;
+  char * charstr=((char *)& ao->___length___)+sizeof(int);
+  int bytewritten=write(fd, charstr, length);
+  if (bytewritten!=length) {
+    printf("ERROR IN NATIVEWRITE\n");
+  }
+  flagorand(sock,0,0xFFFFFFFE);
+}
+
+int ___Socket______nativeRead_____AR_B(struct ___Socket___ * sock, struct ArrayObject * ao) {
+  int fd=sock->___fd___;
+  int length=ao->___length___;
+  char * charstr=((char *)& ao->___length___)+sizeof(int);
+  int byteread=read(fd, charstr, length);
+  
+  if (byteread<0) {
+    printf("ERROR IN NATIVEREAD\n");
+  }
+  flagorand(sock,0,0xFFFFFFFE);
+  return byteread;
+}
+
+void ___Socket______nativeClose____(struct ___Socket___ * sock) {
+  int fd=sock->___fd___;
+  int data;
+  RuntimeHashget(fdtoobject, fd, &data);
+  RuntimeHashremove(fdtoobject, fd, data);
+  removereadfd(fd);
+  close(fd);
+  flagorand(sock,0,0xFFFFFFFE);
+}
index 7501938333723e9d84b244f3b9111d6deffed823..b8db54f7e9a50479e69ab4a79eef2f1bc0c7de85 100755 (executable)
@@ -63,6 +63,7 @@ gcc -I$ROBUSTROOT/Runtime -I. -I$BUILDDIR/specdir \
 -LRuntime/lib/ -lgc -DTASK -g tmpbuilddirectory/methods.c \
 tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c \
 $ROBUSTROOT/Runtime/file.c \
+$ROBUSTROOT/Runtime/socket.c \
 $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c \
 $ROBUSTROOT/Runtime/checkpoint.c \
 $ROBUSTROOT/Runtime/GenericHashtable.c $BUILDDIR/specdir/*.o -o \
index 5b67f8f03e1ffc2f95810855f7f383ffd58a88c6..08784e1e342b00ea8d3f32979b4a5c8958b409cd 100755 (executable)
@@ -5,4 +5,4 @@ shift
 mkdir tmpbuilddirectory
 java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -struct $MAINFILE -task $@
 #gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -O0 -DTASK -g tmpbuilddirectory/methods.c tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/GenericHashtable.c -o $MAINFILE.bin
-gcc -I$ROBUSTROOT/Runtime -I. -IRuntime/include -Itmpbuilddirectory -O0 -DBOEHM_GC -LRuntime/lib/ -lgc -DTASK -DDEBUG -g tmpbuilddirectory/methods.c tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/GenericHashtable.c -o $MAINFILE.bin
\ No newline at end of file
+gcc -I$ROBUSTROOT/Runtime -I. -IRuntime/include -Itmpbuilddirectory -O0 -DBOEHM_GC -LRuntime/lib/ -lgc -DTASK -DDEBUG -g tmpbuilddirectory/methods.c tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/socket.c $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/GenericHashtable.c -o $MAINFILE.bin
\ No newline at end of file