Skip to content
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

mem: add mprotect tests #292

Merged
merged 1 commit into from
Feb 12, 2024
Merged

mem: add mprotect tests #292

merged 1 commit into from
Feb 12, 2024

Conversation

badochov
Copy link
Contributor

@badochov badochov commented Nov 13, 2023

JIRA: RTOS-666

Description

Add tests to new mprotect syscall.

Demo PR showing that tests pass with kernel and libphoenix changes applied.
phoenix-rtos/phoenix-rtos-project#922

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (list targets here).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

@badochov badochov marked this pull request as draft November 13, 2023 23:05
@badochov badochov force-pushed the badochov/mprotect branch 4 times, most recently from 9af2b2a to 0c0f8f7 Compare November 14, 2023 11:24
mem/test_mprotect_fault.c Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Nov 22, 2023

Unit Test Results

6 003 tests  +1   5 362 ✔️ +1   30m 13s ⏱️ -40s
   347 suites +1      641 💤 ±0 
       1 files   ±0          0 ±0 

Results for commit 329cb3a. ± Comparison against base commit 3905060.

This pull request removes 7 and adds 8 tests. Note that renamed tests count towards both.
phoenix-rtos-tests/psh/exit ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/psh/exit
phoenix-rtos-tests/psh/exit ‑ armv7a9-zynq7000-qemu:phoenix-rtos-tests/psh/exit
phoenix-rtos-tests/psh/exit ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/psh/exit
phoenix-rtos-tests/psh/exit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/psh/exit
phoenix-rtos-tests/psh/exit ‑ armv7m7-imxrt106x-evk:phoenix-rtos-tests/psh/exit
phoenix-rtos-tests/psh/exit ‑ ia32-generic-qemu:phoenix-rtos-tests/psh/exit
phoenix-rtos-tests/psh/exit ‑ riscv64-generic-qemu:phoenix-rtos-tests/psh/exit
phoenix-rtos-tests/mem/mprotect ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/mem/mprotect.test_mprotect.test_mprotect_singlecore
phoenix-rtos-tests/mem/mprotect ‑ armv7a9-zynq7000-qemu:phoenix-rtos-tests/mem/mprotect.test_mprotect.test_mprotect_singlecore
phoenix-rtos-tests/mem/mprotect ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/mem/mprotect.test_mprotect.test_mprotect_singlecore
phoenix-rtos-tests/mem/mprotect ‑ ia32-generic-qemu:phoenix-rtos-tests/mem/mprotect.test_mprotect.test_mprotect_singlecore
phoenix-rtos-tests/mem/mprotect-fault ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/mem/mprotect-fault
phoenix-rtos-tests/mem/mprotect-fault ‑ armv7a9-zynq7000-qemu:phoenix-rtos-tests/mem/mprotect-fault
phoenix-rtos-tests/mem/mprotect-fault ‑ armv7a9-zynq7000-zedboard:phoenix-rtos-tests/mem/mprotect-fault
phoenix-rtos-tests/mem/mprotect-fault ‑ ia32-generic-qemu:phoenix-rtos-tests/mem/mprotect-fault

♻️ This comment has been updated with latest results.

mem/Makefile Outdated Show resolved Hide resolved
mem/test_mprotect.c Outdated Show resolved Hide resolved
mem/test_mprotect.c Outdated Show resolved Hide resolved
mem/test_mprotect.c Outdated Show resolved Hide resolved
mem/test_mprotect.c Outdated Show resolved Hide resolved
mem/test_mprotect.c Outdated Show resolved Hide resolved
mem/test_mprotect_fault.c Outdated Show resolved Hide resolved
mem/test_mprotect_fault.c Outdated Show resolved Hide resolved
mem/test_mprotect_fault.c Outdated Show resolved Hide resolved
JIRA: RTOS-666
Copy link
Contributor

@damianloew damianloew left a comment

Choose a reason for hiding this comment

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

Thanks for adding such simple tests, I think we will extend them in the future to provide better coverage for this function.


TEST(test_mprotect, test_mprotect_singlecore)
{
unsigned char *area = mmap(NULL, page_size * PAGES, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be better to not set PROT_READ at the beginning to check whether read access protection has been set properly in the mprotect call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't work then as we require that the protection required by the mrpotect has to be lesser or equal than the one established by mmap


TEST_SETUP(test_mprotect)
{
page_size = sysconf(_SC_PAGESIZE);
Copy link
Contributor

Choose a reason for hiding this comment

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

We could get it once - at the beginning of a test (for example in runner()), not before all test cases, or alternatively only within the test case body.

Copy link
Contributor

Choose a reason for hiding this comment

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

EDIT: I know that now we have only one test case, but when someone will add more of them it's easy to forget about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to the body

Copy link
Contributor

@damianloew damianloew left a comment

Choose a reason for hiding this comment

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

LGTM

@badochov badochov merged commit 84f3612 into master Feb 12, 2024
33 checks passed
@badochov badochov deleted the badochov/mprotect branch February 12, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants