File: test_version.c

package info (click to toggle)
pocl 7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 29,768 kB
  • sloc: lisp: 151,669; ansic: 135,425; cpp: 65,801; python: 1,846; sh: 1,084; ruby: 255; pascal: 231; tcl: 180; makefile: 174; asm: 81; java: 72; xml: 49
file content (71 lines) | stat: -rw-r--r-- 2,028 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* This test is part of pocl.
 * It is intended to run as the first test of the
 * testsuite, checking that the tests are 
 * not run against an other installed OpenCL library.
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "poclu.h"
#include "config.h"
#include "pocl_version.h"

#define S(A) #A
#define STRINGIFY(X) S(X)

int main(void)
{
	cl_context context;
	cl_device_id did;
	cl_platform_id pid; 
	cl_command_queue queue;
	size_t rvs;
	char result[1024];
	char *needle;

	/* Check that the default platform we get from the ICD loader
	 * matches the pocl version string this binary was built against. */
	CHECK_CL_ERROR (poclu_get_any_device2 (&context, &did, &queue, &pid));
        TEST_ASSERT (context);
        TEST_ASSERT (did);
        TEST_ASSERT (queue);

	CHECK_CL_ERROR(clGetPlatformInfo( pid, CL_PLATFORM_VERSION,
				sizeof(result), result, &rvs));

	result[rvs]=0;	// spec doesn't say it is null-terminated.

        const char *expected = "OpenCL " STRINGIFY(POCL_PLATFORM_VERSION_MAJOR)
         "." STRINGIFY(POCL_PLATFORM_VERSION_MINOR) " PoCL " POCL_VERSION_FULL;
        if (strncmp (result, expected, strlen (expected)) != 0)
          {
            printf ("Error: platform is: %s\n", result);
            printf ("Should be: %s\n", expected);
            return 2;
          }
        else
          {
            printf ("Platform is: %s\n", result);
          }

	/* Pocl devices have the form 'type'-'details', if details are
	 * available. If not, they are of the form 'type'.
	 * print here only the type, as the details will be computer
	 * dependent */
	CHECK_CL_ERROR(clGetDeviceInfo( did, CL_DEVICE_NAME,
			      sizeof(result), result, NULL));

	result[rvs]=0;
	needle = strchr(result, '-');
	if( needle != NULL ){
            *needle = 0;
        }
	printf("%s\n", result);

        CHECK_CL_ERROR (clReleaseCommandQueue (queue));
        CHECK_CL_ERROR (clReleaseContext (context));
        CHECK_CL_ERROR (clUnloadPlatformCompiler (pid));
        return 0;
}