Skip to content

Conversation

@giordano
Copy link
Contributor

@giordano giordano commented Jun 23, 2021

The condition self.environment is _Undefined is always False, so the error
is actually never raised.

Without this change, I get a much more obscure error message:

==============================================================================
SUMMARY OF FAILURES
------------------------------------------------------------------------------
FAILURE INFO for Test 
  * Test Description: Test
  * System partition: catalina:default
  * Environment: gnu
  * Stage directory: /home/mose/repo/reframe/stage/catalina/default/gnu/Test
  * Node list: 
  * Job type: local (id=None)
  * Dependencies (conceptual): []
  * Dependencies (actual): []
  * Maintainers: []
  * Failing phase: compile_wait
  * Rerun with '-n Test -p gnu --system catalina:default -r'
  * Reason: build error: stdout: 'rfm_Test_build.out', stderr: 'rfm_Test_build.err'
--- rfm_Test_build.err (first 10 lines) ---
/home/mose/repo/reframe/stage/catalina/default/gnu/Test/rfm_Test_build.sh: line 13: syntax error near unexpected token `newline'
/home/mose/repo/reframe/stage/catalina/default/gnu/Test/rfm_Test_build.sh: line 13: `spack env activate -V -d <reframe.core.buildsystems._UndefinedType object at 0x7effb15a5c70>'
--- rfm_Test_build.err --- 
------------------------------------------------------------------------------
Log file(s) saved in: '/tmp/rfm-mtmrgbz_.log'

With this change I get

==============================================================================
SUMMARY OF FAILURES
------------------------------------------------------------------------------
FAILURE INFO for Test 
  * Test Description: Test
  * System partition: catalina:default
  * Environment: gnu
  * Stage directory: /home/mose/repo/reframe/stage/catalina/default/gnu/Test
  * Node list: 
  * Job type: local (id=None)
  * Dependencies (conceptual): []
  * Dependencies (actual): []
  * Maintainers: []
  * Failing phase: compile
  * Rerun with '-n Test -p gnu --system catalina:default -r'
  * Reason: build system error: no Spack environment is defined
------------------------------------------------------------------------------
Log file(s) saved in: '/tmp/rfm-93cirj79.log'

which I guess was the point of this check

The condition `self.environment is _Undefined` is always `False`, so the error
is actually never raised.
@jenkins-cscs
Copy link
Collaborator

Can I test this patch?

Copy link
Contributor

@jjotero jjotero left a comment

Choose a reason for hiding this comment

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

Hi @giordano. Thanks for spotting this.

I have the feeling that the line you changed was correct before. Instead, the definition of _UndefinedType should be as follows:

class _UndefinedType:
    '''Used as an initial value for undefined values instead of None.'''
    __slots__= ()

    def __deepcopy__(self, memo):
        return self

This would ensure that the _Undefined constant will always be the same instance of _UndefinedType regardless of deep copies and so on.

Could you please try this approach instead? Thanks!

@pep8speaks
Copy link

pep8speaks commented Jun 24, 2021

Hello @giordano, Thank you for updating!

Cheers! There are no PEP8 issues in this Pull Request!Do see the ReFrame Coding Style Guide

Comment last updated at 2021-06-24 08:51:57 UTC

@giordano giordano force-pushed the mg/spack-environment-check branch from ae4f903 to a52dec5 Compare June 24, 2021 08:51
@giordano
Copy link
Contributor Author

Yes, I confirm this also does the trick, thanks!

@victorusu
Copy link
Contributor

victorusu commented Jun 24, 2021

@giordano, thanks. I personally like this change much more. I was about to ask you why not work on the _Undefined since it is = to _UndefinedType?

This fix implies that we had a bug because _UndefinedType is deeply copiable... 🤔

@giordano
Copy link
Contributor Author

Also, I wanted to add a test, but I think
https://github.com/eth-cscs/reframe/blob/9dbb9899d371e22f325feb9adeac379b398511a9/unittests/test_buildsystems.py#L281-L284
is already meant to check this situation and the test was already passing, so... this test is catching some other BuildSystemError?

Copy link
Contributor

@jjotero jjotero left a comment

Choose a reason for hiding this comment

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

@giordano This test is checking this exact same BuildSystemError. The difference is that the Spack(BuildSystem) instance is deep-copied when you actually run ReFrame, and such deep-copy is not done by the unit test. Hence, the deep-copy

if self.environment is _Undefined:
    ...

compares that self.environment is the same instance of _UndefinedType as _Undefined. But because the build system class has been deep-copied, they are not he same instance and this evaluates to False. This is what overriding the __deepcopy__ method of _UndefinedType fixes.

This being said, we already have a mechanism in place to deal with these types of classes (reframe/core/variables.py) and it probably makes sense to make all these BuildSystem classes use all that machinery too. I'll create an issue to discuss that internally.

Thanks again for spotting the bug!

@victorusu are you happy with the changes?

@jjotero jjotero changed the title Make check of Spack environment actually work [bugfix] Fix deep-copy of _Undefined constant Jun 24, 2021
@jjotero jjotero merged commit 24321bb into reframe-hpc:master Jun 24, 2021
@giordano giordano deleted the mg/spack-environment-check branch June 24, 2021 10:28
@vkarak vkarak added this to the ReFrame Sprint 21.06.1 milestone Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants