Loading system/vendor_libs/test_vendor_lib/desktop/test_environment.cc +20 −8 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ using test_vendor_lib::AsyncTaskId; using test_vendor_lib::TaskCallback; void TestEnvironment::initialize(std::promise<void> barrier) { LOG_INFO("%s", __func__); LOG_INFO(); barrier_ = std::move(barrier); Loading @@ -41,12 +41,15 @@ void TestEnvironment::initialize(std::promise<void> barrier) { test_channel_transport_.RegisterCommandHandler( [this, user_id](const std::string& name, const std::vector<std::string>& args) { async_manager_.ExecAsync( user_id, std::chrono::milliseconds(0), [this, name, args]() { test_channel_.HandleCommand(name, args); }); async_manager_.ExecAsync(user_id, std::chrono::milliseconds(0), [this, name, args]() { if (name == "END_SIMULATION") { barrier_.set_value(); } else { test_channel_.HandleCommand(name, args); } }); }); test_model_.Reset(); SetUpTestChannel(); SetUpHciServer([this](int fd) { test_model_.IncomingHciConnection(fd); }); Loading Loading @@ -175,13 +178,22 @@ void TestEnvironment::SetUpTestChannel() { return; } LOG_INFO("Test channel connection accepted."); if (test_channel_open_) { LOG_WARN("Only one connection at a time is supported"); async_manager_.StopWatchingFileDescriptor(conn_fd); test_channel_transport_.SendResponse(conn_fd, "The connection is broken"); return; } test_channel_open_ = true; test_channel_.RegisterSendResponse( [this, conn_fd](const std::string& response) { test_channel_transport_.SendResponse(conn_fd, response); }); [this, conn_fd](const std::string& response) { test_channel_transport_.SendResponse(conn_fd, response); }); async_manager_.WatchFdForNonBlockingReads(conn_fd, [this](int conn_fd) { test_channel_transport_.OnCommandReady(conn_fd, [this, conn_fd]() { async_manager_.StopWatchingFileDescriptor(conn_fd); barrier_.set_value(); test_channel_open_ = false; }); }); }); Loading system/vendor_libs/test_vendor_lib/desktop/test_environment.h +1 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ class TestEnvironment { uint16_t hci_server_port_; uint16_t link_server_port_; std::string default_commands_file_; bool test_channel_open_{false}; std::promise<void> barrier_; test_vendor_lib::AsyncManager async_manager_; Loading system/vendor_libs/test_vendor_lib/model/setup/test_channel_transport.cc +5 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ void TestChannelTransport::OnCommandReady(int fd, std::function<void(void)> unwa int bytes_read = read(fd, &command_name_size, 1); if (bytes_read != 1) { LOG_INFO("Unexpected (command_name_size) bytes_read: %d != %d", bytes_read, 1); close(fd); } vector<uint8_t> command_name_raw; command_name_raw.resize(command_name_size); Loading Loading @@ -148,6 +149,10 @@ void TestChannelTransport::SendResponse(int fd, const std::string& response) con uint8_t size_buf[4] = {static_cast<uint8_t>(size & 0xff), static_cast<uint8_t>((size >> 8) & 0xff), static_cast<uint8_t>((size >> 16) & 0xff), static_cast<uint8_t>((size >> 24) & 0xff)}; int written = write(fd, size_buf, 4); if (written == -1 && errno == EBADFD) { LOG_WARN("Unable to send a response. EBADFD"); return; } ASSERT_LOG(written == 4, "What happened? written = %d errno = %d", written, errno); written = write(fd, response.c_str(), size); ASSERT_LOG(written == static_cast<int>(size), "What happened? written = %d errno = %d", written, errno); Loading system/vendor_libs/test_vendor_lib/model/setup/test_command_handler.cc +1 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ TestCommandHandler::TestCommandHandler(TestModel& test_model) : model_(test_mode SET_HANDLER("set_timer_period", SetTimerPeriod); SET_HANDLER("start_timer", StartTimer); SET_HANDLER("stop_timer", StopTimer); SET_HANDLER("reset", Reset); #undef SET_HANDLER } Loading system/vendor_libs/test_vendor_lib/scripts/test_channel.py +16 −0 Original line number Diff line number Diff line Loading @@ -241,6 +241,22 @@ class TestChannelShell(cmd.Cmd): sleep_time = float(args.split()[0]) time.sleep(sleep_time) def do_reset(self, args): """Arguments: None. Resets the simulation. """ self._test_channel.send_command('reset', []) def do_end(self, args): """Arguments: None. Ends the simulation and exits. """ self._test_channel.send_command('END_SIMULATION', []) print('Goodbye.') return True def do_quit(self, args): """Arguments: None. Loading Loading
system/vendor_libs/test_vendor_lib/desktop/test_environment.cc +20 −8 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ using test_vendor_lib::AsyncTaskId; using test_vendor_lib::TaskCallback; void TestEnvironment::initialize(std::promise<void> barrier) { LOG_INFO("%s", __func__); LOG_INFO(); barrier_ = std::move(barrier); Loading @@ -41,12 +41,15 @@ void TestEnvironment::initialize(std::promise<void> barrier) { test_channel_transport_.RegisterCommandHandler( [this, user_id](const std::string& name, const std::vector<std::string>& args) { async_manager_.ExecAsync( user_id, std::chrono::milliseconds(0), [this, name, args]() { test_channel_.HandleCommand(name, args); }); async_manager_.ExecAsync(user_id, std::chrono::milliseconds(0), [this, name, args]() { if (name == "END_SIMULATION") { barrier_.set_value(); } else { test_channel_.HandleCommand(name, args); } }); }); test_model_.Reset(); SetUpTestChannel(); SetUpHciServer([this](int fd) { test_model_.IncomingHciConnection(fd); }); Loading Loading @@ -175,13 +178,22 @@ void TestEnvironment::SetUpTestChannel() { return; } LOG_INFO("Test channel connection accepted."); if (test_channel_open_) { LOG_WARN("Only one connection at a time is supported"); async_manager_.StopWatchingFileDescriptor(conn_fd); test_channel_transport_.SendResponse(conn_fd, "The connection is broken"); return; } test_channel_open_ = true; test_channel_.RegisterSendResponse( [this, conn_fd](const std::string& response) { test_channel_transport_.SendResponse(conn_fd, response); }); [this, conn_fd](const std::string& response) { test_channel_transport_.SendResponse(conn_fd, response); }); async_manager_.WatchFdForNonBlockingReads(conn_fd, [this](int conn_fd) { test_channel_transport_.OnCommandReady(conn_fd, [this, conn_fd]() { async_manager_.StopWatchingFileDescriptor(conn_fd); barrier_.set_value(); test_channel_open_ = false; }); }); }); Loading
system/vendor_libs/test_vendor_lib/desktop/test_environment.h +1 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ class TestEnvironment { uint16_t hci_server_port_; uint16_t link_server_port_; std::string default_commands_file_; bool test_channel_open_{false}; std::promise<void> barrier_; test_vendor_lib::AsyncManager async_manager_; Loading
system/vendor_libs/test_vendor_lib/model/setup/test_channel_transport.cc +5 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ void TestChannelTransport::OnCommandReady(int fd, std::function<void(void)> unwa int bytes_read = read(fd, &command_name_size, 1); if (bytes_read != 1) { LOG_INFO("Unexpected (command_name_size) bytes_read: %d != %d", bytes_read, 1); close(fd); } vector<uint8_t> command_name_raw; command_name_raw.resize(command_name_size); Loading Loading @@ -148,6 +149,10 @@ void TestChannelTransport::SendResponse(int fd, const std::string& response) con uint8_t size_buf[4] = {static_cast<uint8_t>(size & 0xff), static_cast<uint8_t>((size >> 8) & 0xff), static_cast<uint8_t>((size >> 16) & 0xff), static_cast<uint8_t>((size >> 24) & 0xff)}; int written = write(fd, size_buf, 4); if (written == -1 && errno == EBADFD) { LOG_WARN("Unable to send a response. EBADFD"); return; } ASSERT_LOG(written == 4, "What happened? written = %d errno = %d", written, errno); written = write(fd, response.c_str(), size); ASSERT_LOG(written == static_cast<int>(size), "What happened? written = %d errno = %d", written, errno); Loading
system/vendor_libs/test_vendor_lib/model/setup/test_command_handler.cc +1 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ TestCommandHandler::TestCommandHandler(TestModel& test_model) : model_(test_mode SET_HANDLER("set_timer_period", SetTimerPeriod); SET_HANDLER("start_timer", StartTimer); SET_HANDLER("stop_timer", StopTimer); SET_HANDLER("reset", Reset); #undef SET_HANDLER } Loading
system/vendor_libs/test_vendor_lib/scripts/test_channel.py +16 −0 Original line number Diff line number Diff line Loading @@ -241,6 +241,22 @@ class TestChannelShell(cmd.Cmd): sleep_time = float(args.split()[0]) time.sleep(sleep_time) def do_reset(self, args): """Arguments: None. Resets the simulation. """ self._test_channel.send_command('reset', []) def do_end(self, args): """Arguments: None. Ends the simulation and exits. """ self._test_channel.send_command('END_SIMULATION', []) print('Goodbye.') return True def do_quit(self, args): """Arguments: None. Loading