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

Commit 0e8a3be4 authored by sqian's avatar sqian
Browse files

Generate serial number randomly in VTS unit test

Any fixed integer can be returned by vendor's APIs response.
Ideally it should be a random value for testing a vendor library.

Applying this to all the unit tests serial number.

Cherry-pick from:
  https://googleplex-android-review.git.corp.google.com/#/c/2330821/

Bug: 38499889
Test: adb shell data/local/tmp/VtsHalRadioV1_0TargetTest
Change-Id: I491db829cca607fad9f6a21987de92269d115253
Merged-In: I491db829cca607fad9f6a21987de92269d115253
parent 9119d4cc
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -27,7 +27,8 @@ cc_test {
           "radio_hidl_hal_test.cpp",
           "radio_hidl_hal_test.cpp",
           "radio_hidl_hal_voice.cpp",
           "radio_hidl_hal_voice.cpp",
           "radio_response.cpp",
           "radio_response.cpp",
           "VtsHalRadioV1_0TargetTest.cpp"],
           "VtsHalRadioV1_0TargetTest.cpp",
           "vts_test_util.cpp"],
    shared_libs: [
    shared_libs: [
        "libbase",
        "libbase",
        "liblog",
        "liblog",
@@ -51,7 +52,8 @@ cc_test {
    srcs: ["sap_callback.cpp",
    srcs: ["sap_callback.cpp",
           "sap_hidl_hal_api.cpp",
           "sap_hidl_hal_api.cpp",
           "sap_hidl_hal_test.cpp",
           "sap_hidl_hal_test.cpp",
           "VtsHalSapV1_0TargetTest.cpp"],
           "VtsHalSapV1_0TargetTest.cpp",
           "vts_test_util.cpp"],
    shared_libs: [
    shared_libs: [
        "libbase",
        "libbase",
        "liblog",
        "liblog",
+10 −5
Original line number Original line Diff line number Diff line
@@ -20,6 +20,11 @@ int main(int argc, char** argv) {
    ::testing::AddGlobalTestEnvironment(new RadioHidlEnvironment);
    ::testing::AddGlobalTestEnvironment(new RadioHidlEnvironment);
    ::testing::InitGoogleTest(&argc, argv);
    ::testing::InitGoogleTest(&argc, argv);


    // setup seed for rand function
    int seedSrand = time(NULL);
    std::cout << "seed setup for random function (radio):" + std::to_string(seedSrand) << std::endl;
    srand(seedSrand);

    int status = RUN_ALL_TESTS();
    int status = RUN_ALL_TESTS();
    LOG(INFO) << "Test result = " << status;
    LOG(INFO) << "Test result = " << status;


+11 −6
Original line number Original line Diff line number Diff line
@@ -21,6 +21,11 @@ int main(int argc, char** argv) {
    ::testing::AddGlobalTestEnvironment(new SapHidlEnvironment);
    ::testing::AddGlobalTestEnvironment(new SapHidlEnvironment);
    ::testing::InitGoogleTest(&argc, argv);
    ::testing::InitGoogleTest(&argc, argv);


    // setup seed for rand function
    int seedSrand = time(NULL);
    std::cout << "seed setup for random function (sap):" + std::to_string(seedSrand) << std::endl;
    srand(seedSrand);

    int status = RUN_ALL_TESTS();
    int status = RUN_ALL_TESTS();
    LOG(INFO) << "Test result = " << status;
    LOG(INFO) << "Test result = " << status;


+115 −117
Original line number Original line Diff line number Diff line
@@ -22,7 +22,7 @@ using namespace ::android::hardware::radio::V1_0;
 * Test IRadio.setGsmBroadcastConfig() for the response returned.
 * Test IRadio.setGsmBroadcastConfig() for the response returned.
 */
 */
TEST_F(RadioHidlTest, setGsmBroadcastConfig) {
TEST_F(RadioHidlTest, setGsmBroadcastConfig) {
  int serial = 0;
    int serial = GetRandomSerialNumber();


    // Create GsmBroadcastSmsConfigInfo #1
    // Create GsmBroadcastSmsConfigInfo #1
    GsmBroadcastSmsConfigInfo gbSmsConfig1;
    GsmBroadcastSmsConfigInfo gbSmsConfig1;
@@ -64,11 +64,10 @@ TEST_F(RadioHidlTest, setGsmBroadcastConfig) {
    gbSmsConfig5.toCodeScheme = 255;
    gbSmsConfig5.toCodeScheme = 255;
    gbSmsConfig5.selected = true;
    gbSmsConfig5.selected = true;


  android::hardware::hidl_vec<GsmBroadcastSmsConfigInfo>
    android::hardware::hidl_vec<GsmBroadcastSmsConfigInfo> gsmBroadcastSmsConfigsInfoList = {
      gsmBroadcastSmsConfigsInfoList = {
        gbSmsConfig1, gbSmsConfig2, gbSmsConfig3, gbSmsConfig4, gbSmsConfig5};
        gbSmsConfig1, gbSmsConfig2, gbSmsConfig3, gbSmsConfig4, gbSmsConfig5};


  radio->setGsmBroadcastConfig(++serial, gsmBroadcastSmsConfigsInfoList);
    radio->setGsmBroadcastConfig(serial, gsmBroadcastSmsConfigsInfoList);


    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
@@ -86,17 +85,16 @@ TEST_F(RadioHidlTest, setGsmBroadcastConfig) {
 * Test IRadio.getGsmBroadcastConfig() for the response returned.
 * Test IRadio.getGsmBroadcastConfig() for the response returned.
 */
 */
TEST_F(RadioHidlTest, getGsmBroadcastConfig) {
TEST_F(RadioHidlTest, getGsmBroadcastConfig) {
  int serial = 0;
    int serial = GetRandomSerialNumber();


  radio->getGsmBroadcastConfig(++serial);
    radio->getGsmBroadcastConfig(serial);


    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    EXPECT_EQ(serial, radioRsp->rspInfo.serial);
    EXPECT_EQ(serial, radioRsp->rspInfo.serial);


    if (cardStatus.cardState == CardState::ABSENT) {
    if (cardStatus.cardState == CardState::ABSENT) {
      ASSERT_TRUE(CheckGeneralError() ||
        ASSERT_TRUE(CheckGeneralError() || radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
                  radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
                    radioRsp->rspInfo.error == RadioError::NONE);
                    radioRsp->rspInfo.error == RadioError::NONE);
    }
    }
}
}
@@ -105,17 +103,17 @@ TEST_F(RadioHidlTest, getGsmBroadcastConfig) {
 * Test IRadio.setCdmaBroadcastConfig() for the response returned.
 * Test IRadio.setCdmaBroadcastConfig() for the response returned.
 */
 */
TEST_F(RadioHidlTest, setCdmaBroadcastConfig) {
TEST_F(RadioHidlTest, setCdmaBroadcastConfig) {
  int serial = 0;
    int serial = GetRandomSerialNumber();


    CdmaBroadcastSmsConfigInfo cbSmsConfig;
    CdmaBroadcastSmsConfigInfo cbSmsConfig;
    cbSmsConfig.serviceCategory = 4096;
    cbSmsConfig.serviceCategory = 4096;
    cbSmsConfig.language = 1;
    cbSmsConfig.language = 1;
    cbSmsConfig.selected = true;
    cbSmsConfig.selected = true;


  android::hardware::hidl_vec<CdmaBroadcastSmsConfigInfo>
    android::hardware::hidl_vec<CdmaBroadcastSmsConfigInfo> cdmaBroadcastSmsConfigInfoList = {
      cdmaBroadcastSmsConfigInfoList = {cbSmsConfig};
        cbSmsConfig};


  radio->setCdmaBroadcastConfig(++serial, cdmaBroadcastSmsConfigInfoList);
    radio->setCdmaBroadcastConfig(serial, cdmaBroadcastSmsConfigInfoList);


    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
@@ -131,9 +129,9 @@ TEST_F(RadioHidlTest, setCdmaBroadcastConfig) {
 * Test IRadio.getCdmaBroadcastConfig() for the response returned.
 * Test IRadio.getCdmaBroadcastConfig() for the response returned.
 */
 */
TEST_F(RadioHidlTest, getCdmaBroadcastConfig) {
TEST_F(RadioHidlTest, getCdmaBroadcastConfig) {
  int serial = 0;
    int serial = GetRandomSerialNumber();


  radio->getCdmaBroadcastConfig(++serial);
    radio->getCdmaBroadcastConfig(serial);


    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
@@ -148,10 +146,10 @@ TEST_F(RadioHidlTest, getCdmaBroadcastConfig) {
 * Test IRadio.setCdmaBroadcastActivation() for the response returned.
 * Test IRadio.setCdmaBroadcastActivation() for the response returned.
 */
 */
TEST_F(RadioHidlTest, setCdmaBroadcastActivation) {
TEST_F(RadioHidlTest, setCdmaBroadcastActivation) {
  int serial = 0;
    int serial = GetRandomSerialNumber();
    bool activate = false;
    bool activate = false;


  radio->setCdmaBroadcastActivation(++serial, activate);
    radio->setCdmaBroadcastActivation(serial, activate);


    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
@@ -167,10 +165,10 @@ TEST_F(RadioHidlTest, setCdmaBroadcastActivation) {
 * Test IRadio.setGsmBroadcastActivation() for the response returned.
 * Test IRadio.setGsmBroadcastActivation() for the response returned.
 */
 */
TEST_F(RadioHidlTest, setGsmBroadcastActivation) {
TEST_F(RadioHidlTest, setGsmBroadcastActivation) {
  int serial = 0;
    int serial = GetRandomSerialNumber();
    bool activate = false;
    bool activate = false;


  radio->setGsmBroadcastActivation(++serial, activate);
    radio->setGsmBroadcastActivation(serial, activate);


    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
+152 −157
Original line number Original line Diff line number Diff line
@@ -22,9 +22,9 @@ using namespace ::android::hardware::radio::V1_0;
 * Test IRadio.getDataRegistrationState() for the response returned.
 * Test IRadio.getDataRegistrationState() for the response returned.
 */
 */
TEST_F(RadioHidlTest, getDataRegistrationState) {
TEST_F(RadioHidlTest, getDataRegistrationState) {
  int serial = 0;
    int serial = GetRandomSerialNumber();


  radio->getDataRegistrationState(++serial);
    radio->getDataRegistrationState(serial);


    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
@@ -39,7 +39,7 @@ TEST_F(RadioHidlTest, getDataRegistrationState) {
 * Test IRadio.setupDataCall() for the response returned.
 * Test IRadio.setupDataCall() for the response returned.
 */
 */
TEST_F(RadioHidlTest, setupDataCall) {
TEST_F(RadioHidlTest, setupDataCall) {
  int serial = 0;
    int serial = GetRandomSerialNumber();


    RadioTechnology radioTechnology = RadioTechnology::LTE;
    RadioTechnology radioTechnology = RadioTechnology::LTE;


@@ -67,8 +67,8 @@ TEST_F(RadioHidlTest, setupDataCall) {
    bool roamingAllowed = false;
    bool roamingAllowed = false;
    bool isRoaming = false;
    bool isRoaming = false;


  radio->setupDataCall(++serial, radioTechnology, dataProfileInfo,
    radio->setupDataCall(serial, radioTechnology, dataProfileInfo, modemCognitive, roamingAllowed,
                       modemCognitive, roamingAllowed, isRoaming);
                         isRoaming);


    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
@@ -77,10 +77,8 @@ TEST_F(RadioHidlTest, setupDataCall) {
    if (cardStatus.cardState == CardState::ABSENT) {
    if (cardStatus.cardState == CardState::ABSENT) {
        ASSERT_TRUE(radioRsp->rspInfo.error == RadioError::NONE ||
        ASSERT_TRUE(radioRsp->rspInfo.error == RadioError::NONE ||
                    radioRsp->rspInfo.error == RadioError::RADIO_NOT_AVAILABLE ||
                    radioRsp->rspInfo.error == RadioError::RADIO_NOT_AVAILABLE ||
                  radioRsp->rspInfo.error ==
                    radioRsp->rspInfo.error == RadioError::OP_NOT_ALLOWED_BEFORE_REG_TO_NW ||
                      RadioError::OP_NOT_ALLOWED_BEFORE_REG_TO_NW ||
                    radioRsp->rspInfo.error == RadioError::OP_NOT_ALLOWED_DURING_VOICE_CALL ||
                  radioRsp->rspInfo.error ==
                      RadioError::OP_NOT_ALLOWED_DURING_VOICE_CALL ||
                    CheckOEMError());
                    CheckOEMError());
    }
    }
}
}
@@ -89,11 +87,11 @@ TEST_F(RadioHidlTest, setupDataCall) {
 * Test IRadio.deactivateDataCall() for the response returned.
 * Test IRadio.deactivateDataCall() for the response returned.
 */
 */
TEST_F(RadioHidlTest, deactivateDataCall) {
TEST_F(RadioHidlTest, deactivateDataCall) {
  int serial = 0;
    int serial = GetRandomSerialNumber();
    int cid = 1;
    int cid = 1;
    bool reasonRadioShutDown = false;
    bool reasonRadioShutDown = false;


  radio->deactivateDataCall(++serial, cid, reasonRadioShutDown);
    radio->deactivateDataCall(serial, cid, reasonRadioShutDown);


    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
@@ -108,9 +106,9 @@ TEST_F(RadioHidlTest, deactivateDataCall) {
 * Test IRadio.getDataCallList() for the response returned.
 * Test IRadio.getDataCallList() for the response returned.
 */
 */
TEST_F(RadioHidlTest, getDataCallList) {
TEST_F(RadioHidlTest, getDataCallList) {
  int serial = 0;
    int serial = GetRandomSerialNumber();


  radio->getDataCallList(++serial);
    radio->getDataCallList(serial);


    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
@@ -126,7 +124,7 @@ TEST_F(RadioHidlTest, getDataCallList) {
 * Test IRadio.setInitialAttachApn() for the response returned.
 * Test IRadio.setInitialAttachApn() for the response returned.
 */
 */
TEST_F(RadioHidlTest, setInitialAttachApn) {
TEST_F(RadioHidlTest, setInitialAttachApn) {
  int serial = 0;
    int serial = GetRandomSerialNumber();


    DataProfileInfo dataProfileInfo;
    DataProfileInfo dataProfileInfo;
    memset(&dataProfileInfo, 0, sizeof(dataProfileInfo));
    memset(&dataProfileInfo, 0, sizeof(dataProfileInfo));
@@ -151,8 +149,7 @@ TEST_F(RadioHidlTest, setInitialAttachApn) {
    bool modemCognitive = true;
    bool modemCognitive = true;
    bool isRoaming = false;
    bool isRoaming = false;


  radio->setInitialAttachApn(++serial, dataProfileInfo, modemCognitive,
    radio->setInitialAttachApn(serial, dataProfileInfo, modemCognitive, isRoaming);
                             isRoaming);


    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
@@ -161,8 +158,7 @@ TEST_F(RadioHidlTest, setInitialAttachApn) {
    if (cardStatus.cardState == CardState::ABSENT) {
    if (cardStatus.cardState == CardState::ABSENT) {
        ASSERT_TRUE(radioRsp->rspInfo.error == RadioError::NONE ||
        ASSERT_TRUE(radioRsp->rspInfo.error == RadioError::NONE ||
                    radioRsp->rspInfo.error == RadioError::RADIO_NOT_AVAILABLE ||
                    radioRsp->rspInfo.error == RadioError::RADIO_NOT_AVAILABLE ||
                  radioRsp->rspInfo.error ==
                    radioRsp->rspInfo.error == RadioError::SUBSCRIPTION_NOT_AVAILABLE ||
                      RadioError::SUBSCRIPTION_NOT_AVAILABLE ||
                    CheckOEMError());
                    CheckOEMError());
    }
    }
}
}
@@ -171,10 +167,10 @@ TEST_F(RadioHidlTest, setInitialAttachApn) {
 * Test IRadio.setDataAllowed() for the response returned.
 * Test IRadio.setDataAllowed() for the response returned.
 */
 */
TEST_F(RadioHidlTest, setDataAllowed) {
TEST_F(RadioHidlTest, setDataAllowed) {
  int serial = 0;
    int serial = GetRandomSerialNumber();
    bool allow = true;
    bool allow = true;


  radio->setDataAllowed(++serial, allow);
    radio->setDataAllowed(serial, allow);


    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
@@ -189,7 +185,7 @@ TEST_F(RadioHidlTest, setDataAllowed) {
 * Test IRadio.setDataProfile() for the response returned.
 * Test IRadio.setDataProfile() for the response returned.
 */
 */
TEST_F(RadioHidlTest, setDataProfile) {
TEST_F(RadioHidlTest, setDataProfile) {
  int serial = 0;
    int serial = GetRandomSerialNumber();


    // Create a dataProfileInfo
    // Create a dataProfileInfo
    DataProfileInfo dataProfileInfo;
    DataProfileInfo dataProfileInfo;
@@ -213,12 +209,11 @@ TEST_F(RadioHidlTest, setDataProfile) {
    dataProfileInfo.mvnoMatchData = hidl_string();
    dataProfileInfo.mvnoMatchData = hidl_string();


    // Create a dataProfileInfoList
    // Create a dataProfileInfoList
  android::hardware::hidl_vec<DataProfileInfo> dataProfileInfoList = {
    android::hardware::hidl_vec<DataProfileInfo> dataProfileInfoList = {dataProfileInfo};
      dataProfileInfo};


    bool isRoadming = false;
    bool isRoadming = false;


  radio->setDataProfile(++serial, dataProfileInfoList, isRoadming);
    radio->setDataProfile(serial, dataProfileInfoList, isRoadming);


    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
Loading