GLES2Dbg: initial tests

Also remove GLFunction enum, since the enums already exist in
DebuggerMessage.Function

Change-Id: If273041b73ab51c9aff405ce6d6cce387b4a3725
Signed-off-by: David Li <davidxli@google.com>
This commit is contained in:
David Li
2011-04-15 11:09:16 -07:00
parent c26ad8b03b
commit 7698df91fa
11 changed files with 235 additions and 272 deletions

View File

@@ -6,5 +6,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -5,7 +5,8 @@ Bundle-SymbolicName: GLESv2DebuggerClient; singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.android.glesv2debugger.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime
org.eclipse.core.runtime,
org.junit
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: lib/host-libprotobuf-java-2.3.0-lite.jar,

View File

@@ -1,4 +1,5 @@
source.. = src/
source.. = src/,\
test/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\

View File

@@ -1,67 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright 2011, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
if __name__ == "__main__":
externs = []
lines = open("../../../frameworks/base/opengl/libs/GLES2_dbg/gl2_api_annotated.in").readlines()
output = open("src/com/android/glesv2debugger/GLFunction.java", "w")
i = 0
output.write(
"""/*
** Copyright 2011, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
// auto generated by generate_GLFunction_java.py"
package com.android.glesv2debugger;
public enum GLFunction {
""")
index = 0
for line in lines:
if line.find("API_ENTRY(") >= 0: # a function prototype
returnType = line[0: line.find(" API_ENTRY(")]
functionName = line[line.find("(") + 1: line.find(")")] #extract GL function name
output.write(" %s(%d, DebuggerMessage.Message.Function.%s),\n" % (functionName, index, functionName))
index += 1
output.write(""" ;
public final int index;
public final DebuggerMessage.Message.Function function;
GLFunction(final int index, final DebuggerMessage.Message.Function function) {
this.index = index;
this.function = function;
}
}""")

View File

@@ -37,12 +37,14 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import java.io.IOException;
import java.util.HashMap;
public class BreakpointOption extends ScrolledComposite implements SelectionListener {
public class BreakpointOption extends ScrolledComposite implements SelectionListener,
ProcessMessage {
SampleView sampleView;
HashMap<Function, Button> buttonsBreak = new HashMap<Function, Button>();
Button[] buttonsBreak = new Button[Function.values().length];
/** cache of buttonsBreak[Function.getNumber()].getSelection */
boolean[] breakpoints = new boolean[Function.values().length];
BreakpointOption(SampleView sampleView, Composite parent) {
super(parent, SWT.NO_BACKGROUND | SWT.V_SCROLL | SWT.H_SCROLL);
@@ -62,7 +64,8 @@ public class BreakpointOption extends ScrolledComposite implements SelectionList
btn.addSelectionListener(this);
btn.setText("Break");
btn.setSelection(false);
buttonsBreak.put(Function.values()[i], btn);
breakpoints[Function.values()[i].getNumber()] = btn.getSelection();
buttonsBreak[Function.values()[i].getNumber()] = btn;
}
Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
@@ -74,9 +77,9 @@ public class BreakpointOption extends ScrolledComposite implements SelectionList
this.layout();
}
void setBreakpoint(Function function, boolean enabled) {
void setBreakpoint(final int contextId, final Function function, final boolean enabled) {
Message.Builder builder = Message.newBuilder();
builder.setContextId(0); // FIXME: proper context id
builder.setContextId(contextId);
builder.setType(Type.Response);
builder.setExpectResponse(false);
builder.setFunction(Function.SETPROP);
@@ -84,13 +87,17 @@ public class BreakpointOption extends ScrolledComposite implements SelectionList
builder.setArg0(function.getNumber());
builder.setArg1(enabled ? 1 : 0);
sampleView.messageQueue.addCommand(builder.build());
breakpoints[function.getNumber()] = enabled;
}
@Override
public void widgetSelected(SelectionEvent e) {
Button btn = (Button) e.widget;
Group group = (Group) btn.getParent();
setBreakpoint(Function.valueOf(group.getText()), btn.getSelection());
int contextId = 0;
if (sampleView.current != null)
contextId = sampleView.current.contextId;
setBreakpoint(contextId, Function.valueOf(group.getText()), btn.getSelection());
}
@Override
@@ -100,6 +107,8 @@ public class BreakpointOption extends ScrolledComposite implements SelectionList
private Function lastFunction = Function.NEG;
public boolean processMessage(final MessageQueue queue, final Message msg) throws IOException {
if (!breakpoints[msg.getFunction().getNumber()])
return false;
// use DefaultProcessMessage just to register the GL call
// but do not send response
final int contextId = msg.getContextId();
@@ -158,9 +167,9 @@ public class BreakpointOption extends ScrolledComposite implements SelectionList
builder.setFunction(Function.CONTINUE);
else if (s.startsWith("r"))
{
Button btn = buttonsBreak.get(msg.getFunction());
Button btn = buttonsBreak[msg.getFunction().getNumber()];
btn.setSelection(false);
setBreakpoint(msg.getFunction(), false);
setBreakpoint(msg.getContextId(), msg.getFunction(), false);
builder.setExpectResponse(false);
}
else

View File

@@ -1131,8 +1131,7 @@ public class CodeGen implements IRunnableWithProgress {
private IProgressMonitor progress;
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
public void run(IProgressMonitor monitor) {
progress.beginTask("CodeGenFrames", count + 2);
Context ctx = dbgCtx.getFrame(0).startContext.clone();
codeGenSetup(ctx);

View File

@@ -1,173 +0,0 @@
/*
** Copyright 2011, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
// auto generated by generate_GLFunction_java.py"
package com.android.glesv2debugger;
public enum GLFunction {
glActiveTexture(0, DebuggerMessage.Message.Function.glActiveTexture),
glAttachShader(1, DebuggerMessage.Message.Function.glAttachShader),
glBindAttribLocation(2, DebuggerMessage.Message.Function.glBindAttribLocation),
glBindBuffer(3, DebuggerMessage.Message.Function.glBindBuffer),
glBindFramebuffer(4, DebuggerMessage.Message.Function.glBindFramebuffer),
glBindRenderbuffer(5, DebuggerMessage.Message.Function.glBindRenderbuffer),
glBindTexture(6, DebuggerMessage.Message.Function.glBindTexture),
glBlendColor(7, DebuggerMessage.Message.Function.glBlendColor),
glBlendEquation(8, DebuggerMessage.Message.Function.glBlendEquation),
glBlendEquationSeparate(9, DebuggerMessage.Message.Function.glBlendEquationSeparate),
glBlendFunc(10, DebuggerMessage.Message.Function.glBlendFunc),
glBlendFuncSeparate(11, DebuggerMessage.Message.Function.glBlendFuncSeparate),
glBufferData(12, DebuggerMessage.Message.Function.glBufferData),
glBufferSubData(13, DebuggerMessage.Message.Function.glBufferSubData),
glCheckFramebufferStatus(14, DebuggerMessage.Message.Function.glCheckFramebufferStatus),
glClear(15, DebuggerMessage.Message.Function.glClear),
glClearColor(16, DebuggerMessage.Message.Function.glClearColor),
glClearDepthf(17, DebuggerMessage.Message.Function.glClearDepthf),
glClearStencil(18, DebuggerMessage.Message.Function.glClearStencil),
glColorMask(19, DebuggerMessage.Message.Function.glColorMask),
glCompileShader(20, DebuggerMessage.Message.Function.glCompileShader),
glCompressedTexImage2D(21, DebuggerMessage.Message.Function.glCompressedTexImage2D),
glCompressedTexSubImage2D(22, DebuggerMessage.Message.Function.glCompressedTexSubImage2D),
glCopyTexImage2D(23, DebuggerMessage.Message.Function.glCopyTexImage2D),
glCopyTexSubImage2D(24, DebuggerMessage.Message.Function.glCopyTexSubImage2D),
glCreateProgram(25, DebuggerMessage.Message.Function.glCreateProgram),
glCreateShader(26, DebuggerMessage.Message.Function.glCreateShader),
glCullFace(27, DebuggerMessage.Message.Function.glCullFace),
glDeleteBuffers(28, DebuggerMessage.Message.Function.glDeleteBuffers),
glDeleteFramebuffers(29, DebuggerMessage.Message.Function.glDeleteFramebuffers),
glDeleteProgram(30, DebuggerMessage.Message.Function.glDeleteProgram),
glDeleteRenderbuffers(31, DebuggerMessage.Message.Function.glDeleteRenderbuffers),
glDeleteShader(32, DebuggerMessage.Message.Function.glDeleteShader),
glDeleteTextures(33, DebuggerMessage.Message.Function.glDeleteTextures),
glDepthFunc(34, DebuggerMessage.Message.Function.glDepthFunc),
glDepthMask(35, DebuggerMessage.Message.Function.glDepthMask),
glDepthRangef(36, DebuggerMessage.Message.Function.glDepthRangef),
glDetachShader(37, DebuggerMessage.Message.Function.glDetachShader),
glDisable(38, DebuggerMessage.Message.Function.glDisable),
glDisableVertexAttribArray(39, DebuggerMessage.Message.Function.glDisableVertexAttribArray),
glDrawArrays(40, DebuggerMessage.Message.Function.glDrawArrays),
glDrawElements(41, DebuggerMessage.Message.Function.glDrawElements),
glEnable(42, DebuggerMessage.Message.Function.glEnable),
glEnableVertexAttribArray(43, DebuggerMessage.Message.Function.glEnableVertexAttribArray),
glFinish(44, DebuggerMessage.Message.Function.glFinish),
glFlush(45, DebuggerMessage.Message.Function.glFlush),
glFramebufferRenderbuffer(46, DebuggerMessage.Message.Function.glFramebufferRenderbuffer),
glFramebufferTexture2D(47, DebuggerMessage.Message.Function.glFramebufferTexture2D),
glFrontFace(48, DebuggerMessage.Message.Function.glFrontFace),
glGenBuffers(49, DebuggerMessage.Message.Function.glGenBuffers),
glGenerateMipmap(50, DebuggerMessage.Message.Function.glGenerateMipmap),
glGenFramebuffers(51, DebuggerMessage.Message.Function.glGenFramebuffers),
glGenRenderbuffers(52, DebuggerMessage.Message.Function.glGenRenderbuffers),
glGenTextures(53, DebuggerMessage.Message.Function.glGenTextures),
glGetActiveAttrib(54, DebuggerMessage.Message.Function.glGetActiveAttrib),
glGetActiveUniform(55, DebuggerMessage.Message.Function.glGetActiveUniform),
glGetAttachedShaders(56, DebuggerMessage.Message.Function.glGetAttachedShaders),
glGetAttribLocation(57, DebuggerMessage.Message.Function.glGetAttribLocation),
glGetBooleanv(58, DebuggerMessage.Message.Function.glGetBooleanv),
glGetBufferParameteriv(59, DebuggerMessage.Message.Function.glGetBufferParameteriv),
glGetError(60, DebuggerMessage.Message.Function.glGetError),
glGetFloatv(61, DebuggerMessage.Message.Function.glGetFloatv),
glGetFramebufferAttachmentParameteriv(62, DebuggerMessage.Message.Function.glGetFramebufferAttachmentParameteriv),
glGetIntegerv(63, DebuggerMessage.Message.Function.glGetIntegerv),
glGetProgramiv(64, DebuggerMessage.Message.Function.glGetProgramiv),
glGetProgramInfoLog(65, DebuggerMessage.Message.Function.glGetProgramInfoLog),
glGetRenderbufferParameteriv(66, DebuggerMessage.Message.Function.glGetRenderbufferParameteriv),
glGetShaderiv(67, DebuggerMessage.Message.Function.glGetShaderiv),
glGetShaderInfoLog(68, DebuggerMessage.Message.Function.glGetShaderInfoLog),
glGetShaderPrecisionFormat(69, DebuggerMessage.Message.Function.glGetShaderPrecisionFormat),
glGetShaderSource(70, DebuggerMessage.Message.Function.glGetShaderSource),
glGetString(71, DebuggerMessage.Message.Function.glGetString),
glGetTexParameterfv(72, DebuggerMessage.Message.Function.glGetTexParameterfv),
glGetTexParameteriv(73, DebuggerMessage.Message.Function.glGetTexParameteriv),
glGetUniformfv(74, DebuggerMessage.Message.Function.glGetUniformfv),
glGetUniformiv(75, DebuggerMessage.Message.Function.glGetUniformiv),
glGetUniformLocation(76, DebuggerMessage.Message.Function.glGetUniformLocation),
glGetVertexAttribfv(77, DebuggerMessage.Message.Function.glGetVertexAttribfv),
glGetVertexAttribiv(78, DebuggerMessage.Message.Function.glGetVertexAttribiv),
glGetVertexAttribPointerv(79, DebuggerMessage.Message.Function.glGetVertexAttribPointerv),
glHint(80, DebuggerMessage.Message.Function.glHint),
glIsBuffer(81, DebuggerMessage.Message.Function.glIsBuffer),
glIsEnabled(82, DebuggerMessage.Message.Function.glIsEnabled),
glIsFramebuffer(83, DebuggerMessage.Message.Function.glIsFramebuffer),
glIsProgram(84, DebuggerMessage.Message.Function.glIsProgram),
glIsRenderbuffer(85, DebuggerMessage.Message.Function.glIsRenderbuffer),
glIsShader(86, DebuggerMessage.Message.Function.glIsShader),
glIsTexture(87, DebuggerMessage.Message.Function.glIsTexture),
glLineWidth(88, DebuggerMessage.Message.Function.glLineWidth),
glLinkProgram(89, DebuggerMessage.Message.Function.glLinkProgram),
glPixelStorei(90, DebuggerMessage.Message.Function.glPixelStorei),
glPolygonOffset(91, DebuggerMessage.Message.Function.glPolygonOffset),
glReadPixels(92, DebuggerMessage.Message.Function.glReadPixels),
glReleaseShaderCompiler(93, DebuggerMessage.Message.Function.glReleaseShaderCompiler),
glRenderbufferStorage(94, DebuggerMessage.Message.Function.glRenderbufferStorage),
glSampleCoverage(95, DebuggerMessage.Message.Function.glSampleCoverage),
glScissor(96, DebuggerMessage.Message.Function.glScissor),
glShaderBinary(97, DebuggerMessage.Message.Function.glShaderBinary),
glShaderSource(98, DebuggerMessage.Message.Function.glShaderSource),
glStencilFunc(99, DebuggerMessage.Message.Function.glStencilFunc),
glStencilFuncSeparate(100, DebuggerMessage.Message.Function.glStencilFuncSeparate),
glStencilMask(101, DebuggerMessage.Message.Function.glStencilMask),
glStencilMaskSeparate(102, DebuggerMessage.Message.Function.glStencilMaskSeparate),
glStencilOp(103, DebuggerMessage.Message.Function.glStencilOp),
glStencilOpSeparate(104, DebuggerMessage.Message.Function.glStencilOpSeparate),
glTexImage2D(105, DebuggerMessage.Message.Function.glTexImage2D),
glTexParameterf(106, DebuggerMessage.Message.Function.glTexParameterf),
glTexParameterfv(107, DebuggerMessage.Message.Function.glTexParameterfv),
glTexParameteri(108, DebuggerMessage.Message.Function.glTexParameteri),
glTexParameteriv(109, DebuggerMessage.Message.Function.glTexParameteriv),
glTexSubImage2D(110, DebuggerMessage.Message.Function.glTexSubImage2D),
glUniform1f(111, DebuggerMessage.Message.Function.glUniform1f),
glUniform1fv(112, DebuggerMessage.Message.Function.glUniform1fv),
glUniform1i(113, DebuggerMessage.Message.Function.glUniform1i),
glUniform1iv(114, DebuggerMessage.Message.Function.glUniform1iv),
glUniform2f(115, DebuggerMessage.Message.Function.glUniform2f),
glUniform2fv(116, DebuggerMessage.Message.Function.glUniform2fv),
glUniform2i(117, DebuggerMessage.Message.Function.glUniform2i),
glUniform2iv(118, DebuggerMessage.Message.Function.glUniform2iv),
glUniform3f(119, DebuggerMessage.Message.Function.glUniform3f),
glUniform3fv(120, DebuggerMessage.Message.Function.glUniform3fv),
glUniform3i(121, DebuggerMessage.Message.Function.glUniform3i),
glUniform3iv(122, DebuggerMessage.Message.Function.glUniform3iv),
glUniform4f(123, DebuggerMessage.Message.Function.glUniform4f),
glUniform4fv(124, DebuggerMessage.Message.Function.glUniform4fv),
glUniform4i(125, DebuggerMessage.Message.Function.glUniform4i),
glUniform4iv(126, DebuggerMessage.Message.Function.glUniform4iv),
glUniformMatrix2fv(127, DebuggerMessage.Message.Function.glUniformMatrix2fv),
glUniformMatrix3fv(128, DebuggerMessage.Message.Function.glUniformMatrix3fv),
glUniformMatrix4fv(129, DebuggerMessage.Message.Function.glUniformMatrix4fv),
glUseProgram(130, DebuggerMessage.Message.Function.glUseProgram),
glValidateProgram(131, DebuggerMessage.Message.Function.glValidateProgram),
glVertexAttrib1f(132, DebuggerMessage.Message.Function.glVertexAttrib1f),
glVertexAttrib1fv(133, DebuggerMessage.Message.Function.glVertexAttrib1fv),
glVertexAttrib2f(134, DebuggerMessage.Message.Function.glVertexAttrib2f),
glVertexAttrib2fv(135, DebuggerMessage.Message.Function.glVertexAttrib2fv),
glVertexAttrib3f(136, DebuggerMessage.Message.Function.glVertexAttrib3f),
glVertexAttrib3fv(137, DebuggerMessage.Message.Function.glVertexAttrib3fv),
glVertexAttrib4f(138, DebuggerMessage.Message.Function.glVertexAttrib4f),
glVertexAttrib4fv(139, DebuggerMessage.Message.Function.glVertexAttrib4fv),
glVertexAttribPointer(140, DebuggerMessage.Message.Function.glVertexAttribPointer),
glViewport(141, DebuggerMessage.Message.Function.glViewport),
;
public final int index;
public final DebuggerMessage.Message.Function function;
GLFunction(final int index, final DebuggerMessage.Message.Function function) {
this.index = index;
this.function = function;
}
}

View File

@@ -30,18 +30,25 @@ import java.net.Socket;
import java.nio.ByteOrder;
import java.util.ArrayList;
abstract interface ProcessMessage {
abstract boolean processMessage(final MessageQueue queue, final Message msg)
throws IOException;
}
public class MessageQueue implements Runnable {
private boolean running = false;
private ByteOrder byteOrder;
private FileInputStream file; // if null, create and use socket
private Thread thread = null;
Thread thread = null;
private final ProcessMessage[] processes;
private ArrayList<Message> complete = new ArrayList<Message>(); // synchronized
private ArrayList<Message> commands = new ArrayList<Message>(); // synchronized
private SampleView sampleView;
public MessageQueue(SampleView sampleView) {
public MessageQueue(SampleView sampleView, final ProcessMessage[] processes) {
this.sampleView = sampleView;
this.processes = processes;
}
public void start(final ByteOrder byteOrder, final FileInputStream file) {
@@ -182,15 +189,15 @@ public class MessageQueue implements Runnable {
partials.remove(contextId);
assert msg != null;
assert msg.getType() == Type.BeforeCall;
synchronized (complete) {
complete.add(msg);
}
if (msg != null)
synchronized (complete) {
complete.add(msg);
}
}
// can be used by other message processor as default processor
void defaultProcessMessage(final Message msg, boolean expectResponse,
boolean sendResponse)
throws IOException {
boolean sendResponse) throws IOException {
final int contextId = msg.getContextId();
if (msg.getType() == Type.BeforeCall) {
if (sendResponse) {
@@ -296,13 +303,11 @@ public class MessageQueue implements Runnable {
private void processMessage(final DataOutputStream dos, final Message msg) throws IOException {
if (msg.getExpectResponse()) {
assert file == null; // file cannot be interactive mode
if (sampleView.shaderEditor.processMessage(this, msg))
return;
else if (sampleView.breakpointOption.processMessage(this, msg))
return;
else
defaultProcessMessage(msg, msg.getExpectResponse(), msg.getExpectResponse());
assert dos != null; // readonly source cannot expectResponse
for (ProcessMessage process : processes)
if (process.processMessage(this, msg))
return;
defaultProcessMessage(msg, msg.getExpectResponse(), msg.getExpectResponse());
} else
defaultProcessMessage(msg, msg.getExpectResponse(), msg.getExpectResponse());
}

View File

@@ -93,12 +93,10 @@ public class SampleView extends ViewPart implements Runnable, SelectionListener
boolean running = false;
Thread thread;
MessageQueue messageQueue = new MessageQueue(this);
MessageQueue messageQueue;
SparseArray<DebugContext> debugContexts = new SparseArray<DebugContext>();
/**
* The ID of the view as specified by the extension.
*/
/** The ID of the view as specified by the extension. */
public static final String ID = "glesv2debuggerclient.views.SampleView";
TabFolder tabFolder;
@@ -391,6 +389,10 @@ public class SampleView extends ViewPart implements Runnable, SelectionListener
hookContextMenu();
hookSelectionChanged();
contributeToActionBars();
messageQueue = new MessageQueue(this, new ProcessMessage[] {
breakpointOption, shaderEditor
});
}
private void hookContextMenu() {

View File

@@ -46,7 +46,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class ShaderEditor extends Composite implements SelectionListener, ExtendedModifyListener {
public class ShaderEditor extends Composite implements SelectionListener, ExtendedModifyListener,
ProcessMessage {
SampleView sampleView;
ToolBar toolbar;
@@ -173,6 +174,7 @@ public class ShaderEditor extends Composite implements SelectionListener, Extend
styledText.setLineBackground(ln - 1, 1,
new Color(Display.getCurrent(), 255, 230, 230));
}
file.delete();
if (infolog.length() > 0) {
if (!MessageDialog.openConfirm(getShell(),
"Shader Syntax Error, Continue?", infolog))

View File

@@ -0,0 +1,183 @@
/*
** Copyright 2011, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
package com.android.glesv2debugger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import com.android.glesv2debugger.DebuggerMessage.Message;
import com.android.glesv2debugger.DebuggerMessage.Message.Function;
import com.android.glesv2debugger.DebuggerMessage.Message.Type;
import org.junit.Before;
import org.junit.Test;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteOrder;
public class MessageQueueTest {
private MessageQueue queue;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
queue = new MessageQueue(null, new ProcessMessage[0]);
}
/**
* Test method for
* {@link com.android.glesv2debugger.MessageQueue#defaultProcessMessage(com.android.glesv2debugger.DebuggerMessage.Message, boolean, boolean)}
* .
*
* @throws IOException
*/
@Test
public void testDefaultProcessMessage() throws IOException {
final int contextId = 8784;
assertNull(queue.getPartialMessage(contextId));
Message.Builder builder = Message.newBuilder();
builder.setContextId(contextId);
builder.setExpectResponse(false);
builder.setFunction(Function.glFinish);
builder.setType(Type.BeforeCall);
Message msg = builder.build();
queue.defaultProcessMessage(msg, false, false);
assertNotNull(queue.getPartialMessage(contextId));
builder = msg.toBuilder();
builder.setType(Type.AfterCall);
builder.setTime(5);
msg = builder.build();
queue.defaultProcessMessage(msg, false, false);
assertNull(queue.getPartialMessage(contextId));
Message complete = queue.removeCompleteMessage(contextId);
assertNotNull(complete);
assertEquals(contextId, complete.getContextId());
assertEquals(msg.getFunction(), complete.getFunction());
assertEquals(msg.getTime(), complete.getTime(), 0);
assertEquals(Type.CompleteCall, complete.getType());
// an already complete message should just be added to complete queue
queue.defaultProcessMessage(complete, false, false);
assertNull(queue.getPartialMessage(contextId));
complete = queue.removeCompleteMessage(contextId);
assertNotNull(complete);
assertEquals(contextId, complete.getContextId());
assertEquals(msg.getFunction(), complete.getFunction());
assertEquals(msg.getTime(), complete.getTime(), 0);
assertEquals(Type.CompleteCall, complete.getType());
}
@Test
public void testCompletePartialMessage() throws IOException {
final int contextId = 8784;
assertNull(queue.getPartialMessage(contextId));
Message.Builder builder = Message.newBuilder();
builder.setContextId(contextId);
builder.setExpectResponse(false);
builder.setFunction(Function.glFinish);
builder.setType(Type.BeforeCall);
Message msg = builder.build();
queue.defaultProcessMessage(msg, false, false);
assertNotNull(queue.getPartialMessage(contextId));
queue.completePartialMessage(contextId);
final Message complete = queue.removeCompleteMessage(contextId);
assertNotNull(complete);
assertEquals(contextId, complete.getContextId());
assertEquals(msg.getFunction(), complete.getFunction());
assertEquals(msg.getTime(), complete.getTime(), 0);
assertEquals(Type.BeforeCall, complete.getType());
}
/** Write two messages from two contexts to file and test handling them */
@Test
public void testRunWithFile() throws FileNotFoundException, IOException, InterruptedException {
final File filePath = File.createTempFile("test", ".gles2dbg");
DataOutputStream file = new DataOutputStream(new FileOutputStream(filePath));
Message.Builder builder = Message.newBuilder();
final int contextId0 = 521643, contextId1 = 87634;
assertNull(queue.removeCompleteMessage(contextId0));
assertNull(queue.removeCompleteMessage(contextId1));
builder.setContextId(contextId0).setExpectResponse(false).setType(Type.BeforeCall);
builder.setFunction(Function.glClear).setArg0(contextId0);
Message msg0 = builder.build();
byte[] data = msg0.toByteArray();
file.writeInt(data.length);
file.write(data);
builder = Message.newBuilder();
builder.setContextId(contextId1).setExpectResponse(false).setType(Type.BeforeCall);
builder.setFunction(Function.glDisable).setArg0(contextId1);
Message msg1 = builder.build();
data = msg1.toByteArray();
file.writeInt(data.length);
file.write(data);
builder = Message.newBuilder();
msg0 = builder.setContextId(msg0.getContextId()).setExpectResponse(false)
.setType(Type.AfterCall).setFunction(msg0.getFunction()).setTime(2).build();
data = msg0.toByteArray();
file.writeInt(data.length);
file.write(data);
builder = Message.newBuilder();
msg1 = builder.setContextId(msg1.getContextId()).setExpectResponse(false)
.setType(Type.AfterCall).setFunction(msg1.getFunction()).setTime(465).build();
data = msg1.toByteArray();
file.writeInt(data.length);
file.write(data);
file.close();
FileInputStream fis = new FileInputStream(filePath);
// Java VM uses big endian, so the file was written in big endian
queue.start(ByteOrder.BIG_ENDIAN, fis);
queue.thread.join();
Message complete0 = queue.removeCompleteMessage(msg0.getContextId());
assertNotNull(complete0);
assertNull(queue.removeCompleteMessage(contextId0));
assertEquals(contextId0, complete0.getContextId());
assertEquals(false, complete0.getExpectResponse());
assertEquals(Type.CompleteCall, complete0.getType());
assertEquals(msg0.getFunction(), complete0.getFunction());
assertEquals(contextId0, complete0.getArg0());
assertEquals(msg0.getTime(), complete0.getTime(), 0);
Message complete1 = queue.removeCompleteMessage(msg1.getContextId());
assertNotNull(complete1);
assertNull(queue.removeCompleteMessage(contextId1));
assertEquals(contextId1, complete1.getContextId());
assertEquals(false, complete1.getExpectResponse());
assertEquals(Type.CompleteCall, complete1.getType());
assertEquals(msg1.getFunction(), complete1.getFunction());
assertEquals(contextId1, complete1.getArg0());
assertEquals(msg1.getTime(), complete1.getTime(), 0);
filePath.delete();
}
}