gpu/command_buffer/build_cmd_buffer_lib.py
def WriteGLES2ImplementationUnitTest(self, func, f):
    """Writes the GLES2 Implemention unit test."""
    client_test = func.GetInfo('client_test', True)
    if not client_test:
      return;

    code = """
TEST_F(%(prefix)sImplementationTest, %(name)s) {
  %(type)s data[%(count_param)d][%(count)d] = {{0}};
  struct Cmds {
    cmds::%(name)sImmediate cmd;
    %(type)s data[%(count_param)d][%(count)d];
  };

  Cmds expected;
  for (int ii = 0; ii < %(count_param)d; ++ii) {
    for (int jj = 0; jj < %(count)d; ++jj) {
      data[ii][jj] = static_cast<%(type)s>(ii * %(count)d + jj);
    }
  }
  expected.cmd.Init(%(cmd_args)s);
  gl_->%(name)s(%(args)s);
  EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
}
"""
    cmd_arg_strings = []
    for arg in func.GetCmdArgs():
      if arg.name.endswith("_shm_id"):
        cmd_arg_strings.append("&data[0][0]")
      elif arg.name.endswith("_shm_offset"):
        continue
      else:
        cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func))
    gl_arg_strings = []
    count_param = 0
    for arg in func.GetOriginalArgs():
      if arg.IsPointer():
        valid_value = "&data[0][0]"
      else:
        valid_value = arg.GetValidClientSideArg(func)
      gl_arg_strings.append(valid_value)
      if arg.name == "count":
        count_param = int(valid_value)
    f.write(code % {
          'prefix' : _prefix,
          'name': func.name,
          'type': self.GetArrayType(func),
          'count': self.GetArrayCount(func),
          'args': ", ".join(gl_arg_strings),
          'cmd_args': ", ".join(cmd_arg_strings),
          'count_param': count_param,
        })

    # Test constants for invalid values, as they are not tested by the
    # service.
    constants = [
      arg for arg in func.GetOriginalArgs()[0:-1] if arg.IsConstant()
    ]
    if not constants:
      return

    code = """
TEST_F(%(prefix)sImplementationTest,
       %(name)sInvalidConstantArg%(invalid_index)d) {
  %(type)s data[%(count_param)d][%(count)d] = {{0}};
  for (int ii = 0; ii < %(count_param)d; ++ii) {
    for (int jj = 0; jj < %(count)d; ++jj) {
      data[ii][jj] = static_cast<%(type)s>(ii * %(count)d + jj);
    }
  }
  gl_->%(name)s(%(args)s);
  EXPECT_TRUE(NoCommandsWritten());
  EXPECT_EQ(%(gl_error)s, CheckError());
}
"""
    for invalid_arg in constants:
      gl_arg_strings = []
      invalid = invalid_arg.GetInvalidArg(func)
      for arg in func.GetOriginalArgs():
        if arg is invalid_arg:
          gl_arg_strings.append(invalid[0])
        elif arg.IsPointer():
          gl_arg_strings.append("&data[0][0]")
        else:
          valid_value = arg.GetValidClientSideArg(func)
          gl_arg_strings.append(valid_value)
          if arg.name == "count":
            count_param = int(valid_value)

      f.write(code % {
        'prefix' : _prefix,
        'name': func.name,
        'invalid_index': func.GetOriginalArgs().index(invalid_arg),
        'type': self.GetArrayType(func),
        'count': self.GetArrayCount(func),
        'args': ", ".join(gl_arg_strings),
        'gl_error': invalid[2],
        'count_param': count_param,
      })
Writes the GLES2 Implemention unit test.
Writes the GLES2 Implemention unit test.
Writes the GLES2 Implemention unit test .
def WriteGLES2ImplementationUnitTest(self, func, f):
    client_test = func.GetInfo('client_test', True)
    if not client_test:
      return;
    code = """
TEST_F(%(prefix)sImplementationTest, %(name)s) {
  %(type)s data[%(count_param)d][%(count)d] = {{0}};
  struct Cmds {
    cmds::%(name)sImmediate cmd;
    %(type)s data[%(count_param)d][%(count)d];
  };
  Cmds expected;
  for (int ii = 0; ii < %(count_param)d; ++ii) {
    for (int jj = 0; jj < %(count)d; ++jj) {
      data[ii][jj] = static_cast<%(type)s>(ii * %(count)d + jj);
    }
  }
  expected.cmd.Init(%(cmd_args)s);
  gl_->%(name)s(%(args)s);
  EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
}
"""
    cmd_arg_strings = []
    for arg in func.GetCmdArgs():
      if arg.name.endswith("_shm_id"):
        cmd_arg_strings.append("&data[0][0]")
      elif arg.name.endswith("_shm_offset"):
        continue
      else:
        cmd_arg_strings.append(arg.GetValidClientSideCmdArg(func))
    gl_arg_strings = []
    count_param = 0
    for arg in func.GetOriginalArgs():
      if arg.IsPointer():
        valid_value = "&data[0][0]"
      else:
        valid_value = arg.GetValidClientSideArg(func)
      gl_arg_strings.append(valid_value)
      if arg.name == "count":
        count_param = int(valid_value)
    f.write(code % {
          'prefix' : _prefix,
          'name': func.name,
          'type': self.GetArrayType(func),
          'count': self.GetArrayCount(func),
          'args': ", ".join(gl_arg_strings),
          'cmd_args': ", ".join(cmd_arg_strings),
          'count_param': count_param,
        })
    constants = [
      arg for arg in func.GetOriginalArgs()[0:-1] if arg.IsConstant()
    ]
    if not constants:
      return
    code = """
TEST_F(%(prefix)sImplementationTest,
       %(name)sInvalidConstantArg%(invalid_index)d) {
  %(type)s data[%(count_param)d][%(count)d] = {{0}};
  for (int ii = 0; ii < %(count_param)d; ++ii) {
    for (int jj = 0; jj < %(count)d; ++jj) {
      data[ii][jj] = static_cast<%(type)s>(ii * %(count)d + jj);
    }
  }
  gl_->%(name)s(%(args)s);
  EXPECT_TRUE(NoCommandsWritten());
  EXPECT_EQ(%(gl_error)s, CheckError());
}
"""
    for invalid_arg in constants:
      gl_arg_strings = []
      invalid = invalid_arg.GetInvalidArg(func)
      for arg in func.GetOriginalArgs():
        if arg is invalid_arg:
          gl_arg_strings.append(invalid[0])
        elif arg.IsPointer():
          gl_arg_strings.append("&data[0][0]")
        else:
          valid_value = arg.GetValidClientSideArg(func)
          gl_arg_strings.append(valid_value)
          if arg.name == "count":
            count_param = int(valid_value)
      f.write(code % {
        'prefix' : _prefix,
        'name': func.name,
        'invalid_index': func.GetOriginalArgs().index(invalid_arg),
        'type': self.GetArrayType(func),
        'count': self.GetArrayCount(func),
        'args': ", ".join(gl_arg_strings),
        'gl_error': invalid[2],
        'count_param': count_param,
      })
def WriteGLES2ImplementationUnitTest ( self , func , f ) : client_test = func . GetInfo ( 'client_test' , True ) if not client_test : return ; code = """
TEST_F(%(prefix)sImplementationTest, %(name)s) {
  %(type)s data[%(count_param)d][%(count)d] = {{0}};
  struct Cmds {
    cmds::%(name)sImmediate cmd;
    %(type)s data[%(count_param)d][%(count)d];
  };

  Cmds expected;
  for (int ii = 0; ii < %(count_param)d; ++ii) {
    for (int jj = 0; jj < %(count)d; ++jj) {
      data[ii][jj] = static_cast<%(type)s>(ii * %(count)d + jj);
    }
  }
  expected.cmd.Init(%(cmd_args)s);
  gl_->%(name)s(%(args)s);
  EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
}
""" cmd_arg_strings = [ ] for arg in func . GetCmdArgs ( ) : if arg . name . endswith ( "_shm_id" ) : cmd_arg_strings . append ( "&data[0][0]" ) elif arg . name . endswith ( "_shm_offset" ) : continue else : cmd_arg_strings . append ( arg . GetValidClientSideCmdArg ( func ) ) gl_arg_strings = [ ] count_param = 0 for arg in func . GetOriginalArgs ( ) : if arg . IsPointer ( ) : valid_value = "&data[0][0]" else : valid_value = arg . GetValidClientSideArg ( func ) gl_arg_strings . append ( valid_value ) if arg . name == "count" : count_param = int ( valid_value ) f . write ( code % { 'prefix' : _prefix , 'name' : func . name , 'type' : self . GetArrayType ( func ) , 'count' : self . GetArrayCount ( func ) , 'args' : ", " . join ( gl_arg_strings ) , 'cmd_args' : ", " . join ( cmd_arg_strings ) , 'count_param' : count_param , } ) constants = [ arg for arg in func . GetOriginalArgs ( ) [ 0 : - 1 ] if arg . IsConstant ( ) ] if not constants : return code = """
TEST_F(%(prefix)sImplementationTest,
       %(name)sInvalidConstantArg%(invalid_index)d) {
  %(type)s data[%(count_param)d][%(count)d] = {{0}};
  for (int ii = 0; ii < %(count_param)d; ++ii) {
    for (int jj = 0; jj < %(count)d; ++jj) {
      data[ii][jj] = static_cast<%(type)s>(ii * %(count)d + jj);
    }
  }
  gl_->%(name)s(%(args)s);
  EXPECT_TRUE(NoCommandsWritten());
  EXPECT_EQ(%(gl_error)s, CheckError());
}
""" for invalid_arg in constants : gl_arg_strings = [ ] invalid = invalid_arg . GetInvalidArg ( func ) for arg in func . GetOriginalArgs ( ) : if arg is invalid_arg : gl_arg_strings . append ( invalid [ 0 ] ) elif arg . IsPointer ( ) : gl_arg_strings . append ( "&data[0][0]" ) else : valid_value = arg . GetValidClientSideArg ( func ) gl_arg_strings . append ( valid_value ) if arg . name == "count" : count_param = int ( valid_value ) f . write ( code % { 'prefix' : _prefix , 'name' : func . name , 'invalid_index' : func . GetOriginalArgs ( ) . index ( invalid_arg ) , 'type' : self . GetArrayType ( func ) , 'count' : self . GetArrayCount ( func ) , 'args' : ", " . join ( gl_arg_strings ) , 'gl_error' : invalid [ 2 ] , 'count_param' : count_param , } )
Writes the GLES2 Implemention unit test.
Writes the GLES2 Implemention unit test .
"""Writes the GLES2 Implemention unit test.""" # Test constants for invalid values, as they are not tested by the # service.
self
func
f