From c68ddd5e2a9dd0cfe21c3661404d7d4c323b23cf Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Thu, 31 Oct 2019 17:40:13 +0100
Subject: [PATCH] Enable more 'libgomp.oacc-*/lib-*' testcases for
 non-'openacc_nvidia_accel_selected'

	libgomp/
	* testsuite/libgomp.oacc-c-c++-common/lib-11.c: Enable for all but
	'-DACC_MEM_SHARED=0'.
	* testsuite/libgomp.oacc-c-c++-common/lib-13.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-14.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-15.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-20.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-23.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-24.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-34.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-42.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-44.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-48.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-88.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-89.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-92.c: Likewise.
	* testsuite/libgomp.oacc-fortran/lib-14.f90: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-5.c: Add
	'acc_device_radeon' testing.
	* testsuite/libgomp.oacc-c-c++-common/lib-6.c: Likewise.
	* testsuite/libgomp.oacc-fortran/lib-5.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/lib-7.f90: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-52.c: Enable for all.
	* testsuite/libgomp.oacc-c-c++-common/lib-53.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-54.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-86.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-87.c: Likewise.
	* testsuite/libgomp.oacc-fortran/lib-10.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/lib-8.f90: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-57.c: Improve checking
	for non-'openacc_nvidia_accel_selected'.
	* testsuite/libgomp.oacc-c-c++-common/lib-58.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-62.c: Clarify that "Not
	all implement this checking".
	* testsuite/libgomp.oacc-c-c++-common/lib-63.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-64.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-65.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-67.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/lib-68.c: Likewise.
---
 .../libgomp.oacc-c-c++-common/lib-11.c        | 10 ++--
 .../libgomp.oacc-c-c++-common/lib-13.c        |  2 +-
 .../libgomp.oacc-c-c++-common/lib-14.c        |  2 +-
 .../libgomp.oacc-c-c++-common/lib-15.c        |  2 +-
 .../libgomp.oacc-c-c++-common/lib-20.c        |  4 +-
 .../libgomp.oacc-c-c++-common/lib-23.c        |  4 +-
 .../libgomp.oacc-c-c++-common/lib-24.c        |  2 +-
 .../libgomp.oacc-c-c++-common/lib-34.c        |  4 +-
 .../libgomp.oacc-c-c++-common/lib-42.c        |  4 +-
 .../libgomp.oacc-c-c++-common/lib-44.c        |  4 +-
 .../libgomp.oacc-c-c++-common/lib-48.c        |  4 +-
 .../libgomp.oacc-c-c++-common/lib-5.c         | 20 +++++++-
 .../libgomp.oacc-c-c++-common/lib-52.c        |  6 +--
 .../libgomp.oacc-c-c++-common/lib-53.c        |  6 +--
 .../libgomp.oacc-c-c++-common/lib-54.c        |  6 +--
 .../libgomp.oacc-c-c++-common/lib-57.c        |  2 +-
 .../libgomp.oacc-c-c++-common/lib-58.c        |  2 +-
 .../libgomp.oacc-c-c++-common/lib-6.c         | 47 ++++++++++++++-----
 .../libgomp.oacc-c-c++-common/lib-62.c        |  3 +-
 .../libgomp.oacc-c-c++-common/lib-63.c        |  3 +-
 .../libgomp.oacc-c-c++-common/lib-64.c        |  3 +-
 .../libgomp.oacc-c-c++-common/lib-65.c        |  3 +-
 .../libgomp.oacc-c-c++-common/lib-67.c        |  3 +-
 .../libgomp.oacc-c-c++-common/lib-68.c        |  3 +-
 .../libgomp.oacc-c-c++-common/lib-86.c        | 27 +++++++----
 .../libgomp.oacc-c-c++-common/lib-87.c        | 27 +++++++----
 .../libgomp.oacc-c-c++-common/lib-88.c        |  9 +---
 .../libgomp.oacc-c-c++-common/lib-89.c        | 18 +++----
 .../libgomp.oacc-c-c++-common/lib-92.c        | 18 +++----
 .../testsuite/libgomp.oacc-fortran/lib-10.f90 |  6 +--
 .../testsuite/libgomp.oacc-fortran/lib-14.f90 |  3 +-
 .../testsuite/libgomp.oacc-fortran/lib-5.f90  | 46 ++++++++++++++----
 .../testsuite/libgomp.oacc-fortran/lib-7.f90  | 46 ++++++++++++++----
 .../testsuite/libgomp.oacc-fortran/lib-8.f90  |  6 +--
 34 files changed, 225 insertions(+), 130 deletions(-)

diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-11.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-11.c
index 86cfeb68c5d..1f05161436c 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-11.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-11.c
@@ -1,5 +1,4 @@
-/* Only nvptx plugin does the required error checking.
-   { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -22,6 +21,9 @@ main (int argc, char **argv)
   return 0;
 }
 
-/* { dg-output "CheCKpOInT(\n|\r\n|\r).*" } */
-/* { dg-output "invalid device address" } */
+/* { dg-output "CheCKpOInT(\n|\r\n|\r)+" } */
+/* { dg-output "libgomp: invalid device address(\n|\r\n|\r)+" { target openacc_nvidia_accel_selected } } */
+/* { dg-output "libgomp: GCN fatal error: Could not free device memory(\n|\r\n|\r)+" { target openacc_radeon_accel_selected } }
+   { dg-output "Runtime message: HSA_STATUS_ERROR_INVALID_ALLOCATION: The requested allocation is not valid\.(\n|\r\n|\r)+" { target openacc_radeon_accel_selected } } */
+/* { dg-output "libgomp: error in freeing device memory in acc_free(\n|\r\n|\r)+$" } */
 /* { dg-shouldfail "" } */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-13.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-13.c
index aca4c252091..90b137fb20b 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-13.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-13.c
@@ -1,6 +1,6 @@
 /* Check acc_is_present and acc_delete.  */
 
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include <stdlib.h>
 #include <openacc.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-14.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-14.c
index de6d38b060c..892f97c31ef 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-14.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-14.c
@@ -1,6 +1,6 @@
 /* Check acc_is_present.  */
 
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include <stdlib.h>
 #include <openacc.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-15.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-15.c
index 50c17011fe7..335b26f8fca 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-15.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-15.c
@@ -1,6 +1,6 @@
 /* Check acc_is_present and acc_copyout.  */
 
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include <stdlib.h>
 #include <openacc.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-20.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-20.c
index 10d3cbc5cc6..f1d9a21ecd3 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-20.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-20.c
@@ -1,6 +1,6 @@
-/* Exercise acc_copyin and acc_copyout on nvidia targets.  */
+/* Exercise acc_copyin and acc_copyout.  */
 
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-23.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-23.c
index b1f3e71f278..d39f31e6245 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-23.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-23.c
@@ -1,6 +1,6 @@
-/* Exercise acc_copyin and acc_copyout on nvidia targets.  */
+/* Exercise acc_copyin and acc_copyout.  */
 
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-24.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-24.c
index 09e2817f41d..96e3129e563 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-24.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-24.c
@@ -1,6 +1,6 @@
 /* Exercise acc_create, acc_is_present and acc_delete.  */
 
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include <stdlib.h>
 #include <openacc.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-34.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-34.c
index a24916d1306..8ddd897826f 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-34.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-34.c
@@ -1,6 +1,6 @@
-/* Exercise an invalid acc_present_or_create on nvidia targets.  */
+/* Exercise an invalid acc_present_or_create.  */
 
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-42.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-42.c
index 30b90d49c7b..adab1098ed8 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-42.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-42.c
@@ -1,6 +1,6 @@
-/* Exercise acc_update_device on unmapped data on nvidia targets.  */
+/* Exercise acc_update_device on unmapped data.  */
 
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-44.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-44.c
index 8bbf016a191..f02fe2188dc 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-44.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-44.c
@@ -1,6 +1,6 @@
-/* Exercise acc_update_device with size zero data on nvidia targets.  */
+/* Exercise acc_update_device with size zero data.  */
 
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-48.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-48.c
index afa137ff098..9975c9e990b 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-48.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-48.c
@@ -1,6 +1,6 @@
-/* Exercise acc_update_self with a size zero data mapping on nvidia targets.  */
+/* Exercise acc_update_self with a size zero data mapping.  */
 
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include <stdio.h>
 #include <string.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-5.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-5.c
index 961a62c2b63..1e0ab9cca70 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-5.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-5.c
@@ -35,6 +35,24 @@ main (int argc, char **argv)
       acc_shutdown (acc_device_nvidia);
     }
 
