diff --git a/libraries/abstractions/ble_hal/test/ble_test_scipts/startTests_afqp.py b/libraries/abstractions/ble_hal/test/ble_test_scipts/startTests_afqp.py index 28026c22ee3..993c0d45262 100644 --- a/libraries/abstractions/ble_hal/test/ble_test_scipts/startTests_afqp.py +++ b/libraries/abstractions/ble_hal/test/ble_test_scipts/startTests_afqp.py @@ -79,8 +79,8 @@ def main(): runTest.submitTestResult(isTestSuccessFull, runTest.checkProperties) # CHeck long write - isTestSuccessFull = runTest.writeLongCharacteristic() - runTest.submitTestResult(isTestSuccessFull, runTest.writeLongCharacteristic) + isTestSuccessFull = runTest.writereadLongCharacteristic() + runTest.submitTestResult(isTestSuccessFull, runTest.writereadLongCharacteristic) # Check read/write, simple connection isTestSuccessFull = runTest.readWriteSimpleConnection() diff --git a/libraries/abstractions/ble_hal/test/ble_test_scipts/testClass.py b/libraries/abstractions/ble_hal/test/ble_test_scipts/testClass.py index 49d1021675c..9537a524bcb 100644 --- a/libraries/abstractions/ble_hal/test/ble_test_scipts/testClass.py +++ b/libraries/abstractions/ble_hal/test/ble_test_scipts/testClass.py @@ -149,12 +149,9 @@ def indicationCb(uuid, value, flag): @staticmethod def notificationMTUCb(uuid, value, flag): notification = runTest.notificationMTU2(uuid, value, flag) - if notification == runTest.DUT_FAIL_STRING: - runTest.mainloop.quit() - runTest.isNotificationDeclinedSuccessFull = True if notification == runTest.DUT_MTU_2_STRING: runTest.mainloop.quit() - runTest.isNotificationDeclinedSuccessFull = False + runTest.isNotificationDeclinedSuccessFull = True @staticmethod def errorConnectCb(): @@ -344,9 +341,21 @@ def writeResultWithoutResponse(result): runTest.DUT_WRITE_NO_RESP_CHAR_UUID, result, False) @staticmethod - def writeLongCharacteristic(): + def writereadLongCharacteristic(): long_value="1" * (runTest.MTU_SIZE + 10) #TODO: get correct mtu size, assume 200 for now - return bleAdapter.writeCharacteristic(runTest.DUT_OPEN_CHAR_UUID, long_value) + bleAdapter.writeCharacteristic(runTest.DUT_OPEN_CHAR_UUID, long_value) + (isTestSuccessfull, charRead) = bleAdapter.readCharacteristic(runTest.DUT_OPEN_CHAR_UUID) + + if charRead != long_value: + isTestSuccessfull = False + print( + "readWriteSimpleConnection test: Expected value:" + + long_value + + " got:" + + charRead) + + sys.stdout.flush() + return isTestSuccessfull @staticmethod def _readWriteChecks(charUUID, descrUUID): @@ -706,6 +715,12 @@ def Write_Notification_Size_Greater_Than_MTU_3(scan_filter, isTestSuccessFull_discover = runTest.discoverPrimaryServices() bleAdapter.gatt.updateLocalAttributeTable() + time.sleep(2) # wait for connection parameters update + + # Check device not present. After discovery of services, advertisement + # should have stopped. + runTest.stopAdvertisement(scan_filter) + bleAdapter.setNotificationCallBack(runTest.notificationMTUCb) bleAdapter.subscribeForNotification( runTest.DUT_NOTIFY_CHAR_UUID) # subscribe for next test @@ -842,7 +857,7 @@ def submitTestResult(isSuccessfull, testMethod): runTest.reConnection: "_reConnection", runTest.checkProperties: "_checkProperties", runTest.checkUUIDs: "_checkUUIDs", - runTest.writeLongCharacteristic: "_writeLongCharacteristic", + runTest.writereadLongCharacteristic: "_writereadLongCharacteristic", runTest.readWriteSimpleConnection: "_readWriteSimpleConnection", runTest.writeWithoutResponse: "_writeWithoutResponse", runTest.notification: "_notification", diff --git a/libraries/abstractions/ble_hal/test/include/iot_test_ble_hal_common.h b/libraries/abstractions/ble_hal/test/include/iot_test_ble_hal_common.h index aadc22e0359..06e84420301 100644 --- a/libraries/abstractions/ble_hal/test/include/iot_test_ble_hal_common.h +++ b/libraries/abstractions/ble_hal/test/include/iot_test_ble_hal_common.h @@ -83,6 +83,7 @@ typedef struct #define bletestsDEFAULT_CHAR_VALUE "hello" #define bletestsSTRINGYFIED_UUID_SIZE 36 /* like "8a7f1168-48af-4efb-83b5-e679f9320002" */ #define bletests_LONG_WRITE_LEN 210 +#define bletests_LONG_READ_LEN 210 #define bletestsFULL_PERMISSIONS ( eBTPermRead | eBTPermWrite ) #define bletestsNB_INCLUDEDSERVICES 1 @@ -192,7 +193,7 @@ typedef struct #define QUEUE_LENGTH 20 #define ITEM_SIZE sizeof( void * ) -#define BLE_TESTS_WAIT 10000 /* Wait 10s max */ +#define BLE_TESTS_WAIT 60000 /* Wait 60s max */ #define BLE_TESTS_SHORT_WAIT 4000 /* Wait 4s max */ typedef enum diff --git a/libraries/abstractions/ble_hal/test/include/iot_test_ble_hal_config_defaults.h b/libraries/abstractions/ble_hal/test/include/iot_test_ble_hal_config_defaults.h index f46b068f5c9..392c1e10f37 100644 --- a/libraries/abstractions/ble_hal/test/include/iot_test_ble_hal_config_defaults.h +++ b/libraries/abstractions/ble_hal/test/include/iot_test_ble_hal_config_defaults.h @@ -34,6 +34,7 @@ /* Enable/Disable test cases */ /* AFQP test */ #define ENABLE_TC_AFQP_WRITE_LONG ( 1 ) +#define ENABLE_TC_AFQP_READ_LONG ( 1 ) #define ENABLE_TC_AFQP_ADD_INCLUDED_SERVICE ( 0 ) #define ENABLE_TC_AFQP_SECONDARY_SERVICE ( 0 ) /* Integration test */ diff --git a/libraries/abstractions/ble_hal/test/src/iot_test_ble_hal_afqp.c b/libraries/abstractions/ble_hal/test/src/iot_test_ble_hal_afqp.c index 93c5ac1d949..38677687468 100644 --- a/libraries/abstractions/ble_hal/test/src/iot_test_ble_hal_afqp.c +++ b/libraries/abstractions/ble_hal/test/src/iot_test_ble_hal_afqp.c @@ -47,6 +47,8 @@ extern BTCallbacks_t _xBTManagerCb; extern BTBleAdapterCallbacks_t _xBTBleAdapterCb; extern BTGattServerCallbacks_t _xBTGattServerCb; +static uint8_t LongReadBuffer[ bletests_LONG_READ_LEN ]; + const uint32_t bletestWAIT_MODE1_LEVEL2_QUERY = 10000; /* Wait 10s max */ #if LIBRARY_LOG_LEVEL > IOT_LOG_NONE @@ -113,6 +115,9 @@ TEST_GROUP_RUNNER( Full_BLE ) #if ENABLE_TC_AFQP_WRITE_LONG RUN_TEST_CASE( Full_BLE, BLE_Property_WriteLongCharacteristic ); #endif + #if ENABLE_TC_AFQP_READ_LONG + RUN_TEST_CASE( Full_BLE, BLE_Property_ReadLongCharacteristic ); + #endif RUN_TEST_CASE( Full_BLE, BLE_Property_WriteCharacteristic ); RUN_TEST_CASE( Full_BLE, BLE_Property_WriteDescriptor ); @@ -651,6 +656,43 @@ TEST( Full_BLE, BLE_Property_WriteLongCharacteristic ) } } +TEST( Full_BLE, BLE_Property_ReadLongCharacteristic ) +{ + BLETESTreadAttrCallback_t xReadEvent; + BTGattResponse_t xGattResponse; + BLETESTconfirmCallback_t xConfirmEvent; + BTStatus_t xStatus; + + memset( LongReadBuffer, 49, bletests_LONG_READ_LEN * sizeof( uint8_t ) ); + + /* Read transaction */ + xReadEvent = IotTestBleHal_ReadReceive( bletestATTR_SRVCB_CHAR_A ); + + xGattResponse.usHandle = xReadEvent.usAttrHandle; + xGattResponse.xAttrValue.usHandle = xReadEvent.usAttrHandle; + xGattResponse.xAttrValue.usOffset = xReadEvent.usOffset; + xGattResponse.xAttrValue.xLen = bletests_LONG_READ_LEN; + xGattResponse.xAttrValue.pucValue = LongReadBuffer; + _pxGattServerInterface->pxSendResponse( xReadEvent.usConnId, xReadEvent.ulTransId, eBTStatusSuccess, &xGattResponse ); + + xStatus = IotTestBleHal_WaitEventFromQueue( eBLEHALEventConfimCb, usHandlesBufferB[ bletestATTR_SRVCB_CHAR_A ], ( void * ) &xConfirmEvent, sizeof( BLETESTconfirmCallback_t ), BLE_TESTS_WAIT ); + TEST_ASSERT_EQUAL( eBTStatusSuccess, xConfirmEvent.xStatus ); + TEST_ASSERT_EQUAL( usHandlesBufferB[ bletestATTR_SRVCB_CHAR_A ], xConfirmEvent.usAttrHandle ); + + /* Read blob transaction */ + xStatus = IotTestBleHal_WaitEventFromQueue( eBLEHALEventReadAttrCb, usHandlesBufferB[ bletestATTR_SRVCB_CHAR_A ], ( void * ) &xReadEvent, sizeof( BLETESTreadAttrCallback_t ), BLE_TESTS_WAIT ); + xGattResponse.usHandle = xReadEvent.usAttrHandle; + xGattResponse.xAttrValue.usHandle = xReadEvent.usAttrHandle; + xGattResponse.xAttrValue.usOffset = xReadEvent.usOffset; + xGattResponse.xAttrValue.xLen = bletests_LONG_READ_LEN - xReadEvent.usOffset; + xGattResponse.xAttrValue.pucValue = LongReadBuffer + xReadEvent.usOffset; + _pxGattServerInterface->pxSendResponse( xReadEvent.usConnId, xReadEvent.ulTransId, eBTStatusSuccess, &xGattResponse ); + + xStatus = IotTestBleHal_WaitEventFromQueue( eBLEHALEventConfimCb, usHandlesBufferB[ bletestATTR_SRVCB_CHAR_A ], ( void * ) &xConfirmEvent, sizeof( BLETESTconfirmCallback_t ), BLE_TESTS_WAIT ); + TEST_ASSERT_EQUAL( eBTStatusSuccess, xConfirmEvent.xStatus ); + TEST_ASSERT_EQUAL( usHandlesBufferB[ bletestATTR_SRVCB_CHAR_A ], xConfirmEvent.usAttrHandle ); +} + TEST( Full_BLE, BLE_Connection_ChangeMTUsize ) { } diff --git a/libraries/abstractions/ble_hal/test/src/iot_test_ble_hal_integration.c b/libraries/abstractions/ble_hal/test/src/iot_test_ble_hal_integration.c index ec506465ddb..f56b3c44ffc 100644 --- a/libraries/abstractions/ble_hal/test/src/iot_test_ble_hal_integration.c +++ b/libraries/abstractions/ble_hal/test/src/iot_test_ble_hal_integration.c @@ -59,6 +59,8 @@ extern BTUuid_t xServerUUID; extern BTUuid_t xAppUUID; extern bool CharAddedComplete; +static uint8_t ucLargeBuffer[ bletestsMTU_SIZE1 + 2 ]; + TEST_GROUP( Full_BLE_Integration_Test ); TEST_SETUP( Full_BLE_Integration_Test ) @@ -398,50 +400,23 @@ TEST( Full_BLE_Integration_Test_Advertisement, BLE_Advertise_Interval_Consistent IotTestBleHal_DeleteService( &_xSrvcB ); } -/* If data size is > MTU - 3 then BT stack can truncate it to MTU - 3 and keep trying to send it over to other peer. - * Make sure calling pxSendIndication() with xLen > MTU - 3 and HAL returns failure.*/ -/* 2 chars has the same descriptor uuid which can cause read/write the descriptors of chars to return wrong values. */ TEST( Full_BLE_Integration_Test_Connection, BLE_Write_Notification_Size_Greater_Than_MTU_3 ) { BTStatus_t xStatus, xfStatus; - uint8_t ucLargeBuffer[ bletestsMTU_SIZE1 + 2 ]; - uint8_t cccdFValue; - - /* Create a data payload whose length = MTU + 1. */ - static char bletests_MTU_2_CHAR_VALUE[ bletestsMTU_SIZE1 + 2 ]; - - memset( bletests_MTU_2_CHAR_VALUE, 'a', ( bletestsMTU_SIZE1 + 1 ) * sizeof( char ) ); - bletests_MTU_2_CHAR_VALUE[ bletestsMTU_SIZE1 + 1 ] = '\0'; - cccdFValue = ucRespBuffer[ bletestATTR_SRVCB_CCCD_F ].ucBuffer[ 0 ]; - /* check the value of cccd E is changed from 0 to 1. */ IotTestBleHal_checkNotificationIndication( bletestATTR_SRVCB_CCCD_E, true ); - /* check the value of cccd F does not change */ - TEST_ASSERT_EQUAL( ucRespBuffer[ bletestATTR_SRVCB_CCCD_F ].ucBuffer[ 0 ], cccdFValue ); - memcpy( ucLargeBuffer, bletests_MTU_2_CHAR_VALUE, bletestsMTU_SIZE1 + 1 ); + memset( ucLargeBuffer, 'a', ( bletestsMTU_SIZE1 + 2 ) * sizeof( char ) ); - /* Expect to return failure here. */ xStatus = _pxGattServerInterface->pxSendIndication( _ucBLEServerIf, usHandlesBufferB[ bletestATTR_SRVCB_CHAR_E ], _usBLEConnId, - bletestsMTU_SIZE1 + 1, + bletestsMTU_SIZE1 + 2, ucLargeBuffer, false ); - TEST_ASSERT_NOT_EQUAL( eBTStatusSuccess, xStatus ); + TEST_ASSERT_EQUAL( eBTStatusSuccess, xStatus ); - if( xStatus != eBTStatusSuccess ) - { - /* Notify RPI failure here. Expect to receive "fail" message. */ - memcpy( ucLargeBuffer, bletestsFAIL_CHAR_VALUE, sizeof( bletestsFAIL_CHAR_VALUE ) - 1 ); - xfStatus = _pxGattServerInterface->pxSendIndication( _ucBLEServerIf, - usHandlesBufferB[ bletestATTR_SRVCB_CHAR_E ], - _usBLEConnId, - sizeof( bletestsFAIL_CHAR_VALUE ) - 1, - ucLargeBuffer, - false ); - TEST_ASSERT_EQUAL( eBTStatusSuccess, xfStatus ); - } + IotTestBleHal_checkNotificationIndication( bletestATTR_SRVCB_CCCD_E, false ); } TEST( Full_BLE_Integration_Test_Connection, BLE_Send_Data_After_Disconnected ) diff --git a/projects/nordic/nrf52840-dk/ses/aws_tests/aws_tests.emProject b/projects/nordic/nrf52840-dk/ses/aws_tests/aws_tests.emProject index cb141cf0f14..30dbedfa32e 100644 --- a/projects/nordic/nrf52840-dk/ses/aws_tests/aws_tests.emProject +++ b/projects/nordic/nrf52840-dk/ses/aws_tests/aws_tests.emProject @@ -442,6 +442,7 @@ +