| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // Test fixture for CommandBufferHelper test - Creates a CommandBufferHelper, | 51 // Test fixture for CommandBufferHelper test - Creates a CommandBufferHelper, |
| 52 // using a CommandBufferEngine with a mock AsyncAPIInterface for its interface | 52 // using a CommandBufferEngine with a mock AsyncAPIInterface for its interface |
| 53 // (calling it directly, not through the RPC mechanism). | 53 // (calling it directly, not through the RPC mechanism). |
| 54 class CommandBufferHelperTest : public testing::Test { | 54 class CommandBufferHelperTest : public testing::Test { |
| 55 protected: | 55 protected: |
| 56 virtual void SetUp() { | 56 virtual void SetUp() { |
| 57 api_mock_.reset(new AsyncAPIMock); | 57 api_mock_.reset(new AsyncAPIMock); |
| 58 // ignore noops in the mock - we don't want to inspect the internals of the | 58 // ignore noops in the mock - we don't want to inspect the internals of the |
| 59 // helper. | 59 // helper. |
| 60 EXPECT_CALL(*api_mock_, DoCommand(0, 0, _)) | 60 EXPECT_CALL(*api_mock_, DoCommand(0, 0, _)) |
| 61 .WillRepeatedly(Return(BufferSyncInterface::PARSE_NO_ERROR)); | 61 .WillRepeatedly(Return(BufferSyncInterface::kParseNoError)); |
| 62 engine_.reset(new CommandBufferEngine(api_mock_.get())); | 62 engine_.reset(new CommandBufferEngine(api_mock_.get())); |
| 63 api_mock_->set_engine(engine_.get()); | 63 api_mock_->set_engine(engine_.get()); |
| 64 | 64 |
| 65 engine_->InitConnection(); | 65 engine_->InitConnection(); |
| 66 helper_.reset(new CommandBufferHelper(engine_.get())); | 66 helper_.reset(new CommandBufferHelper(engine_.get())); |
| 67 helper_->Init(10); | 67 helper_->Init(10); |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual void TearDown() { | 70 virtual void TearDown() { |
| 71 helper_.release(); | 71 helper_.release(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 Sequence sequence_; | 119 Sequence sequence_; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 // Checks that commands in the buffer are properly executed, and that the | 122 // Checks that commands in the buffer are properly executed, and that the |
| 123 // status/error stay valid. | 123 // status/error stay valid. |
| 124 TEST_F(CommandBufferHelperTest, TestCommandProcessing) { | 124 TEST_F(CommandBufferHelperTest, TestCommandProcessing) { |
| 125 // Check initial state of the engine - it should have been configured by the | 125 // Check initial state of the engine - it should have been configured by the |
| 126 // helper. | 126 // helper. |
| 127 EXPECT_TRUE(engine()->rpc_impl() != NULL); | 127 EXPECT_TRUE(engine()->rpc_impl() != NULL); |
| 128 EXPECT_TRUE(engine()->parser() != NULL); | 128 EXPECT_TRUE(engine()->parser() != NULL); |
| 129 EXPECT_EQ(BufferSyncInterface::PARSING, engine()->GetStatus()); | 129 EXPECT_EQ(BufferSyncInterface::kParsing, engine()->GetStatus()); |
| 130 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 130 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 131 EXPECT_EQ(0, engine()->Get()); | 131 EXPECT_EQ(0, engine()->Get()); |
| 132 | 132 |
| 133 // Add 3 commands through the helper | 133 // Add 3 commands through the helper |
| 134 AddCommandWithExpect(BufferSyncInterface::PARSE_NO_ERROR, 1, 0, NULL); | 134 AddCommandWithExpect(BufferSyncInterface::kParseNoError, 1, 0, NULL); |
| 135 | 135 |
| 136 CommandBufferEntry args1[2]; | 136 CommandBufferEntry args1[2]; |
| 137 args1[0].value_uint32 = 3; | 137 args1[0].value_uint32 = 3; |
| 138 args1[1].value_float = 4.f; | 138 args1[1].value_float = 4.f; |
| 139 AddCommandWithExpect(BufferSyncInterface::PARSE_NO_ERROR, 2, 2, args1); | 139 AddCommandWithExpect(BufferSyncInterface::kParseNoError, 2, 2, args1); |
| 140 | 140 |
| 141 CommandBufferEntry args2[2]; | 141 CommandBufferEntry args2[2]; |
| 142 args2[0].value_uint32 = 5; | 142 args2[0].value_uint32 = 5; |
| 143 args2[1].value_float = 6.f; | 143 args2[1].value_float = 6.f; |
| 144 AddCommandWithExpect(BufferSyncInterface::PARSE_NO_ERROR, 3, 2, args2); | 144 AddCommandWithExpect(BufferSyncInterface::kParseNoError, 3, 2, args2); |
| 145 | 145 |
| 146 helper()->Flush(); | 146 helper()->Flush(); |
| 147 // Check that the engine has work to do now. | 147 // Check that the engine has work to do now. |
| 148 EXPECT_FALSE(engine()->parser()->IsEmpty()); | 148 EXPECT_FALSE(engine()->parser()->IsEmpty()); |
| 149 | 149 |
| 150 // Wait until it's done. | 150 // Wait until it's done. |
| 151 helper()->Finish(); | 151 helper()->Finish(); |
| 152 // Check that the engine has no more work to do. | 152 // Check that the engine has no more work to do. |
| 153 EXPECT_TRUE(engine()->parser()->IsEmpty()); | 153 EXPECT_TRUE(engine()->parser()->IsEmpty()); |
| 154 | 154 |
| 155 // Check that the commands did happen. | 155 // Check that the commands did happen. |
| 156 Mock::VerifyAndClearExpectations(api_mock()); | 156 Mock::VerifyAndClearExpectations(api_mock()); |
| 157 | 157 |
| 158 // Check the error status. | 158 // Check the error status. |
| 159 ASSERT_EQ(BufferSyncInterface::PARSING, engine()->GetStatus()); | 159 ASSERT_EQ(BufferSyncInterface::kParsing, engine()->GetStatus()); |
| 160 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 160 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Checks that commands in the buffer are properly executed when wrapping the | 163 // Checks that commands in the buffer are properly executed when wrapping the |
| 164 // buffer, and that the status/error stay valid. | 164 // buffer, and that the status/error stay valid. |
| 165 TEST_F(CommandBufferHelperTest, TestCommandWrapping) { | 165 TEST_F(CommandBufferHelperTest, TestCommandWrapping) { |
| 166 // Add 5 commands of size 3 through the helper to make sure we do wrap. | 166 // Add 5 commands of size 3 through the helper to make sure we do wrap. |
| 167 CommandBufferEntry args1[2]; | 167 CommandBufferEntry args1[2]; |
| 168 args1[0].value_uint32 = 3; | 168 args1[0].value_uint32 = 3; |
| 169 args1[1].value_float = 4.f; | 169 args1[1].value_float = 4.f; |
| 170 | 170 |
| 171 for (unsigned int i = 0; i < 5; ++i) { | 171 for (unsigned int i = 0; i < 5; ++i) { |
| 172 AddCommandWithExpect(BufferSyncInterface::PARSE_NO_ERROR, i+1, 2, args1); | 172 AddCommandWithExpect(BufferSyncInterface::kParseNoError, i+1, 2, args1); |
| 173 } | 173 } |
| 174 | 174 |
| 175 helper()->Finish(); | 175 helper()->Finish(); |
| 176 // Check that the commands did happen. | 176 // Check that the commands did happen. |
| 177 Mock::VerifyAndClearExpectations(api_mock()); | 177 Mock::VerifyAndClearExpectations(api_mock()); |
| 178 | 178 |
| 179 // Check the error status. | 179 // Check the error status. |
| 180 ASSERT_EQ(BufferSyncInterface::PARSING, engine()->GetStatus()); | 180 ASSERT_EQ(BufferSyncInterface::kParsing, engine()->GetStatus()); |
| 181 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 181 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 182 } | 182 } |
| 183 | 183 |
| 184 | 184 |
| 185 // Checks that commands in the buffer are properly executed, even if they | 185 // Checks that commands in the buffer are properly executed, even if they |
| 186 // generate a recoverable error. Check that the error status is properly set, | 186 // generate a recoverable error. Check that the error status is properly set, |
| 187 // and reset when queried. | 187 // and reset when queried. |
| 188 TEST_F(CommandBufferHelperTest, TestRecoverableError) { | 188 TEST_F(CommandBufferHelperTest, TestRecoverableError) { |
| 189 CommandBufferEntry args[2]; | 189 CommandBufferEntry args[2]; |
| 190 args[0].value_uint32 = 3; | 190 args[0].value_uint32 = 3; |
| 191 args[1].value_float = 4.f; | 191 args[1].value_float = 4.f; |
| 192 | 192 |
| 193 // Create a command buffer with 3 commands, 2 of them generating errors | 193 // Create a command buffer with 3 commands, 2 of them generating errors |
| 194 AddCommandWithExpect(BufferSyncInterface::PARSE_NO_ERROR, 1, 2, args); | 194 AddCommandWithExpect(BufferSyncInterface::kParseNoError, 1, 2, args); |
| 195 AddCommandWithExpect(BufferSyncInterface::PARSE_UNKNOWN_COMMAND, 2, 2, args); | 195 AddCommandWithExpect(BufferSyncInterface::kParseUnknownCommand, 2, 2, args); |
| 196 AddCommandWithExpect(BufferSyncInterface::PARSE_INVALID_ARGUMENTS, 3, 2, | 196 AddCommandWithExpect(BufferSyncInterface::kParseInvalidArguments, 3, 2, |
| 197 args); | 197 args); |
| 198 | 198 |
| 199 helper()->Finish(); | 199 helper()->Finish(); |
| 200 // Check that the commands did happen. | 200 // Check that the commands did happen. |
| 201 Mock::VerifyAndClearExpectations(api_mock()); | 201 Mock::VerifyAndClearExpectations(api_mock()); |
| 202 | 202 |
| 203 // Check that the error status was set to the first error. | 203 // Check that the error status was set to the first error. |
| 204 EXPECT_EQ(BufferSyncInterface::PARSE_UNKNOWN_COMMAND, | 204 EXPECT_EQ(BufferSyncInterface::kParseUnknownCommand, |
| 205 engine()->GetParseError()); | 205 engine()->GetParseError()); |
| 206 // Check that the error status was reset after the query. | 206 // Check that the error status was reset after the query. |
| 207 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 207 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 208 | 208 |
| 209 engine()->CloseConnection(); | 209 engine()->CloseConnection(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 // Checks that asking for available entries work, and that the parser | 212 // Checks that asking for available entries work, and that the parser |
| 213 // effectively won't use that space. | 213 // effectively won't use that space. |
| 214 TEST_F(CommandBufferHelperTest, TestAvailableEntries) { | 214 TEST_F(CommandBufferHelperTest, TestAvailableEntries) { |
| 215 CommandBufferEntry args[2]; | 215 CommandBufferEntry args[2]; |
| 216 args[0].value_uint32 = 3; | 216 args[0].value_uint32 = 3; |
| 217 args[1].value_float = 4.f; | 217 args[1].value_float = 4.f; |
| 218 | 218 |
| 219 // Add 2 commands through the helper - 8 entries | 219 // Add 2 commands through the helper - 8 entries |
| 220 AddCommandWithExpect(BufferSyncInterface::PARSE_NO_ERROR, 1, 0, NULL); | 220 AddCommandWithExpect(BufferSyncInterface::kParseNoError, 1, 0, NULL); |
| 221 AddCommandWithExpect(BufferSyncInterface::PARSE_NO_ERROR, 2, 0, NULL); | 221 AddCommandWithExpect(BufferSyncInterface::kParseNoError, 2, 0, NULL); |
| 222 AddCommandWithExpect(BufferSyncInterface::PARSE_NO_ERROR, 3, 2, args); | 222 AddCommandWithExpect(BufferSyncInterface::kParseNoError, 3, 2, args); |
| 223 AddCommandWithExpect(BufferSyncInterface::PARSE_NO_ERROR, 4, 2, args); | 223 AddCommandWithExpect(BufferSyncInterface::kParseNoError, 4, 2, args); |
| 224 | 224 |
| 225 // Ask for 5 entries. | 225 // Ask for 5 entries. |
| 226 helper()->WaitForAvailableEntries(5); | 226 helper()->WaitForAvailableEntries(5); |
| 227 | 227 |
| 228 CommandBufferOffset put = get_helper_put(); | 228 CommandBufferOffset put = get_helper_put(); |
| 229 CheckFreeSpace(put, 5); | 229 CheckFreeSpace(put, 5); |
| 230 | 230 |
| 231 // Add more commands. | 231 // Add more commands. |
| 232 AddCommandWithExpect(BufferSyncInterface::PARSE_NO_ERROR, 5, 2, args); | 232 AddCommandWithExpect(BufferSyncInterface::kParseNoError, 5, 2, args); |
| 233 | 233 |
| 234 // Wait until everything is done done. | 234 // Wait until everything is done done. |
| 235 helper()->Finish(); | 235 helper()->Finish(); |
| 236 | 236 |
| 237 // Check that the commands did happen. | 237 // Check that the commands did happen. |
| 238 Mock::VerifyAndClearExpectations(api_mock()); | 238 Mock::VerifyAndClearExpectations(api_mock()); |
| 239 | 239 |
| 240 // Check the error status. | 240 // Check the error status. |
| 241 ASSERT_EQ(BufferSyncInterface::PARSING, engine()->GetStatus()); | 241 ASSERT_EQ(BufferSyncInterface::kParsing, engine()->GetStatus()); |
| 242 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 242 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 243 } | 243 } |
| 244 | 244 |
| 245 // Checks that the InsertToken/WaitForToken work. | 245 // Checks that the InsertToken/WaitForToken work. |
| 246 TEST_F(CommandBufferHelperTest, TestToken) { | 246 TEST_F(CommandBufferHelperTest, TestToken) { |
| 247 CommandBufferEntry args[2]; | 247 CommandBufferEntry args[2]; |
| 248 args[0].value_uint32 = 3; | 248 args[0].value_uint32 = 3; |
| 249 args[1].value_float = 4.f; | 249 args[1].value_float = 4.f; |
| 250 | 250 |
| 251 // Add a first command. | 251 // Add a first command. |
| 252 AddCommandWithExpect(BufferSyncInterface::PARSE_NO_ERROR, 3, 2, args); | 252 AddCommandWithExpect(BufferSyncInterface::kParseNoError, 3, 2, args); |
| 253 // keep track of the buffer position. | 253 // keep track of the buffer position. |
| 254 CommandBufferOffset command1_put = get_helper_put(); | 254 CommandBufferOffset command1_put = get_helper_put(); |
| 255 unsigned int token = helper()->InsertToken(); | 255 unsigned int token = helper()->InsertToken(); |
| 256 | 256 |
| 257 EXPECT_CALL(*api_mock(), DoCommand(SET_TOKEN, 1, _)) | 257 EXPECT_CALL(*api_mock(), DoCommand(kSetToken, 1, _)) |
| 258 .WillOnce(DoAll(Invoke(api_mock(), &AsyncAPIMock::SetToken), | 258 .WillOnce(DoAll(Invoke(api_mock(), &AsyncAPIMock::SetToken), |
| 259 Return(BufferSyncInterface::PARSE_NO_ERROR))); | 259 Return(BufferSyncInterface::kParseNoError))); |
| 260 // Add another command. | 260 // Add another command. |
| 261 AddCommandWithExpect(BufferSyncInterface::PARSE_NO_ERROR, 4, 2, args); | 261 AddCommandWithExpect(BufferSyncInterface::kParseNoError, 4, 2, args); |
| 262 helper()->WaitForToken(token); | 262 helper()->WaitForToken(token); |
| 263 // check that the get pointer is beyond the first command. | 263 // check that the get pointer is beyond the first command. |
| 264 EXPECT_LE(command1_put, engine()->Get()); | 264 EXPECT_LE(command1_put, engine()->Get()); |
| 265 helper()->Finish(); | 265 helper()->Finish(); |
| 266 | 266 |
| 267 // Check that the commands did happen. | 267 // Check that the commands did happen. |
| 268 Mock::VerifyAndClearExpectations(api_mock()); | 268 Mock::VerifyAndClearExpectations(api_mock()); |
| 269 | 269 |
| 270 // Check the error status. | 270 // Check the error status. |
| 271 ASSERT_EQ(BufferSyncInterface::PARSING, engine()->GetStatus()); | 271 ASSERT_EQ(BufferSyncInterface::kParsing, engine()->GetStatus()); |
| 272 EXPECT_EQ(BufferSyncInterface::PARSE_NO_ERROR, engine()->GetParseError()); | 272 EXPECT_EQ(BufferSyncInterface::kParseNoError, engine()->GetParseError()); |
| 273 } | 273 } |
| 274 | 274 |
| 275 } // namespace command_buffer | 275 } // namespace command_buffer |
| 276 } // namespace o3d | 276 } // namespace o3d |
| OLD | NEW |