-  return 0;
+  if (acc_get_num_devices (acc_device_radeon) != 0)
+    {
+      acc_init (acc_device_radeon);
+
+      if (acc_get_device_type () != acc_device_radeon)
+        abort ();
+
+      acc_shutdown (acc_device_radeon);
+
+      acc_init (acc_device_default);
 
+      acc_set_device_type (acc_device_radeon);
+
+      if (acc_get_device_type () != acc_device_radeon)
+        abort ();
+
+      acc_shutdown (acc_device_radeon);
+    }
+
+  return 0;
 }
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-52.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-52.c
index 25c70c226f4..9a562b3d0aa 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-52.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-52.c
@@ -1,6 +1,4 @@
-/* Exercise acc_map_data with a NULL data mapping on nvidia targets.  */
-
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* Exercise acc_map_data with a NULL data mapping.  */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -30,6 +28,6 @@ main (int argc, char **argv)
 }
 
 /* { dg-output "CheCKpOInT(\n|\r\n|\r).*" } */
-/* { dg-output "\\\[\[^\n\r]*,\\\+256\]->\[\[0-9a-fA-FxX\]+,\\\+256\\\] is a bad map" { target openacc_nvidia_accel_selected } } */
+/* { dg-output "\\\[\[^\n\r]*,\\\+256\]->\[\[0-9a-fA-FxX\]+,\\\+256\\\] is a bad map" { target { ! openacc_host_selected } } } */
 /* { dg-output "cannot map data on shared-memory system" { target openacc_host_selected } } */
 /* { dg-shouldfail "" } */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-53.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-53.c
index a8ee7df629c..d452a694750 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-53.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-53.c
@@ -1,6 +1,4 @@
-/* Exercise acc_map_data with a NULL data mapping on nvidia targets.  */
-
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* Exercise acc_map_data with a NULL data mapping.  */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -30,6 +28,6 @@ main (int argc, char **argv)
 }
 
 /* { dg-output "CheCKpOInT(\n|\r\n|\r).*" } */
-/* { dg-output "\\\[\[0-9a-fA-FxX\]+,\\\+256\]->\\\[\[^\n\r]*,\\\+256\\\] is a bad map" { target openacc_nvidia_accel_selected } } */
+/* { dg-output "\\\[\[0-9a-fA-FxX\]+,\\\+256\]->\\\[\[^\n\r]*,\\\+256\\\] is a bad map" { target { ! openacc_host_selected } } } */
 /* { dg-output "cannot map data on shared-memory system" { target openacc_host_selected } } */
 /* { dg-shouldfail "" } */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-54.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-54.c
index fc221f47116..19227546312 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-54.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-54.c
@@ -1,6 +1,4 @@
-/* Exercise acc_map_data with data size of zero on nvidia targets.  */
-
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* Exercise acc_map_data with data size of zero.  */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -30,6 +28,6 @@ main (int argc, char **argv)
 }
 
 /* { dg-output "CheCKpOInT(\n|\r\n|\r).*" } */
-/* { dg-output "\\\[\[0-9a-fA-FxX\]+,\\\+0\\\]->\\\[\[0-9a-fA-FxX\]+,\\\+0\\\] is a bad map" { target openacc_nvidia_accel_selected } } */
+/* { dg-output "\\\[\[0-9a-fA-FxX\]+,\\\+0\\\]->\\\[\[0-9a-fA-FxX\]+,\\\+0\\\] is a bad map" { target { ! openacc_host_selected } } } */
 /* { dg-output "cannot map data on shared-memory system" { target openacc_host_selected } } */
 /* { dg-shouldfail "" } */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-57.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-57.c
index 971a0147f3d..81653c6a083 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-57.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-57.c
@@ -33,6 +33,6 @@ main (int argc, char **argv)
 }
 
 /* { dg-output "CheCKpOInT(\n|\r\n|\r).*" } */
-/* { dg-output "\[0-9a-fA-FxX\]+ is not a mapped block" { target openacc_nvidia_accel_selected } } */
+/* { dg-output "\[0-9a-fA-FxX\]+ is not a mapped block" { target { ! openacc_host_selected } } } */
 /* { dg-output "cannot map data on shared-memory system" { target openacc_host_selected } } */
 /* { dg-shouldfail "" } */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-58.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-58.c
index fedda77004b..c6bc2610cac 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-58.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-58.c
@@ -33,6 +33,6 @@ main (int argc, char **argv)
 }
 
 /* { dg-output "CheCKpOInT(\n|\r\n|\r).*" } */
