• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.graphics.cts;
18 
19 import static android.opengl.EGL14.*;
20 
21 import android.opengl.EGL14;
22 import android.opengl.EGLConfig;
23 import android.opengl.EGLDisplay;
24 
25 import androidx.test.filters.SmallTest;
26 
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.junit.runners.BlockJUnit4ClassRunner;
32 
33 // This class contains tests for the Linux kernel sync file system, and the NDK interfaces for it
34 // (android/sync.h). Unfortunately, the interfaces exposed by the kernel make it difficult to test
35 // for a couple reasons:
36 //
37 // (a) There isn't a standard kernel interface for creating a fence/sync_file. Drivers can create
38 //     them via driver-specific interfaces. Currently this means we have to use APIs like OpenGL ES
39 //     or interact with the system compositor in order to generate fences. That makes tests larger
40 //     and more complicated than they otherwise need to be.
41 //
42 //     This is further complicated by the fact that most of the time GPU work executes in the order
43 //     it was submitted to the kernel; there isn't much out-of-order execution in practice. So
44 //     detecting some kinds of bugs is difficult using only the GPU as an event source.
45 //
46 // (b) A core principal of sync files is that they cannot be created until the work that will
47 //     signal them has been submitted to the kernel, and will complete without further action from
48 //     userland. This means that it is impossible to reliably do something before a sync file has
49 //     signaled.
50 @SmallTest
51 @RunWith(BlockJUnit4ClassRunner.class)
52 public class SyncTest {
53 
54     static {
55         System.loadLibrary("ctsgraphics_jni");
56     }
57 
58     private static final String TAG = SyncTest.class.getSimpleName();
59     private static final boolean DEBUG = false;
60 
61     private EGLDisplay mEglDisplay = EGL_NO_DISPLAY;
62     private EGLConfig mEglConfig = null;
63 
64     @Before
setup()65     public void setup() throws Throwable {
66         mEglDisplay = EGL14.eglGetDisplay(EGL_DEFAULT_DISPLAY);
67         if (mEglDisplay == EGL_NO_DISPLAY) {
68             throw new RuntimeException("no EGL display");
69         }
70         int[] major = new int[1];
71         int[] minor = new int[1];
72         if (!EGL14.eglInitialize(mEglDisplay, major, 0, minor, 0)) {
73             throw new RuntimeException("error in eglInitialize");
74         }
75 
76         int[] numConfigs = new int[1];
77         EGLConfig[] configs = new EGLConfig[1];
78         if (!EGL14.eglChooseConfig(mEglDisplay,
79                 new int[] {
80                     EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
81                     EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
82                     EGL_BUFFER_SIZE, 32,
83                     EGL_NONE},
84                 0, configs, 0, 1, numConfigs, 0)) {
85             throw new RuntimeException("eglChooseConfig failed");
86         }
87         mEglConfig = configs[0];
88     }
89 
90     @After
teardown()91     public void teardown() throws Throwable {
92         EGL14.eglTerminate(mEglDisplay);
93     }
94 
95     @Test
testMergedSyncSignalOrder()96     public void testMergedSyncSignalOrder() {
97         // TODO
98     }
99 
100     private static final int STATUS_UNSIGNALED = 0;
101     private static final int STATUS_SIGNALED = 1;
102     private static final int STATUS_ERROR = -1;
103     private static class SyncFileInfo {
104         String name;            // char name[32]
105         int status;             // __s32 status
106         long flags;             // __u32 flags
107         SyncFenceInfo[] fences; // __u32 num_fences; __u64 sync_fence_info
108     }
109     private static class SyncFenceInfo {
110         String name;            // char obj_name[32]
111         String driver_name;     // char driver_name[32]
112         int status;             // __s32 status
113         long flags;             // __u32 flags
114         long timestamp_ns;      // __u64 timestamp_ns
115     }
116 
nSyncPoll(int[] fds, int[] status)117     private static native boolean nSyncPoll(int[] fds, int[] status);
nSyncMerge(String name, int fd1, int fd2)118     private static native int nSyncMerge(String name, int fd1, int fd2);
nSyncFileInfo(int fd)119     private static native SyncFileInfo nSyncFileInfo(int fd);
nSyncClose(int fd)120     private static native void nSyncClose(int fd);
121 }
122