//write int test_case_1(char **argv, int op_type) { if (send_file_request(argv, "local_file", 1) == -1) { return 1; } int ret = 0; char * str_arr[1]; char *blk_0 = "d1/local_file_blk_0"; FILE *local_fp = fopen("local_file", "rb"); char *local_buf = (char *) malloc(sizeof(char) * DFS_BLOCK_SIZE); char *buf = (char *) malloc(sizeof(char) * DFS_BLOCK_SIZE); sleep(5); str_arr[0] = blk_0; FILE *fp = fopen(str_arr[0], "rb"); if (fp == NULL) return 1; memset(buf, 0, DFS_BLOCK_SIZE); memset(local_buf, 0, DFS_BLOCK_SIZE); fread(buf, DFS_BLOCK_SIZE, 1, fp); fread(local_buf, DFS_BLOCK_SIZE, 1, local_fp); if (memcmp(local_buf, buf, DFS_BLOCK_SIZE) != 0) { ret = 1; } fclose(fp); free(buf); free(local_buf); fclose(local_fp); return ret; }
int test_case_4(char **argv, int op_type) { system("rm -f local_file_medium"); if (send_file_request(argv, "local_file_medium", 0) == -1) { printf("test.c: test_case_4: fail on send_file_request.\n"); return 1; } sleep(5); int ret = 0; FILE *fp = fopen("local_file_medium", "rb"); char *buf = (char *) malloc(sizeof(char) * 4096); char *buf_1 = (char *) malloc(sizeof(char) * 4096); fread(buf, 4096, 1, fp); fclose(fp); fp = fopen("local_file_medium_1", "rb"); fread(buf_1, 4096, 1, fp); fclose(fp); if (memcmp(buf, buf_1, 4096) != 0) { ret = 1; printf("test.c: test_case_4: fail on memcmp.\n"); } free(buf); free(buf_1); return ret; }
int test_case_5(char **argv, int op_type) { if (send_file_request(argv, "local_file_large", 1) == -1) { return 1; } sleep(5); int ret = 0; int i = 0; char * str_arr[8]; char *blk_0 = "d1/local_file_large_blk_0"; char *blk_1 = "d2/local_file_large_blk_1"; char *blk_2 = "d1/local_file_large_blk_2"; char *blk_3 = "d2/local_file_large_blk_3"; char *blk_4 = "d1/local_file_large_blk_4"; char *blk_5 = "d2/local_file_large_blk_5"; char *blk_6 = "d1/local_file_large_blk_6"; char *blk_7 = "d2/local_file_large_blk_7"; FILE *local_fp = fopen("local_file_large", "rb"); char *local_buf = (char *) malloc(sizeof(char) * DFS_BLOCK_SIZE); char *buf = (char *) malloc(sizeof(char) * DFS_BLOCK_SIZE); str_arr[0] = blk_0; str_arr[1] = blk_1; str_arr[2] = blk_2; str_arr[3] = blk_3; str_arr[4] = blk_4; str_arr[5] = blk_5; str_arr[6] = blk_6; str_arr[7] = blk_7; for (; i < 8; i++) { FILE *fp = fopen(str_arr[i], "rb"); if (fp == NULL) { ret = 1; break; } memset(buf, 0, DFS_BLOCK_SIZE); memset(local_buf, 0, DFS_BLOCK_SIZE); fread(buf, DFS_BLOCK_SIZE, 1, fp); fseek(local_fp, i * DFS_BLOCK_SIZE, SEEK_SET); fread(local_buf, DFS_BLOCK_SIZE, 1, local_fp); if (memcmp(local_buf, buf, DFS_BLOCK_SIZE) != 0) { printf("failed on %d\n", i); fclose(fp); ret = 1; break; } fclose(fp); } free(buf); free(local_buf); fclose(local_fp); return ret; }
int test_case_2(char **argv, int op_type) { system("rm local_file"); if (send_file_request(argv, "local_file", 0) == -1) { return 1; } sleep(5); int ret = 0; FILE *fp = fopen("local_file", "rb"); char *buf = (char *) malloc(sizeof(char) * 8192); char *buf_1 = (char *) malloc(sizeof(char) * 8192); fread(buf, 8192, 1, fp); fclose(fp); fp = fopen("local_file_1", "rb"); fread(buf_1, 8192, 1, fp); fclose(fp); if (memcmp(buf, buf_1, 8192) != 0) ret = 1; free(buf); free(buf_1); return ret; }
int test_case_1(char **argv, int op_type) { if (send_file_request(argv, "local_file", 1) == -1) { return 1; } sleep(5); int ret = 0; int fd; FILE *local_fp = fopen("local_file", "rb"); char *buf = (char *) malloc(sizeof(char) * DFS_BLOCK_SIZE); char *buf_local = (char *) malloc(sizeof(char) * DFS_BLOCK_SIZE); sfs_reloadfs("d1/local_fs"); fd = sfs_open("/", "local_file_blk_0"); sfs_read(fd, buf, DFS_BLOCK_SIZE); sfs_close(fd); fread(buf_local, 1, DFS_BLOCK_SIZE, local_fp); if (memcmp(buf_local, buf, DFS_BLOCK_SIZE) != 0) ret = 1; if (ret == 0) { fseek(local_fp, 2 * DFS_BLOCK_SIZE, SEEK_SET); fd = sfs_open("/", "local_file_blk_2"); sfs_read(fd, buf, DFS_BLOCK_SIZE); sfs_close(fd); fread(buf_local, 1, DFS_BLOCK_SIZE, local_fp); if (memcmp(buf_local, buf, DFS_BLOCK_SIZE) != 0) ret = 1; } if (ret == 0) { fseek(local_fp, 4 * DFS_BLOCK_SIZE, SEEK_SET); fd = sfs_open("/", "local_file_blk_4"); sfs_read(fd, buf, DFS_BLOCK_SIZE); sfs_close(fd); fread(buf_local, 1, DFS_BLOCK_SIZE, local_fp); if (memcmp(buf_local, buf, DFS_BLOCK_SIZE) != 0) ret = 1; } if (ret == 0) { fseek(local_fp, 6 * DFS_BLOCK_SIZE, SEEK_SET); fd = sfs_open("/", "local_file_blk_6"); sfs_read(fd, buf, DFS_BLOCK_SIZE); sfs_close(fd); fread(buf_local, 1, DFS_BLOCK_SIZE, local_fp); if (memcmp(buf_local, buf, DFS_BLOCK_SIZE) != 0) ret = 1; } sfs_close_storage(); sfs_reloadfs("d2/local_fs"); fd = sfs_open("/", "local_file_blk_1"); sfs_read(fd, buf, DFS_BLOCK_SIZE); sfs_close(fd); fseek(local_fp, 1 * DFS_BLOCK_SIZE, SEEK_SET); fread(buf_local, 1, DFS_BLOCK_SIZE, local_fp); if (memcmp(buf_local, buf, DFS_BLOCK_SIZE) != 0) ret = 1; if (ret == 0) { fseek(local_fp, 3 * DFS_BLOCK_SIZE, SEEK_SET); fd = sfs_open("/", "local_file_blk_3"); sfs_read(fd, buf, DFS_BLOCK_SIZE); sfs_close(fd); fread(buf_local, 1, DFS_BLOCK_SIZE, local_fp); if (memcmp(buf_local, buf, DFS_BLOCK_SIZE) != 0) ret = 1; } if (ret == 0) { fseek(local_fp, 5 * DFS_BLOCK_SIZE, SEEK_SET); fd = sfs_open("/", "local_file_blk_5"); sfs_read(fd, buf, DFS_BLOCK_SIZE); sfs_close(fd); fread(buf_local, 1, DFS_BLOCK_SIZE, local_fp); if (memcmp(buf_local, buf, DFS_BLOCK_SIZE) != 0) ret = 1; } if (ret == 0) { fseek(local_fp, 7 * DFS_BLOCK_SIZE, SEEK_SET); fd = sfs_open("/", "local_file_blk_7"); sfs_read(fd, buf, DFS_BLOCK_SIZE); sfs_close(fd); fread(buf_local, 1, DFS_BLOCK_SIZE, local_fp); if (memcmp(buf_local, buf, DFS_BLOCK_SIZE) != 0) ret = 1; } sfs_close_storage(); fclose(local_fp); free(buf); free(buf_local); return ret; }