Esempio n. 1
0
int main(void)
{
	int i, len, n;
	const int num_tests = 500000;

	printf("Encode test #1:\n");
	len = sizeof(enc_test_1);
	n = encode_4b6b(enc_test_1, result, len);
	print_bytes(result, n);

	printf("Encode test #2:\n");
	len = sizeof(enc_test_2);
	n = encode_4b6b(enc_test_2, result, len);
	print_bytes(result, n);

	printf("Decode test #1:\n");
	len = sizeof(dec_test_1);
	n = decode_4b6b(dec_test_1, result, len);
	if (n >= 0) {
		print_bytes(result, n);
	} else {
		printf("Decoding error!\n");
		return 1;
	}

	printf("Decode test #2:\n");
	len = sizeof(dec_test_2);
	n = decode_4b6b(dec_test_2, result, len);
	if (n >= 0) {
		print_bytes(result, n);
	} else {
		printf("Decoding error!\n");
		return 1;
	}

	printf("Inverse test:\n");
	for (i = 0; i < num_tests; ++i) {
		randomly_fill(test, 128);
		n = encode_4b6b(test, tmp, 128);
		len = decode_4b6b(tmp, result, n);
		if (len != 128) {
			printf("Decoding error!\n");
			return 1;
		}
		if (memcmp(result, test, 128) != 0) {
			printf("Decoded to wrong value!\n");
			return 1;
		}
	}

	return 0;
}
Esempio n. 2
0
int main(int argc, char *argv[]) {
    int result;

    if(argc < 3) {
        printf("Usage: files [mount-point] [trials]\n");
        exit(EXIT_FAILURE);
    }

    char *root = argv[1];
    int trials = strtol(argv[2], NULL, 10);

    char clkpath[256];
    sprintf(clkpath, "%s/clock", root);

    int clkfd = open(clkpath, O_RDONLY);
    if(clkfd < 0) {
        perror("open");
        exit(EXIT_FAILURE);
    }

    char testpath[256];
    sprintf(testpath, "%s/files_test", root);

    int fd = open(testpath, O_RDWR | O_CREAT, 0777);
    if(fd < 0) {
        perror("open");
        exit(EXIT_FAILURE);
    }

    char *buf = malloc(MAX_FILE_SIZE);
    char *rbuf = malloc(MAX_FILE_SIZE);

    int buf_size = randomly_fill(buf);

    if(lseek(fd, 0, SEEK_SET) < 0) {
        perror("lseek");
        exit(EXIT_FAILURE);
    }
    if(write(fd, buf, buf_size) < 0) {
        perror("write");
        exit(EXIT_FAILURE);
    }

    int i;
    for(i = 0; i < trials; i++) {
        struct stat statbuf;
        if(fstat(clkfd, &statbuf) < 0) {
            perror("fstat");
            exit(EXIT_FAILURE);
        }

        if(lseek(fd, 0, SEEK_SET) < 0) {
            perror("lseek");
            exit(EXIT_FAILURE);
        }
        result = read(fd, rbuf, MAX_FILE_SIZE);
        if(result < 0) {
            perror("write");
            exit(EXIT_FAILURE);
        }

        if(result != buf_size) {
            fprintf(stderr, "File size does not match! (%d != %d)\n",
                    buf_size, result);
            exit(EXIT_FAILURE);
        }
        if(memcmp(buf, rbuf, buf_size) != 0) {
            fprintf(stderr, "File contents do not match!\n");
            exit(EXIT_FAILURE);
        }

        buf_size = randomly_fill(buf);

        if(lseek(fd, 0, SEEK_SET) < 0) {
            perror("lseek");
            exit(EXIT_FAILURE);
        }
        if(write(fd, buf, buf_size) < 0) {
            perror("write");
            exit(EXIT_FAILURE);
        }
    }

    exit(EXIT_SUCCESS);
}