-
Notifications
You must be signed in to change notification settings - Fork 231
test: add zram compression tests for crypto_zstd and crypto_lz4 #4390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1a4b817
test: add zram compression tests for crypto_zstd and crypto_lz4
rlmenge 75f4920
fix(zram): ensure cat cache is clean
rlmenge ac03106
fix(zram): guard zram cleanup unmount to prevent masking test failures
rlmenge 48c8f40
fix(zram) : fix weird quotes in logs
rlmenge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. | ||
|
|
||
| from pathlib import PurePosixPath | ||
| from typing import Any | ||
|
|
||
| from assertpy import assert_that | ||
|
|
||
| from lisa import ( | ||
| Logger, | ||
| Node, | ||
| SkippedException, | ||
| TestCaseMetadata, | ||
| TestSuite, | ||
| TestSuiteMetadata, | ||
| simple_requirement, | ||
| ) | ||
| from lisa.base_tools import Cat | ||
| from lisa.operating_system import BSD, CBLMariner, Windows | ||
| from lisa.sut_orchestrator import AZURE, HYPERV, READY | ||
| from lisa.tools import Echo, Lsmod, Mkfs, Modprobe, Mount | ||
| from lisa.tools.mkfs import FileSystem | ||
| from lisa.tools.rm import Rm | ||
| from lisa.util import UnsupportedDistroException | ||
|
|
||
|
|
||
| @TestSuiteMetadata( | ||
| area="core", | ||
| category="functional", | ||
| description=""" | ||
| This test suite validates zram compression algorithm support. | ||
| It verifies that the kernel can load zram with crypto_zstd and | ||
| crypto_lz4 compression backends and that zram devices function | ||
| correctly with each algorithm. | ||
| """, | ||
| requirement=simple_requirement( | ||
| supported_platform_type=[AZURE, HYPERV, READY], | ||
| unsupported_os=[BSD, Windows], | ||
| ), | ||
| ) | ||
| class ZramCompression(TestSuite): | ||
| # zram device path used for testing | ||
| _ZRAM_DEVICE = "/dev/zram0" | ||
| # 256 MB test disk size | ||
| _ZRAM_SIZE_BYTES = "268435456" | ||
| _ZRAM_MOUNT_POINT = "/mnt/zram_test" | ||
| _COMP_ALGORITHM_PATH = PurePosixPath("/sys/block/zram0/comp_algorithm") | ||
| _DISKSIZE_PATH = PurePosixPath("/sys/block/zram0/disksize") | ||
| _RESET_PATH = PurePosixPath("/sys/block/zram0/reset") | ||
|
|
||
| def before_case(self, log: Logger, **kwargs: Any) -> None: | ||
| node: Node = kwargs["node"] | ||
| if not isinstance(node.os, CBLMariner) or node.os.information.version < "3.0.0": | ||
| raise SkippedException( | ||
| UnsupportedDistroException( | ||
| node.os, | ||
| "zram compression test requires Azure Linux 3.0+.", | ||
| ) | ||
| ) | ||
|
|
||
| @TestCaseMetadata( | ||
| description=""" | ||
| Verify zram works with the zstd compression algorithm. | ||
| Steps: | ||
| 1. Load the crypto_zstd kernel module. | ||
| 2. Load the zram kernel module with num_devices=1. | ||
| 3. Set the compression algorithm to zstd on /dev/zram0. | ||
| 4. Set the disk size and verify the device is usable. | ||
| 5. Reset and clean up the zram device. | ||
| """, | ||
| priority=3, | ||
| ) | ||
| def verify_zram_crypto_zstd(self, node: Node) -> None: | ||
| self._test_zram_compression(node, module="crypto_zstd", algorithm="zstd") | ||
|
|
||
| @TestCaseMetadata( | ||
| description=""" | ||
| Verify zram works with the lz4 compression algorithm. | ||
| Steps: | ||
| 1. Load the crypto_lz4 kernel module. | ||
| 2. Load the zram kernel module with num_devices=1. | ||
| 3. Set the compression algorithm to lz4 on /dev/zram0. | ||
| 4. Set the disk size and verify the device is usable. | ||
| 5. Reset and clean up the zram device. | ||
| """, | ||
| priority=3, | ||
| ) | ||
| def verify_zram_crypto_lz4(self, node: Node) -> None: | ||
| self._test_zram_compression(node, module="crypto_lz4", algorithm="lz4") | ||
|
|
||
| def _test_zram_compression(self, node: Node, module: str, algorithm: str) -> None: | ||
| modprobe = node.tools[Modprobe] | ||
|
|
||
| # Check that the crypto module exists in the kernel | ||
| if not modprobe.module_exists(module): | ||
| raise SkippedException(f"Kernel module '{module}' is not available.") | ||
|
|
||
| # Check that zram module exists | ||
| if not modprobe.module_exists("zram"): | ||
| raise SkippedException("Kernel module 'zram' is not available.") | ||
|
|
||
| try: | ||
| # Load the crypto compression module | ||
| modprobe.load(module) | ||
| node.log.info(f"Loaded kernel module: {module}") | ||
|
|
||
| # Load zram with a single device | ||
| modprobe.load("zram", parameters="num_devices=1") | ||
| node.log.info("Loaded zram module with num_devices=1") | ||
|
|
||
| # Set the compression algorithm | ||
| node.tools[Echo].write_to_file( | ||
| algorithm, | ||
| self._COMP_ALGORITHM_PATH, | ||
| sudo=True, | ||
| ignore_error=False, | ||
| ) | ||
|
|
||
| # Verify the active algorithm (marked with brackets) | ||
| comp_output = node.tools[Cat].read( | ||
| str(self._COMP_ALGORITHM_PATH), sudo=True | ||
| ) | ||
| assert_that(comp_output).described_as( | ||
| f"Expected '{algorithm}' to be active " | ||
| f"(in brackets), got: {comp_output}" | ||
| ).contains(f"[{algorithm}]") | ||
| node.log.info(f"Compression algorithm set to: {algorithm}") | ||
|
|
||
| # Set the disk size | ||
| node.tools[Echo].write_to_file( | ||
| self._ZRAM_SIZE_BYTES, | ||
| self._DISKSIZE_PATH, | ||
| sudo=True, | ||
| ignore_error=False, | ||
| ) | ||
|
|
||
| # Verify disk size was applied | ||
| disksize = node.tools[Cat].read(str(self._DISKSIZE_PATH), sudo=True) | ||
| assert_that(int(disksize.strip())).described_as( | ||
| "zram disk size should match requested value" | ||
| ).is_equal_to(int(self._ZRAM_SIZE_BYTES)) | ||
|
|
||
| # Format and mount the zram device | ||
| node.tools[Mkfs].format_disk(self._ZRAM_DEVICE, FileSystem.ext4) | ||
| node.tools[Mount].mount( | ||
| self._ZRAM_DEVICE, | ||
| self._ZRAM_MOUNT_POINT, | ||
| fs_type=FileSystem.ext4, | ||
| ) | ||
|
|
||
| # Write test data and read it back | ||
| test_string = "zram_compression_validation" | ||
| test_file = PurePosixPath(f"{self._ZRAM_MOUNT_POINT}/testfile") | ||
| node.tools[Echo].write_to_file( | ||
| test_string, | ||
| test_file, | ||
| sudo=True, | ||
| ignore_error=False, | ||
| ) | ||
| read_back = node.tools[Cat].read(str(test_file), sudo=True) | ||
| assert_that(read_back.strip()).described_as( | ||
| "Data read from zram should match written data" | ||
| ).is_equal_to(test_string) | ||
|
|
||
| node.log.info( | ||
| f"zram with '{algorithm}' compression: " "write/read validation passed" | ||
|
rlmenge marked this conversation as resolved.
Outdated
|
||
| ) | ||
|
|
||
| # Verify the module is loaded in the kernel | ||
| lsmod = node.tools[Lsmod] | ||
| assert_that(lsmod.module_exists("zram", force_run=True)).described_as( | ||
| "zram module should be loaded" | ||
| ).is_true() | ||
|
|
||
| finally: | ||
| # Clean up: unmount, reset zram, unload modules | ||
| node.tools[Mount].umount("zram0", self._ZRAM_MOUNT_POINT, erase=False) | ||
|
rlmenge marked this conversation as resolved.
Outdated
|
||
| node.tools[Rm].remove_directory(self._ZRAM_MOUNT_POINT, sudo=True) | ||
| node.tools[Echo].write_to_file("1", self._RESET_PATH, sudo=True) | ||
| modprobe.remove(["zram"], ignore_error=True) | ||
| modprobe.remove([module], ignore_error=True) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.