|
| 1 | +#!/bin/bash |
| 2 | +set -eu |
| 3 | + |
| 4 | +SMALLSIZE=32 |
| 5 | +MEDIUMSIZE=2048 |
| 6 | +LARGESIZE=8192 |
| 7 | + |
| 8 | +echo "=== Truncate tests ===" |
| 9 | +rm -rf blocks |
| 10 | +tests/test.py << TEST |
| 11 | + lfs_format(&lfs, &cfg) => 0; |
| 12 | +TEST |
| 13 | + |
| 14 | +truncate_test() { |
| 15 | +STARTSIZES="$1" |
| 16 | +HOTSIZES="$2" |
| 17 | +COLDSIZES="$3" |
| 18 | +tests/test.py << TEST |
| 19 | + static const lfs_off_t startsizes[] = {$STARTSIZES}; |
| 20 | + static const lfs_off_t hotsizes[] = {$HOTSIZES}; |
| 21 | +
|
| 22 | + lfs_mount(&lfs, &cfg) => 0; |
| 23 | +
|
| 24 | + for (int i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) { |
| 25 | + sprintf((char*)buffer, "hairyhead%d", i); |
| 26 | + lfs_file_open(&lfs, &file[0], (const char*)buffer, |
| 27 | + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0; |
| 28 | +
|
| 29 | + strcpy((char*)buffer, "hair"); |
| 30 | + size = strlen((char*)buffer); |
| 31 | + for (int j = 0; j < startsizes[i]; j += size) { |
| 32 | + lfs_file_write(&lfs, &file[0], buffer, size) => size; |
| 33 | + } |
| 34 | + lfs_file_size(&lfs, &file[0]) => startsizes[i]; |
| 35 | +
|
| 36 | + lfs_file_truncate(&lfs, &file[0], hotsizes[i]) => 0; |
| 37 | + lfs_file_size(&lfs, &file[0]) => hotsizes[i]; |
| 38 | +
|
| 39 | + lfs_file_close(&lfs, &file[0]) => 0; |
| 40 | + } |
| 41 | +
|
| 42 | + lfs_unmount(&lfs) => 0; |
| 43 | +TEST |
| 44 | +tests/test.py << TEST |
| 45 | + static const lfs_off_t startsizes[] = {$STARTSIZES}; |
| 46 | + static const lfs_off_t hotsizes[] = {$HOTSIZES}; |
| 47 | + static const lfs_off_t coldsizes[] = {$COLDSIZES}; |
| 48 | +
|
| 49 | + lfs_mount(&lfs, &cfg) => 0; |
| 50 | +
|
| 51 | + for (int i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) { |
| 52 | + sprintf((char*)buffer, "hairyhead%d", i); |
| 53 | + lfs_file_open(&lfs, &file[0], (const char*)buffer, LFS_O_RDWR) => 0; |
| 54 | + lfs_file_size(&lfs, &file[0]) => hotsizes[i]; |
| 55 | +
|
| 56 | + size = strlen("hair"); |
| 57 | + int j = 0; |
| 58 | + for (; j < startsizes[i] && j < hotsizes[i]; j += size) { |
| 59 | + lfs_file_read(&lfs, &file[0], buffer, size) => size; |
| 60 | + memcmp(buffer, "hair", size) => 0; |
| 61 | + } |
| 62 | +
|
| 63 | + for (; j < hotsizes[i]; j += size) { |
| 64 | + lfs_file_read(&lfs, &file[0], buffer, size) => size; |
| 65 | + memcmp(buffer, "\0\0\0\0", size) => 0; |
| 66 | + } |
| 67 | +
|
| 68 | + lfs_file_truncate(&lfs, &file[0], coldsizes[i]) => 0; |
| 69 | + lfs_file_size(&lfs, &file[0]) => coldsizes[i]; |
| 70 | +
|
| 71 | + lfs_file_close(&lfs, &file[0]) => 0; |
| 72 | + } |
| 73 | +
|
| 74 | + lfs_unmount(&lfs) => 0; |
| 75 | +TEST |
| 76 | +tests/test.py << TEST |
| 77 | + static const lfs_off_t startsizes[] = {$STARTSIZES}; |
| 78 | + static const lfs_off_t hotsizes[] = {$HOTSIZES}; |
| 79 | + static const lfs_off_t coldsizes[] = {$COLDSIZES}; |
| 80 | +
|
| 81 | + lfs_mount(&lfs, &cfg) => 0; |
| 82 | +
|
| 83 | + for (int i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) { |
| 84 | + sprintf((char*)buffer, "hairyhead%d", i); |
| 85 | + lfs_file_open(&lfs, &file[0], (const char*)buffer, LFS_O_RDONLY) => 0; |
| 86 | + lfs_file_size(&lfs, &file[0]) => coldsizes[i]; |
| 87 | +
|
| 88 | + size = strlen("hair"); |
| 89 | + int j = 0; |
| 90 | + for (; j < startsizes[i] && j < hotsizes[i] && j < coldsizes[i]; |
| 91 | + j += size) { |
| 92 | + lfs_file_read(&lfs, &file[0], buffer, size) => size; |
| 93 | + memcmp(buffer, "hair", size) => 0; |
| 94 | + } |
| 95 | +
|
| 96 | + for (; j < coldsizes[i]; j += size) { |
| 97 | + lfs_file_read(&lfs, &file[0], buffer, size) => size; |
| 98 | + memcmp(buffer, "\0\0\0\0", size) => 0; |
| 99 | + } |
| 100 | +
|
| 101 | + lfs_file_close(&lfs, &file[0]) => 0; |
| 102 | + } |
| 103 | +
|
| 104 | + lfs_unmount(&lfs) => 0; |
| 105 | +TEST |
| 106 | +} |
| 107 | + |
| 108 | +echo "--- Cold shrinking truncate ---" |
| 109 | +truncate_test \ |
| 110 | + "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" \ |
| 111 | + "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" \ |
| 112 | + " 0, $SMALLSIZE, $MEDIUMSIZE, $LARGESIZE, 2*$LARGESIZE" |
| 113 | + |
| 114 | +echo "--- Cold expanding truncate ---" |
| 115 | +truncate_test \ |
| 116 | + " 0, $SMALLSIZE, $MEDIUMSIZE, $LARGESIZE, 2*$LARGESIZE" \ |
| 117 | + " 0, $SMALLSIZE, $MEDIUMSIZE, $LARGESIZE, 2*$LARGESIZE" \ |
| 118 | + "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" |
| 119 | + |
| 120 | +echo "--- Warm shrinking truncate ---" |
| 121 | +truncate_test \ |
| 122 | + "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" \ |
| 123 | + " 0, $SMALLSIZE, $MEDIUMSIZE, $LARGESIZE, 2*$LARGESIZE" \ |
| 124 | + " 0, 0, 0, 0, 0" |
| 125 | + |
| 126 | +echo "--- Warm expanding truncate ---" |
| 127 | +truncate_test \ |
| 128 | + " 0, $SMALLSIZE, $MEDIUMSIZE, $LARGESIZE, 2*$LARGESIZE" \ |
| 129 | + "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" \ |
| 130 | + "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" |
| 131 | + |
| 132 | +echo "--- Results ---" |
| 133 | +tests/stats.py |
0 commit comments