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

Commit eec3b8b8 authored by Sarah Chin's avatar Sarah Chin Committed by Automerger Merge Worker
Browse files

Merge "Revert "VTS for IRadio AIDL"" am: 3a16f8fe am: d67460a5 am: 554a0176

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1932964

Change-Id: I9c559bc2d08794442fd2120b590bd80ea86d79bb
parents 252d882d 554a0176
Loading
Loading
Loading
Loading

radio/aidl/vts/Android.bp

deleted100644 → 0
+0 −71
Original line number Diff line number Diff line
// Copyright 2021 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "hardware_interfaces_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["hardware_interfaces_license"],
}

cc_test {
    name: "VtsHalRadioTargetTest",
    defaults: [
        "VtsHalTargetTestDefaults",
        "use_libaidlvintf_gtest_helper_static",
    ],
    srcs: [
        "radio_aidl_hal_utils.cpp",
        "radio_data_indication.cpp",
        "radio_data_response.cpp",
        "radio_data_test.cpp",
        "radio_messaging_indication.cpp",
        "radio_messaging_response.cpp",
        "radio_messaging_test.cpp",
        "radio_modem_indication.cpp",
        "radio_modem_response.cpp",
        "radio_modem_test.cpp",
        "radio_network_indication.cpp",
        "radio_network_response.cpp",
        "radio_network_test.cpp",
        "radio_sim_indication.cpp",
        "radio_sim_response.cpp",
        "radio_sim_test.cpp",
        "radio_voice_indication.cpp",
        "radio_voice_response.cpp",
        "radio_voice_test.cpp",
        "VtsHalRadioTargetTest.cpp",
    ],
    shared_libs: [
        "libbinder_ndk",
        "libvintf",
    ],
    static_libs: [
        "android.hardware.radio-V1-ndk",
        "android.hardware.radio.config-V1-ndk",
        "android.hardware.radio.data-V1-ndk",
        "android.hardware.radio.messaging-V1-ndk",
        "android.hardware.radio.modem-V1-ndk",
        "android.hardware.radio.network-V1-ndk",
        "android.hardware.radio.sim-V1-ndk",
        "android.hardware.radio.voice-V1-ndk",
    ],
    // TODO(b/210712359): enable after b/207695009 is resolved.
    //test_suites: [
    //    "general-tests",
    //    "vts",
    //],
}
+0 −66
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <android/binder_process.h>

#include "radio_data_utils.h"
#include "radio_messaging_utils.h"
#include "radio_modem_utils.h"
#include "radio_network_utils.h"
#include "radio_sim_utils.h"
#include "radio_voice_utils.h"

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(RadioDataTest);
INSTANTIATE_TEST_SUITE_P(
        PerInstance, RadioDataTest,
        testing::ValuesIn(android::getAidlHalInstanceNames(IRadioData::descriptor)),
        android::PrintInstanceNameToString);

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(RadioMessagingTest);
INSTANTIATE_TEST_SUITE_P(
        PerInstance, RadioMessagingTest,
        testing::ValuesIn(android::getAidlHalInstanceNames(IRadioMessaging::descriptor)),
        android::PrintInstanceNameToString);

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(RadioModemTest);
INSTANTIATE_TEST_SUITE_P(
        PerInstance, RadioModemTest,
        testing::ValuesIn(android::getAidlHalInstanceNames(IRadioModem::descriptor)),
        android::PrintInstanceNameToString);

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(RadioNetworkTest);
INSTANTIATE_TEST_SUITE_P(
        PerInstance, RadioNetworkTest,
        testing::ValuesIn(android::getAidlHalInstanceNames(IRadioNetwork::descriptor)),
        android::PrintInstanceNameToString);

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(RadioSimTest);
INSTANTIATE_TEST_SUITE_P(PerInstance, RadioSimTest,
                         testing::ValuesIn(android::getAidlHalInstanceNames(IRadioSim::descriptor)),
                         android::PrintInstanceNameToString);

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(RadioVoiceTest);
INSTANTIATE_TEST_SUITE_P(
        PerInstance, RadioVoiceTest,
        testing::ValuesIn(android::getAidlHalInstanceNames(IRadioVoice::descriptor)),
        android::PrintInstanceNameToString);

