diff --git a/flang/test/Semantics/OpenACC/acc-symbols01.f90 b/flang/test/Semantics/OpenACC/acc-symbols01.f90 --- a/flang/test/Semantics/OpenACC/acc-symbols01.f90 +++ b/flang/test/Semantics/OpenACC/acc-symbols01.f90 @@ -1,5 +1,4 @@ -! RUN: %S/../test_symbols.sh %s %t %flang_fc1 -fopenacc -! REQUIRES: shell +! RUN: python %S/../test_symbols.py %s %t %flang_fc1 -fopenacc !DEF: /mm MainProgram program mm diff --git a/flang/test/Semantics/common.py b/flang/test/Semantics/common.py new file mode 100755 --- /dev/null +++ b/flang/test/Semantics/common.py @@ -0,0 +1,69 @@ +#!/usr/bin/python3 + +import os +import sys +import platform +from pathlib import Path + + +class Common: + """Provides common functionality to the test scripts + Expects source files passed as first argument; + A temporary directory as second argument; + And the Flang frontend driver with options as third argument""" + + def __init__(self, arguments): + self.os = platform.system() + self.test = arguments[0] + self.args = arguments[1:] + + def set_source(self): + self.path_source = Path(self.args[0]) + if self.path_source.is_file() is False: + self.die(self.path_source) + + def set_temp(self): + self.path_temp = Path(self.args[1]) + os.makedirs(self.path_temp, exist_ok=True) + + def set_executable(self): + self.flang_fc1 = Path(self.args[2]) + self.flang_fc1_args = self.args[3:] + if self.flang_fc1.is_file() is False: + self.die(self.flang_fc1) + + def die(self, file=None): + if file is None: + print(self.test + ": " + "FAIL") + else: + print(self.test + ": " + "File not found: " + str(file)) + sys.exit(1) + + def check_args(self): + if len(self.args) < 3: + print("Usage: {test_name} \ + ".format(self.test)) + sys.exit(1) + + def get_src(self): + return self.path_source + + def get_tmp(self): + return self.path_temp + + def get_exec(self): + return self.flang_fc1 + + def get_args(self): + return self.flang_fc1_args + + def main(self): + self.check_args() + self.set_source() + self.set_temp() + self.set_executable() + +if __name__ == '__main__': + program = Common(sys.argv) + program.main() + diff --git a/flang/test/Semantics/common.sh b/flang/test/Semantics/common.sh deleted file mode 100644 --- a/flang/test/Semantics/common.sh +++ /dev/null @@ -1,26 +0,0 @@ -# Common functionality for test scripts -# Process arguments, expecting source file as 1st; optional path to f18 as 2nd -# Set: $FLANG_FC1 to the path to the Flang frontend driver with options; $temp -# to an empty temp directory; and $src to the full path of the single source -# argument. - -function die { - echo "$(basename $0): $*" >&2 - exit 1 -} -if [[ $# < 3 ]]; then - echo "Usage: $(basename $0) " - exit 1 -fi - -case $1 in - (/*) src="$1" ;; - (*) src="$(dirname $0)/$1" ;; -esac -shift -temp=$1 -mkdir -p $temp -shift - -[[ ! -f $1 ]] && die "f18 executable not found: $1" -FLANG_FC1="$*" diff --git a/flang/test/Semantics/kinds01.f90 b/flang/test/Semantics/kinds01.f90 --- a/flang/test/Semantics/kinds01.f90 +++ b/flang/test/Semantics/kinds01.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 !DEF: /MainProgram1/jk1 ObjectEntity INTEGER(1) integer(kind=1) jk1 !DEF: /MainProgram1/js1 ObjectEntity INTEGER(1) diff --git a/flang/test/Semantics/kinds03.f90 b/flang/test/Semantics/kinds03.f90 --- a/flang/test/Semantics/kinds03.f90 +++ b/flang/test/Semantics/kinds03.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 !DEF: /MainProgram1/ipdt DerivedType !DEF: /MainProgram1/ipdt/k TypeParam INTEGER(4) type :: ipdt(k) diff --git a/flang/test/Semantics/omp-do-schedule03.f90 b/flang/test/Semantics/omp-do-schedule03.f90 --- a/flang/test/Semantics/omp-do-schedule03.f90 +++ b/flang/test/Semantics/omp-do-schedule03.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! OpenMP Version 4.5 ! 2.7.1 Schedule Clause ! Test that does not catch non constant integer expressions like xx - xx. diff --git a/flang/test/Semantics/omp-do-schedule04.f90 b/flang/test/Semantics/omp-do-schedule04.f90 --- a/flang/test/Semantics/omp-do-schedule04.f90 +++ b/flang/test/Semantics/omp-do-schedule04.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! OpenMP Version 4.5 ! 2.7.1 Schedule Clause ! Test that does not catch non constant integer expressions like xx - yy. diff --git a/flang/test/Semantics/omp-do01-positivecase.f90 b/flang/test/Semantics/omp-do01-positivecase.f90 --- a/flang/test/Semantics/omp-do01-positivecase.f90 +++ b/flang/test/Semantics/omp-do01-positivecase.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! OpenMP Version 4.5 ! 2.7.1 Loop Construct ! The loop iteration variable may not appear in a firstprivate directive. diff --git a/flang/test/Semantics/omp-do04-positivecase.f90 b/flang/test/Semantics/omp-do04-positivecase.f90 --- a/flang/test/Semantics/omp-do04-positivecase.f90 +++ b/flang/test/Semantics/omp-do04-positivecase.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! OpenMP Version 4.5 ! 2.7.1 Do Loop Constructs diff --git a/flang/test/Semantics/omp-do05-positivecase.f90 b/flang/test/Semantics/omp-do05-positivecase.f90 --- a/flang/test/Semantics/omp-do05-positivecase.f90 +++ b/flang/test/Semantics/omp-do05-positivecase.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! OpenMP Version 4.5 ! 2.7.1 Loop Construct restrictions on single directive. ! A positive case diff --git a/flang/test/Semantics/omp-do06-positivecases.f90 b/flang/test/Semantics/omp-do06-positivecases.f90 --- a/flang/test/Semantics/omp-do06-positivecases.f90 +++ b/flang/test/Semantics/omp-do06-positivecases.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! OpenMP Version 4.5 ! 2.7.1 Loop Construct ! The ordered clause must be present on the loop construct if any ordered diff --git a/flang/test/Semantics/omp-do11.f90 b/flang/test/Semantics/omp-do11.f90 --- a/flang/test/Semantics/omp-do11.f90 +++ b/flang/test/Semantics/omp-do11.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! OpenMP Version 4.5 ! 2.7.1 Do Loop Constructs diff --git a/flang/test/Semantics/omp-do12.f90 b/flang/test/Semantics/omp-do12.f90 --- a/flang/test/Semantics/omp-do12.f90 +++ b/flang/test/Semantics/omp-do12.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! OpenMP Version 4.5 ! 2.7.1 Do Loop constructs. diff --git a/flang/test/Semantics/omp-do14.f90 b/flang/test/Semantics/omp-do14.f90 --- a/flang/test/Semantics/omp-do14.f90 +++ b/flang/test/Semantics/omp-do14.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! OpenMP Version 4.5 ! 2.7.1 Do Loop constructs. diff --git a/flang/test/Semantics/omp-do17.f90 b/flang/test/Semantics/omp-do17.f90 --- a/flang/test/Semantics/omp-do17.f90 +++ b/flang/test/Semantics/omp-do17.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! OpenMP Version 4.5 ! 2.7.1 Do Loop constructs. diff --git a/flang/test/Semantics/omp-reduction08.f90 b/flang/test/Semantics/omp-reduction08.f90 --- a/flang/test/Semantics/omp-reduction08.f90 +++ b/flang/test/Semantics/omp-reduction08.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! OpenMP Version 4.5 ! 2.15.3.6 Reduction Clause Positive cases diff --git a/flang/test/Semantics/omp-reduction09.f90 b/flang/test/Semantics/omp-reduction09.f90 --- a/flang/test/Semantics/omp-reduction09.f90 +++ b/flang/test/Semantics/omp-reduction09.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! OpenMP Version 4.5 ! 2.15.3.6 Reduction Clause Positive cases. !DEF: /omp_reduction MainProgram diff --git a/flang/test/Semantics/omp-symbol01.f90 b/flang/test/Semantics/omp-symbol01.f90 --- a/flang/test/Semantics/omp-symbol01.f90 +++ b/flang/test/Semantics/omp-symbol01.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! Test clauses that accept list. ! 2.1 Directive Format diff --git a/flang/test/Semantics/omp-symbol02.f90 b/flang/test/Semantics/omp-symbol02.f90 --- a/flang/test/Semantics/omp-symbol02.f90 +++ b/flang/test/Semantics/omp-symbol02.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! 1.4.1 Structure of the OpenMP Memory Model diff --git a/flang/test/Semantics/omp-symbol03.f90 b/flang/test/Semantics/omp-symbol03.f90 --- a/flang/test/Semantics/omp-symbol03.f90 +++ b/flang/test/Semantics/omp-symbol03.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! 1.4.1 Structure of the OpenMP Memory Model ! In the inner OpenMP region, SHARED `a` refers to the `a` in the outer OpenMP diff --git a/flang/test/Semantics/omp-symbol04.f90 b/flang/test/Semantics/omp-symbol04.f90 --- a/flang/test/Semantics/omp-symbol04.f90 +++ b/flang/test/Semantics/omp-symbol04.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! 2.15.3 Data-Sharing Attribute Clauses ! Both PARALLEL and DO (worksharing) directives need to create new scope, diff --git a/flang/test/Semantics/omp-symbol05.f90 b/flang/test/Semantics/omp-symbol05.f90 --- a/flang/test/Semantics/omp-symbol05.f90 +++ b/flang/test/Semantics/omp-symbol05.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! 2.15.2 threadprivate Directive ! The threadprivate directive specifies that variables are replicated, diff --git a/flang/test/Semantics/omp-symbol06.f90 b/flang/test/Semantics/omp-symbol06.f90 --- a/flang/test/Semantics/omp-symbol06.f90 +++ b/flang/test/Semantics/omp-symbol06.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! 2.15.3 Data-Sharing Attribute Clauses ! A list item that specifies a given variable may not appear in more than diff --git a/flang/test/Semantics/omp-symbol07.f90 b/flang/test/Semantics/omp-symbol07.f90 --- a/flang/test/Semantics/omp-symbol07.f90 +++ b/flang/test/Semantics/omp-symbol07.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! Generic tests ! 1. subroutine or function calls should not be fixed for DSA or DMA diff --git a/flang/test/Semantics/omp-symbol08.f90 b/flang/test/Semantics/omp-symbol08.f90 --- a/flang/test/Semantics/omp-symbol08.f90 +++ b/flang/test/Semantics/omp-symbol08.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -fopenmp -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 -fopenmp ! 2.15.1.1 Predetermined rules for associated do-loops index variable ! a) The loop iteration variable(s) in the associated do-loop(s) of a do, diff --git a/flang/test/Semantics/procinterface01.f90 b/flang/test/Semantics/procinterface01.f90 --- a/flang/test/Semantics/procinterface01.f90 +++ b/flang/test/Semantics/procinterface01.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 ! Tests for "proc-interface" semantics. ! These cases are all valid. diff --git a/flang/test/Semantics/symbol01.f90 b/flang/test/Semantics/symbol01.f90 --- a/flang/test/Semantics/symbol01.f90 +++ b/flang/test/Semantics/symbol01.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 ! Test that intent-stmt and subprogram prefix and suffix are resolved. !DEF: /m Module diff --git a/flang/test/Semantics/symbol03.f90 b/flang/test/Semantics/symbol03.f90 --- a/flang/test/Semantics/symbol03.f90 +++ b/flang/test/Semantics/symbol03.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 ! Test host association in internal subroutine of main program. !DEF: /main MainProgram diff --git a/flang/test/Semantics/symbol05.f90 b/flang/test/Semantics/symbol05.f90 --- a/flang/test/Semantics/symbol05.f90 +++ b/flang/test/Semantics/symbol05.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 ! Explicit and implicit entities in blocks !DEF: /s1 (Subroutine) Subprogram diff --git a/flang/test/Semantics/symbol06.f90 b/flang/test/Semantics/symbol06.f90 --- a/flang/test/Semantics/symbol06.f90 +++ b/flang/test/Semantics/symbol06.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 !DEF: /main MainProgram program main !DEF: /main/t1 DerivedType diff --git a/flang/test/Semantics/symbol07.f90 b/flang/test/Semantics/symbol07.f90 --- a/flang/test/Semantics/symbol07.f90 +++ b/flang/test/Semantics/symbol07.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 !DEF: /main MainProgram program main implicit complex(z) diff --git a/flang/test/Semantics/symbol08.f90 b/flang/test/Semantics/symbol08.f90 --- a/flang/test/Semantics/symbol08.f90 +++ b/flang/test/Semantics/symbol08.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 !DEF: /main MainProgram program main !DEF: /main/x POINTER ObjectEntity REAL(4) diff --git a/flang/test/Semantics/symbol09.f90 b/flang/test/Semantics/symbol09.f90 --- a/flang/test/Semantics/symbol09.f90 +++ b/flang/test/Semantics/symbol09.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 !DEF: /s1 (Subroutine) Subprogram subroutine s1 !DEF: /s1/a ObjectEntity REAL(4) diff --git a/flang/test/Semantics/symbol10.f90 b/flang/test/Semantics/symbol10.f90 --- a/flang/test/Semantics/symbol10.f90 +++ b/flang/test/Semantics/symbol10.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 !DEF: /m1 Module module m1 contains diff --git a/flang/test/Semantics/symbol11.f90 b/flang/test/Semantics/symbol11.f90 --- a/flang/test/Semantics/symbol11.f90 +++ b/flang/test/Semantics/symbol11.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 !DEF: /s1 (Subroutine) Subprogram subroutine s1 implicit none diff --git a/flang/test/Semantics/symbol12.f90 b/flang/test/Semantics/symbol12.f90 --- a/flang/test/Semantics/symbol12.f90 +++ b/flang/test/Semantics/symbol12.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 ! Verify that SAVE attribute is propagated by EQUIVALENCE !DEF: /s1 (Subroutine) Subprogram diff --git a/flang/test/Semantics/symbol13.f90 b/flang/test/Semantics/symbol13.f90 --- a/flang/test/Semantics/symbol13.f90 +++ b/flang/test/Semantics/symbol13.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 ! Old-style "*length" specifiers (R723) !DEF: /f1 (Function) Subprogram CHARACTER(1_8,1) diff --git a/flang/test/Semantics/symbol14.f90 b/flang/test/Semantics/symbol14.f90 --- a/flang/test/Semantics/symbol14.f90 +++ b/flang/test/Semantics/symbol14.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 ! "Bare" uses of type parameters and components !DEF: /MainProgram1/t1 DerivedType diff --git a/flang/test/Semantics/symbol15.f90 b/flang/test/Semantics/symbol15.f90 --- a/flang/test/Semantics/symbol15.f90 +++ b/flang/test/Semantics/symbol15.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 ! Forward references in pointer initializers and TBP bindings. !DEF: /m Module diff --git a/flang/test/Semantics/symbol16.f90 b/flang/test/Semantics/symbol16.f90 --- a/flang/test/Semantics/symbol16.f90 +++ b/flang/test/Semantics/symbol16.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 ! Statement functions !DEF: /p1 MainProgram diff --git a/flang/test/Semantics/symbol17.f90 b/flang/test/Semantics/symbol17.f90 --- a/flang/test/Semantics/symbol17.f90 +++ b/flang/test/Semantics/symbol17.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 ! Forward references to derived types (non-error cases) !DEF: /main MainProgram diff --git a/flang/test/Semantics/symbol18.f90 b/flang/test/Semantics/symbol18.f90 --- a/flang/test/Semantics/symbol18.f90 +++ b/flang/test/Semantics/symbol18.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 ! Intrinsic function in type declaration statement: type is ignored diff --git a/flang/test/Semantics/symbol19.f90 b/flang/test/Semantics/symbol19.f90 --- a/flang/test/Semantics/symbol19.f90 +++ b/flang/test/Semantics/symbol19.f90 @@ -1,5 +1,4 @@ -! RUN: %S/test_symbols.sh %s %t %flang_fc1 -! REQUIRES: shell +! RUN: python %S/test_symbols.py %s %t %flang_fc1 ! Test that a procedure is only implicitly resolved as an intrinsic function ! (resp. subroutine) if this is a function (resp. subroutine) diff --git a/flang/test/Semantics/test_symbols.py b/flang/test/Semantics/test_symbols.py new file mode 100755 --- /dev/null +++ b/flang/test/Semantics/test_symbols.py @@ -0,0 +1,79 @@ +#!/usr/bin/python3 + +# Compiles a source file with "-fdebug-unparse-with-symbols' and verifies +# we get the right symbols in the output, i.e. the output should be +# the same as the input, except for the copyright comment. +import os +import sys +import platform +import re +import subprocess + +from difflib import unified_diff +from pathlib import Path, PurePath +from common import Common + +func = Common(sys.argv) +func.main() + +src = func.get_src() +tmp = func.get_tmp() +src1 = PurePath(tmp).joinpath("1.f90") +src2 = PurePath(tmp).joinpath("2.f90") +src3 = PurePath(tmp).joinpath("3.f90") +diffs = PurePath(tmp).joinpath("diffs") + +flang_fc1 = func.get_exec() +flang_fc1_args = func.get_args() +flang_fc1_options = "-fdebug-unparse-with-symbols" + +cmd = [str(flang_fc1), flang_fc1_args, flang_fc1_options, str(src2)] + +# Strips out blak lines and all comments except for "!DEF:", "!REF:", and "!$omp" +with open(src, 'r') as text_in, \ + open(src1, 'w') as text_out: + for line in text_in: + + text = re.sub("!(?![DR]EF:|\$omp|\$acc).*", "", line) + text = re.sub("^\s*$", "", text) + text_out.write(text) + +# Strips out "!DEF:" ad "!REF:" comments +with open(src1, 'r') as text_in, \ + open(src2, 'w') as text_out: + for line in text_in: + + text = re.sub("![DR]EF:.*", "", line) + text = re.sub("^\s*$", "", text) + text_out.write(text) + +# Compiles, inserting comments for symbols: +with open(src3, 'w') as text_out: + proc = subprocess.Popen(cmd, universal_newlines=True, stdout=subprocess.PIPE) + text = proc.communicate()[0] + text_out.write(text) + +# Removes all whitespace to compare diffrences in files +diff1 = open(src1).readlines() +diff1 = [x.replace(" ", "") for x in diff1] +diff2 = open(src3).readlines() +diff2 = [x.replace(" ", "") for x in diff2] +diff_check = "" + +# Compares the input with the output +with open(diffs, 'w') as diffs: + for line in unified_diff(diff1, diff2, n=999999, fromfile="1.90", tofile="3.f90"): + diffs.write(line) + line = re.sub("^\s*$", "", line) + diff_check = diff_check + line + +if diff_check != "": + print(diff_check) + print("") + print("FAIL") + sys.exit(1) +else: + print() + print("PASS") + sys.exit(0) + diff --git a/flang/test/Semantics/test_symbols.sh b/flang/test/Semantics/test_symbols.sh deleted file mode 100755 --- a/flang/test/Semantics/test_symbols.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# Compile a source file with '-fdebug-unparse-with-symbols' and verify -# we get the right symbols in the output, i.e. the output should be -# the same as the input, except for the copyright comment. -# Change the frontend driver by setting the FLANG_FC1 environment variable. - -FLANG_FC1_OPTIONS="-fdebug-unparse-with-symbols" -srcdir=$(dirname $0) -source $srcdir/common.sh -[[ ! -f $src ]] && echo "File not found: $src" && exit 1 - -src1=$temp/1.f90 -src2=$temp/2.f90 -src3=$temp/3.f90 -diffs=$temp/diffs - -# Strip out blank lines and all comments except "!DEF:", "!REF:", and "!$omp" -sed -e 's/!\([DR]EF:\)/KEEP \1/' -e 's/!\($omp\)/KEEP \1/' \ - -e 's/!\($acc\)/KEEP \1/' -e 's/!.*//' -e 's/ *$//' -e '/^$/d' \ - -e 's/KEEP \([DR]EF:\)/!\1/' -e 's/KEEP \($omp\)/!\1/' \ - -e 's/KEEP \($acc\)/!\1/' \ - $src > $src1 -egrep -v '![DR]EF:' $src1 > $src2 # strip out DEF and REF comments -# compile, inserting comments for symbols: -( cd $temp; $FLANG_FC1 $FLANG_FC1_OPTIONS $(basename $src2) ) > $src3 - -if diff -w -U999999 $src1 $src3 > $diffs; then - echo PASS -else - sed '1,/^\@\@/d' $diffs - echo - echo FAIL - exit 1 -fi