Add tests, generate hdd images on the fly.

This commit is contained in:
Ivan Baravy 2018-05-19 18:48:10 +03:00
parent 326e6fa663
commit bd2e078d13
11 changed files with 2585 additions and 18 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ mkdirrange
*.img.gz
*.img.lz4
*.img.info
t_*.out

74
img/makefile Normal file
View File

@ -0,0 +1,74 @@
MKDIRRANGE=../tools/mkdirrange
LOOP_DEV=/dev/loop8
TEMP_DIR:=$(shell mktemp -d)
all: s512_xfs_v4_ftype0.img s512_xfs_v4_ftype1.img s512_xfs_v4_ftype1_btree_dirs.img
s512_xfs_v4_ftype0.img:
dd if=/dev/zero of=$@ bs=1M count=64
parted --script $@ mktable gpt
parted --script --align optimal $@ mkpart primary 1MiB 100%
sudo losetup $(LOOP_DEV) --partscan $@
sudo mkfs.xfs -m crc=0,finobt=0,rmapbt=0,reflink=0 -d sectsize=512 -i maxpct=100 -n ftype=0 $(LOOP_DEV)p1
sudo mount $(LOOP_DEV)p1 $(TEMP_DIR)
sudo chown $(shell whoami) $(TEMP_DIR) -R
#
mkdir $(TEMP_DIR)/sf
$(MKDIRRANGE) $(TEMP_DIR)/sf 3
#
mkdir $(TEMP_DIR)/block
$(MKDIRRANGE) $(TEMP_DIR)/block 20
#
mkdir $(TEMP_DIR)/leaf
$(MKDIRRANGE) $(TEMP_DIR)/leaf 70
#
mkdir $(TEMP_DIR)/node
$(MKDIRRANGE) $(TEMP_DIR)/node 520
#
mkdir $(TEMP_DIR)/btree
$(MKDIRRANGE) $(TEMP_DIR)/btree 600
sudo umount $(TEMP_DIR)
sudo losetup -d $(LOOP_DEV)
s512_xfs_v4_ftype1.img:
dd if=/dev/zero of=$@ bs=1M count=64
parted --script $@ mktable gpt
parted --script --align optimal $@ mkpart primary 1MiB 100%
sudo losetup $(LOOP_DEV) --partscan $@
sudo mkfs.xfs -m crc=0,finobt=0,rmapbt=0,reflink=0 -d sectsize=512 -i maxpct=100 -n ftype=1 $(LOOP_DEV)p1
sudo mount $(LOOP_DEV)p1 $(TEMP_DIR)
sudo chown $(shell whoami) $(TEMP_DIR) -R
#
mkdir $(TEMP_DIR)/sf
$(MKDIRRANGE) $(TEMP_DIR)/sf 3
#
mkdir $(TEMP_DIR)/block
$(MKDIRRANGE) $(TEMP_DIR)/block 20
#
mkdir $(TEMP_DIR)/leaf
$(MKDIRRANGE) $(TEMP_DIR)/leaf 70
#
mkdir $(TEMP_DIR)/node
$(MKDIRRANGE) $(TEMP_DIR)/node 520
#
mkdir $(TEMP_DIR)/btree
$(MKDIRRANGE) $(TEMP_DIR)/btree 600
sudo umount $(TEMP_DIR)
sudo losetup -d $(LOOP_DEV)
s512_xfs_v4_ftype1_btree_dirs.img:
dd if=/dev/zero of=$@ bs=1M count=128
parted --script $@ mktable gpt
parted --script --align optimal $@ mkpart primary 1MiB 100%
sudo losetup $(LOOP_DEV) --partscan $@
sudo mkfs.xfs -m crc=0,finobt=0,rmapbt=0,reflink=0 -d sectsize=512 -i maxpct=100 -n ftype=1 $(LOOP_DEV)p1
sudo mount $(LOOP_DEV)p1 $(TEMP_DIR)
sudo chown $(shell whoami) $(TEMP_DIR) -R
#
mkdir $(TEMP_DIR)/btree1
$(MKDIRRANGE) $(TEMP_DIR)/btree1 293181
sudo umount $(TEMP_DIR)
sudo losetup -d $(LOOP_DEV)

5
kofu.c
View File

@ -20,7 +20,8 @@ bool is_tty;
int cmd_num = 0;
void prompt() {
fprintf(stderr, "#%d> ", cmd_num);
printf("#%d> ", cmd_num);
fflush(stdout);
}
bool next_line() {
@ -143,7 +144,7 @@ int main(int argc, char **argv) {
while(next_line()) {
if (!is_tty) {
prompt();
fprintf(stderr, "%s", cmd_buf);
printf("%s", cmd_buf);
}
char **arg = split_args(cmd_buf);
bool found = false;

12
test/makefile Normal file
View File

@ -0,0 +1,12 @@
KOFU=../kofu
all: t_000_ls_all_dir_types_ftype0 t_001_ls_all_dir_types_ftype1
.PHONY: t_000_ls_all_dir_types_ftype0 t_001_ls_all_dir_types_ftype1
t_000_ls_all_dir_types_ftype0:
$(KOFU) ../img/s512_xfs_v4_ftype0.img < $@ > $@.out
cmp $@.ref $@.out
t_001_ls_all_dir_types_ftype1:
$(KOFU) ../img/s512_xfs_v4_ftype1.img < $@ > $@.out
cmp $@.ref $@.out

View File

@ -0,0 +1,5 @@
ls /hd0/1/sf
ls /hd0/1/block
ls /hd0/1/leaf
ls /hd0/1/node
ls /hd0/1/btree

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,5 @@
ls /hd0/1/sf
ls /hd0/1/block
ls /hd0/1/leaf
ls /hd0/1/node
ls /hd0/1/btree

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +0,0 @@
ls /hd0/1/123
stat /hd0/1/123/two

View File

@ -1 +0,0 @@
ls /hd0/1/btree1

View File

@ -2,30 +2,46 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <errno.h>
int main(int argc, char *argv[])
{
unsigned long begin, end, current;
char dirname[256] = "dir0123456789_blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah\0";
if(argc != 3) {
fprintf(stderr, "%s num_begin num_end\n", argv[0]);
unsigned begin = 0, end;
char *path;
if (argc == 3) {
path = argv[1];
sscanf(argv[2], "%u", &end);
} else if (argc == 4) {
path = argv[1];
sscanf(argv[2], "%u", &begin);
sscanf(argv[3], "%u", &end);
} else {
fprintf(stderr, "mkdirrange directory num_begin num_end\n");
exit(1);
}
sscanf(argv[1], "%lu", &begin);
sscanf(argv[2], "%lu", &end);
for(current=begin; current<=end; current++) {
sprintf(dirname + 3, "%10.10lu", current);
dirname[13] = '_';
if(mkdir(dirname, 0755)) {
fprintf(stderr, "error: %s\n", strerror(errno));
int dirfd = open(path, O_DIRECTORY);
if (dirfd == -1) {
fprintf(stderr, "Can't open %s: %s\n", path, strerror(errno));
exit(1);
}
char dirname[256];
memset(dirname, 'x', 256);
for(unsigned current = begin; current < end; current++) {
int length = sprintf(dirname, "d%10.10u_", current);
dirname[length] = 'x';
length += current % 244;
dirname[length] = '\0';
if(mkdirat(dirfd, dirname, 0755)) {
fprintf(stderr, "Can't mkdir %s: %s\n", dirname, strerror(errno));
exit(1);
} else {
dirname[length] = 'x';
}
}
return 0;