Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5b1dd98d authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "binderRecordReplayTest: test arrays" am: 6049ba28 am: 9ef36924

parents c28f7784 9ef36924
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -76,6 +76,7 @@ cc_test {
    ],
    ],
    static_libs: [
    static_libs: [
        "binderRecordReplayTestIface-cpp",
        "binderRecordReplayTestIface-cpp",
        "binderReadParcelIface-cpp",
    ],
    ],
    test_suites: ["general-tests"],
    test_suites: ["general-tests"],
    require_root: true,
    require_root: true,
@@ -87,6 +88,13 @@ aidl_interface {
    srcs: [
    srcs: [
        "IBinderRecordReplayTest.aidl",
        "IBinderRecordReplayTest.aidl",
    ],
    ],
    imports: ["binderReadParcelIface"],
    backend: {
        java: {
            enabled: true,
            platform_apis: true,
        },
    },
}
}


cc_test {
cc_test {
+34 −0
Original line number Original line Diff line number Diff line
@@ -13,6 +13,7 @@
 * See the License for the specific language governing permissions and
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * limitations under the License.
 */
 */
import parcelables.SingleDataParcelable;


interface IBinderRecordReplayTest {
interface IBinderRecordReplayTest {
    void setByte(byte input);
    void setByte(byte input);
@@ -35,4 +36,37 @@ interface IBinderRecordReplayTest {


    void setDouble(double input);
    void setDouble(double input);
    double getDouble();
    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();
}
}
+143 −27
Original line number Original line Diff line number Diff line
@@ -27,13 +27,16 @@


#include <sys/prctl.h>
#include <sys/prctl.h>


#include "parcelables/SingleDataParcelable.h"

using namespace android;
using namespace android;
using android::binder::Status;
using android::binder::Status;
using android::binder::debug::RecordedTransaction;
using android::binder::debug::RecordedTransaction;
using parcelables::SingleDataParcelable;


const String16 kServerName = String16("binderRecordReplay");
const String16 kServerName = String16("binderRecordReplay");


#define GENERATE_GETTER_SETTER(name, T) \
#define GENERATE_GETTER_SETTER_PRIMITIVE(name, T) \
    Status set##name(T input) {                   \
    Status set##name(T input) {                   \
        m##name = input;                          \
        m##name = input;                          \
        return Status::ok();                      \
        return Status::ok();                      \
@@ -45,31 +48,56 @@ const String16 kServerName = String16("binderRecordReplay");
    }                                             \
    }                                             \
    T m##name
    T m##name


#define GENERATE_GETTER_SETTER(name, T) \
    Status set##name(const T& input) {  \
        m##name = input;                \
        return Status::ok();            \
    }                                   \
                                        \
    Status get##name(T* output) {       \
        *output = m##name;              \
        return Status::ok();            \
    }                                   \
    T m##name

class MyRecordReplay : public BnBinderRecordReplayTest {
class MyRecordReplay : public BnBinderRecordReplayTest {
public:
public:
    GENERATE_GETTER_SETTER(Boolean, bool);
    GENERATE_GETTER_SETTER_PRIMITIVE(Boolean, bool);
    GENERATE_GETTER_SETTER(Byte, int8_t);
    GENERATE_GETTER_SETTER_PRIMITIVE(Byte, int8_t);
    GENERATE_GETTER_SETTER(Int, int);
    GENERATE_GETTER_SETTER_PRIMITIVE(Int, int);
    GENERATE_GETTER_SETTER(Char, char16_t);
    GENERATE_GETTER_SETTER_PRIMITIVE(Char, char16_t);
    GENERATE_GETTER_SETTER(Long, int64_t);
    GENERATE_GETTER_SETTER_PRIMITIVE(Long, int64_t);
    GENERATE_GETTER_SETTER(Float, float);
    GENERATE_GETTER_SETTER_PRIMITIVE(Float, float);
    GENERATE_GETTER_SETTER(Double, double);
    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:
public:
    void SetUp() override {
    void SetUp() override {
        // get the remote service
        // get the remote service
        mBinder = defaultServiceManager()->getService(kServerName);
        auto binder = defaultServiceManager()->getService(kServerName);
        ASSERT_NE(nullptr, mBinder);
        ASSERT_NE(nullptr, binder);
        mInterface = interface_cast<IBinderRecordReplayTest>(mBinder);
        mInterface = interface_cast<IBinderRecordReplayTest>(binder);
        mBpBinder = mBinder->remoteBinder();
        mBpBinder = binder->remoteBinder();
        ASSERT_NE(nullptr, mBpBinder);
        ASSERT_NE(nullptr, mBpBinder);
    }
    }


