Skip to content

Commit 365d3a3

Browse files
committed
Use hfsfuse to test correctness of sparsebundlefs
1 parent 970ad5e commit 365d3a3

File tree

6 files changed

+54
-10
lines changed

6 files changed

+54
-10
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
sparsebundlefs
2+
hfsdump
3+
hfsfuse
24
*.o
35
*.dSYM

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "hfsfuse"]
2+
path = src/3rdparty/hfsfuse
3+
url = https://github.com/0x09/hfsfuse.git

Dockerfile.linux-gcc

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ RUN dpkg --add-architecture $arch && \
66
apt-get update && \
77
apt-get install -y \
88
build-essential \
9+
git \
910
g++-multilib \
1011
pkg-config:$arch \
1112
libfuse-dev:$arch \

Makefile

+24-10
Original file line numberDiff line numberDiff line change
@@ -150,30 +150,44 @@ FUSE_LDFLAGS := $(shell $(PKG_CONFIG) fuse --libs)
150150
$(TARGET): sparsebundlefs.o
151151
$(CXX) $< -o $@ $(LDFLAGS) $(ARCH_FLAGS) $(FUSE_LDFLAGS)
152152

153+
HFSFUSE_DIR := $(SRC_DIR)/src/3rdparty/hfsfuse
154+
HFSFUSE_DEPS := $(shell find $(HFSFUSE_DIR))
155+
export HFSFUSE_DIR
156+
157+
hfsfuse: $(HFSFUSE_DEPS)
158+
$(if $(wildcard $(HFSFUSE_DIR)/.git),,$(error Please init and update git submodules))
159+
$(call ensure_binary,git)
160+
@printf "Building hfsfuse... "
161+
@tmpdir=$$(mktemp -d); GIT_DIR=$(HFSFUSE_DIR)/.git GIT_WORK_TREE=$$tmpdir git checkout . \
162+
&& make -C $$tmpdir CFLAGS="$(ARCH_FLAGS) -D_FILE_OFFSET_BITS=64" LDFLAGS=$(ARCH_FLAGS) >/dev/null 2>&1 \
163+
&& cp $$tmpdir/hfsfuse $(CURDIR) && cp $$tmpdir/hfsdump $(CURDIR) \
164+
&& printf "OK\n" && rm -Rf $$tmpdir
165+
153166
TESTS_DIR=$(SRC_DIR)/tests
154167
TESTDATA_DIR := $(TESTS_DIR)/data
155-
TEST_BUNDLE := $(TESTDATA_DIR)/test.sparsebundle
156-
export TEST_BUNDLE
168+
$(TESTDATA_DIR):
169+
@mkdir $(TESTDATA_DIR)
157170

158-
ifneq ($(filter testdata,$(ACTUAL_GOALS)),)
159-
.PHONY:: testdata
160-
endif
171+
TEST_BUNDLE := $(TESTDATA_DIR)/basic.sparsebundle
172+
export TEST_BUNDLE
161173

162-
vpath $(TESTDATA_DIR) $(SRC_DIR)
163-
$(TESTDATA_DIR):
174+
$(TEST_BUNDLE): $(TESTDATA_DIR) $(HFSFUSE_DEPS)
164175
$(call ensure_binary,hdiutil)
165-
@rm -Rf $(TESTDATA_DIR) && mkdir $(TESTDATA_DIR)
166-
hdiutil create -size 1TB -type SPARSEBUNDLE -layout NONE -fs HFS+ $(TEST_BUNDLE)
176+
@test ! -e $@ || rm -Rf $@
177+
@printf "Creating testdata..." \
178+
&& hdiutil create -size 1TB -format SPARSEBUNDLE -layout NONE \
179+
-fs HFS+ -srcfolder $(HFSFUSE_DIR) $@
167180

168181
check_%: check ; @:
169-
check: $(TARGET) $(TESTDATA_DIR)
182+
check: $(TARGET) $(TEST_BUNDLE) hfsfuse
170183
@echo "============== $(PLATFORMS) =============="
171184
@PATH="$(CURDIR):$(PATH)" $(SRC_DIR)/tests/testrunner.sh $(TESTS_DIR)/*.tst \
172185
$(subst check_,test_,$(filter check_%,$(ACTUAL_GOALS)))
173186

174187
clean:
175188
rm -f $(TARGET)
176189
rm -Rf $(TARGET).dSYM
190+
rm -f hfsfuse hfsdump
177191
rm -f *.o
178192

179193
distclean: clean

src/3rdparty/hfsfuse

Submodule hfsfuse added at fca1c88

tests/20_mount.tst

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env testrunner.sh
2+
3+
source "$(dirname "$0")/testhelpers.sh"
4+
5+
function setup() {
6+
mount_sparsebundle
7+
}
8+
9+
function test_dmg_has_correct_number_of_blocks() {
10+
hfsdump $dmg_file | grep "total_blocks: 268435456"
11+
}
12+
13+
function test_dmg_contents_is_same_as_testdata() {
14+
for f in $(ls $HFSFUSE_DIR/src); do
15+
echo "Diffing $HFSFUSE_DIR/src/$f"
16+
diff $HFSFUSE_DIR/src/$f <(hfsdump $dmg_file read "/src/$f")
17+
done
18+
}
19+
20+
function teardown() {
21+
umount $mount_dir
22+
rm -Rf $mount_dir
23+
}

0 commit comments

Comments
 (0)