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

Commit ac656b2d authored by Pawan Wagh's avatar Pawan Wagh
Browse files

Adding primitive types to binderRecordReplayTest

Adding AIDL supported primitive types to record replay test

Test: m binderRecordReplayTest && adb sync data && adb shell /data/nativetest64/binderRecordReplayTest/binderRecordReplayTest
Bug: 279646634
Change-Id: If163fe2a8a4e66794cf09e57db98000507811b94
parent 02359977
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -15,6 +15,24 @@
 */

interface IBinderRecordReplayTest {
    void setByte(byte input);
    byte getByte();

    void setChar(char input);
    char getChar();

    void setBoolean(boolean input);
    boolean getBoolean();

    void setInt(int input);
    int getInt();

    void setFloat(float input);
    float getFloat();

    void setLong(long input);
    long getLong();

    void setDouble(double input);
    double getDouble();
}
+52 −14
Original line number Diff line number Diff line
@@ -33,19 +33,27 @@ using android::binder::debug::RecordedTransaction;

const String16 kServerName = String16("binderRecordReplay");

#define GENERATE_GETTER_SETTER(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

class MyRecordReplay : public BnBinderRecordReplayTest {
public:
    Status setInt(int input) {
        mInt = input;
        return Status::ok();
    }
    Status getInt(int* output) {
        *output = mInt;
        return Status::ok();
    }

private:
    int mInt = 0;
    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);
};

class BinderClearBuf : public ::testing::Test {
@@ -60,7 +68,7 @@ public:
    }

    template <typename T>
    void DoTest(Status (IBinderRecordReplayTest::*set)(T), T recordedValue,
    void recordReplay(Status (IBinderRecordReplayTest::*set)(T), T recordedValue,
                      Status (IBinderRecordReplayTest::*get)(T*), T changedValue) {
        base::unique_fd fd(open("/data/local/tmp/binderRecordReplayTest.rec",
                                O_RDWR | O_CREAT | O_CLOEXEC, 0666));
@@ -112,8 +120,38 @@ private:
    sp<IBinderRecordReplayTest> mInterface;
};

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

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

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

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

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

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

TEST_F(BinderClearBuf, RecordReplayRepeatDouble) {
    recordReplay(&IBinderRecordReplayTest::setDouble, 0.00, &IBinderRecordReplayTest::getDouble,
                 1.11);
}

int main(int argc, char** argv) {