-/* { dg-output "\[^\n\r]* is not a mapped block" { target openacc_nvidia_accel_selected } } */
+/* { dg-output "\[^\n\r]* is not a mapped block" { target { ! openacc_host_selected } } } */
 /* { dg-output "cannot map data on shared-memory system" { target openacc_host_selected } } */
 /* { dg-shouldfail "" } */
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-6.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-6.c
index afdd480cb71..a3affc0c20d 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-6.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-6.c
@@ -11,26 +11,47 @@ main (int argc, char **argv)
   if (acc_get_device_type () == acc_device_default)
     abort ();
 
-  if (acc_get_num_devices (acc_device_nvidia) == 0)
-    return 0;
+  if (acc_get_num_devices (acc_device_nvidia))
+    {
+      acc_set_device_type (acc_device_nvidia);
 
-  acc_set_device_type (acc_device_nvidia);
+      if (acc_get_device_type () != acc_device_nvidia)
+	abort ();
 
-  if (acc_get_device_type () != acc_device_nvidia)
-    abort ();
+      acc_shutdown (acc_device_nvidia);
 
-  acc_shutdown (acc_device_nvidia);
+      acc_set_device_type (acc_device_nvidia);
 
-  acc_set_device_type (acc_device_nvidia);
+      if (acc_get_device_type () != acc_device_nvidia)
+	abort ();
 
-  if (acc_get_device_type () != acc_device_nvidia)
-    abort ();
+      devnum = acc_get_num_devices (acc_device_host);
+      if (devnum != 1)
+	abort ();
 
-  devnum = acc_get_num_devices (acc_device_host);
-  if (devnum != 1)
-    abort ();
+      acc_shutdown (acc_device_nvidia);
+    }
+
+  if (acc_get_num_devices (acc_device_radeon))
+    {
+      acc_set_device_type (acc_device_radeon);
+
+      if (acc_get_device_type () != acc_device_radeon)
+	abort ();
+
+      acc_shutdown (acc_device_radeon);
+
+      acc_set_device_type (acc_device_radeon);
+
+      if (acc_get_device_type () != acc_device_radeon)
+	abort ();
+
+      devnum = acc_get_num_devices (acc_device_host);
+      if (devnum != 1)
+	abort ();
 
-  acc_shutdown (acc_device_nvidia);
+      acc_shutdown (acc_device_radeon);
+    }
 
   if (acc_get_device_type () == acc_device_default)
     abort ();
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-62.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-62.c
index ace4b058b9b..2e7184a918b 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-62.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-62.c
@@ -1,4 +1,5 @@
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* Not all implement this checking.
+   { dg-skip-if "" { openacc_radeon_accel_selected || openacc_host_selected } } */
 
 #include <stdio.h>
 #include <string.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-63.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-63.c
index a3fa728510f..84bbccb448e 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-63.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-63.c
@@ -1,4 +1,5 @@
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* Not all implement this checking.
+   { dg-skip-if "" { openacc_radeon_accel_selected || openacc_host_selected } } */
 
 #include <stdio.h>
 #include <string.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-64.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-64.c
index b57f67a0058..e26681a7b4d 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-64.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-64.c
@@ -1,4 +1,5 @@
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* Not all implement this checking.
+   { dg-skip-if "" { openacc_radeon_accel_selected || openacc_host_selected } } */
 
 #include <stdio.h>
 #include <string.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-65.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-65.c
index 0fca8214e76..69add3ffedb 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-65.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-65.c
@@ -1,4 +1,5 @@
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* Not all implement this checking.
+   { dg-skip-if "" { openacc_radeon_accel_selected || openacc_host_selected } } */
 
 #include <stdio.h>
 #include <string.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-67.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-67.c
index ec3c2a53baf..c13333b3b48 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-67.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-67.c
@@ -1,4 +1,5 @@
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* Not all implement this checking.
+   { dg-skip-if "" { openacc_radeon_accel_selected || openacc_host_selected } } */
 
 #include <stdio.h>
 #include <string.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-68.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-68.c
