Skip to content

Commit

Permalink
#2671 Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sergisiso committed Nov 13, 2024
1 parent e4c58bf commit bed3c56
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/psyclone/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,5 +749,5 @@ def code_transformation_mode(input_file, recipe_file, output_file,
if output_file:
shutil.copyfile(input_file, output_file)
else:
print(f"File '{input_file}' in FILES_TO_SKIP list.",
file=sys.stdout)
print(f"File '{input_file}' skiped because it is listed in "
"FILES_TO_SKIP.", file=sys.stdout)
6 changes: 3 additions & 3 deletions src/psyclone/psyir/transformations/omp_target_trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ def validate(self, node, options=None):
routine = node.ancestor(Routine)
if routine and routine.return_symbol:
# if it is a function, the target must not include its return sym
for node in node_list:
for ref in node.walk(Reference):
for check_node in node_list:
for ref in check_node.walk(Reference):
if ref.symbol is routine.return_symbol:
raise TransformationError(
f"OpenMP Target cannot enclose a region that has"
f"OpenMP Target cannot enclose a region that has "
f"a function return value symbol, but found one in"
f" '{routine.return_symbol.name}'.")

Expand Down
10 changes: 9 additions & 1 deletion src/psyclone/tests/generator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ def test_main_expected_fatal_error(capsys):
assert output == expected_output


def test_code_transformation_skip_files_error(tmpdir):
def test_code_transformation_skip_files_error(tmpdir, capsys):
''' Test that applying recipes in the code-transformation mode skips the
files marked as FILES_TO_SKIP '''
code = '''
Expand Down Expand Up @@ -819,6 +819,14 @@ def trans(psyir):
new_code = my_file.read()
assert new_code == code

# When doing the same but without a '-o' (output file), we just print
# in stdout that the file was skipped.
outputfile = str(tmpdir.join("output.f90"))
main([inputfile, "-s", recipefile])
output, _ = capsys.readouterr()
assert ("funny_syntax.f90' skiped because it is listed in FILES_TO_SKIP."
in output)


def test_code_transformation_trans(tmpdir):
''' Test that applying recipes that have a trans, and are not listed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def test_omptargettrans_validate(fortran_reader):
function myfunc(a)
integer :: a
integer :: myfunc
do i = 1, 1
myfunc = a
enddo
end function
subroutine my_subroutine()
integer, dimension(10, 10) :: A
Expand All @@ -133,11 +136,17 @@ def test_omptargettrans_validate(fortran_reader):

with pytest.raises(TransformationError) as err:
omptargettrans.validate(loops[0])
assert ("OpenMP Target cannot enclose a region that has a function "
"return value symbol, but found one in 'myfunc'."
in str(err.value))

with pytest.raises(TransformationError) as err:
omptargettrans.validate(loops[1])
assert ("'myfunc' is not available on the accelerator device, and "
"therefore it cannot be called from within an OMP Target region."
in str(err.value))

with pytest.raises(TransformationError) as err:
omptargettrans.validate(loops[1])
omptargettrans.validate(loops[2])
assert ("Nodes of type 'CodeBlock' cannot be enclosed by a OMPTarget"
"Trans transformation" in str(err.value))

0 comments on commit bed3c56

Please sign in to comment.