Add some report time tests & fix comments]

This commit is contained in:
Ciaran Woodward
2021-12-15 12:44:39 +00:00
parent 5be97ac227
commit c3e95a379f
4 changed files with 139 additions and 31 deletions

View File

@@ -2,12 +2,14 @@
// This Software is subject to the terms of the XMOS Public Licence: Version 1. // This Software is subject to the terms of the XMOS Public Licence: Version 1.
#include <assert.h> #include <assert.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <xs1.h> #include <xs1.h>
#include "descriptor_defs.h" #include "descriptor_defs.h"
#include "xua_hid_report.h" #include "xua_hid_report.h"
#include "hid_report_descriptor.h" #include "hid_report_descriptor.h"
#include <stdio.h>
#define HID_REPORT_ITEM_LOCATION_SIZE ( 1 ) #define HID_REPORT_ITEM_LOCATION_SIZE ( 1 )
#define HID_REPORT_DESCRIPTOR_ITEM_COUNT ( sizeof hidReportDescriptorItems / sizeof ( USB_HID_Short_Item_t* )) #define HID_REPORT_DESCRIPTOR_ITEM_COUNT ( sizeof hidReportDescriptorItems / sizeof ( USB_HID_Short_Item_t* ))
@@ -376,6 +378,7 @@ void hidReportInit( void )
s_hidCurrentPeriod[ idx ] = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS; s_hidCurrentPeriod[ idx ] = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS;
} }
memset( s_hidIdleActive, 0, sizeof( s_hidIdleActive ) ); memset( s_hidIdleActive, 0, sizeof( s_hidIdleActive ) );
memset( s_hidChangePending, 0, sizeof( s_hidChangePending ) );
} }
void hidResetReportDescriptor( void ) void hidResetReportDescriptor( void )

View File

@@ -133,9 +133,8 @@ typedef struct
* Calling this function for a given Report ID indicates that the changed * Calling this function for a given Report ID indicates that the changed
* HID data has been reported to the USB Host. * HID data has been reported to the USB Host.
* *
* \warning This function will fail silently if given a Report ID outside of * \warning This function will fail silently if given an id that is not
* the supported range. * either the value zero, or a Report ID that is in use.
* The supported range runs from zero inclusive to HID_REPORT_COUNT exclusive.
* *
* \param[in] id A HID Report ID. * \param[in] id A HID Report ID.
* Zero clears the pending status of all Report IDs. * Zero clears the pending status of all Report IDs.
@@ -259,7 +258,7 @@ void hidCalcNextReportTime( const unsigned id );
void hidCaptureReportTime( const unsigned id, const unsigned time ); void hidCaptureReportTime( const unsigned id, const unsigned time );
/** /**
* @brief Get the time to send the next HID Report time for the given \a id * @brief Get the time to send the next HID Report for the given \a id
* *
* Parameters: * Parameters:
* *
@@ -331,11 +330,8 @@ unsigned hidGetReportTime( const unsigned id );
* Calling this function with a given Report ID returns an indication of * Calling this function with a given Report ID returns an indication of
* whether unreported HID data exists for that Report ID. * whether unreported HID data exists for that Report ID.
* *
* \warning This function will return zero if given a Report ID outside of * \warning This function will return zero if given an id that is not
* the supported range. * either the value zero, or a Report ID that is in use.
* If not using Report IDs, the supported range consists of the value zero only.
* If using Report IDs, the supported range runs from zero inclusive to
* HID_REPORT_COUNT exclusive.
* *
* \param[in] id A HID Report ID. * \param[in] id A HID Report ID.
* Zero reports the pending status of all Report IDs. * Zero reports the pending status of all Report IDs.
@@ -410,11 +406,8 @@ void hidResetReportDescriptor( void );
* for that Report ID has changed and has not yet been reported to the USB * for that Report ID has changed and has not yet been reported to the USB
* Host. * Host.
* *
* \warning This function will fail silently if given a Report ID outside of * \warning This function will fail silently if given an id that is not
* the supported range. * either the value zero, or a Report ID that is in use.
* If not using Report IDs, the supported range consists of the value zero only.
* If using Report IDs, the supported range runs from one inclusive to
* HID_REPORT_COUNT exclusive.
* *
* \param[in] id A HID Report ID. * \param[in] id A HID Report ID.
* Use zero if the application does not use Report IDs. * Use zero if the application does not use Report IDs.

View File

@@ -53,19 +53,6 @@ void setUp( void )
hidResetReportDescriptor(); hidResetReportDescriptor();
} }
void test_print_report( void )
{
hidPrepareReportDescriptor();
unsigned char* report = hidGetReportDescriptor();
size_t reportLen = hidGetReportDescriptorLength();
printf("ReportDescriptor:");
for (size_t i = 0; i < reportLen; i++) {
printf(" %02x", report[i]);
}
printf("\n");
}
void test_validate_report( void ) { void test_validate_report( void ) {
unsigned retVal = hidReportValidate(); unsigned retVal = hidReportValidate();
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
@@ -740,7 +727,7 @@ void test_initial_modification_with_subsequent_verification_2( void )
} }
} }
//setIdle functionality tests //setIdle and associated timing functionality tests
void test_set_idle( void ) void test_set_idle( void )
{ {
unsigned reportIdAll = 0; unsigned reportIdAll = 0;
@@ -776,7 +763,7 @@ void test_set_all_idle( void )
unsigned setIdle = hidIsIdleActive( reportId ); unsigned setIdle = hidIsIdleActive( reportId );
TEST_ASSERT_EQUAL_UINT( 0, setIdle ); TEST_ASSERT_EQUAL_UINT( 0, setIdle );
setIdle = hidIsIdleActive( reportId2 ); setIdle = hidIsIdleActive( reportId2 );
TEST_ASSERT_EQUAL_UINT( 0, setIdle ); TEST_ASSERT_EQUAL_UINT( 0, setIdle );
setIdle = hidIsIdleActive( reportIdAll ); setIdle = hidIsIdleActive( reportIdAll );
@@ -790,4 +777,94 @@ void test_set_all_idle( void )
setIdle = hidIsIdleActive( reportIdAll ); setIdle = hidIsIdleActive( reportIdAll );
TEST_ASSERT_EQUAL_UINT( 1, setIdle ); TEST_ASSERT_EQUAL_UINT( 1, setIdle );
} }
void test_change_pending( void )
{
unsigned reportIdAll = 0;
unsigned reportId = 1;
unsigned reportId2 = 2;
unsigned changePending = hidIsChangePending( reportId );
TEST_ASSERT_EQUAL_UINT( 0, changePending );
changePending = hidIsChangePending( reportId2 );
TEST_ASSERT_EQUAL_UINT( 0, changePending );
changePending = hidIsChangePending( reportIdAll );
TEST_ASSERT_EQUAL_UINT( 0, changePending );
hidSetChangePending( reportId );
changePending = hidIsChangePending( reportId );
TEST_ASSERT_EQUAL_UINT( 1, changePending );
changePending = hidIsChangePending( reportIdAll );
TEST_ASSERT_EQUAL_UINT( 1, changePending );
changePending = hidIsChangePending( reportId2 );
TEST_ASSERT_EQUAL_UINT( 0, changePending );
}
void test_change_pending_all( void )
{
unsigned reportIdAll = 0;
unsigned reportId = 1;
unsigned changePending = hidIsChangePending( reportId );
TEST_ASSERT_EQUAL_UINT( 0, changePending );
changePending = hidIsChangePending( reportIdAll );
TEST_ASSERT_EQUAL_UINT( 0, changePending );
for ( reportId = 1; reportId <= HID_REPORT_COUNT; ++reportId ) {
hidSetChangePending( reportId );
changePending = hidIsChangePending( reportId );
TEST_ASSERT_EQUAL_UINT( 1, changePending );
}
changePending = hidIsChangePending( reportIdAll );
TEST_ASSERT_EQUAL_UINT( 1, changePending );
}
void test_report_time( void )
{
unsigned reportTime1 = 123;
unsigned reportTime2 = 456;
hidCaptureReportTime(1, reportTime1);
hidCaptureReportTime(2, reportTime2);
reportTime1 = hidGetReportTime(1);
reportTime2 = hidGetReportTime(2);
TEST_ASSERT_EQUAL_UINT(123, reportTime1);
TEST_ASSERT_EQUAL_UINT(456, reportTime2);
}
void test_report_time_calc( void )
{
unsigned reportTime1 = 123;
unsigned reportTime2 = 456;
unsigned reportPeriod1 = 10;
unsigned reportPeriod2 = 5;
hidCaptureReportTime(1, reportTime1);
hidCaptureReportTime(2, reportTime2);
hidSetReportPeriod(1, reportPeriod1);
hidSetReportPeriod(2, reportPeriod2);
reportTime1 = hidGetReportTime(1);
reportTime2 = hidGetReportTime(2);
reportPeriod1 = hidGetReportPeriod(1);
reportPeriod2 = hidGetReportPeriod(2);
TEST_ASSERT_EQUAL_UINT(123, reportTime1);
TEST_ASSERT_EQUAL_UINT(456, reportTime2);
TEST_ASSERT_EQUAL_UINT(10, reportPeriod1);
TEST_ASSERT_EQUAL_UINT(5, reportPeriod2);
hidCalcNextReportTime(1);
hidCalcNextReportTime(2);
unsigned nextReportTime1 = hidGetNextReportTime(1);
unsigned nextReportTime2 = hidGetNextReportTime(2);
TEST_ASSERT_EQUAL_UINT( reportTime1 + reportPeriod1, nextReportTime1 );
TEST_ASSERT_EQUAL_UINT( reportTime2 + reportPeriod2, nextReportTime2 );
}

View File

@@ -586,3 +586,38 @@ void test_set_idle( void )
setIdle = hidIsIdleActive( reportId ); setIdle = hidIsIdleActive( reportId );
TEST_ASSERT_EQUAL_UINT( 1, setIdle ); TEST_ASSERT_EQUAL_UINT( 1, setIdle );
} }
void test_change_pending( void )
{
unsigned reportId = 0;
unsigned changePending = hidIsChangePending( reportId );
TEST_ASSERT_EQUAL_UINT( 0, changePending );
hidSetChangePending( reportId );
changePending = hidIsChangePending( reportId );
TEST_ASSERT_EQUAL_UINT( 1, changePending );
hidClearChangePending( reportId );
changePending = hidIsChangePending( reportId );
TEST_ASSERT_EQUAL_UINT( 0, changePending );
}
void test_report_time( void )
{
unsigned reportTime = 123;
unsigned reportPeriod = 10;
hidSetReportPeriod(0, reportPeriod);
hidCaptureReportTime(0, reportTime);
reportTime = hidGetReportTime(0);
reportPeriod = hidGetReportPeriod(0);
TEST_ASSERT_EQUAL_UINT(123, reportTime);
TEST_ASSERT_EQUAL_UINT(10, reportPeriod);
hidCalcNextReportTime(0);
unsigned nextReportTime = hidGetNextReportTime(0);
TEST_ASSERT_EQUAL_UINT(133, nextReportTime);
}