int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    ABinderProcess_setThreadPoolMaxThreadCount(1);
    ABinderProcess_startThreadPool();
    return RUN_ALL_TESTS();
}
+0 −176
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#define LOG_TAG "RadioTest"

#include "radio_aidl_hal_utils.h"
#include <iostream>
#include "VtsCoreUtil.h"

using namespace aidl::android::hardware::radio::network;

#define WAIT_TIMEOUT_PERIOD 75

aidl::android::hardware::radio::sim::CardStatus cardStatus = {};

int GetRandomSerialNumber() {
    return rand();
}

::testing::AssertionResult CheckAnyOfErrors(RadioError err, std::vector<RadioError> errors,
                                            CheckFlag flag) {
    const static std::vector<RadioError> generalErrors = {
            RadioError::RADIO_NOT_AVAILABLE,   RadioError::NO_MEMORY,
            RadioError::INTERNAL_ERR,          RadioError::SYSTEM_ERR,
            RadioError::REQUEST_NOT_SUPPORTED, RadioError::CANCELLED};
    if (flag == CHECK_GENERAL_ERROR || flag == CHECK_OEM_AND_GENERAL_ERROR) {
        for (size_t i = 0; i < generalErrors.size(); i++) {
            if (err == generalErrors[i]) {
                return testing::AssertionSuccess();
            }
        }
    }
    if (flag == CHECK_OEM_ERROR || flag == CHECK_OEM_AND_GENERAL_ERROR) {
        if (err >= RadioError::OEM_ERROR_1 && err <= RadioError::OEM_ERROR_25) {
            return testing::AssertionSuccess();
        }
    }
    for (size_t i = 0; i < errors.size(); i++) {
        if (err == errors[i]) {
            return testing::AssertionSuccess();
        }
    }
    return testing::AssertionFailure() << "RadioError:" + toString(err) + " is returned";
}

// Runs "pm list features" and attempts to find the specified feature in its output.
bool deviceSupportsFeature(const char* feature) {
    bool hasFeature = false;
    FILE* p = popen("/system/bin/pm list features", "re");
    if (p) {
        char* line = NULL;
        size_t len = 0;
        while (getline(&line, &len, p) > 0) {
            if (strstr(line, feature)) {
                hasFeature = true;
                break;
            }
        }
        pclose(p);
    } else {
        __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, "popen failed: %d", errno);
        _exit(EXIT_FAILURE);
    }
    __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Feature %s: %ssupported", feature,
                        hasFeature ? "" : "not ");
    return hasFeature;
}

bool isSsSsEnabled() {
    // Do not use checkSubstringInCommandOutput("getprop persist.radio.multisim.config", "")
    // until b/148904287 is fixed. We need exact matching instead of partial matching. (i.e.
    // by definition the empty string "" is a substring of any string).
    return !isDsDsEnabled() && !isTsTsEnabled();
}

bool isDsDsEnabled() {
    return testing::checkSubstringInCommandOutput("getprop persist.radio.multisim.config", "dsds");
}

bool isTsTsEnabled() {
    return testing::checkSubstringInCommandOutput("getprop persist.radio.multisim.config", "tsts");
}

bool isVoiceInService(RegState state) {
    return RegState::REG_HOME == state || RegState::REG_ROAMING == state;
}

bool isVoiceEmergencyOnly(RegState state) {
    return RegState::NOT_REG_MT_NOT_SEARCHING_OP_EM == state ||
           RegState::NOT_REG_MT_SEARCHING_OP_EM == state || RegState::REG_DENIED_EM == state ||
           RegState::UNKNOWN_EM == state;
}

