Skip to content

Conversation

@fsammoura1980
Copy link
Contributor

@fsammoura1980 fsammoura1980 commented Dec 9, 2025

The existing PMP permission tests relied on hardcoded region indices (e.g., index 0 or 2). This makes the tests fragile and dependent on the exact memory attribute region setup.

This change refactors the tests to dynamically determine region counts and indices based on the output of mem_attr_get_regions():

  • test_pmp_change_perm_invalid_permission: Uses the last valid region index to test invalid permission flags.
  • test_pmp_change_perm_invalid_region_index: Uses the total number of regions as the out-of-bounds index.
  • test_successful_permission_change: Locates the index of the target test region (dt_regions[0]) by matching its base address and size. The test now also inverts the X bit of the current permissions to ensure a change is applied and verified.

These changes make the tests more robust and less dependent on a specific static configuration.

@zephyrbot zephyrbot added area: RISCV RISCV Architecture (32-bit & 64-bit) area: Tests Issues related to a particular existing or missing test labels Dec 9, 2025
@fsammoura1980 fsammoura1980 force-pushed the improve_perm_test branch 3 times, most recently from 6848683 to a54cdb7 Compare December 9, 2025 03:23
Copy link
Contributor

@jimmyzhe jimmyzhe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • test_successful_permission_change: Locates the index of the target test region (dt_regions[1]) by matching its base address and size. The test now also inverts the R/W bits of the current permissions to ensure a change is applied and verified.

Seems that test_successful_permission_change uses test region dt_regions[0] and inverts the X bit. Could you update the commit message and the comment?

Other than that, these changes LGTM.

The existing PMP permission tests relied on hardcoded region indices
(e.g., index 0 or 2). This makes the tests fragile and dependent
on the exact memory attribute region setup.

This change refactors the tests to dynamically determine region counts
and indices based on the output of `mem_attr_get_regions()`:

-   `test_pmp_change_perm_invalid_permission`: Uses the last valid
    region index to test invalid permission flags.
-   `test_pmp_change_perm_invalid_region_index`: Uses the total number
    of regions as the out-of-bounds index.
-   `test_successful_permission_change`: Locates the index of the
    target test region (`dt_regions[0]`) by matching its base address
    and size. The test now also inverts the X bit of the current
    permissions to ensure a change is applied and verified.

These changes make the tests more robust and less dependent on a
specific static configuration.

Signed-off-by: Firas Sammoura <[email protected]>
@fsammoura1980
Copy link
Contributor Author

  • test_successful_permission_change: Locates the index of the target test region (dt_regions[1]) by matching its base address and size. The test now also inverts the R/W bits of the current permissions to ensure a change is applied and verified.

Seems that test_successful_permission_change uses test region dt_regions[0] and inverts the X bit. Could you update the commit message and the comment?

Other than that, these changes LGTM.

Done

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: RISCV RISCV Architecture (32-bit & 64-bit) area: Tests Issues related to a particular existing or missing test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants