Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Add read long value test #1477

Merged
merged 5 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
29 changes: 22 additions & 7 deletions libraries/abstractions/ble_hal/test/ble_test_scipts/testClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
41 changes: 41 additions & 0 deletions libraries/abstractions/ble_hal/test/src/iot_test_ble_hal_afqp.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,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 );
Expand Down Expand Up @@ -651,6 +654,44 @@ TEST( Full_BLE, BLE_Property_WriteLongCharacteristic )
}
}

TEST( Full_BLE, BLE_Property_ReadLongCharacteristic )
{
BLETESTreadAttrCallback_t xReadEvent;
BTGattResponse_t xGattResponse;
BLETESTconfirmCallback_t xConfirmEvent;
BTStatus_t xStatus;
uint8_t LongReadBuffer[ bletests_LONG_WRITE_LEN ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bletests_LONG_WRITE_LEN - Can we have a separate define for the long reads, like bletests_LONG_READ_LEN

Also its better to not allocate long read buffer on stack, as it might over flow the stack buffer. Could be a static global variable instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure


memset( LongReadBuffer, 49, bletests_LONG_WRITE_LEN * sizeof( uint8_t ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of memset you can directly assign to {0} in the declaration above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now we just use the same value { '1', '1', '1', ...} that the long write test sent. It's easier to check the value on the RPi side.


/* 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_WRITE_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_WRITE_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 )
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,50 +398,24 @@ 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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@
<file file_name="../../../../../libraries/abstractions/ble_hal/test/include/iot_test_ble_hal_integration.h" />
<file file_name="../../../../../libraries/abstractions/ble_hal/test/include/iot_test_ble_hal_kpi.h" />
<file file_name="../../../../../libraries/abstractions/ble_hal/test/include/iot_test_ble_hal_stress_test.h" />
<file file_name="../../../../../libraries/abstractions/ble_hal/test/include/iot_test_ble_hal_config_defaults.h" />
</folder>
</folder>
</folder>
Expand Down