|
| 1 | +# HDF5 Compression Tests for EmpCylSL |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This directory contains tests for the HDF5 compression functionality implemented in the EmpCylSL cylindrical disk basis cache system. |
| 6 | + |
| 7 | +## Test File: `cyl_compression_test.py` |
| 8 | + |
| 9 | +This comprehensive test suite validates the HDF5 compression implementation by testing: |
| 10 | + |
| 11 | +### Test 1: Compression Disabled |
| 12 | +- Verifies that compression can be disabled by setting `compress: 0` in the YAML configuration |
| 13 | +- Creates a basis with no compression and verifies the cache file is created and readable |
| 14 | + |
| 15 | +### Test 2: Compression Enabled |
| 16 | +- Tests multiple compression levels (1, 5, 9) |
| 17 | +- Verifies that each compression level works correctly |
| 18 | +- Ensures cache files are created and readable for all compression levels |
| 19 | + |
| 20 | +### Test 3: Compressed File Readback |
| 21 | +- Creates a compressed cache file with compression level 5 |
| 22 | +- Verifies the file can be read back correctly by a second basis instance |
| 23 | +- Ensures data integrity is maintained through compression/decompression |
| 24 | + |
| 25 | +### Test 4: Compression Level Validation |
| 26 | +- Tests valid compression levels (0, 5, 9) |
| 27 | +- Tests out-of-range compression levels (10, 15, 100) |
| 28 | +- Verifies that out-of-range values are clamped to 9 as implemented in `setH5Params` |
| 29 | + |
| 30 | +### Test 5: Shuffle Parameter |
| 31 | +- Verifies the shuffle filter works in conjunction with compression |
| 32 | +- Note: The shuffle parameter is enabled by default in `setH5Params` when compression is enabled |
| 33 | +- Tests indirectly by verifying successful cache creation with compression |
| 34 | + |
| 35 | +### Test 6: Compression Comparison |
| 36 | +- Compares file sizes between uncompressed (level 0) and compressed (level 9) cache files |
| 37 | +- Provides visual feedback on compression effectiveness |
| 38 | +- Note: Small test datasets may not compress significantly |
| 39 | + |
| 40 | +## Running the Tests |
| 41 | + |
| 42 | +### Via CMake/CTest |
| 43 | + |
| 44 | +After building the project: |
| 45 | + |
| 46 | +```bash |
| 47 | +cd build |
| 48 | +ctest -R pyexpCylCompressionTest --output-on-failure |
| 49 | +``` |
| 50 | + |
| 51 | +Or as part of the full test suite: |
| 52 | + |
| 53 | +```bash |
| 54 | +ctest -L long --output-on-failure |
| 55 | +``` |
| 56 | + |
| 57 | +### Direct Execution |
| 58 | + |
| 59 | +You can also run the test directly if pyEXP is built and in your PYTHONPATH: |
| 60 | + |
| 61 | +```bash |
| 62 | +cd tests/Disk |
| 63 | +python3 cyl_compression_test.py |
| 64 | +``` |
| 65 | + |
| 66 | +## Expected Output |
| 67 | + |
| 68 | +When all tests pass, you should see output similar to: |
| 69 | + |
| 70 | +``` |
| 71 | +====================================================================== |
| 72 | +EmpCylSL HDF5 Compression Test Suite |
| 73 | +====================================================================== |
| 74 | +
|
| 75 | +Test 1: Testing compression disabled (compress=0)... |
| 76 | + ✓ Compression disabled test passed |
| 77 | +
|
| 78 | +Test 2: Testing compression enabled with different levels... |
| 79 | + Testing compression level 1... |
| 80 | + ✓ Compression level 1 test passed |
| 81 | + Testing compression level 5... |
| 82 | + ✓ Compression level 5 test passed |
| 83 | + Testing compression level 9... |
| 84 | + ✓ Compression level 9 test passed |
| 85 | + ✓ All compression level tests passed |
| 86 | +
|
| 87 | +[... more tests ...] |
| 88 | +
|
| 89 | +====================================================================== |
| 90 | +Test Summary |
| 91 | +====================================================================== |
| 92 | +Passed: 6/6 |
| 93 | +✓ All tests passed! |
| 94 | +``` |
| 95 | + |
| 96 | +## Implementation Details |
| 97 | + |
| 98 | +The compression functionality is implemented in: |
| 99 | +- `src/Cylinder.cc`: Reads the `compress` parameter from YAML config and calls `setH5Params` |
| 100 | +- `include/EmpCylSL.H`: Defines `setH5Params` method with validation |
| 101 | +- `exputil/EmpCylSL.cc`: Applies compression settings when writing HDF5 cache files |
| 102 | + |
| 103 | +The `setH5Params` method signature: |
| 104 | +```cpp |
| 105 | +void setH5Params(unsigned compress, bool shuffle=true, bool szip=false) |
| 106 | +``` |
| 107 | +
|
| 108 | +Where: |
| 109 | +- `compress`: Gzip compression level 0-9 (0=off, 9=max) |
| 110 | +- `shuffle`: Enable byte shuffle filter (default: true) |
| 111 | +- `szip`: Enable szip compression (default: false) |
| 112 | +
|
| 113 | +## Test Coverage |
| 114 | +
|
| 115 | +These tests address the feedback from PR #183: |
| 116 | +- ✅ Compression can be enabled/disabled via the compress parameter |
| 117 | +- ✅ Compressed cache files can be read back correctly |
| 118 | +- ✅ The shuffle parameter works as expected |
| 119 | +- ✅ Validation of the compression level (0-9 range) |
0 commit comments