forked from OSchip/llvm-project
[flang] Add tests for .mod file writing
The source files contain the expected contents of generated .mod files. `test_modfile.sh` compiles the source file and verifies that the correct .mod files are generated. Original-commit: flang-compiler/f18@a23f53c1a7 Reviewed-on: https://github.com/flang-compiler/f18/pull/126 Tree-same-pre-rewrite: false
This commit is contained in:
parent
0c575ed548
commit
43f2ce0739
|
@ -55,6 +55,13 @@ set(SYMBOL_TESTS
|
|||
symbol01.f90
|
||||
)
|
||||
|
||||
# These test files have expected .mod file contents in the source
|
||||
set(MODFILE_TESTS
|
||||
modfile01.f90
|
||||
modfile02.f90
|
||||
modfile03.f90
|
||||
)
|
||||
|
||||
foreach(test ${ERROR_TESTS})
|
||||
add_test(NAME ${test} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_errors.sh ${test})
|
||||
endforeach()
|
||||
|
@ -62,3 +69,7 @@ endforeach()
|
|||
foreach(test ${SYMBOL_TESTS})
|
||||
add_test(NAME ${test} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_symbols.sh ${test})
|
||||
endforeach()
|
||||
|
||||
foreach(test ${MODFILE_TESTS})
|
||||
add_test(NAME ${test} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_modfile.sh ${test})
|
||||
endforeach()
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
! Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
|
||||
!
|
||||
! Licensed under the Apache License, Version 2.0 (the "License");
|
||||
! you may not use this file except in compliance with the License.
|
||||
! You may obtain a copy of the License at
|
||||
!
|
||||
! http://www.apache.org/licenses/LICENSE-2.0
|
||||
!
|
||||
! Unless required by applicable law or agreed to in writing, software
|
||||
! distributed under the License is distributed on an "AS IS" BASIS,
|
||||
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
! See the License for the specific language governing permissions and
|
||||
! limitations under the License.
|
||||
|
||||
! Check correct modfile generation for type with private component.
|
||||
module m
|
||||
integer :: i
|
||||
integer, private :: j
|
||||
type :: t
|
||||
integer :: i
|
||||
integer, private :: j
|
||||
end type
|
||||
type, private :: u
|
||||
end type
|
||||
type(t) :: x
|
||||
end
|
||||
|
||||
!Expect: m.mod
|
||||
!module m
|
||||
!integer::i
|
||||
!type::t
|
||||
!integer::i
|
||||
!integer,private::j
|
||||
!end type
|
||||
!type(t)::x
|
||||
!end
|
|
@ -0,0 +1,34 @@
|
|||
! Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
|
||||
!
|
||||
! Licensed under the Apache License, Version 2.0 (the "License");
|
||||
! you may not use this file except in compliance with the License.
|
||||
! You may obtain a copy of the License at
|
||||
!
|
||||
! http://www.apache.org/licenses/LICENSE-2.0
|
||||
!
|
||||
! Unless required by applicable law or agreed to in writing, software
|
||||
! distributed under the License is distributed on an "AS IS" BASIS,
|
||||
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
! See the License for the specific language governing permissions and
|
||||
! limitations under the License.
|
||||
|
||||
! Check modfile generation for private type in public API.
|
||||
|
||||
module m
|
||||
type, private :: t1
|
||||
integer :: i
|
||||
end type
|
||||
type, private :: t2
|
||||
integer :: i
|
||||
end type
|
||||
type(t1) :: x1
|
||||
type(t2), private :: x2
|
||||
end
|
||||
|
||||
!Expect: m.mod
|
||||
!module m
|
||||
!type,private::t1
|
||||
!integer::i
|
||||
!end type
|
||||
!type(t1)::x1
|
||||
!end
|
|
@ -0,0 +1,57 @@
|
|||
! Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
|
||||
!
|
||||
! Licensed under the Apache License, Version 2.0 (the "License");
|
||||
! you may not use this file except in compliance with the License.
|
||||
! You may obtain a copy of the License at
|
||||
!
|
||||
! http://www.apache.org/licenses/LICENSE-2.0
|
||||
!
|
||||
! Unless required by applicable law or agreed to in writing, software
|
||||
! distributed under the License is distributed on an "AS IS" BASIS,
|
||||
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
! See the License for the specific language governing permissions and
|
||||
! limitations under the License.
|
||||
|
||||
! Check modfile generation with use-association.
|
||||
|
||||
module m1
|
||||
integer :: x1
|
||||
integer, private :: x2
|
||||
end
|
||||
|
||||
module m2
|
||||
use m1
|
||||
integer :: y1
|
||||
end
|
||||
|
||||
module m3
|
||||
use m2, z1 => x1
|
||||
end
|
||||
|
||||
module m4
|
||||
use m1
|
||||
use m2
|
||||
end
|
||||
|
||||
!Expect: m1.mod
|
||||
!module m1
|
||||
!integer::x1
|
||||
!end
|
||||
|
||||
!Expect: m2.mod
|
||||
!module m2
|
||||
!use m1,only:x1
|
||||
!integer::y1
|
||||
!end
|
||||
|
||||
!Expect: m3.mod
|
||||
!module m3
|
||||
!use m2,only:y1
|
||||
!use m2,only:z1=>x1
|
||||
!end
|
||||
|
||||
!Expect: m4.mod
|
||||
!module m4
|
||||
!use m1,only:x1
|
||||
!use m2,only:y1
|
||||
!end
|
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/bash
|
||||
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Compile a source file and compare generated .mod files against expected.
|
||||
|
||||
set -e
|
||||
PATH=/usr/bin
|
||||
srcdir=$(dirname $0)
|
||||
CMD="${F18:-../../../tools/f18/f18} -fdebug-resolve-names -fparse-only"
|
||||
|
||||
if [[ $# != 1 ]]; then
|
||||
echo "Usage: $0 <fortran-source>"
|
||||
exit 1
|
||||
fi
|
||||
src=$srcdir/$1
|
||||
[[ ! -f $src ]] && echo "File not found: $src" && exit 1
|
||||
|
||||
if [[ $KEEP ]]; then
|
||||
temp=.
|
||||
else
|
||||
temp=$(mktemp --directory --tmpdir=.)
|
||||
trap "rm -rf $temp" EXIT
|
||||
fi
|
||||
|
||||
( cd $temp && $CMD $src )
|
||||
|
||||
actual=$temp/actual.mod
|
||||
expect=$temp/expect.mod
|
||||
actual_files=$temp/actual_files
|
||||
diffs=$temp/diffs
|
||||
|
||||
( cd $temp && ls -1 *.mod ) > $actual_files
|
||||
expected_files=$(sed -n 's/^!Expect: \(.*\)/\1/p' $src)
|
||||
extra_files=$(echo "$expected_files" | comm -23 $actual_files -)
|
||||
if [[ ! -z "$extra_files" ]]; then
|
||||
echo "Unexpected .mod files produced:" $extra_files
|
||||
echo FAIL
|
||||
exit 1
|
||||
fi
|
||||
for mod in $expected_files; do
|
||||
if [[ ! -f $temp/$mod ]]; then
|
||||
echo "Compilation did not produce expected mod file: $mod"
|
||||
echo FAIL
|
||||
exit 1
|
||||
fi
|
||||
sed '/^!mod\$/d' $temp/$mod > $actual
|
||||
sed '1,/^!Expect: '"$mod"'/d' $src | sed -e '/^$/,$d' -e 's/^!//' > $expect
|
||||
if ! diff -U999999 $actual $expect > $diffs; then
|
||||
echo "Module file $mod differs from expected:"
|
||||
sed '1,2d' $diffs
|
||||
echo FAIL
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
echo PASS
|
Loading…
Reference in New Issue