[flang-commits] [flang] eabae4c - [Flang] Ported test_symbols to Python

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Mon Aug 9 08:20:26 PDT 2021


Author: Ivan Zhechev
Date: 2021-08-09T16:20:06+01:00
New Revision: eabae4cf57b9e7429db27fdfd3016d31901fa2ea

URL: https://github.com/llvm/llvm-project/commit/eabae4cf57b9e7429db27fdfd3016d31901fa2ea
DIFF: https://github.com/llvm/llvm-project/commit/eabae4cf57b9e7429db27fdfd3016d31901fa2ea.diff

LOG: [Flang] Ported test_symbols to Python

Due to unavailability of Flang testing on Windows, the shell scripts
are being ported to Python. The following changes are being made in
this patch: removed test_symbols.sh and common.sh, and ported them
to Python. Changes to the tests themselves so that they use the
python scripts instead of the shell script.

Reviewed By: Meinersbur, awarzynski, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D107041

Added: 
    flang/test/Semantics/common.py
    flang/test/Semantics/test_symbols.py

Modified: 
    flang/test/Semantics/OpenACC/acc-symbols01.f90
    flang/test/Semantics/kinds01.f90
    flang/test/Semantics/kinds03.f90
    flang/test/Semantics/omp-do-schedule03.f90
    flang/test/Semantics/omp-do-schedule04.f90
    flang/test/Semantics/omp-do01-positivecase.f90
    flang/test/Semantics/omp-do04-positivecase.f90
    flang/test/Semantics/omp-do05-positivecase.f90
    flang/test/Semantics/omp-do06-positivecases.f90
    flang/test/Semantics/omp-do11.f90
    flang/test/Semantics/omp-do12.f90
    flang/test/Semantics/omp-do14.f90
    flang/test/Semantics/omp-do17.f90
    flang/test/Semantics/omp-reduction08.f90
    flang/test/Semantics/omp-reduction09.f90
    flang/test/Semantics/omp-symbol01.f90
    flang/test/Semantics/omp-symbol02.f90
    flang/test/Semantics/omp-symbol03.f90
    flang/test/Semantics/omp-symbol04.f90
    flang/test/Semantics/omp-symbol05.f90
    flang/test/Semantics/omp-symbol06.f90
    flang/test/Semantics/omp-symbol07.f90
    flang/test/Semantics/omp-symbol08.f90
    flang/test/Semantics/procinterface01.f90
    flang/test/Semantics/symbol01.f90
    flang/test/Semantics/symbol02.f90
    flang/test/Semantics/symbol03.f90
    flang/test/Semantics/symbol05.f90
    flang/test/Semantics/symbol06.f90
    flang/test/Semantics/symbol07.f90
    flang/test/Semantics/symbol08.f90
    flang/test/Semantics/symbol09.f90
    flang/test/Semantics/symbol10.f90
    flang/test/Semantics/symbol11.f90
    flang/test/Semantics/symbol12.f90
    flang/test/Semantics/symbol13.f90
    flang/test/Semantics/symbol14.f90
    flang/test/Semantics/symbol15.f90
    flang/test/Semantics/symbol16.f90
    flang/test/Semantics/symbol17.f90
    flang/test/Semantics/symbol18.f90
    flang/test/Semantics/symbol19.f90

Removed: 
    flang/test/Semantics/test_symbols.sh


################################################################################
diff  --git a/flang/test/Semantics/OpenACC/acc-symbols01.f90 b/flang/test/Semantics/OpenACC/acc-symbols01.f90
index f08317ac12bf1..8e07f8d5c592e 100644
--- 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 %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
index 0000000000000..14323f4a70d87
--- /dev/null
+++ b/flang/test/Semantics/common.py
@@ -0,0 +1,44 @@
+"""Provides common functionality to the test scripts."""
+
+import os
+import sys
+from pathlib import Path
+
+def set_source(source):
+    """Checks whether the source file exists and returns its path."""
+    if not Path(source).is_file():
+        die(source)
+    return Path(source)
+
+def set_executable(executable):
+    """Checks whether a Flang executable has been set and returns its path."""
+    flang_fc1 = Path(executable)
+    if not flang_fc1.is_file():
+        die(flang_fc1)
+    return str(flang_fc1)
+
+def set_temp(tmp):
+    """Sets a temporary directory or creates one if it doesn't exist."""
+    os.makedirs(Path(tmp), exist_ok=True)
+    return Path(tmp)
+
+def die(file=None):
+    """Used in other functions."""
+    if file is None:
+        print(f"{sys.argv[0]}: FAIL")
+    else:
+        print(f"{sys.argv[0]}: File not found: {file}")
+    sys.exit(1)
+
+def check_args(args):
+    """Verifies that 2 arguments have been passed."""
+    if len(args) < 3:
+        print(f"Usage: {args[0]} <fortran-source> <flang-command>")
+        sys.exit(1)
+
+def check_args_long(args):
+    """Verifies that 3 arguments have been passed."""
+    if len(args) < 4:
+        print(f"Usage: {args[0]} <fortran-source> <temp-test-dir> <flang-command>")
+        sys.exit(1)
+

diff  --git a/flang/test/Semantics/kinds01.f90 b/flang/test/Semantics/kinds01.f90
index ef6edfb683195..5238a90719fe4 100644
--- 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 %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
index cd81b28ab2381..58a41a70ad7a5 100644
--- 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 %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
index 1f7445497c062..4b5fb029c7ea0 100644
--- 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 %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
index b3fcd65720ef1..05daa05fc1590 100644
--- 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 %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
index f77104d11a952..a810f93795959 100644
--- 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 %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
index c9ef67752d8b8..5a549a863afd1 100644
--- 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 %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
index 1886da987cc81..9de1337cd4454 100644
--- 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 %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
index 5cb8268dc6373..07057102df4ac 100644
--- 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 %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
index f5e800058d226..c12eb1cee4715 100644
--- 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 %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
index 264eb15df8cad..36ba685e50c91 100644
--- 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 %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
index f49a29f8e9aa9..87e6f7207886f 100644
--- 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 %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
index fb23176309b50..0b1245e53f59a 100644
--- 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 %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
index 1e6c56d62d675..e46585a068b74 100644
--- 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 %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
index e93699f596f1f..e1ca4b0cfcebc 100644
--- 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 %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
index 377af74ea54e5..06d5d7cbf8e9c 100644
--- 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 %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
index 35047015c4e32..de3650565716f 100644
--- 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 %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
index 33dfe27582bbe..4c37c5adce648 100644
--- 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 %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
index 0f18b8b595d43..cf892a96932d3 100644
--- 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 %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
index 50e1d91cb91a6..72be56f99b4b7 100644
--- 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 %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
index 5a8325d9a096a..5b6621f8fdbb9 100644
--- 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 %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
index f333e572fe2d1..0d88276ebb98c 100644
--- 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 %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
index 4fd01e718fd52..25b49ee070c3e 100644
--- 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 %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
index 3e794b1270084..7fc3c75e1e0f8 100644
--- 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 %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
index 359c183c70472..9fc64e19f2e2a 100644
--- 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 %flang_fc1
 ! Test that intent-stmt and subprogram prefix and suffix are resolved.
 
 !DEF: /m Module

diff  --git a/flang/test/Semantics/symbol02.f90 b/flang/test/Semantics/symbol02.f90
index b266e70d56eb7..e3f76c778e9bd 100644
--- a/flang/test/Semantics/symbol02.f90
+++ b/flang/test/Semantics/symbol02.f90
@@ -1,5 +1,4 @@
-! RUN: %S/test_symbols.sh %s %t %flang_fc1
-! REQUIRES: shell
+! RUN: %python %S/test_symbols.py %s %flang_fc1
 ! Test host association in module subroutine and internal subroutine.
 
 !DEF: /m Module

diff  --git a/flang/test/Semantics/symbol03.f90 b/flang/test/Semantics/symbol03.f90
index eb7d4b303ea41..d132747ca8c9e 100644
--- 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 %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
index facaef5e01d54..442bd19d1f200 100644
--- 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 %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
index 1faa17793bb8d..bbd6d4d071c89 100644
--- 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 %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
index b4cfbcc0efebc..f3cc934e51b16 100644
--- 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 %flang_fc1
 !DEF: /main MainProgram
 program main
  implicit complex(z)

