-
Notifications
You must be signed in to change notification settings - Fork 117
[feat] Implement test dependency API #769
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7f6e5d3
Implement test dependency API
933a77e
Fix unit tests failure
0af25bb
Minor fixes and improvements
599c85c
Fix PEP8 issue
0862025
Address PR comments
35ceee8
Merge branch 'master' into feat/testdep-api
f91e627
Fix documentation of build_deps()
37951d7
Merge branch 'feat/testdep-api' of github.com:vkarak/reframe into fea…
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
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
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
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,81 @@ | ||
| # | ||
| # Test case graph functionality | ||
| # | ||
|
|
||
| import collections | ||
|
|
||
| import reframe as rfm | ||
| from reframe.core.exceptions import DependencyError | ||
|
|
||
|
|
||
| def build_deps(cases): | ||
| """Build dependency graph from test cases. | ||
|
|
||
| The graph is represented as an adjacency list in a Python dictionary | ||
| holding test cases. The dependency information is also encoded inside each | ||
| test cases. | ||
| """ | ||
|
|
||
| # Index cases for quick access | ||
| cases_by_part = {} | ||
| cases_revmap = {} | ||
| for c in cases: | ||
| cname = c.check.name | ||
| pname = c.partition.fullname | ||
| ename = c.environ.name | ||
| cases_by_part.setdefault((cname, pname), []) | ||
| cases_revmap.setdefault((cname, pname, ename), None) | ||
| cases_by_part[cname, pname].append(c) | ||
| cases_revmap[cname, pname, ename] = c | ||
|
|
||
| def resolve_dep(target, from_map, *args): | ||
| errmsg = 'could not resolve dependency: %s' % target | ||
| try: | ||
| ret = from_map[args] | ||
| except KeyError: | ||
| raise DependencyError(errmsg) | ||
| else: | ||
| if not ret: | ||
| raise DependencyError(errmsg) | ||
|
|
||
| return ret | ||
|
|
||
| # NOTE on variable names | ||
| # | ||
| # c stands for check or case depending on the context | ||
| # p stands for partition | ||
| # e stands for environment | ||
| # t stands for target | ||
|
|
||
| graph = {} | ||
| for c in cases: | ||
| graph[c] = c.deps | ||
| cname = c.check.name | ||
| pname = c.partition.fullname | ||
| ename = c.environ.name | ||
| for dep in c.check.user_deps(): | ||
| tname, how, subdeps = dep | ||
| if how == rfm.DEPEND_FULLY: | ||
| c.deps.extend(resolve_dep(c, cases_by_part, tname, pname)) | ||
| elif how == rfm.DEPEND_BY_ENV: | ||
| c.deps.append(resolve_dep(c, cases_revmap, | ||
| tname, pname, ename)) | ||
| elif how == rfm.DEPEND_EXACT: | ||
| for env, tenvs in subdeps.items(): | ||
| if env != ename: | ||
| continue | ||
|
|
||
| for te in tenvs: | ||
| c.deps.append(resolve_dep(c, cases_revmap, | ||
| tname, pname, te)) | ||
|
|
||
| return graph | ||
|
|
||
|
|
||
| def print_deps(graph): | ||
| for c, deps in graph.items(): | ||
| print(c, '->', deps) | ||
|
|
||
|
|
||
| def validate_deps(graph): | ||
| """Validate dependency graph.""" |
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
37 changes: 37 additions & 0 deletions
37
unittests/resources/checks_unlisted/dependencies/normal.py
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,37 @@ | ||
| import reframe as rfm | ||
| import reframe.utility.sanity as sn | ||
|
|
||
|
|
||
| @rfm.simple_test | ||
| class Test0(rfm.RunOnlyRegressionTest): | ||
| def __init__(self): | ||
| super().__init__() | ||
| self.valid_systems = ['sys0:p0', 'sys0:p1'] | ||
| self.valid_prog_environs = ['e0', 'e1'] | ||
| self.executable = 'echo' | ||
| self.executable_opts = [self.name] | ||
| self.sanity_patterns = sn.assert_found(self.name, self.stdout) | ||
|
|
||
|
|
||
| @rfm.parameterized_test(*([kind] for kind in ['fully', 'by_env', | ||
| 'exact', 'default'])) | ||
| class Test1(rfm.RunOnlyRegressionTest): | ||
| def __init__(self, kind): | ||
| super().__init__() | ||
| kindspec = { | ||
| 'fully': rfm.DEPEND_FULLY, | ||
| 'by_env': rfm.DEPEND_BY_ENV, | ||
| 'exact': rfm.DEPEND_EXACT, | ||
| } | ||
| self.valid_systems = ['sys0:p0', 'sys0:p1'] | ||
| self.valid_prog_environs = ['e0', 'e1'] | ||
| self.executable = 'echo' | ||
| self.executable_opts = [self.name] | ||
| self.sanity_patterns = sn.assert_found(self.name, self.stdout) | ||
| if kind == 'default': | ||
| self.depends_on('Test0') | ||
| elif kindspec[kind] == rfm.DEPEND_EXACT: | ||
| self.depends_on('Test0', kindspec[kind], | ||
| {'e0': ['e0', 'e1'], 'e1': ['e1']}) | ||
| else: | ||
| self.depends_on('Test0', kindspec[kind]) |
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
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
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.