1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <string> 20 #include <vector> 21 22 #include <android-base/file.h> 23 #include <android-base/unique_fd.h> 24 25 namespace test_utils { 26 27 // Reads raw data from |fd| until it closes or errors. 28 std::string ReadRaw(android::base::borrowed_fd fd); 29 30 // / Reads shell protocol data from |fd| until it closes or errors. Fills 31 // |stdout| and |stderr| with their respective data, and returns the exit code 32 // read from the protocol or -1 if an exit code packet was not received. 33 int ReadShellProtocol(android::base::borrowed_fd fd, std::string* std_out, std::string* std_err); 34 35 // Checks if each line in |lines| exists in the same order in |output|. Blank 36 // lines in |output| are ignored for simplicity. 37 bool ExpectLinesEqual(const std::string& output, const std::vector<std::string>& lines); 38 39 // Allows the device to allocate a port, which is returned to the caller. 40 // Also returns the associated fd. 41 int GetUnassignedPort(android::base::unique_fd& fd); 42 43 } // namespace test_utils 44