forked from openwrt/make_ext4fs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-and-test.sh
More file actions
executable file
·135 lines (112 loc) · 3.09 KB
/
build-and-test.sh
File metadata and controls
executable file
·135 lines (112 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2024 Eric Herman <eric@freesa.org>
if [[ -n "${VERBOSE}" && "${VERBOSE}" -gt 0 ]]; then
set -x
fi
set -eo pipefail
if [ "_${1}" != "_" ]; then
UUID_IN="$1"
if [ "_${2}" != "_" ]; then
UUID_OUT_EXPECTED="$2"
else
UUID_OUT_EXPECTED="$1"
fi
else
UUID_OUT_EXPECTED='4badc0de-00ab-cdef-0123-456789abcdef'
UUID_MIXED_CASE='{ 4badc0de-00AB-CDEF-0123-456789abcdef }'
UUID_IN="$UUID_MIXED_CASE"
fi
if [ -z "$VALGRIND" ]; then
if command -v valgrind >/dev/null 2>&1; then
VALGRIND='valgrind --leak-check=full'
fi
fi
if [ -z "$BUILD_DIR" ]; then
export BUILD_DIR=build
fi
if [ -z "$DEBUG_DIR" ]; then
export DEBUG_DIR=$BUILD_DIR/debug
fi
if [ -z "$COVER_DIR" ]; then
export COVER_DIR=$BUILD_DIR/cover
fi
echo "BUILD_TYPE=$BUILD_TYPE"
if [ -z "$BUILD_TYPE" ] ; then
BUILD_TYPE=build
fi
echo "BUILD_TYPE=$BUILD_TYPE"
if [ "$BUILD_TYPE" == 'build' ]; then
mkdir -pv $BUILD_DIR
MK_TARGET=default
TEST_DIR=$( mktemp --tmpdir=$BUILD_DIR --directory test-XXXX )
EXE=$BUILD_DIR/make_ext4fs
elif [ "$BUILD_TYPE" == 'debug' ]; then
mkdir -pv $DEBUG_DIR
MK_TARGET=debug
TEST_DIR=$( mktemp --tmpdir=$DEBUG_DIR --directory test-XXXX )
EXE=$DEBUG_DIR/make_ext4fs
elif [ "$BUILD_TYPE" == 'cover' ]; then
mkdir -pv $COVER_DIR
MK_TARGET=coverage
TEST_DIR=$( mktemp --tmpdir=$COVER_DIR --directory test-XXXX )
EXE=$COVER_DIR/make_ext4fs
fi
make $MK_TARGET
dd if=/dev/zero of=$TEST_DIR/blockfile bs=1M count=128
function setup-loopback() {
DEV_LOOPX=$( sudo losetup -f )
echo $DEV_LOOPX
sudo losetup $DEV_LOOPX $TEST_DIR/blockfile
if [[ -n "${VERBOSE}" && "${VERBOSE}" -gt 0 ]]; then
losetup --json --list $DEV_LOOPX
fi
}
if [ -n "$DIRECT_BLOCKFILE" ]; then
FS_TARGET=$TEST_DIR/blockfile
else
setup-loopback
FS_TARGET=$DEV_LOOPX
fi
function cleanup() {
sudo umount -v $DEV_LOOPX || true
sudo losetup -v -d $DEV_LOOPX || true
if [ -z "KEEP_TEST_DIR" ]; then
sudo rm -vfr $TEST_DIR || true
fi
echo "cleanup complete"
}
trap cleanup EXIT
mkdir -pv $TEST_DIR/test-fs-files
echo "foo" > $TEST_DIR/test-fs-files/foo.txt
mkdir -pv $TEST_DIR/test-out
FS_EPOCH=1
sudo $VALGRIND $EXE -v \
-T $FS_EPOCH \
-L test-fs-foo \
-u "$UUID_IN" \
$FS_TARGET \
$TEST_DIR/test-fs-files \
| tee $TEST_DIR/test-out/test-fs-foo.make_ext4fs.out
grep "Label: test-fs-foo" $TEST_DIR/test-out/test-fs-foo.make_ext4fs.out
grep "UUID: $UUID_OUT_EXPECTED" $TEST_DIR/test-out/test-fs-foo.make_ext4fs.out
mkdir -pv $TEST_DIR/mnt-test-fs-foo
if [ -n "$DIRECT_BLOCKFILE" ]; then
setup-loopback
fi
sudo mount $DEV_LOOPX $TEST_DIR/mnt-test-fs-foo
sudo ls -l $TEST_DIR/mnt-test-fs-foo
ERRORS=0
sudo diff -u \
$TEST_DIR/test-fs-files/foo.txt \
$TEST_DIR/mnt-test-fs-foo/foo.txt \
|| ERRORS=$(( 1 + $ERRORS ))
sudo blkid $DEV_LOOPX | tee $TEST_DIR/test-out/test-fs-foo.blkid.out
grep --only-matching "LABEL=\"test-fs-foo\"" \
$TEST_DIR/test-out/test-fs-foo.blkid.out \
|| ERRORS=$(( 1 + $ERRORS ))
grep --only-matching "UUID=\"${UUID_OUT_EXPECTED}\"" \
$TEST_DIR/test-out/test-fs-foo.blkid.out \
|| ERRORS=$(( 1 + $ERRORS ))
if [ $ERRORS -gt 255 ]; then ERRORS=255; fi
exit $ERRORS