Fix NVIDIA driver detection.
[profile/ivi/libva.git] / test / test_common.c
1 /*
2  * Copyright (c) 2007 Intel Corporation. All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  * 
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 #ifdef IN_LIBVA
26 #include <va_x11.h>
27 #else
28 #include <va/va_x11.h>
29 #endif
30
31 #include "assert.h"
32 #include <stdarg.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <stdint.h>
37 #include <dlfcn.h>
38
39 #define ASSERT  assert
40
41 Display *dpy;
42 VADisplay va_dpy;
43 VAStatus va_status;
44 int major_version, minor_version;
45 int print_status = 0;
46 int num_profiles;
47 VAProfile *profiles = NULL;
48
49 void pre();
50 void test();
51 void post();
52
53 void status(const char *msg, ...)
54 {
55   if (!print_status) return;
56   va_list args;
57   printf("--- ");
58   va_start(args, msg);
59   vfprintf(stdout, msg, args);
60   va_end(args);
61 }
62
63
64 int main(int argc, const char* argv[])
65 {
66   const char *name = strrchr(argv[0], '/');
67   if (name)
68       name++;
69   else
70       name = argv[0];
71   printf("*** %s: %s\n", name, TEST_DESCRIPTION);
72   pre();
73   print_status = 1;
74   test();
75   print_status = 0;
76   post();
77   printf("*** %s: Finished\n", name);
78   return 0;
79 }
80
81 void test_init()
82 {
83   dpy = XOpenDisplay(NULL);
84   ASSERT( dpy );
85   status("XOpenDisplay: dpy = %08x\n", dpy);
86   
87   va_dpy = vaGetDisplay(dpy);
88   ASSERT( va_dpy );  
89   status("vaGetDisplay: va_dpy = %08x\n", va_dpy);
90   
91   va_status = vaInitialize(va_dpy, &major_version, &minor_version);
92   ASSERT( VA_STATUS_SUCCESS == va_status );
93   status("vaInitialize: major = %d minor = %d\n", major_version, minor_version);
94 }
95
96 void test_terminate()
97 {
98   va_status = vaTerminate(va_dpy);
99   ASSERT( VA_STATUS_SUCCESS == va_status );
100   status("vaTerminate\n");
101
102   XCloseDisplay(dpy);
103   status("XCloseDisplay\n");
104
105   if (profiles)
106   {
107       free(profiles);
108       profiles = NULL;
109   }
110 }
111
112 #define PROFILE(profile)        case VAProfile##profile:        return("VAProfile" #profile);
113
114 const char *profile2string(VAProfile profile)
115 {
116     switch(profile)
117     {
118         PROFILE(MPEG2Simple)
119         PROFILE(MPEG2Main)
120         PROFILE(MPEG4Simple)
121         PROFILE(MPEG4AdvancedSimple)
122         PROFILE(MPEG4Main)
123         PROFILE(H264Baseline)
124         PROFILE(H264Main)
125         PROFILE(H264High)
126         PROFILE(VC1Simple)
127         PROFILE(VC1Main)
128         PROFILE(VC1Advanced)
129     }
130     ASSERT(0);
131     return "Unknown";
132 }
133
134 #define ENTRYPOINT(profile)     case VAEntrypoint##profile:     return("VAEntrypoint" #profile);
135
136 const char *entrypoint2string(VAEntrypoint entrypoint)
137 {
138     switch(entrypoint)
139     {
140         ENTRYPOINT(VLD)
141         ENTRYPOINT(IZZ)
142         ENTRYPOINT(IDCT)
143         ENTRYPOINT(MoComp)
144         ENTRYPOINT(Deblocking)
145     }
146     ASSERT(0);
147     return "Unknown";
148 }
149
150
151 void test_profiles()
152 {
153     int max_profiles;
154     int i;
155     max_profiles = vaMaxNumProfiles(va_dpy);
156     status("vaMaxNumProfiles = %d\n", max_profiles);
157     ASSERT(max_profiles > 0);
158     profiles = malloc(max_profiles * sizeof(VAProfile));
159     ASSERT(profiles);
160       
161     va_status = vaQueryConfigProfiles(va_dpy, profiles, &num_profiles);
162     ASSERT( VA_STATUS_SUCCESS == va_status );
163       
164     status("vaQueryConfigProfiles reports %d profiles\n", num_profiles);
165     ASSERT(num_profiles <= max_profiles);
166     ASSERT(num_profiles > 0);
167     
168     if (print_status)
169     {
170         for(i = 0; i < num_profiles; i++)
171         {
172             status("  profile %d [%s]\n", profiles[i], profile2string(profiles[i]));
173         }
174     }
175 }