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

arch: Ensure compiler check catches permission errors #2340

Merged

Conversation

gbruer15
Copy link
Contributor

I added a test for #2336, but I'm not sure if it will actually error on the bug I was encountering, so I'd like to run the standard test suite to make sure.

Closes #2336

Copy link
Contributor

@mloubout mloubout left a comment

Choose a reason for hiding this comment

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

Thanks!.

You can the test locally to make sure it does what you want with

py.test -vsx tests/test_error_checking.py -k test_sniff_compiler_version

(-vsx is just for verbosity)

tests/test_error_checking.py Outdated Show resolved Hide resolved
])
def test_sniff_compiler_version(cc):
with pytest.raises(SystemExit) as e:
sniff_compiler_version(cc)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it needs to be

with pytest.raises(SystemExit) as e:
        sniff_compiler_version(cc)
 assert e == SystemExit

so there is a test.

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 could add assert e.type == SystemExit, but pytest.raises(SystemExit) catches only a SystemExit exception, there's no point. If it's not a SystemExit exception, it won't get caught.

For an example, consider the test.py below, where non-SystemExit exceptions simply cause the test to fail.

import pytest
import sys

def test_succeeds():
    with pytest.raises(SystemExit) as e:
        sys.exit(1)
    assert e.type == SystemExit

def test_fails():
    with pytest.raises(SystemExit) as e:
        raise NotImplementedError

def test_succeeds_again():
    with pytest.raises(NotImplementedError) as e:
        raise NotImplementedError
$ python -m pytest test.py
================================== test session starts ===================================
platform linux -- Python 3.9.15, pytest-8.1.1, pluggy-1.4.0
rootdir: /home/gbruer/a
plugins: anyio-3.5.0
collected 3 items                                                                        

test.py .F.                                                                        [100%]

======================================== FAILURES ========================================
_______________________________________ test_fails _______________________________________

    def test_fails():
        with pytest.raises(SystemExit) as e:
>           raise NotImplementedError
E           NotImplementedError

test.py:12: NotImplementedError
================================ short test summary info =================================
FAILED test.py::test_fails - NotImplementedError
============================== 1 failed, 2 passed in 0.08s ===============================

Copy link
Contributor

Choose a reason for hiding this comment

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

Also: this test should be moved to some other files as this one, test_error_checking, is supposed to be for runtime (C-level) numerical and computational errors.

Perhaps test_environment?

Copy link
Contributor

Choose a reason for hiding this comment

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

sys.exit(...) is also quite brutal, perhaps we turn it into a RuntimeError?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test_environment.py seems to be making sure the test environment is usable, so this test doesn't fit there in my opinion. This test is independent of the test environment. Should there be a second test file for non-numerical runtime errors?

I agree that RuntimeError is better. I'll make that change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a second test file for non-numerical runtime errors?

perhaps test_arch.py where in the future we can also add all other /devito/arch related tests?

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 moved the test to test_arch.py and fixed the pep8 errors, so as far as I know, this is ready to be merged.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is benchmark setup that needs fixing and rebase, I'll do it and get it merged

@gbruer15
Copy link
Contributor Author

I tested locally and it's fine. The issue is I'm not sure how I should consistently trigger the PermissionDenied error to ensure it's being caught.

I could make a file without execute permissions and delete it afterwards. I'm not sure if that will be portable for the OS's that Devito supports, though.

@gbruer15 gbruer15 marked this pull request as ready for review March 29, 2024 18:20
@mloubout mloubout added CI continuous integration arch jitting, archinfo, ... labels Apr 1, 2024
Copy link
Contributor

@mloubout mloubout left a comment

Choose a reason for hiding this comment

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

Looks good to me. Not sure where else to put that test though but not critical IMO

Copy link

codecov bot commented Apr 2, 2024

Codecov Report

Attention: Patch coverage is 71.42857% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 66.18%. Comparing base (e2743e0) to head (a1dabe9).

Files Patch % Lines
devito/arch/compiler.py 50.00% 1 Missing ⚠️
devito/mpi/distributed.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2340       +/-   ##
===========================================
- Coverage   86.72%   66.18%   -20.54%     
===========================================
  Files         232      184       -48     
  Lines       43641    28818    -14823     
  Branches     8075     6381     -1694     
===========================================
- Hits        37848    19074    -18774     
- Misses       5084     8891     +3807     
- Partials      709      853      +144     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@FabioLuporini FabioLuporini left a comment

Choose a reason for hiding this comment

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

We just ened to find a better place for the test, test_error_checking is meant for something else, and perhaps we should rename it

])
def test_sniff_compiler_version(cc):
with pytest.raises(SystemExit) as e:
sniff_compiler_version(cc)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a second test file for non-numerical runtime errors?

perhaps test_arch.py where in the future we can also add all other /devito/arch related tests?

@FabioLuporini
Copy link
Contributor

FabioLuporini commented Apr 9, 2024

@gbruer15 gbruer15 changed the title Ensure compiler check catches permission errors arch: Ensure compiler check catches permission errors Apr 23, 2024
@mloubout mloubout force-pushed the gbruer/missing-compiler-catch branch 4 times, most recently from 418cc24 to 695c437 Compare April 29, 2024 13:03
Fixed compiler version sniff and test

Added more information for failed MPI import

Carry mpi4py import error in dummy MPI class

Raised RuntimeError for missing compiler instead of sys.exit()

Fixed flake8 errors

Moved test to test_arch.py
@mloubout mloubout force-pushed the gbruer/missing-compiler-catch branch from 695c437 to a1dabe9 Compare April 29, 2024 19:50
@mloubout mloubout merged commit cafebc1 into devitocodes:master Apr 29, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch jitting, archinfo, ... CI continuous integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad error message when missing compiler
3 participants