diff  --git a/flang/test/Semantics/symbol08.f90 b/flang/test/Semantics/symbol08.f90
index fe2c40b509789..61dab798955c5 100644
--- 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 %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
index 95a142195d77f..0b49f45cd9cc3 100644
--- 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 %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
index ea366789a4fcd..ba1f5ab45f533 100644
--- 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 %flang_fc1
 !DEF: /m1 Module
 module m1
 contains

diff  --git a/flang/test/Semantics/symbol11.f90 b/flang/test/Semantics/symbol11.f90
index ebdf65f35d658..b3e6e26f366da 100644
--- 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 %flang_fc1
 !DEF: /s1 (Subroutine) Subprogram
 subroutine s1
  implicit none

diff  --git a/flang/test/Semantics/symbol12.f90 b/flang/test/Semantics/symbol12.f90
index ee165cf2d3c11..bada819773533 100644
--- 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 %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
index 17bd99e6ad170..9a3395e61f01f 100644
--- 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 %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
index 037db56c4478e..611c43aea1f1f 100644
--- 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 %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
index ff534baedb554..97dc50a23845f 100644
--- 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 %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
index ea198b047bfc3..b710bc6901979 100644
--- 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 %flang_fc1
 ! Statement functions
 
 !DEF: /p1 MainProgram

diff  --git a/flang/test/Semantics/symbol17.f90 b/flang/test/Semantics/symbol17.f90
index 0b6b930804d91..434f124509a32 100644
--- 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 %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
index 44fdcd51b8720..a37792bce21d7 100644
--- 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 %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
index d8f4cd5128d26..541c5ccbf9468 100644
--- 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 %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
index 0000000000000..2ca2301745d0d
--- /dev/null
+++ b/flang/test/Semantics/test_symbols.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env 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.
+Expects a source file passed as the first argument;
+Expects the Flang frontdriver with options as second argument."""
+
+import sys
+import re
+import subprocess
+import common as cm
+
+from 
diff lib import unified_
diff 
+
+cm.check_args(sys.argv)
+src = cm.set_source(sys.argv[1])
+
diff 1 = ""
+
diff 2 = ""
+
+flang_fc1 = cm.set_executable(sys.argv[2])
+flang_fc1_args = sys.argv[3:]
+flang_fc1_options = "-fdebug-unparse-with-symbols"
+
+# Strips out blank lines and all comments except for "!DEF:", "!REF:", "!$acc" and "!$omp"
+with open(src, 'r') as text_in:
+    for line in text_in:
+        text = re.sub(r"!(?![DR]EF:|\$omp|\$acc).*", "", line)
+        text = re.sub(r"^\s*$", "", text)
+        
diff 1 += text
+
+# Strips out "!DEF:" and "!REF:" comments
+for line in 
diff 1:
+    text = re.sub(r"![DR]EF:.*", "", line)
+    
diff 2 += text
+
+# Compiles, inserting comments for symbols:
+cmd = [flang_fc1, *flang_fc1_args, flang_fc1_options]
+
diff 3 = subprocess.check_output(cmd, input=
diff 2, universal_newlines=True)
+
+# Removes all whitespace to compare 
diff erences in files
+
diff 1 = 
diff 1.replace(" ", "")
+
diff 3 = 
diff 3.replace(" ", "")
+
diff _check = ""
+
+# Compares the input with the output
+for line in unified_
diff (
diff 1, 
diff 3, n=999999,
+                         fromfile="Expected output", tofile="Actual output"):
+    
diff _check += line
+
+if 
diff _check != "":
+    print(
diff _check.replace(" ", ""))
+    print()
+    print("FAIL")
+    sys.exit(1)
+else:
+    print()
+    print("PASS")
+

diff  --git a/flang/test/Semantics/test_symbols.sh b/flang/test/Semantics/test_symbols.sh
deleted file mode 100755
index 56337c2746f0d..0000000000000
--- 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
-
diff s=$temp/
diff s
-
-# 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 > $
diff s; then
-  echo PASS
-else
-  sed '1,/^\@\@/d' $
diff s
-  echo
-  echo FAIL
-  exit 1
-fi


        


More information about the flang-commits mailing list