Skip to content

Commit 1874628

Browse files
committed
WIP fixed issues with expanding directories in tests
(Some where legitimate test failures)
1 parent 2da9392 commit 1874628

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

lfs.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ static int lfs_commit_move(lfs_t *lfs, struct lfs_commit *commit,
658658
int32_t res = lfs_commit_get(lfs, commit->block,
659659
commit->off, commit->ptag,
660660
lfs_tag_isuser(tag) ? 0x7ffff000 : 0x7c3ff000,
661-
LFS_MKTAG(lfs_tag_type(tag), toid, 0),
661+
(tag & 0x7fc00000) | LFS_MKTAG(0, toid, 0),
662662
0, NULL, true);
663663
if (res < 0 && res != LFS_ERR_NOENT) {
664664
return res;
@@ -1166,7 +1166,7 @@ static int lfs_dir_compact(lfs_t *lfs,
11661166
tail.tail[0] = dir->tail[0];
11671167
tail.tail[1] = dir->tail[1];
11681168

1169-
err = lfs_dir_compact(lfs, &tail, attrs, dir, ack+1-expanding, end);
1169+
err = lfs_dir_compact(lfs, &tail, attrs, source, ack+1-expanding, end);
11701170
if (err) {
11711171
return err;
11721172
}
@@ -1346,8 +1346,12 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_mdir_t *dir,
13461346
lfs_global_xor(&lfs->globals, &canceldiff);
13471347

13481348
// update any directories that are affected
1349+
lfs_mdir_t copy = *dir;
1350+
1351+
// two passes, once for things that aren't us, and one
1352+
// for things that are
13491353
for (lfs_mlist_t *d = lfs->mlist; d; d = d->next) {
1350-
if (lfs_pair_cmp(d->m.pair, dir->pair) == 0) {
1354+
if (lfs_pair_cmp(d->m.pair, copy.pair) == 0) {
13511355
d->m = *dir;
13521356
if (d->id == lfs_tag_id(deletetag)) {
13531357
d->m.pair[0] = 0xffffffff;

tests/test_alloc.sh

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,45 +194,62 @@ tests/test.py << TEST
194194
lfs_file_read(&lfs, &file[0], buffer, size) => size;
195195
memcmp(buffer, "exhaustion", size) => 0;
196196
lfs_file_close(&lfs, &file[0]) => 0;
197+
lfs_remove(&lfs, "exhaustion") => 0;
197198
lfs_unmount(&lfs) => 0;
198199
TEST
199200

200201
echo "--- Dir exhaustion test ---"
201202
tests/test.py << TEST
202203
lfs_mount(&lfs, &cfg) => 0;
203-
lfs_remove(&lfs, "exhaustion") => 0;
204204
205-
lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
205+
// find out max file size
206+
lfs_mkdir(&lfs, "exhaustiondir") => 0;
206207
size = strlen("blahblahblahblah");
207208
memcpy(buffer, "blahblahblahblah", size);
208-
for (lfs_size_t i = 0;
209-
i < (cfg.block_count-4)*(cfg.block_size-8);
210-
i += size) {
209+
lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
210+
int count = 0;
211+
int err;
212+
while (true) {
213+
err = lfs_file_write(&lfs, &file[0], buffer, size);
214+
if (err < 0) {
215+
break;
216+
}
217+
218+
count += 1;
219+
}
220+
err => LFS_ERR_NOSPC;
221+
lfs_file_close(&lfs, &file[0]) => 0;
222+
223+
lfs_remove(&lfs, "exhaustion") => 0;
224+
lfs_remove(&lfs, "exhaustiondir") => 0;
225+
226+
// see if dir fits with max file size
227+
lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
228+
for (int i = 0; i < count; i++) {
211229
lfs_file_write(&lfs, &file[0], buffer, size) => size;
212230
}
213231
lfs_file_close(&lfs, &file[0]) => 0;
214232
215233
lfs_mkdir(&lfs, "exhaustiondir") => 0;
216234
lfs_remove(&lfs, "exhaustiondir") => 0;
235+
lfs_remove(&lfs, "exhaustion") => 0;
217236
218-
lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_APPEND);
219-
size = strlen("blahblahblahblah");
220-
memcpy(buffer, "blahblahblahblah", size);
221-
for (lfs_size_t i = 0;
222-
i < (cfg.block_size-8);
223-
i += size) {
237+
// see if dir fits with > max file size
238+
lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
239+
for (int i = 0; i < count+1; i++) {
224240
lfs_file_write(&lfs, &file[0], buffer, size) => size;
225241
}
226242
lfs_file_close(&lfs, &file[0]) => 0;
227243
228244
lfs_mkdir(&lfs, "exhaustiondir") => LFS_ERR_NOSPC;
245+
246+
lfs_remove(&lfs, "exhaustion") => 0;
229247
lfs_unmount(&lfs) => 0;
230248
TEST
231249

232250
echo "--- Chained dir exhaustion test ---"
233251
tests/test.py << TEST
234252
lfs_mount(&lfs, &cfg) => 0;
235-
lfs_remove(&lfs, "exhaustion") => 0;
236253
237254
lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
238255
size = strlen("blahblahblahblah");

tests/test_entries.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ set -eu
44
# Note: These tests are intended for 512 byte inline size at different
55
# inline sizes they should still pass, but won't be testing anything
66

7-
echo "=== Directory tests ==="
7+
echo "=== Entry tests ==="
8+
rm -rf blocks
89
function read_file {
910
cat << TEST
1011

0 commit comments

Comments
 (0)