int main(int argc, char *argv[]) { printf("Running third test case.\n"); char *dirname = argv[1]; char *srvIpOrDomName = argv[2]; int srvPort = atoi(argv[3]); int id = atoi(argv[4]); printf("here"); fsMount(srvIpOrDomName, srvPort, dirname); printf("here"); char t1_file_name[] = "/test_file1"; char* path = malloc(strlen(dirname)+strlen(t1_file_name)+1); *path = '\0'; strcat(path, dirname); strcat(path, t1_file_name); char buf[] = "abcdef123456"; int i; for (i = 1; i <= 20; i++) { printf("%d: %d\n", id, i); sleep(1); int ff = fsOpen(path, 1); if(ff < 0) { perror("fsOpen(write)"); exit(1); } if(fsWrite(ff, buf + (id-1)*6, 3) < 3) { // fprintf(stderr, "fsWrite() wrote fewer than 3\n"); } if(fsWrite(ff, buf + (id-1)*6 + 3, 3) < 3) { // fprintf(stderr, "fsWrite() wrote fewer than 3\n"); } if(fsClose(ff) < 0) { perror("fsClose"); exit(1); } } if (id == 1) { int ff = fsOpen(path, 0); if(ff < 0) { perror("fsOpen"); exit(1); } // else printf("fsOpen(): %d\n", ff); char data[7]; if(fsRead(ff, (void *)data, 6) < 0) { perror("fsRead"); exit(1); } data[6] = '\0'; if (strcmp(data,"abcdef") && strcmp(data, "123456")) { printf("Something is wrong... Investigate"); fsClose(ff); exit(1); } else { printf("Give full mark"); fsClose(ff); exit(0); } fsClose(ff); } printf("Finsihed running third test case.\n"); return 0; }
int main(int argc, char *argv[]) { if (argc < 5) { printf("Need: <ip1> <port1> <ip2> <port2> \n"); exit(1); } const char *ip = argv[1]; const int port = atoi(argv[2]); const char *ip2 = argv[3]; const int port2 = atoi(argv[4]); printf("fsMount1:\n"); if (fsMount(ip, port, "foo") < 0) { perror("fsMount"); exit(1); } printf("fsMount2:\n"); if (fsMount(ip, port, "foo") >= 0) { printf("ERROR: Should not be able to mount the same folder twice\n"); exit(1); } printf("fsMount3:\n"); if (fsMount(ip2, port2, "foo2") < 0) { perror("fsMount"); exit(1); } printf("open1:\n"); int fd; if ((fd = fsOpen("foo/file1.txt", 0)) < 0) { perror("fsOpen"); exit(1); } printf("fd: %d\n", fd); printf("open2:\n"); int fd2; if ((fd2 = fsOpen("foo2/file2.txt", 0)) < 0) { perror("fsOpen"); exit(1); } printf("fd2: %d\n", fd2); printf("open3:\n"); if (fsOpen("foo/file2.txt", 0) >= 0) { printf("ERROR: There should be no file2.txt in server#1\n"); exit(1); } printf("open4:\n"); if (fsOpen("foo2/file1.txt", 0) >= 0) { printf("ERROR: There should be no file1.txt in server#2\n"); exit(1); } printf("open5:\n"); if (fsOpen("foo3/file1.txt", 0) >= 0) { printf("ERROR: There is no mounted folder called foo3\n"); exit(1); } printf("read1:\n"); printf("fd: %d\n", fd); printf("fd2: %d\n", fd2); char buf[3001]; int bytesread; int i = 0; bytesread = fsRead(fd, (void *)buf, 3000); perror("fsRead"); *((char *) buf + bytesread) = '\0'; printf("Bytes=%d, String='%s'\n", bytesread, buf); if (strncmp(buf, "Hello World1", 12) != 0) { printf("ERROR: Read on file1.txt should return 'Hello World1' \n"); exit(1); } printf("read2:\n"); bytesread = fsRead(fd2, (void *)buf, 3000); *((char *) buf + bytesread) = '\0'; if (strncmp(buf, "Hello World2", 12) != 0) { printf("ERROR: Read on file2.txt should return 'Hello World2' \n"); exit(1); } printf("read3:\n"); while ((bytesread = fsRead(fd2, (void *)buf, 3000)) > 0) { *((char *) buf + bytesread) = '\0'; printf("%s", (char *) buf); i += 1; } printf("\n"); printf("close:\n"); if (fsClose(fd) < 0) { perror("fsClose"); exit(1); } if ((fd = fsOpen("foo/file1.txt", 1)) < 0) { perror("fsOpen"); exit(1); } printf("write 1:\n"); //Write to "../server1/file1.txt" if(fsWrite(fd,(void *)"Hello Hello", 8)<0) { printf("write failed:\n"); } printf("write 2:\n"); //Write to "../server1/file1.txt" if(fsWrite(fd,(void *)"Hola Hola", 4)<0) { printf("write2 failed:\n"); } printf("close:\n"); if (fsClose(fd) < 0) { perror("fsClose"); exit(1); } printf("close2:\n"); if (fsClose(fd2) < 0) { perror("fsClose"); exit(1); } // printf("remove:\n"); // if (fsRemove("foo/file1.txt") < 0) { // printf("ERROR: remove file 1 failed\n"); exit(1); // } // printf("remove2:\n"); // if (fsRemove("foo") == 0 || fsRemove("foo2") == 0) { // printf("ERROR: Should not be able to delete mounted folder\n"); exit(1); // } printf("openDir:\n"); FSDIR* tempFsDir=fsOpenDir("foo"); if(tempFsDir==NULL) { printf("FSDir is NULL\n"); } printf("readDir:\n"); struct fsDirent* tempfsDirent=NULL; do { tempfsDirent=fsReadDir(tempFsDir); if(tempfsDirent!=NULL) { printf("fsDirent: entName: %s\n", tempfsDirent->entName); } }while(tempfsDirent!=NULL); //printf("fsDirent: entName: %s\n", tempfsDirent->entName); printf("closeDir:\n"); if(fsCloseDir(tempFsDir)<0) { printf("closeDir failed\n"); } printf("unmount:\n"); if (fsUnmount("foo") < 0) { perror("fsUnmount"); exit(1); } printf("unmount2:\n"); if (fsUnmount("foo2") < 0) { perror("fsUnmount"); exit(1); } printf("All tests passed!\n"); return 0; }
int main(int argc, char *argv[]) { if (argc < 5) { printf("Need: <ip1> <port1> <ip2> <port2> \n"); exit(1); } const char *ip = argv[1]; const int port = atoi(argv[2]); const char *ip2 = argv[3]; const int port2 = atoi(argv[4]); printf("1\n"); if (fsMount(ip, port, "foo") < 0) { perror("fsMount"); exit(1); } printf("2\n"); if (fsMount(ip, port, "foo") >= 0) { printf("ERROR: Should not be able to mount the same folder twice\n"); exit(1); } printf("3\n"); if (fsMount(ip2, port2, "foo2") < 0) { perror("fsMount"); exit(1); } int fd; printf("4\n"); if ((fd = fsOpen("foo/file1.txt", 0)) < 0) { perror("fsOpen"); exit(1); } int fd2; printf("5\n"); if ((fd2 = fsOpen("foo2/file2.txt", 0)) < 0) { perror("fsOpen"); exit(1); } printf("6\n"); if (fsOpen("foo/file2.txt", 0) >= 0) { printf("ERROR: There should be no file2.txt in server#1\n"); exit(1); } printf("7\n"); if (fsOpen("foo2/file1.txt", 0) >= 0) { printf("ERROR: There should be no file1.txt in server#2\n"); exit(1); } printf("8\n"); if (fsOpen("foo3/file1.txt", 0) >= 0) { printf("ERROR: There is no mounted folder called foo3\n"); exit(1); } char buf[3001]; int bytesread; int i = 0; printf("9\n"); bytesread = fsRead(fd, (void *)buf, 3000); *((char *) buf + bytesread) = '\0'; if (strncmp(buf, "Hello World1", 12) != 0) { printf("ERROR: Read on file1.txt should return 'Hello World1' \n"); exit(1); } printf("10\n"); bytesread = fsRead(fd2, (void *)buf, 3000); *((char *) buf + bytesread) = '\0'; if (strncmp(buf, "Hello World2", 12) != 0) { printf("ERROR: Read on file2.txt should return 'Hello World2' \n"); exit(1); } printf("11\n"); while ((bytesread = fsRead(fd2, (void *)buf, 3000)) > 0) { *((char *) buf + bytesread) = '\0'; printf("%s", (char *) buf); i += 1; } printf("\n"); printf("12\n"); if (fsRemove("foo/file1.txt") >= 0) { printf("ERROR: Should not be able to delete file1.txt while its open\n"); exit(1); } printf("13\n"); if (fsRemove("foo") >= 0 || fsRemove("foo2") >= 0) { printf("ERROR: Should not be able to delete mounted folder\n"); exit(1); } printf("14\n"); if (fsClose(fd) < 0) { perror("fsClose"); exit(1); } printf("15\n"); if (fsClose(fd2) < 0) { perror("fsClose"); exit(1); } printf("16\n"); if (fsUnmount("foo") < 0) { perror("fsUnmount"); exit(1); } printf("17\n"); if (fsUnmount("foo2") < 0) { perror("fsUnmount"); exit(1); } printf("All tests passed!\n"); return 0; }
int main(int argc, char *argv[]) { if(argc < 4) { fprintf(stderr, "usage: %s <srv-ip/name> <srv-port> <local dir name>\n", argv[0]); exit(1); } printf ("\n\n\n\nenter main fs_client \n. ***********\n test case involves mounting 3 server alias, opendir 3 aliases and unmount 3 server alias \n"); char *dirname = argv[3]; printf("fsMount(): %d\n", fsMount(argv[1], atoi(argv[2]), dirname)); printf("fsMount(): - folderAlsia %d\n", fsMount(argv[1],atoi(argv[2]), "folderAlias")); printf("fsMount(): - ../exFolder %d\n", fsMount(argv[1],atoi(argv[2]), "../exFolder")); FSDIR *fd = fsOpenDir(dirname); //printf("client app, returned fd-> num is: %i\n",fd->num) ; if(fd == NULL) { perror("fsOpenDir"); exit(1); } printf ("successfully opened dir with id of FSDIR: %i \n",fd->num); FSDIR *fd2 = fsOpenDir("folderAlias/apples/"); //printf("client app, -- testin second open returned fd-> num is: %i\n",fd2->num) ; if(fd2 == NULL) { perror("fsOpenDir For second failed"); exit(1); } printf ("successfully opened dir with id of FSDIR: %i \n",fd2->num); FSDIR *fd3 = fsOpenDir("../exFolder/apples/bananas/"); if(fd3 == NULL) { perror("fsOpenDir exFolder/apples/bananas failed \n");exit(1); } printf ("successfully oepened bananas dir with id of FSDIR : %i \n",fd3->num); printf ("\t now checking fsDirent part\n"); struct fsDirent *fdent = NULL; printf("client app, fd->num is : %i\n",fd->num); for(fdent = fsReadDir(fd); fdent != NULL; fdent = fsReadDir(fd)) { printf("\t %s, %d\n", fdent->entName, (int)(fdent->entType)); } if(errno != 0) { perror("fsReadDir"); } printf("fsCloseDir(): %d\n", fsCloseDir(fd)); struct fsDirent *fdent2 = NULL; printf("client app, fd2->num is : %i\n",fd2->num); for(fdent2 = fsReadDir(fd2); fdent2 != NULL; fdent2 = fsReadDir(fd2)) { printf("\t %s, %d\n", fdent2->entName, (int)(fdent2->entType)); } if(errno != 0) { perror("fsReadDir"); } printf("fsCloseDir(): %d\n", fsCloseDir(fd2)); struct fsDirent *fdent3 = NULL; printf("client app, fd3->num is : %i\n",fd3->num); for(fdent3 = fsReadDir(fd3); fdent3 != NULL; fdent3 = fsReadDir(fd3)) { printf("\t %s, %d\n", fdent3->entName, (int)(fdent3->entType)); } if(errno != 0) { perror("fsReadDir"); } // part to test open close and write int ff = open("/dev/urandom", 0); if(ff < 0) { perror("open(/dev/urandom)"); exit(1); } else printf("open(): %d\n", ff); //return 0; char fname[256]; sprintf(fname, "%s/", dirname); if(read(ff, (void *)(fname+strlen(dirname)+1), 10) < 0) { perror("read(/dev/urandom)"); exit(1); } int i; for(i = 0; i < 10; i++) { //printf("%d\n", ((unsigned char)(fname[i]))%26); fname[i+strlen(dirname)+1] = ((unsigned char)(fname[i+strlen(dirname)+1]))%26 + 'a'; } fname[10+strlen(dirname)+1] = (char)0; printf("Filename to write: %s\n", (char *)fname); char buf[256]; if(read(ff, (void *)buf, 256) < 0) { perror("read(2)"); exit(1); } printBuf(buf, 256); printf("close(): %d\n", close(ff)); int ctr; // for (ctr =0; ctr < 100;ctr++){ ff = fsOpen("../exFolder/apples/01.txt", 1); if(ff < 0) { perror("fsOpen(write)"); exit(1); } if(fsWrite(ff, buf, 256) < 256) { fprintf(stderr, "fsWrite() wrote fewer than 256\n"); } sleep(60); //return 0; if(fsClose(ff) < 0) { perror("fsClose"); exit(1); } sleep(60); //return 0; char readbuf[256]; if((ff = fsOpen("../exFolder/apples/01.txt", 0)) < 0) { perror("fsOpen(read)"); exit(1); } int readcount = -1; if((readcount = fsRead(ff, readbuf, 256)) < 256) { fprintf(stderr, "fsRead() read fewer than 256\n"); } if(memcmp(readbuf, buf, readcount)) { fprintf(stderr, "return buf from fsRead() differs from data written!\n"); } else { printf("fsread(): return buf identical to data written upto %d bytes.\n", readcount); } if(fsClose(ff) < 0) { perror("fsClose return is < 0"); exit(1); } ff = fsOpen("sample/apples/value_write_01",1); if (ff < 0){ perror("fsOpen(value_write) probably failed");exit(1); } char *testBuf= "line 01 to be added to the file\n"; if (fsWrite(ff,testBuf,strlen(testBuf)) < strlen(testBuf)){ perror ("fsWrite line 01 on value_write failed");exit(1); } char *testBuf2= "line 02"; if (fsWrite(ff,testBuf2,strlen(testBuf2)) < strlen(testBuf2)){ perror ("fsWrite line 02 on value_write failed");exit(1); } if (fsClose(ff) < 0) { perror("fsClose with value_write file failed");exit(1);} printf("fsCloseDir(): %d\n", fsCloseDir(fd3)); printf("fsUnmount(): folderAlias %i\n",fsUnmount("folderAlias")); printf("fsUnmount(): ../exFolder/ %i\n",fsUnmount("../exFolder")); printf("fsUnmount(): dirFolder entered %i \n",fsUnmount(dirname)); //printf("fsUnmount(): %s\n",dirname,fsUnmount(dirname)); //return 0; //*/ printf ("\n\n successfully exit fs_client test 0_10 \n. ***********\n test case involves mounting 3 server alias, opendir 3 aliases and unmount 3 server alias\n \t\t subsequent writes are appended, new writes are overridden\n \n open 01.txt in apples folder without sleep. write to it and then read from it after\n"); return 0; }