OSDN Git Service

Test write permission
[android-x86/hardware-intel-common-libva.git] / libva / 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 #include <va_x11.h>
26
27 #include "assert.h"
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <stdint.h>
33 #include <dlfcn.h>
34
35 #define ASSERT  assert
36
37 Display *dpy;
38 VADisplay va_dpy;
39 VAStatus va_status;
40 int major_version, minor_version;
41 int print_status = 0;
42 int num_profiles;
43 VAProfile *profiles = NULL;
44
45 void pre();
46 void test();
47 void post();
48
49 void status(const char *msg, ...)
50 {
51   if (!print_status) return;
52   va_list args;
53   printf("--- ");
54   va_start(args, msg);
55   vfprintf(stdout, msg, args);
56   va_end(args);
57 }
58
59
60 int main(int argc, const char* argv[])
61 {
62   const char *name = rindex(argv[0], '/');
63   if (name)
64       name++;
65   else
66       name = argv[0];
67   printf("*** %s: %s\n", name, TEST_DESCRIPTION);
68   pre();
69   print_status = 1;
70   test();
71   print_status = 0;
72   post();
73   printf("*** %s: Finished\n", name);
74   return 0;
75 }
76
77 void test_init()
78 {
79   dpy = XOpenDisplay(NULL);
80   ASSERT( dpy );
81   status("XOpenDisplay: dpy = %08x\n", dpy);
82   
83   va_dpy = vaGetDisplay(dpy);
84   ASSERT( va_dpy );  
85   status("vaGetDisplay: va_dpy = %08x\n", va_dpy);
86   
87   va_status = vaInitialize(va_dpy, &major_version, &minor_version);
88   ASSERT( VA_STATUS_SUCCESS == va_status );
89   status("vaInitialize: major = %d minor = %d\n", major_version, minor_version);
90 }
91
92 void test_terminate()
93 {
94   va_status = vaTerminate(va_dpy);
95   ASSERT( VA_STATUS_SUCCESS == va_status );
96   status("vaTerminate\n");
97
98   XCloseDisplay(dpy);
99   status("XCloseDisplay\n");
100
101   if (profiles)
102   {
103       free(profiles);
104       profiles = NULL;
105   }
106 }
107
108 #define PROFILE(profile)        case VAProfile##profile:        return("VAProfile" #profile);
109
110 const char *profile2string(VAProfile profile)
111 {
112     switch(profile)
113     {
114         PROFILE(MPEG2Simple)
115         PROFILE(MPEG2Main)
116         PROFILE(MPEG4Simple)
117         PROFILE(MPEG4AdvancedSimple)
118         PROFILE(MPEG4Main)
119         PROFILE(H264Baseline)
120         PROFILE(H264Main)
121         PROFILE(H264High)
122         PROFILE(VC1Simple)
123         PROFILE(VC1Main)
124         PROFILE(VC1Advanced)
125     }
126     ASSERT(0);
127     return "Unknown";
128 }
129
130 #define ENTRYPOINT(profile)     case VAEntrypoint##profile:     return("VAEntrypoint" #profile);
131
132 const char *entrypoint2string(VAEntrypoint entrypoint)
133 {
134     switch(entrypoint)
135     {
136         ENTRYPOINT(VLD)
137         ENTRYPOINT(IZZ)
138         ENTRYPOINT(IDCT)
139         ENTRYPOINT(MoComp)
140         ENTRYPOINT(Deblocking)
141     }
142     ASSERT(0);
143     return "Unknown";
144 }
145
146
147 void test_profiles()
148 {
149     int max_profiles;
150     int i;
151     max_profiles = vaMaxNumProfiles(va_dpy);
152     status("vaMaxNumProfiles = %d\n", max_profiles);
153     ASSERT(max_profiles > 0);
154     profiles = malloc(max_profiles * sizeof(VAProfile));
155     ASSERT(profiles);
156       
157     va_status = vaQueryConfigProfiles(va_dpy, profiles, &num_profiles);
158     ASSERT( VA_STATUS_SUCCESS == va_status );
159       
160     status("vaQueryConfigProfiles reports %d profiles\n", num_profiles);
161     ASSERT(num_profiles <= max_profiles);
162     ASSERT(num_profiles > 0);
163     
164     if (print_status)
165     {
166         for(i = 0; i < num_profiles; i++)
167         {
168             status("  profile %d [%s]\n", profiles[i], profile2string(profiles[i]));
169         }
170     }
171 }