bool isServiceValidForDeviceConfiguration(std::string& serviceName) {
    if (isSsSsEnabled()) {
        // Device is configured as SSSS.
        if (serviceName != RADIO_SERVICE_SLOT1_NAME) {
            ALOGI("%s instance is not valid for SSSS device.", serviceName.c_str());
            return false;
        }
    } else if (isDsDsEnabled()) {
        // Device is configured as DSDS.
        if (serviceName != RADIO_SERVICE_SLOT1_NAME && serviceName != RADIO_SERVICE_SLOT2_NAME) {
            ALOGI("%s instance is not valid for DSDS device.", serviceName.c_str());
            return false;
        }
    } else if (isTsTsEnabled()) {
        // Device is configured as TSTS.
        if (serviceName != RADIO_SERVICE_SLOT1_NAME && serviceName != RADIO_SERVICE_SLOT2_NAME &&
            serviceName != RADIO_SERVICE_SLOT3_NAME) {
            ALOGI("%s instance is not valid for TSTS device.", serviceName.c_str());
            return false;
        }
    }
    return true;
}

/*
 * Notify that the response message is received.
 */
void RadioResponseWaiter::notify(int receivedSerial) {
    std::unique_lock<std::mutex> lock(mtx_);
    if (serial == receivedSerial) {
        count_++;
        cv_.notify_one();
    }
}

/*
 * Wait till the response message is notified or till WAIT_TIMEOUT_PERIOD.
 */
std::cv_status RadioResponseWaiter::wait() {
    std::unique_lock<std::mutex> lock(mtx_);
    std::cv_status status = std::cv_status::no_timeout;
    auto now = std::chrono::system_clock::now();
    while (count_ == 0) {
        status = cv_.wait_until(lock, now + std::chrono::seconds(WAIT_TIMEOUT_PERIOD));
        if (status == std::cv_status::timeout) {
            return status;
        }
    }
    count_--;
    return status;
}

/**
 * Specific features on the Radio HAL rely on Radio HAL Capabilities.
 * The VTS test related to those features must not run if the related capability is disabled.
 * Typical usage within VTS: if (getRadioHalCapabilities()) return;
 */
bool RadioResponseWaiter::getRadioHalCapabilities() {
    // TODO(b/210712359): implement after RadioConfig VTS is created
    /**
    // Get HalDeviceCapabilities from the radio config
    std::shared_ptr<RadioConfigResponse> radioConfigRsp = new (std::nothrow)
    RadioConfigResponse(*this); radioConfig->setResponseFunctions(radioConfigRsp, nullptr); serial =
    GetRandomSerialNumber();

    radioConfig->getHalDeviceCapabilities(serial);
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    return radioConfigRsp->modemReducedFeatureSet1;
    **/
    return true;
}
 No newline at end of file
+0 −140
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <aidl/Gtest.h>
#include <aidl/Vintf.h>
#include <aidl/android/hardware/radio/RadioError.h>
#include <aidl/android/hardware/radio/network/RegState.h>
#include <aidl/android/hardware/radio/sim/CardStatus.h>
#include <utils/Log.h>
#include <vector>

using namespace aidl::android::hardware::radio;
using aidl::android::hardware::radio::sim::CardStatus;

extern CardStatus cardStatus;

/*
 * MACRO used to skip test case when radio response return error REQUEST_NOT_SUPPORTED
 * on HAL versions which has deprecated the request interfaces. The MACRO can only be used
 * AFTER receiving radio response.
 */
#define SKIP_TEST_IF_REQUEST_NOT_SUPPORTED_WITH_HAL(__ver__, __radio__, __radioRsp__)      \
    do {                                                                                   \
        sp<::android::hardware::radio::V##__ver__::IRadio> __radio =                       \
                ::android::hardware::radio::V##__ver__::IRadio::castFrom(__radio__);       \
        if (__radio && __radioRsp__->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED) { \
            GTEST_SKIP() << "REQUEST_NOT_SUPPORTED";                                       \
        }                                                                                  \
    } while (0)

