/* read the data referred to by pointers in the tslice struct */ size_t read_tslice(Phdiag * pdp, int num,FILE * fp) { int i; size_t nr = 0; CA_FLOAT * in_array,*inp; int n_array; in_array = (CA_FLOAT *) calloc(pdp->tslices[num].ndata * PHASEDIAG_NPERPOINT, sizeof(CA_FLOAT)); inp=in_array; n_array=0; pdp->tslices[num].regdata = (Pd_num_t *) calloc(pdp->tslices[num].ndata,sizeof(Pd_num_t)); pdp->tslices[num].data = (CA_FLOAT **) calloc(pdp->tslices[num].ndata,sizeof(CA_FLOAT *)); nr = READARRAY(pdp->tslices[num].regdata,sizeof(Pd_num_t),pdp->tslices[num].ndata,fp); /*TODO: check the size */ nr = checkread(&n_array,sizeof(size_t),1,fp); nr = READARRAY(in_array,sizeof(CA_FLOAT),n_array,fp); /*TODO: check the size */ for (i=0; i<pdp->tslices[num].ndata; i++) { if ( pdp->regions[pdp->tslices[num].regdata[i]].np == 2 ) { pdp->tslices[num].data[i] = (CA_FLOAT *) calloc(PHASEDIAG_NPERPOINT,sizeof(CA_FLOAT)); memcpy(pdp->tslices[num].data[i],inp,PHASEDIAG_NPERPOINT * sizeof(CA_FLOAT)); inp += PHASEDIAG_NPERPOINT ; } } free(in_array); return (nr); }
size_t read_phasediag(Phdiag * pdp, const char * filename) { FILE * fp; int i; size_t nr=0; size_t nread=0; fp=fopen(filename,"r"); nr = checkread(pdp,sizeof(Phdiag),1,fp); alloc_phasediag(pdp); nr = checkread(pdp->comp, sizeof(Comp),pdp->ncomp,fp); for(i=0; i<pdp->ncomp; i++) { nr = read_comp(pdp,i,fp); } nr = checkread(pdp->phases, sizeof(Pha),pdp->n_phases,fp); for(i=0; i<pdp->n_phases; i++) { nr = read_phase(pdp,i,fp); } nr = checkread(pdp->regions,sizeof(Reg),pdp->n_regions,fp); for (i=0; i<pdp->n_regions; i++) { nr = read_region(pdp,i,fp); } nr = READARRAY(pdp->tslices,sizeof(Tslice),pdp->n_tslice,fp); #ifndef BL_COMPRESS nr *= sizeof(Tslice); #endif if (nr != pdp->n_tslice * sizeof(Tslice) ) { fprintf(stderr,"ERROR:read_phasediag: Read error, expecting %li got %li\n",pdp->n_tslice,nr); exit(0); } for (i=0; i<pdp->n_tslice; i++) { nr = read_tslice(pdp,i,fp); } return(nread); }
void test_rle() { int ret = 1; printf("==RLE==\n"); for (int j = NUM_REPEATS; j > 0; j--) { uart.write_encoded_byte(0xDE,1,0); uart.dump_runs(); uart.write_encoded_byte(0xAD,2,0); uart.dump_runs(); uart.write_encoded_byte(0xBE,1,0); uart.dump_runs(); uart.decode_runs(); ret &= checkread(0xDE); ret &= checkread(0xAD); uart.write_encoded_byte(0x13,1,0); uart.dump_runs(); uart.write_encoded_byte(0x3E,2,0); uart.dump_runs(); uart.decode_runs(); ret &= checkread(0xBE); ret &= checkread(0x13); uart.write_encoded_byte(0x3E,1,0); uart.dump_runs(); uart.write_encoded_byte(0xEF,1,1); uart.dump_runs(); uart.write_run(1,1); // one more stop bit to finish it off.. uart.dump_runs(); uart.decode_runs(); ret &= checkread(0x3E); ret &= checkread(0x3E); ret &= checkread(0xEF); // for (int i=0; i<5; i++) // { // printread(); // } } if (ret) { printf("success\n"); } else { printf("FAIL\n"); } }
size_t read_region(Phdiag * pdp,int num,FILE * fp) { int i; Pd_num_t phnum; size_t nr=0; pdp->regions[num].phases = (Pha *) calloc(pdp->regions[num].np,sizeof(Pha)); for(i=0; i<pdp->regions[num].np; i++) { nr += checkread(&phnum,sizeof(Pd_num_t),1,fp); pdp->regions[num].phases[i] = pdp->phases[phnum]; } if (pdp->regions[num].ntie > 0 ) { alloc_tiedata( &(pdp->regions[num]) ); nr += READARRAY(pdp->regions[num].tiedata,sizeof(Pd_tri),pdp->regions[num].ntie,fp); } return(nr); }
int main(int argc, char *argv[]) { int pid, i; if(argc != 3){ fprintf(stderr, "Usage: test-lab-2-a dir1 dir2\n"); exit(1); } sprintf(d1, "%s/d%d", argv[1], getpid()); if(mkdir(d1, 0777) != 0){ fprintf(stderr, "test-lab-2-a: failed: mkdir(%s): %s\n", d1, strerror(errno)); exit(1); } sprintf(d2, "%s/d%d", argv[2], getpid()); if(access(d2, 0) != 0){ fprintf(stderr, "test-lab-2-a: failed: access(%s) after mkdir %s: %s\n", d2, d1, strerror(errno)); exit(1); } setbuf(stdout, 0); for(i = 0; i < sizeof(big)-1; i++) big[i] = 'x'; for(i = 0; i < sizeof(huge)-1; i++) huge[i] = '0'; //addddddddddddd printf("Concurrent creates: "); pid = fork(); if(pid < 0){ perror("test-lab-2-a: fork"); exit(1); } if(pid == 0){ createn(d2, "xx", 20, false); exit(0); } createn(d1, "yy", 20, false); sleep(10); reap(pid); dircheck(d1, 40); checkn(d1, "xx", 20); checkn(d2, "yy", 20); unlinkn(d1, "xx", 20); unlinkn(d1, "yy", 20); printf("OK\n"); printf("Concurrent create/delete: "); createn(d1, "x1", 20, false); createn(d2, "x2", 20, false); pid = fork(); if(pid < 0){ perror("test-lab-2-a: fork"); exit(1); } if(pid == 0){ unlinkn(d2, "x1", 20); createn(d1, "x3", 20, false); exit(0); } createn(d1, "x4", 20, false); reap(pid); unlinkn(d2, "x2", 20); unlinkn(d2, "x4", 20); unlinkn(d2, "x3", 20); dircheck(d1, 0); printf("OK\n"); //additional printf("Create then read: "); create1(d1, "f1", "aaa"); check1(d2, "f1", "aaa"); check1(d1, "f1", "aaa"); printf("OK\n"); printf("Unlink: "); unlink1(d2, "f1"); create1(d1, "fx1", "fxx"); /* checknot f1 fails w/o these */ unlink1(d1, "fx1"); checknot(d1, "f1"); checknot(d2, "f1"); create1(d1, "f2", "222"); unlink1(d2, "f2"); checknot(d1, "f2"); checknot(d2, "f2"); create1(d1, "f3", "333"); check1(d2, "f3", "333"); check1(d1, "f3", "333"); unlink1(d1, "f3"); create1(d2, "fx2", "22"); /* checknot f3 fails w/o these */ unlink1(d2, "fx2"); checknot(d2, "f3"); checknot(d1, "f3"); printf("OK\n"); printf("Append: "); create1(d2, "f1", "aaa"); append1(d1, "f1", "bbb"); append1(d2, "f1", "ccc"); check1(d1, "f1", "aaabbbccc"); check1(d2, "f1", "aaabbbccc"); printf("OK\n"); printf("Readdir: "); dircheck(d1, 1); dircheck(d2, 1); unlink1(d1, "f1"); dircheck(d1, 0); dircheck(d2, 0); create1(d2, "f2", "aaa"); create1(d1, "f3", "aaa"); dircheck(d1, 2); dircheck(d2, 2); unlink1(d2, "f2"); dircheck(d2, 1); dircheck(d1, 1); unlink1(d2, "f3"); dircheck(d1, 0); dircheck(d2, 0); printf("OK\n"); printf("Many sequential creates: "); createn(d1, "aa", 10, false); createn(d2, "bb", 10, false); dircheck(d2, 20); checkn(d2, "bb", 10); checkn(d2, "aa", 10); checkn(d1, "aa", 10); checkn(d1, "bb", 10); unlinkn(d1, "aa", 10); unlinkn(d2, "bb", 10); printf("OK\n"); printf("Write 20000 bytes: "); create1(d1, "bf", big); check1(d1, "bf", big); check1(d2, "bf", big); unlink1(d1, "bf"); printf("OK\n"); printf("Concurrent creates: "); pid = fork(); if(pid < 0){ perror("test-lab-2-a: fork"); exit(1); } if(pid == 0){ createn(d2, "xx", 20, false); exit(0); } createn(d1, "yy", 20, false); sleep(10); reap(pid); dircheck(d1, 40); checkn(d1, "xx", 20); checkn(d2, "yy", 20); unlinkn(d1, "xx", 20); unlinkn(d1, "yy", 20); printf("OK\n"); printf("Concurrent creates of the same file: "); pid = fork(); if(pid < 0){ perror("test-lab-2-a: fork"); exit(1); } if(pid == 0){ createn(d2, "zz", 20, true); exit(0); } createn(d1, "zz", 20, true); sleep(4); dircheck(d1, 20); reap(pid); checkn(d1, "zz", 20); checkn(d2, "zz", 20); unlinkn(d1, "zz", 20); printf("OK\n"); printf("Concurrent create/delete: "); createn(d1, "x1", 20, false); createn(d2, "x2", 20, false); pid = fork(); if(pid < 0){ perror("test-lab-2-a: fork"); exit(1); } if(pid == 0){ unlinkn(d2, "x1", 20); createn(d1, "x3", 20, false); exit(0); } createn(d1, "x4", 20, false); reap(pid); unlinkn(d2, "x2", 20); unlinkn(d2, "x4", 20); unlinkn(d2, "x3", 20); dircheck(d1, 0); printf("OK\n"); printf("Concurrent creates, same file, same server: "); pid = fork(); if(pid < 0){ perror("test-lab-2-a: fork"); exit(1); } if(pid == 0){ createn(d1, "zz", 20, true); exit(0); } createn(d1, "zz", 20, true); sleep(2); dircheck(d1, 20); reap(pid); checkn(d1, "zz", 20); unlinkn(d1, "zz", 20); printf("OK\n"); printf("Concurrent writes to different parts of same file: "); create1(d1, "www", huge); pid = fork(); if(pid < 0){ perror("test-lab-2-a: fork"); exit(1); } if(pid == 0){ write1(d2, "www", 65536, 64, '2'); exit(0); } write1(d1, "www", 0, 64, '1'); reap(pid); checkread(d1, "www", 0, 64, '1'); checkread(d2, "www", 0, 64, '1'); checkread(d1, "www", 65536, 64, '2'); checkread(d2, "www", 65536, 64, '2'); printf("OK\n"); printf("test-lab-2-a: Passed all tests.\n"); exit(0); return(0); }