summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGard Spreemann <gspr@nonempty.org>2022-10-12 20:04:44 +0200
committerGard Spreemann <gspr@nonempty.org>2022-10-12 20:26:11 +0200
commitfdf4be1df3c6cf2db3255eb719d6bcabb694ae6d (patch)
treeea99a388552689fb2b7491c52962b566d0626f31
parentc400964a57cd5aa0b0705cfcd29fc9c97dc26070 (diff)
Add autopkgtests
Run the upstream testsuite on a CPU-based POCL device. The POCL platform and device are detected before running.
-rw-r--r--debian/changelog6
-rw-r--r--debian/tests/control3
-rw-r--r--debian/tests/find_pocl.c86
-rwxr-xr-xdebian/tests/tests.sh91
4 files changed, 186 insertions, 0 deletions
diff --git a/debian/changelog b/debian/changelog
index eac6c9af..44d8d16a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+clblast (1.5.2-3) UNRELEASED; urgency=medium
+
+ * Add autopkgtests.
+
+ -- Gard Spreemann <gspr@nonempty.org> Wed, 12 Oct 2022 20:07:27 +0200
+
clblast (1.5.2-2) unstable; urgency=medium
* Add patch to correct typo in installation path of CMake
diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 00000000..3bfaea7a
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,3 @@
+Tests: tests.sh
+Depends: clblast-tests, colorized-logs, gcc, ocl-icd-opencl-dev | opencl-dev, pocl-opencl-icd
+Restrictions: allow-stderr
diff --git a/debian/tests/find_pocl.c b/debian/tests/find_pocl.c
new file mode 100644
index 00000000..dfd25a82
--- /dev/null
+++ b/debian/tests/find_pocl.c
@@ -0,0 +1,86 @@
+/*
+ * Identify a POCL platform and device ID for running autopkgtests.
+ */
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+
+#define CL_MINIMUM_OPENCL_VERSION 120
+#define CL_TARGET_OPENCL_VERSION 120
+#define CL_CL_1_2_DEFAULT_BUILD
+
+#include <CL/opencl.h>
+
+static const cl_uint MAX_PLATFORMS = 128;
+static const cl_uint MAX_DEVICES = 128;
+static const size_t MAX_PLATFORM_NAME_LEN = 4096;
+static const char POCL_NAME[] = "Portable Computing Language";
+
+int main(int argc, char ** argv)
+{
+ cl_uint num_platforms = 0;
+ cl_platform_id platforms[MAX_PLATFORMS];
+ cl_int status = clGetPlatformIDs(MAX_PLATFORMS, platforms, &num_platforms);
+ if (status != CL_SUCCESS)
+ {
+ fprintf(stderr, "Failed to query OpenCL platforms.\n");
+ return 1;
+ }
+ num_platforms = num_platforms < MAX_PLATFORMS ? num_platforms : MAX_PLATFORMS;
+ if (num_platforms < 1)
+ {
+ fprintf(stderr, "Found no OpenCL platforms.\n");
+ return 1;
+ }
+
+ char platform_name[MAX_PLATFORM_NAME_LEN];
+ size_t platform_name_len = 0;
+ bool pocl_platform_found = false;
+ cl_uint platform_idx = MAX_PLATFORMS;
+ for (cl_uint i = 0; i < num_platforms; ++i)
+ {
+ status = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, MAX_PLATFORM_NAME_LEN-1, platform_name, &platform_name_len);
+ if (status != CL_SUCCESS)
+ {
+ fprintf(stderr, "Failed to get name for OpenCL platform number %u.\n", i);
+ return 1;
+ }
+ platform_name[platform_name_len < MAX_PLATFORM_NAME_LEN - 1 ? platform_name_len : MAX_PLATFORM_NAME_LEN - 1] = '\0';
+ if (strcmp(platform_name, POCL_NAME) == 0)
+ {
+ platform_idx = i;
+ pocl_platform_found = true;
+ break;
+ }
+ }
+
+ if (!pocl_platform_found)
+ {
+ fprintf(stderr, "Could not find the POCL platform.\n");
+ return 1;
+ }
+
+
+ cl_device_id devices[MAX_DEVICES];
+ cl_uint num_devices = 0;
+ cl_uint device_idx = MAX_DEVICES;
+ status = clGetDeviceIDs(platforms[platform_idx], CL_DEVICE_TYPE_CPU, MAX_DEVICES, devices, &num_devices);
+ if (status != CL_SUCCESS)
+ {
+ fprintf(stderr, "Failed to query OpenCL CPU devices for platform.\n");
+ return 1;
+ }
+ num_devices = num_devices < MAX_DEVICES ? num_devices : MAX_DEVICES;
+
+ if (num_devices < 1)
+ {
+ fprintf(stderr, "Failed to find any devices on platform.\n");
+ return 1;
+ }
+
+ device_idx = 0; // We default to running on the first POCL device.
+
+ printf("%u %u\n", platform_idx, device_idx);
+ return 0;
+}
diff --git a/debian/tests/tests.sh b/debian/tests/tests.sh
new file mode 100755
index 00000000..31f445e8
--- /dev/null
+++ b/debian/tests/tests.sh
@@ -0,0 +1,91 @@
+#!/bin/sh
+
+set -u
+set -e
+
+tests="\
+xamax \
+xasum \
+xaxpy \
+xaxpybatched \
+xcol2im \
+xconvgemm \
+xcopy \
+xdot \
+xdotc \
+xdotu \
+xgbmv \
+xgemm \
+xgemmbatched \
+xgemmstridedbatched \
+xgemv \
+xger \
+xgerc \
+xgeru \
+xhad \
+xhbmv \
+xhemm \
+xhemv \
+xher \
+xher2 \
+xher2k \
+xherk \
+xhpmv \
+xhpr \
+xhpr2 \
+xim2col \
+xnrm2 \
+xomatcopy \
+xsbmv \
+xscal \
+xspmv \
+xspr \
+xspr2 \
+xswap \
+xsymm \
+xsymv \
+xsyr \
+xsyr2 \
+xsyr2k \
+xsyrk \
+xtbmv \
+xtpmv \
+xtrmm \
+xtrmv \
+xtrsm \
+xtrsv"
+
+gcc -std=c11 -Wall -pedantic -o ${AUTOPKGTEST_TMP}/find_pocl debian/tests/find_pocl.c -lOpenCL
+
+pocl_platform_and_device=$(${AUTOPKGTEST_TMP}/find_pocl)
+pocl_platform=$(echo $pocl_platform_and_device | awk '{ print $1 }')
+pocl_device=$(echo $pocl_platform_and_device | awk '{ print $2 }')
+
+echo "POCL is platform ${pocl_platform}, device ${pocl_device}."
+
+set +e
+
+errors=0
+
+for test in $tests
+do
+ echo "--------------------------------------------------"
+ echo "Running test set ${test}."
+ echo "--------------------------------------------------"
+ output=$(/usr/bin/clblast_test_${test} -platform $pocl_platform -device $pocl_device)
+ if [ $? -ne 0 ]
+ then
+ errors=$(($errors+1))
+ fi
+ printf "%s\n" "$output" | ansi2txt
+done
+
+echo "--------------------------------------------------"
+echo "$errors errors encounted."
+echo "--------------------------------------------------"
+
+if [ $errors -ne 0 ]
+then
+ exit 1
+fi
+