enum CheckFlag {
    CHECK_DEFAULT = 0,
    CHECK_GENERAL_ERROR = 1,
    CHECK_OEM_ERROR = 2,
    CHECK_OEM_AND_GENERAL_ERROR = 3,
    CHECK_SAP_ERROR = 4,
};

static constexpr const char* FEATURE_VOICE_CALL = "android.software.connectionservice";

static constexpr const char* FEATURE_TELEPHONY = "android.hardware.telephony";

static constexpr const char* FEATURE_TELEPHONY_GSM = "android.hardware.telephony.gsm";

static constexpr const char* FEATURE_TELEPHONY_CDMA = "android.hardware.telephony.cdma";

#define MODEM_EMERGENCY_CALL_ESTABLISH_TIME 3
#define MODEM_EMERGENCY_CALL_DISCONNECT_TIME 3
#define MODEM_SET_SIM_POWER_DELAY_IN_SECONDS 2

#define RADIO_SERVICE_SLOT1_NAME "slot1"  // HAL instance name for SIM slot 1 or single SIM device
#define RADIO_SERVICE_SLOT2_NAME "slot2"  // HAL instance name for SIM slot 2 on dual SIM device
#define RADIO_SERVICE_SLOT3_NAME "slot3"  // HAL instance name for SIM slot 3 on triple SIM device

/*
 * Generate random serial number for radio test
 */
int GetRandomSerialNumber();

/*
 * Check multiple radio error codes which are possibly returned because of the different
 * vendor/devices implementations. It allows optional checks for general errors or/and oem errors.
 */
::testing::AssertionResult CheckAnyOfErrors(RadioError err, std::vector<RadioError> generalError,
                                            CheckFlag flag = CHECK_DEFAULT);

/*
 * Check if device supports feature.
 */
bool deviceSupportsFeature(const char* feature);

/*
 * Check if device is in SsSs (Single SIM Single Standby).
 */
bool isSsSsEnabled();

/*
 * Check if device is in DSDS (Dual SIM Dual Standby).
 */
bool isDsDsEnabled();

/*
 * Check if device is in TSTS (Triple SIM Triple Standby).
 */
bool isTsTsEnabled();

/*
 * Check if voice status is in emergency only.
 */
bool isVoiceEmergencyOnly(aidl::android::hardware::radio::network::RegState state);

/*
 * Check if voice status is in service.
 */
bool isVoiceInService(aidl::android::hardware::radio::network::RegState state);

/*
 * Check if service is valid for device configuration
 */
bool isServiceValidForDeviceConfiguration(std::string& serviceName);

/**
 * Used when waiting for an asynchronous response from the HAL.
 */
class RadioResponseWaiter {
  protected:
    std::mutex mtx_;
    std::condition_variable cv_;
    int count_;

  public:
    /* Serial number for radio request */
    int serial;

    /* Used as a mechanism to inform the test about data/event callback */
    void notify(int receivedSerial);

    /* Test code calls this function to wait for response */
    std::cv_status wait();

    // TODO(b/210712359): this probably isn't the best place to put this, but it works for now
    //  since all RadioXTest extend RadioResponseWaiter
    /* Used to get the radio HAL capabilities */
    bool getRadioHalCapabilities();
};
+0 −39
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "radio_data_utils.h"

RadioDataIndication::RadioDataIndication(RadioDataTest& parent) : parent_data(parent) {}

ndk::ScopedAStatus RadioDataIndication::dataCallListChanged(
        RadioIndicationType /*type*/, const std::vector<SetupDataCallResult>& /*dcList*/) {
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus RadioDataIndication::keepaliveStatus(RadioIndicationType /*type*/,
                                                        const KeepaliveStatus& /*status*/) {
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus RadioDataIndication::pcoData(RadioIndicationType /*type*/,
                                                const PcoDataInfo& /*pco*/) {
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus RadioDataIndication::unthrottleApn(RadioIndicationType /*type*/,
                                                      const DataProfileInfo& /*dataProfileInfo*/) {
    return ndk::ScopedAStatus::ok();
}
Loading