index f10903443d8..7fffd0b9f0b 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-68.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-68.c
@@ -1,4 +1,5 @@
-/* { dg-do run { target openacc_nvidia_accel_selected } } */
+/* Not all implement this checking.
+   { dg-skip-if "" { openacc_radeon_accel_selected || openacc_host_selected } } */
 
 #include <stdio.h>
 #include <string.h>
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-86.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-86.c
index b8a8ee94a58..7e8a7e20203 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-86.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-86.c
@@ -7,9 +7,6 @@
 int
 main (int argc, char **argv)
 {
-  if (acc_get_num_devices (acc_device_nvidia) == 0)
-    return 0;
-
   if (acc_get_current_cuda_device () != 0)
     abort ();
 
@@ -20,18 +17,28 @@ main (int argc, char **argv)
 
   acc_shutdown (acc_device_host);
 
-  if (acc_get_num_devices (acc_device_nvidia) == 0)
-    return 0;
-
   if (acc_get_current_cuda_device () != 0)
     abort ();
 
-  acc_init (acc_device_nvidia);
+  if (acc_get_num_devices (acc_device_nvidia))
+    {
+      acc_init (acc_device_nvidia);
 
-  if (acc_get_current_cuda_device () == 0)
-    abort ();
+      if (acc_get_current_cuda_device () == 0)
+	abort ();
+
+      acc_shutdown (acc_device_nvidia);
+    }
+
+  if (acc_get_num_devices (acc_device_radeon))
+    {
+      acc_init (acc_device_radeon);
+
+      if (acc_get_current_cuda_device () != 0)
+	abort ();
 
-  acc_shutdown (acc_device_nvidia);
+      acc_shutdown (acc_device_radeon);
+    }
 
   if (acc_get_current_cuda_device () != 0)
     abort ();
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-87.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-87.c
index 147d443b54d..cdc87edc590 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-87.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-87.c
@@ -7,9 +7,6 @@
 int
 main (int argc, char **argv)
 {
-  if (acc_get_num_devices (acc_device_nvidia) == 0)
-    return 0;
-
   if (acc_get_current_cuda_context () != 0)
     abort ();
 
@@ -20,18 +17,28 @@ main (int argc, char **argv)
 
   acc_shutdown (acc_device_host);
 
-  if (acc_get_num_devices (acc_device_nvidia) == 0)
-    return 0;
-
   if (acc_get_current_cuda_context () != 0)
     abort ();
 
-  acc_init (acc_device_nvidia);
+  if (acc_get_num_devices (acc_device_nvidia))
+    {
+      acc_init (acc_device_nvidia);
 
-  if (acc_get_current_cuda_context () == 0)
-    abort ();
+      if (acc_get_current_cuda_context () == 0)
+	abort ();
+
+      acc_shutdown (acc_device_nvidia);
+    }
+
+  if (acc_get_num_devices (acc_device_radeon))
+    {
+      acc_init (acc_device_radeon);
+
+      if (acc_get_current_cuda_context () != 0)
+	abort ();
 
-  acc_shutdown (acc_device_nvidia);
+      acc_shutdown (acc_device_radeon);
+    }
 
   if (acc_get_current_cuda_context () != 0)
     abort ();
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-88.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-88.c
index 10f4ad8664a..c1cccd919c3 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-88.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-88.c
@@ -1,4 +1,4 @@
-/* { dg-do run } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include <stdio.h>
 #include <pthread.h>
@@ -47,10 +47,7 @@ main (int argc, char **argv)
   pthread_attr_t attr;
   pthread_t *tid;
 
-  if (acc_get_num_devices (acc_device_nvidia) == 0)
-    return 0;
-
-  acc_init (acc_device_nvidia);
+  acc_init (acc_device_default);
 
   x = (unsigned char *) malloc (N);
 
@@ -103,8 +100,6 @@ main (int argc, char **argv)
   if (acc_is_present (x, N) != 0)
     abort ();
 
-  acc_shutdown (acc_device_nvidia);
-
   return 0;
 }
 
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-89.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-89.c
index 061c4099c2d..6b4e3acf7db 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-89.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-89.c
@@ -1,4 +1,4 @@
-/* { dg-do run } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include <stdio.h>
 #include <pthread.h>
@@ -23,11 +23,16 @@ test (void *arg)
 
   tid = (int) (long) arg;
 
-  devnum = acc_get_device_num (acc_device_nvidia);
-  acc_set_device_num (devnum, acc_device_nvidia);
+  devnum = acc_get_device_num (acc_device_default);
+  acc_set_device_num (devnum, acc_device_default);
 
+#if ACC_DEVICE_TYPE_nvidia
   if (acc_get_current_cuda_context () == NULL)
     abort ();
+#else
+  if (acc_get_current_cuda_context () != NULL)
+    abort ();
+#endif
 
   p = (unsigned char *) malloc (N);
 
@@ -50,10 +55,7 @@ main (int argc, char **argv)
   pthread_attr_t attr;
   pthread_t *tid;
 
-  if (acc_get_num_devices (acc_device_nvidia) == 0)
-    return 0;
-
-  acc_init (acc_device_nvidia);
+  acc_init (acc_device_default);
 
   x = (unsigned char **) malloc (NTHREADS * N);
   d_x = (void **) malloc (NTHREADS * N);
@@ -110,8 +112,6 @@ main (int argc, char **argv)
 	abort ();
     }
 
-  acc_shutdown (acc_device_nvidia);
-
   return 0;
 }
 
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-92.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-92.c
index 18193e0e8f9..0043fb3109d 100644
--- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-92.c
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-92.c
@@ -1,4 +1,4 @@
-/* { dg-do run } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
 
 #include <pthread.h>
 #include <stdio.h>
@@ -22,11 +22,16 @@ test (void *arg)
 
   tid = (int) (long) arg;
 
-  devnum = acc_get_device_num (acc_device_nvidia);
-  acc_set_device_num (devnum, acc_device_nvidia);
+  devnum = acc_get_device_num (acc_device_default);
+  acc_set_device_num (devnum, acc_device_default);
 
+#if ACC_DEVICE_TYPE_nvidia
   if (acc_get_current_cuda_context () == NULL)
     abort ();
+#else
+  if (acc_get_current_cuda_context () != NULL)
+    abort ();
+#endif
 
   acc_copyout (x[tid], N);
 
@@ -49,10 +54,7 @@ main (int argc, char **argv)
   pthread_t *tid;
   unsigned char *p;
 
-  if (acc_get_num_devices (acc_device_nvidia) == 0)
-    return 0;
-
-  acc_init (acc_device_nvidia);
+  acc_init (acc_device_default);
 
   x = (unsigned char **) malloc (NTHREADS * N);
   d_x = (void **) malloc (NTHREADS * N);
@@ -104,8 +106,6 @@ main (int argc, char **argv)
 	abort ();
     }
 
-  acc_shutdown (acc_device_nvidia);
-
   return 0;
 }
 
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/lib-10.f90 b/libgomp/testsuite/libgomp.oacc-fortran/lib-10.f90
index 2875f162ba4..2b2f8fede02 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/lib-10.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/lib-10.f90
@@ -15,9 +15,7 @@ program main
   integer, parameter :: c_size = sizeof (c)
   integer, parameter :: r_size = sizeof (r)
 
-  if (acc_get_num_devices (acc_device_nvidia) .eq. 0) call exit
-
-  call acc_init (acc_device_nvidia)
+  call acc_init (acc_device_default)
 
   call set3d (.FALSE., a_3d_i, a_3d_c, a_3d_r)
 
@@ -39,8 +37,6 @@ program main
     end do
   end do
 
-  call acc_shutdown (acc_device_nvidia)
-
 contains
 
   subroutine set3d (clear, a_i, a_c, a_r)
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/lib-14.f90 b/libgomp/testsuite/libgomp.oacc-fortran/lib-14.f90
index bf35631c96b..90c2868e643 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/lib-14.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/lib-14.f90
@@ -1,7 +1,8 @@
 ! Exercise the data movement runtime library functions on non-shared memory
 ! targets.
 
-! { dg-do run { target openacc_nvidia_accel_selected } }
+! { dg-do run }
+! { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } }
 
 program main
   use openacc
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/lib-5.f90 b/libgomp/testsuite/libgomp.oacc-fortran/lib-5.f90
index 505b2c6f246..08808a4023b 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/lib-5.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/lib-5.f90
@@ -6,26 +6,52 @@ program main
 
   integer n
 
-  if (acc_get_num_devices (acc_device_nvidia) .eq. 0) call exit
+  if (acc_get_num_devices (acc_device_nvidia) .ne. 0) then
 
-  call acc_init (acc_device_nvidia)
+     call acc_init (acc_device_nvidia)
 
-  n = 0
+     n = 0
 
-  call acc_set_device_num (n, acc_device_nvidia)
+     call acc_set_device_num (n, acc_device_nvidia)
 
-  if (acc_get_device_num (acc_device_nvidia) .ne. 0) STOP 1
+     if (acc_get_device_num (acc_device_nvidia) .ne. 0) stop 11
 
-  if (acc_get_num_devices (acc_device_nvidia) .gt. 1) then
+     if (acc_get_num_devices (acc_device_nvidia) .gt. 1) then
 
-    n = 1
+        n = 1
 
-    call acc_set_device_num (n, acc_device_nvidia)
+        call acc_set_device_num (n, acc_device_nvidia)
 
-    if (acc_get_device_num (acc_device_nvidia) .ne. 1) STOP 2
+        if (acc_get_device_num (acc_device_nvidia) .ne. 1) stop 12
+
+     end if
+
+     call acc_shutdown (acc_device_nvidia)
 
   end if
 
-  call acc_shutdown (acc_device_nvidia)
+  if (acc_get_num_devices (acc_device_radeon) .ne. 0) then
+
+     call acc_init (acc_device_radeon)
+
+     n = 0
+
+     call acc_set_device_num (n, acc_device_radeon)
+
+     if (acc_get_device_num (acc_device_radeon) .ne. 0) stop 21
+
+     if (acc_get_num_devices (acc_device_radeon) .gt. 1) then
+
+        n = 1
+
+        call acc_set_device_num (n, acc_device_radeon)
+
+        if (acc_get_device_num (acc_device_radeon) .ne. 1) stop 22
+
+     end if
+
+     call acc_shutdown (acc_device_radeon)
+
+  end if
 
 end program
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/lib-7.f90 b/libgomp/testsuite/libgomp.oacc-fortran/lib-7.f90
index 2ce93c359ca..fa610b16d34 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/lib-7.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/lib-7.f90
@@ -6,26 +6,52 @@ program main
 
   integer n
 
-  if (acc_get_num_devices (acc_device_nvidia) .eq. 0) call exit
+  if (acc_get_num_devices (acc_device_nvidia) .ne. 0) then
 
-  call acc_init (acc_device_nvidia)
+     call acc_init (acc_device_nvidia)
 
-  n = 0
+     n = 0
 
-  call acc_set_device_num (n, acc_device_nvidia)
+     call acc_set_device_num (n, acc_device_nvidia)
 
-  if (acc_get_device_num (acc_device_nvidia) .ne. 0) STOP 1
+     if (acc_get_device_num (acc_device_nvidia) .ne. 0) STOP 1
 
-  if (acc_get_num_devices (acc_device_nvidia) .gt. 1) then
+     if (acc_get_num_devices (acc_device_nvidia) .gt. 1) then
 
-    n = 1
+        n = 1
 
-    call acc_set_device_num (n, acc_device_nvidia)
+        call acc_set_device_num (n, acc_device_nvidia)
 
-    if (acc_get_device_num (acc_device_nvidia) .ne. 1) STOP 2
+        if (acc_get_device_num (acc_device_nvidia) .ne. 1) STOP 2
+
+     end if
+
+     call acc_shutdown (acc_device_nvidia)
 
   end if
 
-  call acc_shutdown (acc_device_nvidia)
+  if (acc_get_num_devices (acc_device_radeon) .ne. 0) then
+
+     call acc_init (acc_device_radeon)
+
+     n = 0
+
+     call acc_set_device_num (n, acc_device_radeon)
+
+     if (acc_get_device_num (acc_device_radeon) .ne. 0) STOP 1
+
+     if (acc_get_num_devices (acc_device_radeon) .gt. 1) then
+
+        n = 1
+
+        call acc_set_device_num (n, acc_device_radeon)
+
+        if (acc_get_device_num (acc_device_radeon) .ne. 1) STOP 2
+
+     end if
+
+     call acc_shutdown (acc_device_radeon)
+
+  end if
 
 end program
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/lib-8.f90 b/libgomp/testsuite/libgomp.oacc-fortran/lib-8.f90
index 263cedb5c5b..2b36b4078f6 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/lib-8.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/lib-8.f90
@@ -16,9 +16,7 @@ program main
   integer, parameter :: c_size = sizeof (c)
   integer, parameter :: r_size = sizeof (r)
 
-  if (acc_get_num_devices (acc_device_nvidia) .eq. 0) call exit
-
-  call acc_init (acc_device_nvidia)
+  call acc_init (acc_device_default)
 
   call set3d (.FALSE., a_3d_i, a_3d_c, a_3d_r)
 
@@ -40,8 +38,6 @@ program main
     end do
   end do
 
-  call acc_shutdown (acc_device_nvidia)
-
 contains
 
   subroutine set3d (clear, a_i, a_c, a_r)
-- 
2.30.2

