diff --git a/.gitignore b/.gitignore index e8d8444..ce47bf4 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ test/test2.txt test/scripts/hello.bin test/scripts/hello2.bin test/scripts/testlog.txt +test/scripts/generate_file diff --git a/test/scripts/Makefile b/test/scripts/Makefile new file mode 100644 index 0000000..13d0606 --- /dev/null +++ b/test/scripts/Makefile @@ -0,0 +1,13 @@ +CC = gcc + +%.o: %.c + $(CC) -c -o $@ $< + +generate_file: generate_file.o + $(CC) -o $@ $^ + +all: generate_file + +clean: + rm -f *.o + rm -f generate_file diff --git a/test/scripts/generate_file.c b/test/scripts/generate_file.c new file mode 100644 index 0000000..eb1bc5d --- /dev/null +++ b/test/scripts/generate_file.c @@ -0,0 +1,26 @@ +#include +#include + +int main(int argc, char** argv) { + if (argc != 3) { + fprintf(stderr, "Syntax: %s \n", argv[0]); + exit(1); + } + + char* filename = argv[1]; + long file_size = atoi(argv[2]); + + FILE* fd = fopen(filename, "w"); + if (!fd) { + fprintf(stderr, "Unable to open the file %s for writing.\n", filename); + exit(1); + } + + for(size_t i = 0; i < file_size; i++) { + char byte = i % 255; + fwrite(&byte, 1, 1, fd); + } + + fclose(fd); + return 0; +} diff --git a/test/scripts/test_5.sh b/test/scripts/test_5.sh index 09373f3..7a27d46 100755 --- a/test/scripts/test_5.sh +++ b/test/scripts/test_5.sh @@ -40,7 +40,7 @@ function body { #A client of server 2 wants the file at server 1 eval "$IPFS2" cat QmYAXgX8ARiriupMQsbGXtKdDyGzWry1YV3sycKw1qqmgH - check_failure_with_exit "cat" $? + check_failure "cat" $? kill -9 $daemon_id_1 kill -9 $daemon_id_2 diff --git a/test/scripts/test_helpers.sh b/test/scripts/test_helpers.sh index 225c32e..e1d10fd 100755 --- a/test/scripts/test_helpers.sh +++ b/test/scripts/test_helpers.sh @@ -25,12 +25,7 @@ function create_binary_file { if [ $num_bytes -eq 0 ]; then num_bytes=255; fi - let num_bytes-- - for ((byte=0;byte<=$num_bytes;byte++)); - do - let remainder=($byte % 255) - printf "\\$(printf "%o" $remainder)" >> hello.bin - done + exec ./generate_file hello.bin $num_bytes } ####