/* proc1 writes some data, commits it, then exits */ void proc1() { rvm_t rvm; trans_t trans; char* segs[1]; rvm = rvm_init(__FILE__ ".d"); rvm_destroy(rvm, "testseg"); segs[0] = (char *) rvm_map(rvm, "testseg", 10000); trans = rvm_begin_trans(rvm, 1, (void **) segs); rvm_about_to_modify(trans, segs[0], 0, 100); sprintf(segs[0], "one"); rvm_commit_trans(trans); trans = rvm_begin_trans(rvm, 1, (void **) segs); rvm_about_to_modify(trans, segs[0], 0, 100); sprintf(segs[0], "two"); rvm_abort_trans(trans); trans = rvm_begin_trans(rvm, 1, (void **) segs); rvm_about_to_modify(trans, segs[0], 0, 100); sprintf(segs[0], "foo"); rvm_commit_trans(trans); abort(); }
/* proc2 opens the segments and reads from them */ void proc2() { char* segs[2]; rvm_t rvm; rvm = rvm_init("rvm_segments"); segs[0] = (char *) rvm_map(rvm, "testseg", 10000); if(!strcmp(segs[0], "hello, world")) { fprintf(stderr, "A second process found aborted changes committed.\n"); fprintf(stderr, "found %s\n", segs[0]); exit(2); } if(!strcmp(segs[0]+1000, "hello, world")) { fprintf(stderr, "A second process found aborted changes committed.\n"); fprintf(stderr, "found %s\n", segs[0]+1000); exit(3); } segs[1] = (char *) rvm_map(rvm, "anotherseg", 10000); if(!strcmp(segs[1], "hello, world")) { fprintf(stderr, "A second process found aborted changes committed.\n"); fprintf(stderr, "found %s\n", segs[0]); exit(4); } if(!strcmp(segs[1]+1000, "hello, world")) { fprintf(stderr, "A second process found aborted changes committed.\n"); fprintf(stderr, "found %s\n", segs[0]+1000); exit(5); } }
void proc1() { rvm_t rvm; char* segs[2]; trans_t trans; printf(">>> proc1()\n"); rvm = rvm_init("rvm_segments"); rvm_destroy(rvm, SEGNAME0); rvm_destroy(rvm, SEGNAME1); segs[0] = (char*) rvm_map(rvm, SEGNAME0, 1000); segs[1] = (char*) rvm_map(rvm, SEGNAME1, 1000); segs[0] = (char*) rvm_map(rvm, SEGNAME0, 300); trans = rvm_begin_trans(rvm, 2, (void **)segs); rvm_about_to_modify(trans, segs[0], OFFSET0, 100); strcpy(segs[0]+OFFSET0, STRING0); rvm_about_to_modify(trans, segs[1], OFFSET1, 100); strcpy(segs[1]+OFFSET1, STRING1); rvm_commit_trans(trans); abort(); }
/* proc1 writes some data, commits it, then exits */ void proc1() { rvm_t rvm; trans_t trans; char* segs[1]; rvm = rvm_init("rvm_segments"); rvm_destroy(rvm, "testseg"); segs[0] = (char *) rvm_map(rvm, "testseg", 1000); trans = rvm_begin_trans(rvm, 1, (void **) segs); rvm_about_to_modify(trans, segs[0], 0, 1000); char * currChar = segs[0]; for (int counter= 0; counter < 1000; counter++){ *currChar = '!'; currChar++; } rvm_commit_trans(trans); abort(); }
/* proc1 writes some data, commits it, then exits */ void proc1() { rvm_t rvm; trans_t trans; char* segs[1]; rvm = rvm_init("rvm_segments"); rvm_destroy(rvm, "testseg"); segs[0] = (char *) rvm_map(rvm, "testseg", 10000); trans = rvm_begin_trans(rvm, 1, (void **) segs); // rvm_about_to_modify(trans, segs[0], 0, 100); // sprintf(segs[0], TEST_STRING); // printf("Segment Data %s\n", segs[0]); rvm_about_to_modify(trans, segs[0], OFFSET2, 100); sprintf(segs[0]+OFFSET2, TEST_STRING); sprintf(segs[0], BAD_STRING); printf("Segment Data %s\n", segs[0]); rvm_commit_trans(trans); abort(); }
int main(int argc, char** argv) { rvm_t rvm; trans_t trans; char* segs[1]; rvm = rvm_init("rvm_segments"); rvm_destroy(rvm, "testseg01"); segs[0] = (char*) rvm_map(rvm, "testseg01", 10000); trans = rvm_begin_trans(rvm, 1, (void**) segs); rvm_about_to_modify(trans, segs[0], 0, 100); sprintf(segs[0], TEST_STRING); rvm_about_to_modify(trans, segs[0], OFFSET2, 100); sprintf(segs[0] + OFFSET2, TEST_STRING); rvm_commit_trans(trans); // This should fail rvm_destroy(rvm, "testseg01"); rvm_unmap(rvm, segs[0]); rvm_truncate_log(rvm); if (file_exists("rvm_segments/seg_testseg01.rvm")) { printf("OK\n"); } else { printf("ERROR: Segment file no longer present"); } return 0; }
void proc1() { rvm_t rvm; char* segs[2]; trans_t trans[2]; rvm = rvm_init("rvm_segments"); rvm_destroy(rvm, SEGNAME0); rvm_destroy(rvm, SEGNAME1); segs[0] = (char*) rvm_map(rvm, SEGNAME0, 1000); segs[1] = (char*) rvm_map(rvm, SEGNAME1, 1000); trans[0] = rvm_begin_trans(rvm, 1, &segs[0]); trans[1] = rvm_begin_trans(rvm, 1, &segs[1]); rvm_about_to_modify(trans[0], segs[0], OFFSET0, 100); strcpy(segs[0]+OFFSET0, STRING0); rvm_about_to_modify(trans[1], segs[1], OFFSET1, 100); strcpy(segs[1]+OFFSET1, STRING1); rvm_commit_trans(trans[0]); rvm_commit_trans(trans[1]); rvm_unmap(rvm, segs[0]); rvm_unmap(rvm, segs[1]); }
void proc1() { rvm_t rvm; char* segs[2]; trans_t trans; rvm = rvm_init("rvm_segments"); rvm_destroy(rvm, SEGNAME0); rvm_destroy(rvm, SEGNAME1); segs[0] = (char*) rvm_map(rvm, SEGNAME0, 1000); segs[1] = (char*) rvm_map(rvm, SEGNAME1, 1000); trans = rvm_begin_trans(rvm, 2, (void **)segs); rvm_about_to_modify(trans, segs[0], OFFSET0, 100); strcpy(segs[0]+OFFSET0, STRING0); rvm_about_to_modify(trans, segs[1], OFFSET1, 100); strcpy(segs[1]+OFFSET1, STRING1); rvm_commit_trans(trans); char *str; (str = strdup("foo"))[3] = '\n'; printf("Length of foo: %d\n", strlen(str)); }
/* proc1 writes some data, commits it, then exits */ void proc1() { rvm_t rvm; trans_t trans; char* segs[2]; rvm = rvm_init("rvm_segments"); segs[0] = (char *) rvm_map(rvm, "testseg", 10000); segs[1] = (char *) rvm_map(rvm, "anotherseg", 10000); trans = rvm_begin_trans(rvm, 2, (void **) segs); rvm_about_to_modify(trans, segs[0], 0, 100); sprintf(segs[0], "hello, world"); rvm_about_to_modify(trans, segs[0], 1000, 100); sprintf(segs[0]+1000, "hello, world"); rvm_about_to_modify(trans, segs[1], 0, 100); sprintf(segs[1], "hello, world"); rvm_about_to_modify(trans, segs[1], 1000, 100); sprintf(segs[1]+1000, "hello, world"); rvm_abort_trans(trans); abort(); }
int main(int argc, char **argv) { rvm_t rvm; rvm = rvm_init("rvm_segments"); printf("\nTesting directory creation:\n"); system("ls -l rvm_segments"); return 0; }
void proc1() { rvm_t rvm; char* segs[2]; trans_t trans; char** segnames; int i; int numSegments = 100; rvm = rvm_init(__FILE__ ".d"); // Allocate some memory segnames = (char **)malloc(numSegments * sizeof(char *)); for(i = 0; i < numSegments; i++) { segnames[i] = (char *)malloc(MAX_SEGMENT_NAME_LEN); sprintf(segnames[i],"testseg%i",i); rvm_destroy(rvm, segnames[i]); } //all segments contain the first string (aa) for(i = 0; i < numSegments; i++) { segs[0] = (char *) rvm_map(rvm, segnames[i], 3); trans = rvm_begin_trans(rvm, 1, (void **) segs); rvm_about_to_modify(trans, segs[0], 0, 3); sprintf(segs[0],"aa"); rvm_commit_trans(trans); rvm_unmap(rvm,segs[0]); } //only even segments contain the second string (modify aa to ab) for(i = 0; i < numSegments; i++) { segs[0] = (char *) rvm_map(rvm, segnames[i], 3); trans = rvm_begin_trans(rvm, 1, (void **) segs); rvm_about_to_modify(trans, segs[0], 1, 1); segs[0][1]='b'; assert(strcmp("ab", segs[0]) == 0); if(i%2==0){ //the modulus is 1, we are even rvm_commit_trans(trans); } } // Free memory for(i = 0; i < numSegments; i++) { free(segnames[i]); } free(segnames); }
int main(int argc, char **argv) { rvm_t rvm; char *seg; void *segs[1]; trans_t trans; rvm = rvm_init("rvm_segments"); rvm_destroy(rvm, "testseg"); seg = (char *) rvm_map(rvm, "testseg", 10000); segs[0] = seg; /* write some data and commit it */ trans = rvm_begin_trans(rvm, 1, segs); rvm_about_to_modify(trans, seg, 0, 100); sprintf(seg, TEST_STRING1); rvm_about_to_modify(trans, seg, OFFSET2, 100); sprintf(seg+OFFSET2, TEST_STRING1); rvm_commit_trans(trans); /* start writing some different data, but abort */ trans = rvm_begin_trans(rvm, 1, segs); rvm_about_to_modify(trans, seg, 0, 100); sprintf(seg, TEST_STRING2); rvm_about_to_modify(trans, seg, OFFSET2, 100); sprintf(seg+OFFSET2, TEST_STRING2); rvm_abort_trans(trans); /* test that the data was restored */ if(strcmp(seg+OFFSET2, TEST_STRING1)) { printf("ERROR: second hello is incorrect (%s)\n", seg+OFFSET2); exit(2); } if(strcmp(seg, TEST_STRING1)) { printf("ERROR: first hello is incorrect (%s)\n", seg); exit(2); } rvm_unmap(rvm, seg); printf("OK\n"); exit(0); }
/* proc2 opens the segments and reads from them */ void proc2() { char* segs[1]; rvm_t rvm; rvm = rvm_init(__FILE__ ".d"); segs[0] = (char *) rvm_map(rvm, "testseg", 10000); assert(strcmp(segs[0], "foo") == 0); printf("OK\n"); exit(0); }
int main() { rvm_t rvm = rvm_init("rvm_segments"); char* segs[2]; segs[0] = (char *) rvm_map(rvm, "testseg", 10000); segs[1] = (char *) rvm_map(rvm, "testseg", 10000); if(segs[1]==NULL){ cout<<"OK"<<endl; }else{ cout<<"ERROR: DID NOT DETECT MAP TWICE CASE!"<<endl; } return 0; }
void proc1() { rvm_t rvm; char* segs[1] = { 0 }; rvm = rvm_init("rvm_segments"); // this should fail rvm_unmap(rvm, segs[0]); printf("ERROR: Unmap() before mapping\n"); segs[0] = (char*) rvm_map(rvm, "testseg03", 10000); return; }
int main() { rvm_verbose(0); rvm_t rvm = rvm_init("bak"); std::cout << rvm->directory << std::endl; char* segs[1]; segs[0] = (char *) rvm_map(rvm, "testseg", 10000); rvm_map(rvm, "testseg", 10000); rvm_unmap(rvm, segs[0]); segs[0] = (char *) rvm_map(rvm, "testseg", 10000); rvm_verbose(1); rvm_unmap(rvm, segs[0]); rvm_destroy(rvm,"testseg"); return 0; }
int main(int argc, char **argv) { rvm_t rvm; printf("Before Truncation:\n"); system("ls -l rvm_segments"); rvm = rvm_init("rvm_segments"); rvm_truncate_log(rvm); printf("\nAfter Truncation:\n"); system("ls -l rvm_segments"); return 0; }
void proc1() { rvm_t rvm; trans_t trans = 0; char* segs[1]; rvm = rvm_init("rvm_segments"); rvm_destroy(rvm, "testseg"); segs[0] = (char*) rvm_map(rvm, "testseg", 10000); // this should exit rvm_about_to_modify(trans, segs[0], 0, 100); fprintf(stderr, "ERROR: This should not be printed\n"); abort(); }
/* test the resulting segment */ void test() { char* segs[1]; rvm_t rvm; // rvm = rvm_init(__FILE__ ".d"); rvm = rvm_init("rvm_segments"); segs[0] = (char *) rvm_map(rvm, "testseg", 10); /* ensure originals */ assert(strcmp(segs[0] + 0, "foo") == 0); assert(strcmp(segs[0] + 4, "bar") == 0); printf("OK\n"); exit(0); }
void proc2() { rvm_t rvm; char *segs[2]; char** segnames; int i; int numSegments = 100; // Allocate some memory segnames = (char **)malloc(numSegments * sizeof(char *)); for(i = 0; i < numSegments; i++) { segnames[i] = (char *)malloc(MAX_SEGMENT_NAME_LEN); sprintf(segnames[i],"testseg%i",i); } rvm = rvm_init(__FILE__ ".d"); for(i = 0; i < numSegments; i++) { segs[0] = (char *) rvm_map(rvm, segnames[i], 3); if(i%2==0){ if(strcmp(segs[0], "ab")) { printf("ERROR in segment %i, string should be ab, but it is (%s)\n", i,segs[0]); exit(2); } } else { if(strcmp(segs[0], "aa")) { printf("ERROR in segment %i, string should be aa, but it is (%s)\n", i,segs[0]); exit(2); } } rvm_unmap(rvm,segs[0]); } printf("OK\n"); // Free memory for(i = 0; i < numSegments; i++) { free(segnames[i]); } free(segnames); }
void proc1() { rvm_t rvm; trans_t trans = 0; char *segs1[2], *segs2[1]; rvm = rvm_init("rvm_segments"); rvm_destroy(rvm, "testseg"); segs1[0] = (char*) rvm_map(rvm, "testseg", 10000); segs2[0] = (char*) rvm_map(rvm, "testseg02", 10000); trans = rvm_begin_trans(rvm, 1, (void**) segs1); // this should exit rvm_about_to_modify(trans, segs2[0], 0, 100); fprintf(stderr, "ERROR: Segment mapped is not the one being modified\n"); abort(); }
/* proc2 opens the segments and reads from them */ void proc2() { char* segs[1]; rvm_t rvm; rvm = rvm_init("rvm_segments"); char * currChar; segs[0] = (char *) rvm_map(rvm, "testseg", 1000 + 1000); currChar = segs[0]; for (int counter = 0; counter < 1000; counter++){ if (*currChar !='!'){ fprintf(stderr, "ERROR %c instead of !", *currChar); } } printf("OK\n"); exit(0); }
/* proc2 opens the segments and reads from them */ void proc2() { char* segs[1]; rvm_t rvm; rvm = rvm_init("rvm_segments"); segs[0] = (char *) rvm_map(rvm, "testseg", 10000); if(!strcmp(segs[0], BAD_STRING)) { printf("ERROR: illegal change got recorded in segment 1: %s\n", segs[0]); exit(2); } if(strcmp(segs[0]+OFFSET2, TEST_STRING)) { printf("ERROR: hello not present in segment 2\n"); exit(2); } printf("OK\n"); exit(0); }
/* proc2 opens the segments and reads from them */ void proc2() { char* segs[1]; rvm_t rvm; rvm = rvm_init("rvm_segments"); segs[0] = (char *) rvm_map(rvm, "testseg", 10000); if(strcmp(segs[0], TEST_STRING)) { printf("ERROR: first hello not present\n"); exit(2); } if(strcmp(segs[0]+OFFSET2, TEST_STRING)) { printf("ERROR: second hello not present\n"); exit(2); } printf("OK\n"); exit(0); }
/* create the scenario */ void create() { // rvm_t rvm = rvm_init(__FILE__ ".d"); rvm_t rvm = rvm_init("rvm_segments"); rvm_destroy(rvm, "testseg"); char* segs[1]; /*-- without unmapping (first half of segment) --*/ segs[0] = (char *) rvm_map(rvm, "testseg", 10); trans_t tid = rvm_begin_trans(rvm, 1, (void **) segs); rvm_about_to_modify(tid, segs[0], 0, 5); sprintf(segs[0], "foo"); /* write "foo" */ rvm_commit_trans(tid); tid = rvm_begin_trans(rvm, 1, (void **) segs); segs[0][0] = 'b'; /* change to boo without logging */ assert(strcmp(segs[0], "boo") == 0); /* ensure change */ rvm_commit_trans(tid); /*-- unmap and remap (second half of segment) --*/ tid = rvm_begin_trans(rvm, 1, (void **) segs); rvm_about_to_modify(tid, segs[0], 4, 5); sprintf(segs[0] + 4, "bar"); /* write "bar" */ rvm_commit_trans(tid); rvm_unmap(rvm, segs[0]); segs[0] = (char *) rvm_map(rvm, "testseg", 10); tid = rvm_begin_trans(rvm, 1, (void **) segs); segs[0][6] = 'z'; /* change to baz without logging */ assert(strcmp(segs[0] + 4, "baz") == 0); /* ensure change */ rvm_commit_trans(tid); abort(); }
/* proc2 opens the segments and reads from them */ void proc2() { char* segs[1]; char *seg; rvm_t rvm; rvm = rvm_init("rvm_segments"); segs[0] = (char *) rvm_map(rvm, "testseg", 10000); seg = segs[0]; if (strcmp(seg + OFFSET2, TEST_STRING2)) { printf("ERROR: blew is incorrect (%s)\n", seg + OFFSET2); exit(2); } if (strcmp(seg, TEST_STRING1)) { printf("ERROR: first hello is incorrect (%s)\n", seg); exit(2); } printf("OK\n"); exit(0); }
int main(int argc, char **argv) { rvm_t rvm; char* segs[2]; char* badsegs; trans_t trans; /* initialize */ rvm = rvm_init("rvm_segments"); rvm_destroy(rvm, SEGNAME0); rvm_destroy(rvm, SEGNAME1); rvm_destroy(rvm, SEGNAME2); segs[0] = (char*) rvm_map(rvm, SEGNAME0, 1000); segs[1] = (char*) rvm_map(rvm, SEGNAME1, 1000); badsegs = (char*) rvm_map(rvm, SEGNAME2, 1000); /* write in some initial data */ trans = rvm_begin_trans(rvm, 2, (void **) segs); rvm_about_to_modify(trans, segs[0], OFFSET0, 100); strcpy(segs[0]+OFFSET0, GOOD_STRING); rvm_about_to_modify(trans, badsegs, OFFSET0, 100); strcpy(badsegs+OFFSET0, GOOD_STRING); rvm_commit_trans(trans); /* test the strings */ if(strcmp(badsegs + OFFSET0, GOOD_STRING)) { printf("ERROR segment not mentioned in rvm_begin_trans yet modifications made (%s)\n", badsegs+OFFSET0); exit(2); } printf("OK\n"); return 0; }
void proc2() { rvm_t rvm; char *segs[2]; rvm = rvm_init("rvm_segments"); segs[0] = (char*) rvm_map(rvm, SEGNAME0, 1000); segs[1] = (char*) rvm_map(rvm, SEGNAME1, 1000); if(strcmp(segs[0] + OFFSET0, STRING0)) { printf("ERROR in segment 0 (%s)\n", segs[0]+OFFSET0); exit(2); } if(strcmp(segs[1] + OFFSET1, STRING1)) { printf("ERROR in segment 1 (%s)\n", segs[1]+OFFSET1); exit(2); } printf("OK\n"); }
/* proc2 opens the segments and reads from them */ void proc2() { char* segs[5]; rvm_t rvm; rvm = rvm_init("rvm_segments"); segs[0] = (char *) rvm_map(rvm, "page0", 10000); segs[1] = (char *) rvm_map(rvm, "page1", 10100); segs[2] = (char *) rvm_map(rvm, "page2", 10200); segs[3] = (char *) rvm_map(rvm, "page3", 10300); segs[4] = (char *) rvm_map(rvm, "page4", 10400); for (int i = 0; i < 5; i++) { if (strcmp(segs[i] + OFFSET1 * i, TEST_STRING)) { printf("ERROR: hello not present @ %d\n", i); exit(2); } } printf("OK\n"); exit(0); }
int main(int argc, char **argv) { #if 1 int pid; pid = fork(); if(pid < 0) { perror("fork"); exit(2); } if(pid == 0) { proc1(); exit(0); } waitpid(pid, NULL, 0); proc2(); #else /* truncate test */ proc1(); rvm_t rvm; printf("Before Truncation:\n"); system("ls -l rvm_segments"); rvm = rvm_init("rvm_segments"); rvm_truncate_log(rvm); printf("\nAfter Truncation:\n"); system("ls -l rvm_segments"); #endif return 0; }