From 0ff4a818743c47108883d6dd863f695479efc451 Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Thu, 2 Jul 2015 08:29:15 -0500
Subject: [PATCH] XFail some tests that don't work on Apple

---
 pyopencl/characterize/__init__.py | 12 ++++++++++++
 test/test_algorithm.py            |  7 ++++++-
 test/test_array.py                |  8 ++++++++
 test/test_clmath.py               |  5 +++++
 test/test_wrapper.py              |  5 +++++
 5 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/pyopencl/characterize/__init__.py b/pyopencl/characterize/__init__.py
index a671c095..e4676a68 100644
--- a/pyopencl/characterize/__init__.py
+++ b/pyopencl/characterize/__init__.py
@@ -320,3 +320,15 @@ def get_simd_group_size(dev, type_size):
         return 1
 
     return None
+
+
+def has_struct_arg_count_bug(dev):
+    """Checks whether the device is expected to have the
+    `argument counting bug <https://github.com/pocl/pocl/issues/197>`_.
+    """
+
+    if dev.platform.name == "Apple" and dev.type & cl.device_type.CPU:
+        return True
+    if dev.platform.name == "Portable Computing Language":
+        return True
+    return False
diff --git a/test/test_algorithm.py b/test/test_algorithm.py
index 88c3097b..5518d508 100644
--- a/test/test_algorithm.py
+++ b/test/test_algorithm.py
@@ -327,8 +327,13 @@ def test_dot(ctx_factory):
     context = ctx_factory()
     queue = cl.CommandQueue(context)
 
+    dev = context.devices[0]
+    from pyopencl.characterize import has_struct_arg_count_bug
+    if has_struct_arg_count_bug(dev):
+        pytest.xfail("device has struct arg counting bug")
+
     dtypes = [np.float32, np.complex64]
-    if has_double_support(context.devices[0]):
+    if has_double_support(dev):
         dtypes.extend([np.float64, np.complex128])
 
     for a_dtype in dtypes:
diff --git a/test/test_array.py b/test/test_array.py
index ecfd3ba9..adb2f744 100644
--- a/test/test_array.py
+++ b/test/test_array.py
@@ -95,6 +95,11 @@ def test_mix_complex(ctx_factory):
     context = ctx_factory()
     queue = cl.CommandQueue(context)
 
+    dev = context.devices[0]
+    from pyopencl.characterize import has_struct_arg_count_bug
+    if has_struct_arg_count_bug(dev):
+        pytest.xfail("device has struct arg counting bug")
+
     size = 10
 
     dtypes = [
@@ -169,6 +174,9 @@ def test_pow_neg1_vs_inv(ctx_factory):
     if not has_double_support(device):
         from pytest import skip
         skip("double precision not supported on %s" % device)
+    from pyopencl.characterize import has_struct_arg_count_bug
+    if has_struct_arg_count_bug(device):
+        pytest.xfail("device has struct arg counting bug")
 
     a_dev = make_random_array(queue, np.complex128, 20000)
 
diff --git a/test/test_clmath.py b/test/test_clmath.py
index 64af63d4..4173180e 100644
--- a/test/test_clmath.py
+++ b/test/test_clmath.py
@@ -76,6 +76,11 @@ def make_unary_function_test(name, limits=(0, 1), threshold=0, use_complex=False
         gpu_func = getattr(clmath, name)
         cpu_func = getattr(np, numpy_func_names.get(name, name))
 
+        dev = context.devices[0]
+        from pyopencl.characterize import has_struct_arg_count_bug
+        if use_complex and has_struct_arg_count_bug(dev):
+            pytest.xfail("device has struct arg counting bug")
+
         if has_double_support(context.devices[0]):
             if use_complex:
                 dtypes = [np.float32, np.float64, np.complex64, np.complex128]
diff --git a/test/test_wrapper.py b/test/test_wrapper.py
index 01382ec6..c5bd45c0 100644
--- a/test/test_wrapper.py
+++ b/test/test_wrapper.py
@@ -27,6 +27,7 @@ THE SOFTWARE.
 
 import numpy as np
 import numpy.linalg as la
+import pytest
 
 import pyopencl as cl
 import pyopencl.array as cl_array
@@ -675,6 +676,10 @@ def test_enqueue_task(ctx_factory):
 
 
 def test_platform_get_devices(platform):
+    if platform.name == "Apple":
+        pytest.xfail("Apple doesn't understand all the values we pass "
+                "for dev_type")
+
     dev_types = [cl.device_type.ACCELERATOR, cl.device_type.ALL,
                  cl.device_type.CPU, cl.device_type.DEFAULT, cl.device_type.GPU]
     if (platform._get_cl_version() >= (1, 2) and
-- 
GitLab