    template <typename T>
    template <typename T, typename U>
    void recordReplay(Status (IBinderRecordReplayTest::*set)(T), T recordedValue,
    void recordReplay(Status (IBinderRecordReplayTest::*set)(T), U recordedValue,
                      Status (IBinderRecordReplayTest::*get)(T*), T changedValue) {
                      Status (IBinderRecordReplayTest::*get)(U*), U changedValue) {
        base::unique_fd fd(open("/data/local/tmp/binderRecordReplayTest.rec",
        base::unique_fd fd(open("/data/local/tmp/binderRecordReplayTest.rec",
                                O_RDWR | O_CREAT | O_CLOEXEC, 0666));
                                O_RDWR | O_CREAT | O_CLOEXEC, 0666));
        ASSERT_TRUE(fd.ok());
        ASSERT_TRUE(fd.ok());
@@ -81,7 +109,7 @@ public:
        mBpBinder->stopRecordingBinder();
        mBpBinder->stopRecordingBinder();


        // test transaction does the thing we expect it to do
        // test transaction does the thing we expect it to do
        T output;
        U output;
        status = (*mInterface.*get)(&output);
        status = (*mInterface.*get)(&output);
        EXPECT_TRUE(status.isOk());
        EXPECT_TRUE(status.isOk());
        EXPECT_EQ(output, recordedValue);
        EXPECT_EQ(output, recordedValue);
@@ -103,8 +131,8 @@ public:
        // TODO: move logic to replay RecordedTransaction into RecordedTransaction
        // TODO: move logic to replay RecordedTransaction into RecordedTransaction
        Parcel data;
        Parcel data;
        data.setData(transaction->getDataParcel().data(), transaction->getDataParcel().dataSize());
        data.setData(transaction->getDataParcel().data(), transaction->getDataParcel().dataSize());
        auto result = mBinder->remoteBinder()->transact(transaction->getCode(), data, nullptr,
        auto result =
                                                        transaction->getFlags());
                mBpBinder->transact(transaction->getCode(), data, nullptr, transaction->getFlags());


        // make sure recording does the thing we expect it to do
        // make sure recording does the thing we expect it to do
        EXPECT_EQ(OK, result);
        EXPECT_EQ(OK, result);
@@ -115,45 +143,133 @@ public:
    }
    }


private:
private:
    sp<IBinder> mBinder;
    sp<BpBinder> mBpBinder;
    sp<BpBinder> mBpBinder;
    sp<IBinderRecordReplayTest> mInterface;
    sp<IBinderRecordReplayTest> mInterface;
};
};


TEST_F(BinderClearBuf, RecordReplayRepeatByte) {
TEST_F(BinderRecordReplayTest, ReplayByte) {
    recordReplay(&IBinderRecordReplayTest::setByte, int8_t{122}, &IBinderRecordReplayTest::getByte,
    recordReplay(&IBinderRecordReplayTest::setByte, int8_t{122}, &IBinderRecordReplayTest::getByte,
                 int8_t{90});
                 int8_t{90});
}
}


TEST_F(BinderClearBuf, RecordReplayRepeatBoolean) {
TEST_F(BinderRecordReplayTest, ReplayBoolean) {
    recordReplay(&IBinderRecordReplayTest::setBoolean, true, &IBinderRecordReplayTest::getBoolean,
    recordReplay(&IBinderRecordReplayTest::setBoolean, true, &IBinderRecordReplayTest::getBoolean,
                 false);
                 false);
}
}


TEST_F(BinderClearBuf, RecordReplayRepeatChar) {
TEST_F(BinderRecordReplayTest, ReplayChar) {
    recordReplay(&IBinderRecordReplayTest::setChar, char16_t{'G'},
    recordReplay(&IBinderRecordReplayTest::setChar, char16_t{'G'},
                 &IBinderRecordReplayTest::getChar, char16_t{'K'});
                 &IBinderRecordReplayTest::getChar, char16_t{'K'});
}
}


TEST_F(BinderClearBuf, RecordReplayRepeatInt) {
TEST_F(BinderRecordReplayTest, ReplayInt) {
    recordReplay(&IBinderRecordReplayTest::setInt, 3, &IBinderRecordReplayTest::getInt, 5);
    recordReplay(&IBinderRecordReplayTest::setInt, 3, &IBinderRecordReplayTest::getInt, 5);
}
}


TEST_F(BinderClearBuf, RecordReplayRepeatFloat) {
TEST_F(BinderRecordReplayTest, ReplayFloat) {
    recordReplay(&IBinderRecordReplayTest::setFloat, 1.1f, &IBinderRecordReplayTest::getFloat,
    recordReplay(&IBinderRecordReplayTest::setFloat, 1.1f, &IBinderRecordReplayTest::getFloat,
                 22.0f);
                 22.0f);
}
}


TEST_F(BinderClearBuf, RecordReplayRepeatLong) {
TEST_F(BinderRecordReplayTest, ReplayLong) {
    recordReplay(&IBinderRecordReplayTest::setLong, int64_t{1LL << 55},
    recordReplay(&IBinderRecordReplayTest::setLong, int64_t{1LL << 55},
                 &IBinderRecordReplayTest::getLong, int64_t{1LL << 12});
                 &IBinderRecordReplayTest::getLong, int64_t{1LL << 12});
}
}


TEST_F(BinderClearBuf, RecordReplayRepeatDouble) {
TEST_F(BinderRecordReplayTest, ReplayDouble) {
    recordReplay(&IBinderRecordReplayTest::setDouble, 0.00, &IBinderRecordReplayTest::getDouble,
    recordReplay(&IBinderRecordReplayTest::setDouble, 0.00, &IBinderRecordReplayTest::getDouble,
                 1.11);
                 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) {
int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    ::testing::InitGoogleTest(&argc, argv);