diff options
author | Christopher Haster <chaster@utexas.edu> | 2018-01-21 02:30:40 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2018-01-21 04:22:44 +0300 |
commit | d88f0ac02ff93b549418d38d464b5591fce4f688 (patch) | |
tree | a10fb4ed3bbcaed8d24180a04532c20c15a24fc7 /tests/test_truncate.sh | |
parent | 2ad435ed6309096979d6f90aa762632d23202a42 (diff) |
Added lfs_file_truncate
As a copy-on-write filesystem, the truncate function is a very nice
function to have, as it can take advantage of reusing the data already
written out to disk.
Diffstat (limited to 'tests/test_truncate.sh')
-rwxr-xr-x | tests/test_truncate.sh | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/tests/test_truncate.sh b/tests/test_truncate.sh new file mode 100755 index 0000000..1da0cce --- /dev/null +++ b/tests/test_truncate.sh @@ -0,0 +1,133 @@ +#!/bin/bash +set -eu + +SMALLSIZE=32 +MEDIUMSIZE=2048 +LARGESIZE=8192 + +echo "=== Truncate tests ===" +rm -rf blocks +tests/test.py << TEST + lfs_format(&lfs, &cfg) => 0; +TEST + +truncate_test() { +STARTSIZES="$1" +HOTSIZES="$2" +COLDSIZES="$3" +tests/test.py << TEST + static const lfs_off_t startsizes[] = {$STARTSIZES}; + static const lfs_off_t hotsizes[] = {$HOTSIZES}; + + lfs_mount(&lfs, &cfg) => 0; + + for (int i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) { + sprintf((char*)buffer, "hairyhead%d", i); + lfs_file_open(&lfs, &file[0], (const char*)buffer, + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0; + + strcpy((char*)buffer, "hair"); + size = strlen((char*)buffer); + for (int j = 0; j < startsizes[i]; j += size) { + lfs_file_write(&lfs, &file[0], buffer, size) => size; + } + lfs_file_size(&lfs, &file[0]) => startsizes[i]; + + lfs_file_truncate(&lfs, &file[0], hotsizes[i]) => 0; + lfs_file_size(&lfs, &file[0]) => hotsizes[i]; + + lfs_file_close(&lfs, &file[0]) => 0; + } + + lfs_unmount(&lfs) => 0; +TEST +tests/test.py << TEST + static const lfs_off_t startsizes[] = {$STARTSIZES}; + static const lfs_off_t hotsizes[] = {$HOTSIZES}; + static const lfs_off_t coldsizes[] = {$COLDSIZES}; + + lfs_mount(&lfs, &cfg) => 0; + + for (int i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) { + sprintf((char*)buffer, "hairyhead%d", i); + lfs_file_open(&lfs, &file[0], (const char*)buffer, LFS_O_RDWR) => 0; + lfs_file_size(&lfs, &file[0]) => hotsizes[i]; + + size = strlen("hair"); + int j = 0; + for (; j < startsizes[i] && j < hotsizes[i]; j += size) { + lfs_file_read(&lfs, &file[0], buffer, size) => size; + memcmp(buffer, "hair", size) => 0; + } + + for (; j < hotsizes[i]; j += size) { + lfs_file_read(&lfs, &file[0], buffer, size) => size; + memcmp(buffer, "\0\0\0\0", size) => 0; + } + + lfs_file_truncate(&lfs, &file[0], coldsizes[i]) => 0; + lfs_file_size(&lfs, &file[0]) => coldsizes[i]; + + lfs_file_close(&lfs, &file[0]) => 0; + } + + lfs_unmount(&lfs) => 0; +TEST +tests/test.py << TEST + static const lfs_off_t startsizes[] = {$STARTSIZES}; + static const lfs_off_t hotsizes[] = {$HOTSIZES}; + static const lfs_off_t coldsizes[] = {$COLDSIZES}; + + lfs_mount(&lfs, &cfg) => 0; + + for (int i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) { + sprintf((char*)buffer, "hairyhead%d", i); + lfs_file_open(&lfs, &file[0], (const char*)buffer, LFS_O_RDONLY) => 0; + lfs_file_size(&lfs, &file[0]) => coldsizes[i]; + + size = strlen("hair"); + int j = 0; + for (; j < startsizes[i] && j < hotsizes[i] && j < coldsizes[i]; + j += size) { + lfs_file_read(&lfs, &file[0], buffer, size) => size; + memcmp(buffer, "hair", size) => 0; + } + + for (; j < coldsizes[i]; j += size) { + lfs_file_read(&lfs, &file[0], buffer, size) => size; + memcmp(buffer, "\0\0\0\0", size) => 0; + } + + lfs_file_close(&lfs, &file[0]) => 0; + } + + lfs_unmount(&lfs) => 0; +TEST +} + +echo "--- Cold shrinking truncate ---" +truncate_test \ + "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" \ + "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" \ + " 0, $SMALLSIZE, $MEDIUMSIZE, $LARGESIZE, 2*$LARGESIZE" + +echo "--- Cold expanding truncate ---" +truncate_test \ + " 0, $SMALLSIZE, $MEDIUMSIZE, $LARGESIZE, 2*$LARGESIZE" \ + " 0, $SMALLSIZE, $MEDIUMSIZE, $LARGESIZE, 2*$LARGESIZE" \ + "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" + +echo "--- Warm shrinking truncate ---" +truncate_test \ + "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" \ + " 0, $SMALLSIZE, $MEDIUMSIZE, $LARGESIZE, 2*$LARGESIZE" \ + " 0, 0, 0, 0, 0" + +echo "--- Warm expanding truncate ---" +truncate_test \ + " 0, $SMALLSIZE, $MEDIUMSIZE, $LARGESIZE, 2*$LARGESIZE" \ + "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" \ + "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" + +echo "--- Results ---" +tests/stats.py |