diff options
| author | 2023-05-12 06:05:00 +0000 | |
|---|---|---|
| committer | 2023-05-12 06:05:00 +0000 | |
| commit | c86e5475ec5407bce8b2bbe15ff7f0cee98a681b (patch) | |
| tree | adabd84625bc6825eb500b43b5fefcdf6ae91ffb | |
| parent | 12a296d55246aeda9e081f716d0fbb969cda9b71 (diff) | |
| parent | f14019f5a58cff2fc2f0d85959840e298fb41ad9 (diff) | |
Merge "binderRecordReplayTest: test arrays" am: 6049ba2807 am: 9ef369248a am: 5b1dd98d58 am: f14019f5a5
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2585154
Change-Id: I8268d26fb9c96d1da2d53d6ba55e7563d0731571
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | libs/binder/tests/Android.bp | 8 | ||||
| -rw-r--r-- | libs/binder/tests/IBinderRecordReplayTest.aidl | 34 | ||||
| -rw-r--r-- | libs/binder/tests/binderRecordReplayTest.cpp | 170 |
3 files changed, 185 insertions, 27 deletions
diff --git a/libs/binder/tests/Android.bp b/libs/binder/tests/Android.bp index 6bf1539b4e..41856f9b79 100644 --- a/libs/binder/tests/Android.bp +++ b/libs/binder/tests/Android.bp @@ -76,6 +76,7 @@ cc_test { ], static_libs: [ "binderRecordReplayTestIface-cpp", + "binderReadParcelIface-cpp", ], test_suites: ["general-tests"], require_root: true, @@ -87,6 +88,13 @@ aidl_interface { srcs: [ "IBinderRecordReplayTest.aidl", ], + imports: ["binderReadParcelIface"], + backend: { + java: { + enabled: true, + platform_apis: true, + }, + }, } cc_test { diff --git a/libs/binder/tests/IBinderRecordReplayTest.aidl b/libs/binder/tests/IBinderRecordReplayTest.aidl index 2497277177..bd6b03c6e0 100644 --- a/libs/binder/tests/IBinderRecordReplayTest.aidl +++ b/libs/binder/tests/IBinderRecordReplayTest.aidl @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import parcelables.SingleDataParcelable; interface IBinderRecordReplayTest { void setByte(byte input); @@ -35,4 +36,37 @@ interface IBinderRecordReplayTest { void setDouble(double input); double getDouble(); + + void setString(String input); + String getString(); + + void setSingleDataParcelable(in SingleDataParcelable p); + SingleDataParcelable getSingleDataParcelable(); + + void setByteArray(in byte[] input); + byte[] getByteArray(); + + void setCharArray(in char[] input); + char[] getCharArray(); + + void setBooleanArray(in boolean[] input); + boolean[] getBooleanArray(); + + void setIntArray(in int[] input); + int[] getIntArray(); + + void setFloatArray(in float[] input); + float[] getFloatArray(); + + void setLongArray(in long[] input); + long[] getLongArray(); + + void setDoubleArray(in double[] input); + double[] getDoubleArray(); + + void setStringArray(in String[] input); + String[] getStringArray(); + + void setSingleDataParcelableArray(in SingleDataParcelable[] input); + SingleDataParcelable[] getSingleDataParcelableArray(); } diff --git a/libs/binder/tests/binderRecordReplayTest.cpp b/libs/binder/tests/binderRecordReplayTest.cpp index 599889caf2..db7854679f 100644 --- a/libs/binder/tests/binderRecordReplayTest.cpp +++ b/libs/binder/tests/binderRecordReplayTest.cpp @@ -27,14 +27,29 @@ #include <sys/prctl.h> +#include "parcelables/SingleDataParcelable.h" + using namespace android; using android::binder::Status; using android::binder::debug::RecordedTransaction; +using parcelables::SingleDataParcelable; const String16 kServerName = String16("binderRecordReplay"); +#define GENERATE_GETTER_SETTER_PRIMITIVE(name, T) \ + Status set##name(T input) { \ + m##name = input; \ + return Status::ok(); \ + } \ + \ + Status get##name(T* output) { \ + *output = m##name; \ + return Status::ok(); \ + } \ + T m##name + #define GENERATE_GETTER_SETTER(name, T) \ - Status set##name(T input) { \ + Status set##name(const T& input) { \ m##name = input; \ return Status::ok(); \ } \ @@ -47,29 +62,42 @@ const String16 kServerName = String16("binderRecordReplay"); class MyRecordReplay : public BnBinderRecordReplayTest { public: - GENERATE_GETTER_SETTER(Boolean, bool); - GENERATE_GETTER_SETTER(Byte, int8_t); - GENERATE_GETTER_SETTER(Int, int); - GENERATE_GETTER_SETTER(Char, char16_t); - GENERATE_GETTER_SETTER(Long, int64_t); - GENERATE_GETTER_SETTER(Float, float); - GENERATE_GETTER_SETTER(Double, double); + GENERATE_GETTER_SETTER_PRIMITIVE(Boolean, bool); + GENERATE_GETTER_SETTER_PRIMITIVE(Byte, int8_t); + GENERATE_GETTER_SETTER_PRIMITIVE(Int, int); + GENERATE_GETTER_SETTER_PRIMITIVE(Char, char16_t); + GENERATE_GETTER_SETTER_PRIMITIVE(Long, int64_t); + GENERATE_GETTER_SETTER_PRIMITIVE(Float, float); + GENERATE_GETTER_SETTER_PRIMITIVE(Double, double); + + GENERATE_GETTER_SETTER(String, String16); + GENERATE_GETTER_SETTER(SingleDataParcelable, SingleDataParcelable); + + GENERATE_GETTER_SETTER(BooleanArray, std::vector<bool>); + GENERATE_GETTER_SETTER(ByteArray, std::vector<uint8_t>); + GENERATE_GETTER_SETTER(IntArray, std::vector<int>); + GENERATE_GETTER_SETTER(CharArray, std::vector<char16_t>); + GENERATE_GETTER_SETTER(LongArray, std::vector<int64_t>); + GENERATE_GETTER_SETTER(FloatArray, std::vector<float>); + GENERATE_GETTER_SETTER(DoubleArray, std::vector<double>); + GENERATE_GETTER_SETTER(StringArray, std::vector<::android::String16>); + GENERATE_GETTER_SETTER(SingleDataParcelableArray, std::vector<SingleDataParcelable>); }; -class BinderClearBuf : public ::testing::Test { +class BinderRecordReplayTest : public ::testing::Test { public: void SetUp() override { // get the remote service - mBinder = defaultServiceManager()->getService(kServerName); - ASSERT_NE(nullptr, mBinder); - mInterface = interface_cast<IBinderRecordReplayTest>(mBinder); - mBpBinder = mBinder->remoteBinder(); + auto binder = defaultServiceManager()->getService(kServerName); + ASSERT_NE(nullptr, binder); + mInterface = interface_cast<IBinderRecordReplayTest>(binder); + mBpBinder = binder->remoteBinder(); ASSERT_NE(nullptr, mBpBinder); } - template <typename T> - void recordReplay(Status (IBinderRecordReplayTest::*set)(T), T recordedValue, - Status (IBinderRecordReplayTest::*get)(T*), T changedValue) { + template <typename T, typename U> + void recordReplay(Status (IBinderRecordReplayTest::*set)(T), U recordedValue, + Status (IBinderRecordReplayTest::*get)(U*), U changedValue) { base::unique_fd fd(open("/data/local/tmp/binderRecordReplayTest.rec", O_RDWR | O_CREAT | O_CLOEXEC, 0666)); ASSERT_TRUE(fd.ok()); @@ -81,7 +109,7 @@ public: mBpBinder->stopRecordingBinder(); // test transaction does the thing we expect it to do - T output; + U output; status = (*mInterface.*get)(&output); EXPECT_TRUE(status.isOk()); EXPECT_EQ(output, recordedValue); @@ -103,8 +131,8 @@ public: // TODO: move logic to replay RecordedTransaction into RecordedTransaction Parcel data; data.setData(transaction->getDataParcel().data(), transaction->getDataParcel().dataSize()); - auto result = mBinder->remoteBinder()->transact(transaction->getCode(), data, nullptr, - transaction->getFlags()); + auto result = + mBpBinder->transact(transaction->getCode(), data, nullptr, transaction->getFlags()); // make sure recording does the thing we expect it to do EXPECT_EQ(OK, result); @@ -115,45 +143,133 @@ public: } private: - sp<IBinder> mBinder; sp<BpBinder> mBpBinder; sp<IBinderRecordReplayTest> mInterface; }; -TEST_F(BinderClearBuf, RecordReplayRepeatByte) { +TEST_F(BinderRecordReplayTest, ReplayByte) { recordReplay(&IBinderRecordReplayTest::setByte, int8_t{122}, &IBinderRecordReplayTest::getByte, int8_t{90}); } -TEST_F(BinderClearBuf, RecordReplayRepeatBoolean) { +TEST_F(BinderRecordReplayTest, ReplayBoolean) { recordReplay(&IBinderRecordReplayTest::setBoolean, true, &IBinderRecordReplayTest::getBoolean, false); } -TEST_F(BinderClearBuf, RecordReplayRepeatChar) { +TEST_F(BinderRecordReplayTest, ReplayChar) { recordReplay(&IBinderRecordReplayTest::setChar, char16_t{'G'}, &IBinderRecordReplayTest::getChar, char16_t{'K'}); } -TEST_F(BinderClearBuf, RecordReplayRepeatInt) { +TEST_F(BinderRecordReplayTest, ReplayInt) { recordReplay(&IBinderRecordReplayTest::setInt, 3, &IBinderRecordReplayTest::getInt, 5); } -TEST_F(BinderClearBuf, RecordReplayRepeatFloat) { +TEST_F(BinderRecordReplayTest, ReplayFloat) { recordReplay(&IBinderRecordReplayTest::setFloat, 1.1f, &IBinderRecordReplayTest::getFloat, 22.0f); } -TEST_F(BinderClearBuf, RecordReplayRepeatLong) { +TEST_F(BinderRecordReplayTest, ReplayLong) { recordReplay(&IBinderRecordReplayTest::setLong, int64_t{1LL << 55}, &IBinderRecordReplayTest::getLong, int64_t{1LL << 12}); } -TEST_F(BinderClearBuf, RecordReplayRepeatDouble) { +TEST_F(BinderRecordReplayTest, ReplayDouble) { recordReplay(&IBinderRecordReplayTest::setDouble, 0.00, &IBinderRecordReplayTest::getDouble, 1.11); } +TEST_F(BinderRecordReplayTest, ReplayString) { + const ::android::String16& input1 = String16("This is saved string"); + const ::android::String16& input2 = String16("This is changed string"); + recordReplay(&IBinderRecordReplayTest::setString, input1, &IBinderRecordReplayTest::getString, + input2); +} + +TEST_F(BinderRecordReplayTest, ReplaySingleDataParcelable) { + SingleDataParcelable saved, changed; + saved.data = 3; + changed.data = 5; + recordReplay(&IBinderRecordReplayTest::setSingleDataParcelable, saved, + &IBinderRecordReplayTest::getSingleDataParcelable, changed); +} + +TEST_F(BinderRecordReplayTest, ReplayByteArray) { + std::vector<uint8_t> savedArray = {uint8_t{255}, uint8_t{0}, uint8_t{127}}; + std::vector<uint8_t> changedArray = {uint8_t{2}, uint8_t{7}, uint8_t{117}}; + recordReplay(&IBinderRecordReplayTest::setByteArray, savedArray, + &IBinderRecordReplayTest::getByteArray, changedArray); +} + +TEST_F(BinderRecordReplayTest, ReplayBooleanArray) { + std::vector<bool> savedArray = {true, false, true}; + std::vector<bool> changedArray = {false, true, false}; + recordReplay(&IBinderRecordReplayTest::setBooleanArray, savedArray, + &IBinderRecordReplayTest::getBooleanArray, changedArray); +} + +TEST_F(BinderRecordReplayTest, ReplayCharArray) { + std::vector<char16_t> savedArray = {char16_t{'G'}, char16_t{'L'}, char16_t{'K'}, char16_t{'T'}}; + std::vector<char16_t> changedArray = {char16_t{'X'}, char16_t{'Y'}, char16_t{'Z'}}; + recordReplay(&IBinderRecordReplayTest::setCharArray, savedArray, + &IBinderRecordReplayTest::getCharArray, changedArray); +} + +TEST_F(BinderRecordReplayTest, ReplayIntArray) { + std::vector<int> savedArray = {12, 45, 178}; + std::vector<int> changedArray = {32, 14, 78, 1899}; + recordReplay(&IBinderRecordReplayTest::setIntArray, savedArray, + &IBinderRecordReplayTest::getIntArray, changedArray); +} + +TEST_F(BinderRecordReplayTest, ReplayFloatArray) { + std::vector<float> savedArray = {12.14f, 45.56f, 123.178f}; + std::vector<float> changedArray = {0.00f, 14.0f, 718.1f, 1899.122f, 3268.123f}; + recordReplay(&IBinderRecordReplayTest::setFloatArray, savedArray, + &IBinderRecordReplayTest::getFloatArray, changedArray); +} + +TEST_F(BinderRecordReplayTest, ReplayLongArray) { + std::vector<int64_t> savedArray = {int64_t{1LL << 11}, int64_t{1LL << 55}, int64_t{1LL << 45}}; + std::vector<int64_t> changedArray = {int64_t{1LL << 1}, int64_t{1LL << 21}, int64_t{1LL << 33}, + int64_t{1LL << 63}}; + recordReplay(&IBinderRecordReplayTest::setLongArray, savedArray, + &IBinderRecordReplayTest::getLongArray, changedArray); +} + +TEST_F(BinderRecordReplayTest, ReplayDoubleArray) { + std::vector<double> savedArray = {12.1412313, 45.561232, 123.1781111}; + std::vector<double> changedArray = {0.00111, 14.32130, 712312318.19, 1899212.122, + 322168.122123}; + recordReplay(&IBinderRecordReplayTest::setDoubleArray, savedArray, + &IBinderRecordReplayTest::getDoubleArray, changedArray); +} + +TEST_F(BinderRecordReplayTest, ReplayStringArray) { + std::vector<String16> savedArray = {String16("This is saved value"), String16(), + String16("\0\0", 2), String16("\xF3\x01\xAC\xAD\x21\xAF")}; + + std::vector<String16> changedArray = {String16("This is changed value"), String16("\1\2", 30)}; + recordReplay(&IBinderRecordReplayTest::setStringArray, savedArray, + &IBinderRecordReplayTest::getStringArray, changedArray); +} + +TEST_F(BinderRecordReplayTest, ReplaySingleDataParcelableArray) { + SingleDataParcelable s1, s2, s3, s4, s5; + s1.data = 5213; + s2.data = 1512; + s3.data = 4233; + s4.data = 123124; + s5.data = 0; + std::vector<SingleDataParcelable> saved = {s1, s2, s3}; + std::vector<SingleDataParcelable> changed = {s4, s5}; + + recordReplay(&IBinderRecordReplayTest::setSingleDataParcelableArray, saved, + &IBinderRecordReplayTest::getSingleDataParcelableArray, changed); +} + int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); |