Home | History | Annotate | Download | only in functional
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include <android-base/logging.h>
     18 
     19 #include <VtsHalHidlTargetTestBase.h>
     20 #include <VtsHalHidlTargetTestEnvBase.h>
     21 #include <chrono>
     22 #include <condition_variable>
     23 #include <mutex>
     24 
     25 #include <android/hardware/radio/1.0/ISap.h>
     26 #include <android/hardware/radio/1.0/ISapCallback.h>
     27 #include <android/hardware/radio/1.0/types.h>
     28 
     29 #include "vts_test_util.h"
     30 
     31 using namespace ::android::hardware::radio::V1_0;
     32 
     33 using ::android::hardware::hidl_string;
     34 using ::android::hardware::hidl_vec;
     35 using ::android::hardware::Return;
     36 using ::android::hardware::Void;
     37 using ::android::sp;
     38 
     39 #define TIMEOUT_PERIOD 40
     40 #define SAP_SERVICE_NAME "slot1"
     41 
     42 class SapHidlTest;
     43 
     44 /* Callback class for sap response */
     45 class SapCallback : public ISapCallback {
     46    private:
     47     SapHidlTest& parent;
     48 
     49    public:
     50     SapResultCode sapResultCode;
     51     int32_t sapResponseToken;
     52 
     53     SapCallback(SapHidlTest& parent);
     54 
     55     virtual ~SapCallback() = default;
     56 
     57     Return<void> connectResponse(int32_t token, SapConnectRsp sapConnectRsp, int32_t maxMsgSize);
     58 
     59     Return<void> disconnectResponse(int32_t token);
     60 
     61     Return<void> disconnectIndication(int32_t token, SapDisconnectType disconnectType);
     62 
     63     Return<void> apduResponse(int32_t token, SapResultCode resultCode,
     64                               const ::android::hardware::hidl_vec<uint8_t>& apduRsp);
     65 
     66     Return<void> transferAtrResponse(int32_t token, SapResultCode resultCode,
     67                                      const ::android::hardware::hidl_vec<uint8_t>& atr);
     68 
     69     Return<void> powerResponse(int32_t token, SapResultCode resultCode);
     70 
     71     Return<void> resetSimResponse(int32_t token, SapResultCode resultCode);
     72 
     73     Return<void> statusIndication(int32_t token, SapStatus status);
     74 
     75     Return<void> transferCardReaderStatusResponse(int32_t token, SapResultCode resultCode,
     76                                                   int32_t cardReaderStatus);
     77 
     78     Return<void> errorResponse(int32_t token);
     79 
     80     Return<void> transferProtocolResponse(int32_t token, SapResultCode resultCode);
     81 };
     82 
     83 // Test environment for Sap HIDL HAL.
     84 class SapHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
     85    public:
     86     // get the test environment singleton
     87     static SapHidlEnvironment* Instance() {
     88         static SapHidlEnvironment* instance = new SapHidlEnvironment;
     89         return instance;
     90     }
     91     virtual void registerTestServices() override { registerTestService<ISap>(); }
     92 
     93    private:
     94     SapHidlEnvironment() {}
     95 };
     96 
     97 // The main test class for Sap HIDL.
     98 class SapHidlTest : public ::testing::VtsHalHidlTargetTestBase {
     99    private:
    100     std::mutex mtx;
    101     std::condition_variable cv;
    102     int count;
    103 
    104    public:
    105     virtual void SetUp() override;
    106 
    107     virtual void TearDown() override;
    108 
    109     /* Used as a mechanism to inform the test about data/event callback */
    110     void notify(int receivedToken);
    111 
    112     /* Test code calls this function to wait for response */
    113     std::cv_status wait();
    114 
    115     /* Sap service */
    116     sp<ISap> sap;
    117 
    118     /* Sap Callback object */
    119     sp<SapCallback> sapCb;
    120 
    121     /* Token for sap request */
    122     int32_t token;
    123 };
    124