forked from agorise/c-ipfs
Made test file generation faster
This commit is contained in:
parent
71c216defb
commit
a6a54fb69b
5 changed files with 42 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -13,3 +13,4 @@ test/test2.txt
|
|||
test/scripts/hello.bin
|
||||
test/scripts/hello2.bin
|
||||
test/scripts/testlog.txt
|
||||
test/scripts/generate_file
|
||||
|
|
13
test/scripts/Makefile
Normal file
13
test/scripts/Makefile
Normal file
|
@ -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
|
26
test/scripts/generate_file.c
Normal file
26
test/scripts/generate_file.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Syntax: %s <filename> <size>\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;
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
####
|
||||
|
|
Loading…
Reference in a new issue