gpu/command_buffer/build_cmd_buffer_lib.py
def WriteImmediateServiceUnitTest(self, func, f, *extras):
    """Writes the service unit test for a command."""
    valid_test = """
TEST_P(%(test_name)s, %(name)sValidArgs) {
  cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();
  SpecializedSetup<cmds::%(name)s, 0>(true);
  %(data_type)s temp[%(data_count)s] = { %(data_value)s, };
  cmd.Init(%(gl_client_args)s, &temp[0]);
  EXPECT_CALL(
      *gl_,
      %(gl_func_name)s(%(gl_args)s, %(expectation)s));
  EXPECT_EQ(error::kNoError,
            ExecuteImmediateCmd(cmd, sizeof(temp)));
  EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
"""
    gl_client_arg_strings = [
      arg.GetValidArg(func) for arg in func.GetOriginalArgs()[0:-1]
    ]
    gl_arg_strings = [
      arg.GetValidGLArg(func) for arg in func.GetOriginalArgs()[0:-1]
    ]
    gl_any_strings = ["_"] * len(gl_arg_strings)
    data_count = self.GetArrayCount(func)
    if func.GetInfo('first_element_only'):
      expectation = "temp[0]"
    else:
      expectation = "PointsToArray(temp, %s)" % data_count

    extra = {
      'expectation': expectation,
      'data_type': self.GetArrayType(func),
      'data_count': data_count,
      'data_value': func.GetInfo('data_value') or '0',
      'gl_client_args': ", ".join(gl_client_arg_strings),
      'gl_args': ", ".join(gl_arg_strings),
      'gl_any_args': ", ".join(gl_any_strings),
    }
    self.WriteValidUnitTest(func, f, valid_test, extra, *extras)

    invalid_test = """
TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
  cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();"""
    if func.IsES3():
      invalid_test += """
  EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_any_args)s, _)).Times(1);
"""
    else:
      invalid_test += """
  EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_any_args)s, _)).Times(0);
"""
    invalid_test += """
  SpecializedSetup<cmds::%(name)s, 0>(false);
  %(data_type)s temp[%(data_count)s] = { %(data_value)s, };
  cmd.Init(%(all_but_last_args)s, &temp[0]);
  EXPECT_EQ(error::%(parse_result)s,
            ExecuteImmediateCmd(cmd, sizeof(temp)));
  %(gl_error_test)s
}
"""
    self.WriteInvalidUnitTest(func, f, invalid_test, extra, *extras)
Writes the service unit test for a command.
Writes the service unit test for a command.
Writes the service unit test for a command .
def WriteImmediateServiceUnitTest(self, func, f, *extras):
    valid_test = """
TEST_P(%(test_name)s, %(name)sValidArgs) {
  cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();
  SpecializedSetup<cmds::%(name)s, 0>(true);
  %(data_type)s temp[%(data_count)s] = { %(data_value)s, };
  cmd.Init(%(gl_client_args)s, &temp[0]);
  EXPECT_CALL(
      *gl_,
      %(gl_func_name)s(%(gl_args)s, %(expectation)s));
  EXPECT_EQ(error::kNoError,
            ExecuteImmediateCmd(cmd, sizeof(temp)));
  EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
"""
    gl_client_arg_strings = [
      arg.GetValidArg(func) for arg in func.GetOriginalArgs()[0:-1]
    ]
    gl_arg_strings = [
      arg.GetValidGLArg(func) for arg in func.GetOriginalArgs()[0:-1]
    ]
    gl_any_strings = ["_"] * len(gl_arg_strings)
    data_count = self.GetArrayCount(func)
    if func.GetInfo('first_element_only'):
      expectation = "temp[0]"
    else:
      expectation = "PointsToArray(temp, %s)" % data_count
    extra = {
      'expectation': expectation,
      'data_type': self.GetArrayType(func),
      'data_count': data_count,
      'data_value': func.GetInfo('data_value') or '0',
      'gl_client_args': ", ".join(gl_client_arg_strings),
      'gl_args': ", ".join(gl_arg_strings),
      'gl_any_args': ", ".join(gl_any_strings),
    }
    self.WriteValidUnitTest(func, f, valid_test, extra, *extras)
    invalid_test = """
TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
  cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();"""
    if func.IsES3():
      invalid_test += """
  EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_any_args)s, _)).Times(1);
"""
    else:
      invalid_test += """
  EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_any_args)s, _)).Times(0);
"""
    invalid_test += """
  SpecializedSetup<cmds::%(name)s, 0>(false);
  %(data_type)s temp[%(data_count)s] = { %(data_value)s, };
  cmd.Init(%(all_but_last_args)s, &temp[0]);
  EXPECT_EQ(error::%(parse_result)s,
            ExecuteImmediateCmd(cmd, sizeof(temp)));
  %(gl_error_test)s
}
"""
    self.WriteInvalidUnitTest(func, f, invalid_test, extra, *extras)
def WriteImmediateServiceUnitTest ( self , func , f , * extras ) : valid_test = """
TEST_P(%(test_name)s, %(name)sValidArgs) {
  cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();
  SpecializedSetup<cmds::%(name)s, 0>(true);
  %(data_type)s temp[%(data_count)s] = { %(data_value)s, };
  cmd.Init(%(gl_client_args)s, &temp[0]);
  EXPECT_CALL(
      *gl_,
      %(gl_func_name)s(%(gl_args)s, %(expectation)s));
  EXPECT_EQ(error::kNoError,
            ExecuteImmediateCmd(cmd, sizeof(temp)));
  EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
""" gl_client_arg_strings = [ arg . GetValidArg ( func ) for arg in func . GetOriginalArgs ( ) [ 0 : - 1 ] ] gl_arg_strings = [ arg . GetValidGLArg ( func ) for arg in func . GetOriginalArgs ( ) [ 0 : - 1 ] ] gl_any_strings = [ "_" ] * len ( gl_arg_strings ) data_count = self . GetArrayCount ( func ) if func . GetInfo ( 'first_element_only' ) : expectation = "temp[0]" else : expectation = "PointsToArray(temp, %s)" % data_count extra = { 'expectation' : expectation , 'data_type' : self . GetArrayType ( func ) , 'data_count' : data_count , 'data_value' : func . GetInfo ( 'data_value' ) or '0' , 'gl_client_args' : ", " . join ( gl_client_arg_strings ) , 'gl_args' : ", " . join ( gl_arg_strings ) , 'gl_any_args' : ", " . join ( gl_any_strings ) , } self . WriteValidUnitTest ( func , f , valid_test , extra , * extras ) invalid_test = """
TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
  cmds::%(name)s& cmd = *GetImmediateAs<cmds::%(name)s>();""" if func . IsES3 ( ) : invalid_test += """
  EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_any_args)s, _)).Times(1);
""" else : invalid_test += """
  EXPECT_CALL(*gl_, %(gl_func_name)s(%(gl_any_args)s, _)).Times(0);
""" invalid_test += """
  SpecializedSetup<cmds::%(name)s, 0>(false);
  %(data_type)s temp[%(data_count)s] = { %(data_value)s, };
  cmd.Init(%(all_but_last_args)s, &temp[0]);
  EXPECT_EQ(error::%(parse_result)s,
            ExecuteImmediateCmd(cmd, sizeof(temp)));
  %(gl_error_test)s
}
""" self . WriteInvalidUnitTest ( func , f , invalid_test , extra , * extras )
Writes the service unit test for a command.
Writes the service unit test for a command .
"""Writes the service unit test for a command."""
self
func
f