1 /*
2 * Copyright (C) 2021 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 #include <android-base/hex.h>
18 #include <android-base/logging.h>
19 #include <android-base/macros.h>
20 #include <android-base/properties.h>
21 #include <android-base/strings.h>
22 #include <binder/Parcel.h>
23 #include <binder/RpcSession.h>
24 #include <binder/Status.h>
25 #include <gtest/gtest.h>
26
27 #include "../Debug.h"
28
29 namespace android {
30
31 static const int32_t kInt32Array[] = {-1, 0, 17};
32 static const uint8_t kByteArray[] = {0, 17, 255};
33 enum EnumInt8 : int8_t { Int8A, Int8B };
34 enum EnumInt32 : int32_t { Int32A, Int32B };
35 enum EnumInt64 : int64_t { Int64A, Int64B };
36 struct AParcelable : Parcelable {
writeToParcelandroid::AParcelable37 status_t writeToParcel(Parcel* parcel) const { return parcel->writeInt32(37); }
readFromParcelandroid::AParcelable38 status_t readFromParcel(const Parcel*) { return OK; }
39 };
40
41 // clang-format off
42 constexpr size_t kFillFunIndexLineBase = __LINE__ + 2;
43 static const std::vector<std::function<void(Parcel* p)>> kFillFuns {
__anonf530b55b0102(Parcel* p) 44 [](Parcel* p) { ASSERT_EQ(OK, p->writeInterfaceToken(String16(u"tok"))); },
__anonf530b55b0202(Parcel* p) 45 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32(-1)); },
__anonf530b55b0302(Parcel* p) 46 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32(0)); },
__anonf530b55b0402(Parcel* p) 47 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32(17)); },
__anonf530b55b0502(Parcel* p) 48 [](Parcel* p) { ASSERT_EQ(OK, p->writeUint32(0)); },
__anonf530b55b0602(Parcel* p) 49 [](Parcel* p) { ASSERT_EQ(OK, p->writeUint32(1)); },
__anonf530b55b0702(Parcel* p) 50 [](Parcel* p) { ASSERT_EQ(OK, p->writeUint32(10003)); },
__anonf530b55b0802(Parcel* p) 51 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt64(-1)); },
__anonf530b55b0902(Parcel* p) 52 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt64(0)); },
__anonf530b55b0a02(Parcel* p) 53 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt64(17)); },
__anonf530b55b0b02(Parcel* p) 54 [](Parcel* p) { ASSERT_EQ(OK, p->writeUint64(0)); },
__anonf530b55b0c02(Parcel* p) 55 [](Parcel* p) { ASSERT_EQ(OK, p->writeUint64(1)); },
__anonf530b55b0d02(Parcel* p) 56 [](Parcel* p) { ASSERT_EQ(OK, p->writeUint64(10003)); },
__anonf530b55b0e02(Parcel* p) 57 [](Parcel* p) { ASSERT_EQ(OK, p->writeFloat(0.0f)); },
__anonf530b55b0f02(Parcel* p) 58 [](Parcel* p) { ASSERT_EQ(OK, p->writeFloat(0.1f)); },
__anonf530b55b1002(Parcel* p) 59 [](Parcel* p) { ASSERT_EQ(OK, p->writeFloat(9.1f)); },
__anonf530b55b1102(Parcel* p) 60 [](Parcel* p) { ASSERT_EQ(OK, p->writeDouble(0.0)); },
__anonf530b55b1202(Parcel* p) 61 [](Parcel* p) { ASSERT_EQ(OK, p->writeDouble(0.1)); },
__anonf530b55b1302(Parcel* p) 62 [](Parcel* p) { ASSERT_EQ(OK, p->writeDouble(9.1)); },
__anonf530b55b1402(Parcel* p) 63 [](Parcel* p) { ASSERT_EQ(OK, p->writeCString("")); },
__anonf530b55b1502(Parcel* p) 64 [](Parcel* p) { ASSERT_EQ(OK, p->writeCString("a")); },
__anonf530b55b1602(Parcel* p) 65 [](Parcel* p) { ASSERT_EQ(OK, p->writeCString("baba")); },
__anonf530b55b1702(Parcel* p) 66 [](Parcel* p) { ASSERT_EQ(OK, p->writeString8(String8(""))); },
__anonf530b55b1802(Parcel* p) 67 [](Parcel* p) { ASSERT_EQ(OK, p->writeString8(String8("a"))); },
__anonf530b55b1902(Parcel* p) 68 [](Parcel* p) { ASSERT_EQ(OK, p->writeString8(String8("baba"))); },
__anonf530b55b1a02(Parcel* p) 69 [](Parcel* p) { ASSERT_EQ(OK, p->writeString16(String16(u""))); },
__anonf530b55b1b02(Parcel* p) 70 [](Parcel* p) { ASSERT_EQ(OK, p->writeString16(String16(u"a"))); },
__anonf530b55b1c02(Parcel* p) 71 [](Parcel* p) { ASSERT_EQ(OK, p->writeString16(String16(u"baba"))); },
__anonf530b55b1d02(Parcel* p) 72 [](Parcel* p) { ASSERT_EQ(OK, p->writeStrongBinder(nullptr)); },
__anonf530b55b1e02(Parcel* p) 73 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32Array(arraysize(kInt32Array), kInt32Array)); },
__anonf530b55b1f02(Parcel* p) 74 [](Parcel* p) { ASSERT_EQ(OK, p->writeByteArray(arraysize(kByteArray), kByteArray)); },
__anonf530b55b2002(Parcel* p) 75 [](Parcel* p) { ASSERT_EQ(OK, p->writeBool(true)); },
__anonf530b55b2102(Parcel* p) 76 [](Parcel* p) { ASSERT_EQ(OK, p->writeBool(false)); },
__anonf530b55b2202(Parcel* p) 77 [](Parcel* p) { ASSERT_EQ(OK, p->writeChar('a')); },
__anonf530b55b2302(Parcel* p) 78 [](Parcel* p) { ASSERT_EQ(OK, p->writeChar('?')); },
__anonf530b55b2402(Parcel* p) 79 [](Parcel* p) { ASSERT_EQ(OK, p->writeChar('\0')); },
__anonf530b55b2502(Parcel* p) 80 [](Parcel* p) { ASSERT_EQ(OK, p->writeByte(-128)); },
__anonf530b55b2602(Parcel* p) 81 [](Parcel* p) { ASSERT_EQ(OK, p->writeByte(0)); },
__anonf530b55b2702(Parcel* p) 82 [](Parcel* p) { ASSERT_EQ(OK, p->writeByte(127)); },
__anonf530b55b2802(Parcel* p) 83 [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8AsUtf16(std::string(""))); },
__anonf530b55b2902(Parcel* p) 84 [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8AsUtf16(std::string("a"))); },
__anonf530b55b2a02(Parcel* p) 85 [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8AsUtf16(std::string("abab"))); },
__anonf530b55b2b02(Parcel* p) 86 [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8AsUtf16(std::nullopt)); },
__anonf530b55b2c02(Parcel* p) 87 [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8AsUtf16(std::optional<std::string>(""))); },
__anonf530b55b2d02(Parcel* p) 88 [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8AsUtf16(std::optional<std::string>("a"))); },
__anonf530b55b2e02(Parcel* p) 89 [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8AsUtf16(std::optional<std::string>("abab"))); },
__anonf530b55b2f02(Parcel* p) 90 [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::optional<std::vector<int8_t>>(std::nullopt))); },
__anonf530b55b3002(Parcel* p) 91 [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::optional<std::vector<int8_t>>({-1, 0, 17}))); },
__anonf530b55b3102(Parcel* p) 92 [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::vector<int8_t>({}))); },
__anonf530b55b3202(Parcel* p) 93 [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::vector<int8_t>({-1, 0, 17}))); },
__anonf530b55b3302(Parcel* p) 94 [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::optional<std::vector<uint8_t>>(std::nullopt))); },
__anonf530b55b3402(Parcel* p) 95 [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::optional<std::vector<uint8_t>>({0, 1, 17}))); },
__anonf530b55b3502(Parcel* p) 96 [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::vector<uint8_t>({}))); },
__anonf530b55b3602(Parcel* p) 97 [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::vector<uint8_t>({0, 1, 17}))); },
__anonf530b55b3702(Parcel* p) 98 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32Vector(std::optional<std::vector<int32_t>>(std::nullopt))); },
__anonf530b55b3802(Parcel* p) 99 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32Vector(std::optional<std::vector<int32_t>>({-1, 0, 17}))); },
__anonf530b55b3902(Parcel* p) 100 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32Vector(std::vector<int32_t>({}))); },
__anonf530b55b3a02(Parcel* p) 101 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32Vector(std::vector<int32_t>({-1, 0, 17}))); },
__anonf530b55b3b02(Parcel* p) 102 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt64Vector(std::optional<std::vector<int64_t>>(std::nullopt))); },
__anonf530b55b3c02(Parcel* p) 103 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt64Vector(std::optional<std::vector<int64_t>>({-1, 0, 17}))); },
__anonf530b55b3d02(Parcel* p) 104 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt64Vector(std::vector<int64_t>({}))); },
__anonf530b55b3e02(Parcel* p) 105 [](Parcel* p) { ASSERT_EQ(OK, p->writeInt64Vector(std::vector<int64_t>({-1, 0, 17}))); },
__anonf530b55b3f02(Parcel* p) 106 [](Parcel* p) { ASSERT_EQ(OK, p->writeUint64Vector(std::optional<std::vector<uint64_t>>(std::nullopt))); },
__anonf530b55b4002(Parcel* p) 107 [](Parcel* p) { ASSERT_EQ(OK, p->writeUint64Vector(std::optional<std::vector<uint64_t>>({0, 1, 17}))); },
__anonf530b55b4102(Parcel* p) 108 [](Parcel* p) { ASSERT_EQ(OK, p->writeUint64Vector(std::vector<uint64_t>({}))); },
__anonf530b55b4202(Parcel* p) 109 [](Parcel* p) { ASSERT_EQ(OK, p->writeUint64Vector(std::vector<uint64_t>({0, 1, 17}))); },
__anonf530b55b4302(Parcel* p) 110 [](Parcel* p) { ASSERT_EQ(OK, p->writeFloatVector(std::optional<std::vector<float>>(std::nullopt))); },
__anonf530b55b4402(Parcel* p) 111 [](Parcel* p) { ASSERT_EQ(OK, p->writeFloatVector(std::optional<std::vector<float>>({0.0f, 0.1f, 9.1f}))); },
__anonf530b55b4502(Parcel* p) 112 [](Parcel* p) { ASSERT_EQ(OK, p->writeFloatVector(std::vector<float>({}))); },
__anonf530b55b4602(Parcel* p) 113 [](Parcel* p) { ASSERT_EQ(OK, p->writeFloatVector(std::vector<float>({0.0f, 0.1f, 9.1f}))); },
__anonf530b55b4702(Parcel* p) 114 [](Parcel* p) { ASSERT_EQ(OK, p->writeDoubleVector(std::optional<std::vector<double>>(std::nullopt))); },
__anonf530b55b4802(Parcel* p) 115 [](Parcel* p) { ASSERT_EQ(OK, p->writeDoubleVector(std::optional<std::vector<double>>({0.0, 0.1, 9.1}))); },
__anonf530b55b4902(Parcel* p) 116 [](Parcel* p) { ASSERT_EQ(OK, p->writeDoubleVector(std::vector<double>({}))); },
__anonf530b55b4a02(Parcel* p) 117 [](Parcel* p) { ASSERT_EQ(OK, p->writeDoubleVector(std::vector<double>({0.0, 0.1, 9.1}))); },
__anonf530b55b4b02(Parcel* p) 118 [](Parcel* p) { ASSERT_EQ(OK, p->writeBoolVector(std::optional<std::vector<bool>>(std::nullopt))); },
__anonf530b55b4c02(Parcel* p) 119 [](Parcel* p) { ASSERT_EQ(OK, p->writeBoolVector(std::optional<std::vector<bool>>({true, false}))); },
__anonf530b55b4d02(Parcel* p) 120 [](Parcel* p) { ASSERT_EQ(OK, p->writeBoolVector(std::vector<bool>({}))); },
__anonf530b55b4e02(Parcel* p) 121 [](Parcel* p) { ASSERT_EQ(OK, p->writeBoolVector(std::vector<bool>({true, false}))); },
__anonf530b55b4f02(Parcel* p) 122 [](Parcel* p) { ASSERT_EQ(OK, p->writeCharVector(std::optional<std::vector<char16_t>>(std::nullopt))); },
__anonf530b55b5002(Parcel* p) 123 [](Parcel* p) { ASSERT_EQ(OK, p->writeCharVector(std::optional<std::vector<char16_t>>({'a', '\0', '?'}))); },
__anonf530b55b5102(Parcel* p) 124 [](Parcel* p) { ASSERT_EQ(OK, p->writeCharVector(std::vector<char16_t>({}))); },
__anonf530b55b5202(Parcel* p) 125 [](Parcel* p) { ASSERT_EQ(OK, p->writeCharVector(std::vector<char16_t>({'a', '\0', '?'}))); },
__anonf530b55b5302(Parcel* p) 126 [](Parcel* p) { ASSERT_EQ(OK, p->writeString16Vector(std::optional<std::vector<std::optional<String16>>>(std::nullopt))); },
__anonf530b55b5402(Parcel* p) 127 [](Parcel* p) { ASSERT_EQ(OK, p->writeString16Vector(std::optional<std::vector<std::optional<String16>>>({std::nullopt, String16(), String16(u"a")}))); },
__anonf530b55b5502(Parcel* p) 128 [](Parcel* p) { ASSERT_EQ(OK, p->writeString16Vector(std::vector<std::optional<String16>>({}))); },
__anonf530b55b5602(Parcel* p) 129 [](Parcel* p) { ASSERT_EQ(OK, p->writeString16Vector(std::vector<std::optional<String16>>({std::nullopt, String16(), String16(u"a")}))); },
__anonf530b55b5702(Parcel* p) 130 [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8VectorAsUtf16Vector(std::optional<std::vector<std::optional<std::string>>>(std::nullopt))); },
__anonf530b55b5802(Parcel* p) 131 [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8VectorAsUtf16Vector(std::optional<std::vector<std::optional<std::string>>>({std::nullopt, std::string(), std::string("a")}))); },
__anonf530b55b5902(Parcel* p) 132 [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8VectorAsUtf16Vector(std::vector<std::optional<std::string>>({}))); },
__anonf530b55b5a02(Parcel* p) 133 [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8VectorAsUtf16Vector(std::vector<std::optional<std::string>>({std::nullopt, std::string(), std::string("a")}))); },
__anonf530b55b5b02(Parcel* p) 134 [](Parcel* p) { ASSERT_EQ(OK, p->writeStrongBinderVector(std::optional<std::vector<sp<IBinder>>>(std::nullopt))); },
__anonf530b55b5c02(Parcel* p) 135 [](Parcel* p) { ASSERT_EQ(OK, p->writeStrongBinderVector(std::optional<std::vector<sp<IBinder>>>({nullptr}))); },
__anonf530b55b5d02(Parcel* p) 136 [](Parcel* p) { ASSERT_EQ(OK, p->writeStrongBinderVector(std::vector<sp<IBinder>>({}))); },
__anonf530b55b5e02(Parcel* p) 137 [](Parcel* p) { ASSERT_EQ(OK, p->writeStrongBinderVector(std::vector<sp<IBinder>>({nullptr}))); },
__anonf530b55b5f02(Parcel* p) 138 [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::optional<std::vector<EnumInt8>>(std::nullopt))); },
__anonf530b55b6002(Parcel* p) 139 [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::optional<std::vector<EnumInt8>>({Int8A, Int8B}))); },
__anonf530b55b6102(Parcel* p) 140 [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::vector<EnumInt8>({Int8A, Int8B}))); },
__anonf530b55b6202(Parcel* p) 141 [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::optional<std::vector<EnumInt32>>(std::nullopt))); },
__anonf530b55b6302(Parcel* p) 142 [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::optional<std::vector<EnumInt32>>({Int32A, Int32B}))); },
__anonf530b55b6402(Parcel* p) 143 [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::vector<EnumInt32>({Int32A, Int32B}))); },
__anonf530b55b6502(Parcel* p) 144 [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::optional<std::vector<EnumInt64>>(std::nullopt))); },
__anonf530b55b6602(Parcel* p) 145 [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::optional<std::vector<EnumInt64>>({Int64A, Int64B}))); },
__anonf530b55b6702(Parcel* p) 146 [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::vector<EnumInt64>({Int64A, Int64B}))); },
__anonf530b55b6802(Parcel* p) 147 [](Parcel* p) { ASSERT_EQ(OK, p->writeParcelableVector(std::optional<std::vector<std::optional<AParcelable>>>(std::nullopt))); },
__anonf530b55b6902(Parcel* p) 148 [](Parcel* p) { ASSERT_EQ(OK, p->writeParcelableVector(std::optional<std::vector<std::optional<AParcelable>>>({AParcelable()}))); },
__anonf530b55b6a02(Parcel* p) 149 [](Parcel* p) { ASSERT_EQ(OK, p->writeParcelableVector(std::vector<AParcelable>({AParcelable()}))); },
__anonf530b55b6b02(Parcel* p) 150 [](Parcel* p) { ASSERT_EQ(OK, p->writeNullableParcelable(std::optional<AParcelable>(std::nullopt))); },
__anonf530b55b6c02(Parcel* p) 151 [](Parcel* p) { ASSERT_EQ(OK, p->writeNullableParcelable(std::optional<AParcelable>(AParcelable()))); },
__anonf530b55b6d02(Parcel* p) 152 [](Parcel* p) { ASSERT_EQ(OK, p->writeParcelable(AParcelable())); },
__anonf530b55b6e02(Parcel* p) 153 [](Parcel* p) { ASSERT_EQ(OK, p->writeVectorSize(std::vector<int32_t>({0, 1, 17}))); },
__anonf530b55b6f02(Parcel* p) 154 [](Parcel* p) { ASSERT_EQ(OK, p->writeVectorSize(std::vector<AParcelable>({}))); },
__anonf530b55b7002(Parcel* p) 155 [](Parcel* p) { ASSERT_EQ(OK, p->writeVectorSize(std::optional<std::vector<int32_t>>(std::nullopt))); },
__anonf530b55b7102(Parcel* p) 156 [](Parcel* p) { ASSERT_EQ(OK, p->writeVectorSize(std::optional<std::vector<int32_t>>({0, 1, 17}))); },
__anonf530b55b7202(Parcel* p) 157 [](Parcel* p) { ASSERT_EQ(OK, p->writeNoException()); },
__anonf530b55b7302(Parcel* p) 158 [](Parcel* p) { ASSERT_EQ(OK, binder::Status::ok().writeToParcel(p)); },
__anonf530b55b7402(Parcel* p) 159 [](Parcel* p) { ASSERT_EQ(OK, binder::Status::fromExceptionCode(7, ":D").writeToParcel(p)); },
__anonf530b55b7502(Parcel* p) 160 [](Parcel* p) { ASSERT_EQ(OK, binder::Status::fromServiceSpecificError(8, ":/").writeToParcel(p)); },
161 };
162 // clang-format on
163
setParcelForRpc(Parcel * p,uint32_t version)164 static void setParcelForRpc(Parcel* p, uint32_t version) {
165 auto session = RpcSession::make();
166 CHECK(session->setProtocolVersion(version));
167 CHECK_EQ(OK, session->addNullDebuggingClient());
168 p->markForRpc(session);
169 }
170
buildRepr(uint32_t version)171 static std::string buildRepr(uint32_t version) {
172 std::string result;
173 for (size_t i = 0; i < kFillFuns.size(); i++) {
174 if (i != 0) result += "|";
175 Parcel p;
176 setParcelForRpc(&p, version);
177 kFillFuns[i](&p);
178
179 result += base::HexString(p.data(), p.dataSize());
180 }
181 return result;
182 }
183
checkRepr(const std::string & repr,uint32_t version)184 static void checkRepr(const std::string& repr, uint32_t version) {
185 const std::string actualRepr = buildRepr(version);
186
187 auto expected = base::Split(repr, "|");
188 ASSERT_EQ(expected.size(), kFillFuns.size());
189
190 auto actual = base::Split(actualRepr, "|");
191 ASSERT_EQ(actual.size(), kFillFuns.size());
192
193 for (size_t i = 0; i < kFillFuns.size(); i++) {
194 EXPECT_EQ(expected[i], actual[i])
195 << "Format mismatch, see " __FILE__ " line " << (kFillFunIndexLineBase + i);
196 }
197
198 // same check as in the loop, but the above error is more clear to debug,
199 // and this error is more clear to be able to update the source file here.
200 EXPECT_EQ(repr, actualRepr);
201 }
202
203 const std::string kCurrentRepr =
204 "0300000074006f006b000000|ffffffff|00000000|11000000|00000000|01000000|13270000|"
205 "ffffffffffffffff|0000000000000000|1100000000000000|0000000000000000|0100000000000000|"
206 "1327000000000000|00000000|cdcccc3d|9a991141|0000000000000000|9a9999999999b93f|"
207 "3333333333332240|00000000|61000000|6261626100000000|0000000000000000|0100000061000000|"
208 "040000006261626100000000|0000000000000000|0100000061000000|"
209 "04000000620061006200610000000000|0000000000000000|03000000ffffffff0000000011000000|"
210 "030000000011ff00|01000000|00000000|61000000|3f000000|00000000|80ffffff|00000000|7f000000|"
211 "0000000000000000|0100000061000000|04000000610062006100620000000000|ffffffff|"
212 "0000000000000000|0100000061000000|04000000610062006100620000000000|ffffffff|"
213 "03000000ff001100|00000000|03000000ff001100|ffffffff|0300000000011100|00000000|"
214 "0300000000011100|ffffffff|03000000ffffffff0000000011000000|00000000|"
215 "03000000ffffffff0000000011000000|ffffffff|"
216 "03000000ffffffffffffffff00000000000000001100000000000000|00000000|"
217 "03000000ffffffffffffffff00000000000000001100000000000000|ffffffff|"
218 "03000000000000000000000001000000000000001100000000000000|00000000|"
219 "03000000000000000000000001000000000000001100000000000000|ffffffff|"
220 "0300000000000000cdcccc3d9a991141|00000000|0300000000000000cdcccc3d9a991141|ffffffff|"
221 "0300000000000000000000009a9999999999b93f3333333333332240|00000000|"
222 "0300000000000000000000009a9999999999b93f3333333333332240|ffffffff|"
223 "020000000100000000000000|00000000|020000000100000000000000|ffffffff|"
224 "0300000061000000000000003f000000|00000000|0300000061000000000000003f000000|ffffffff|"
225 "03000000ffffffff00000000000000000100000061000000|00000000|"
226 "03000000ffffffff00000000000000000100000061000000|ffffffff|"
227 "03000000ffffffff00000000000000000100000061000000|00000000|"
228 "03000000ffffffff00000000000000000100000061000000|ffffffff|010000000000000000000000|"
229 "00000000|010000000000000000000000|ffffffff|0200000000010000|0200000000010000|ffffffff|"
230 "020000000000000001000000|020000000000000001000000|ffffffff|"
231 "0200000000000000000000000100000000000000|0200000000000000000000000100000000000000|"
232 "ffffffff|010000000100000025000000|010000000100000025000000|00000000|0100000025000000|"
233 "0100000025000000|03000000|00000000|ffffffff|03000000|00000000|00000000|"
234 "07000000020000003a0044000000000000000000|f8ffffff020000003a002f00000000000000000008000000";
235
TEST(RpcWire,V0)236 TEST(RpcWire, V0) {
237 checkRepr(kCurrentRepr, 0);
238 }
239
TEST(RpcWire,V1)240 TEST(RpcWire, V1) {
241 checkRepr(kCurrentRepr, 1);
242 }
243
TEST(RpcWire,CurrentVersion)244 TEST(RpcWire, CurrentVersion) {
245 checkRepr(kCurrentRepr, RPC_WIRE_PROTOCOL_VERSION);
246 }
247
248 static_assert(RPC_WIRE_PROTOCOL_VERSION == 1,
249 "If the binder wire protocol is updated, this test should test additional versions. "
250 "The binder wire protocol should only be updated on upstream AOSP.");
251
TEST(RpcWire,NextIsPlusOneReminder)252 TEST(RpcWire, NextIsPlusOneReminder) {
253 if (RPC_WIRE_PROTOCOL_VERSION != RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL) {
254 EXPECT_EQ(RPC_WIRE_PROTOCOL_VERSION + 1, RPC_WIRE_PROTOCOL_VERSION_NEXT)
255 << "Make sure to note what the next version should be.";
256 }
257 }
258
TEST(RpcWire,ReleaseBranchHasFrozenRpcWireProtocol)259 TEST(RpcWire, ReleaseBranchHasFrozenRpcWireProtocol) {
260 if (RPC_WIRE_PROTOCOL_VERSION == RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL) {
261 EXPECT_FALSE(base::GetProperty("ro.build.version.codename", "") == "REL")
262 << "Binder RPC wire protocol must be frozen on a release branch!";
263 }
264 }
265
TEST(RpcWire,IfNotExperimentalCodeHasNoExperimentalFeatures)266 TEST(RpcWire, IfNotExperimentalCodeHasNoExperimentalFeatures) {
267 if (RPC_WIRE_PROTOCOL_VERSION == RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL) {
268 GTEST_SKIP() << "Version is experimental, so experimental features are okay.";
269 }
270
271 // if we set the wire protocol version to experimental, none of the code
272 // should introduce a difference (if this fails, it means we have features
273 // which are enabled under experimental mode, but we aren't actually using
274 // or testing them!)
275 checkRepr(kCurrentRepr, RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL);
276 }
277
278 } // namespace android
279