forked from PAWPAW-Mirror/lib_xua
Merge pull request #2 from CiaranWoodward/feature/multiple_hid_reports_tests
Update tests to work with new report-id api
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -20,6 +20,8 @@
|
||||
test_results.csv
|
||||
_build*
|
||||
**/.venv/**
|
||||
**/.vscode/**
|
||||
**.egg-info
|
||||
|
||||
# waf build files
|
||||
.lock-waf_*
|
||||
|
||||
@@ -29,41 +29,55 @@ unsigned char hidReportDescriptor[] =
|
||||
};
|
||||
#endif
|
||||
|
||||
#define USB_HID_REPORT_ID_CONSUMER ( 0x02 )
|
||||
#define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x02 )
|
||||
|
||||
/*
|
||||
* Define non-configurable items in the HID Report descriptor.
|
||||
*/
|
||||
static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }};
|
||||
|
||||
static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }};
|
||||
|
||||
static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }};
|
||||
|
||||
static const USB_HID_Short_Item_t hidReportCount2 = { .header = 0x95, .data = { 0x02, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidReportCount2 = { .header = 0x95, .data = { 0x02, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }};
|
||||
|
||||
static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }, .location = 0x00 };
|
||||
|
||||
static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = 0x05, .data = { 0x0C, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = 0x05, .data = { 0x0C, 0x00 }};
|
||||
|
||||
/*
|
||||
* Define configurable items in the HID Report descriptor.
|
||||
*/
|
||||
static USB_HID_Short_Item_t hidUsageByte0Bit5 = { .header = 0x09, .data = { 0xE2, 0x00 }, .location = 0x50 }; // Mute
|
||||
static USB_HID_Short_Item_t hidUsageByte0Bit4 = { .header = 0x09, .data = { 0xEA, 0x00 }, .location = 0x40 }; // Vol-
|
||||
static USB_HID_Short_Item_t hidUsageByte0Bit3 = { .header = 0x09, .data = { 0xE9, 0x00 }, .location = 0x30 }; // Vol+
|
||||
static USB_HID_Short_Item_t hidUsageByte0Bit2 = { .header = 0x09, .data = { 0xB6, 0x00 }, .location = 0x20 }; // Scan Prev
|
||||
static USB_HID_Short_Item_t hidUsageByte0Bit1 = { .header = 0x09, .data = { 0xB5, 0x00 }, .location = 0x10 }; // Scan Next
|
||||
static USB_HID_Short_Item_t hidUsageByte0Bit0 = { .header = 0x09, .data = { 0xB0, 0x00 }, .location = 0x00 }; // Play
|
||||
static USB_HID_Report_Element_t hidUsageByte0Bit5 = { .item.header = 0x09, .item.data = { 0xE2, 0x00 },
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 5 ) }; // Mute
|
||||
static USB_HID_Report_Element_t hidUsageByte0Bit4 = { .item.header = 0x09, .item.data = { 0xEA, 0x00 },
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 4 ) }; // Vol-
|
||||
static USB_HID_Report_Element_t hidUsageByte0Bit3 = { .item.header = 0x09, .item.data = { 0xE9, 0x00 },
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 3 ) }; // Vol+
|
||||
static USB_HID_Report_Element_t hidUsageByte0Bit2 = { .item.header = 0x09, .item.data = { 0xB6, 0x00 },
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 2 ) }; // Scan Prev
|
||||
static USB_HID_Report_Element_t hidUsageByte0Bit1 = { .item.header = 0x09, .item.data = { 0xB5, 0x00 },
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 1 ) }; // Scan Next
|
||||
static USB_HID_Report_Element_t hidUsageByte0Bit0 = { .item.header = 0x09, .item.data = { 0xB0, 0x00 },
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 0 ) }; // Play
|
||||
|
||||
static USB_HID_Short_Item_t hidReportID1 = { .header = 0x85, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00}};
|
||||
static const USB_HID_Report_Element_t hidReportConsumer = {
|
||||
.item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 1, 0, 0 )
|
||||
};
|
||||
|
||||
/*
|
||||
* List the configurable items in the HID Report descriptor.
|
||||
*/
|
||||
static USB_HID_Short_Item_t* const hidConfigurableItems[] = {
|
||||
static USB_HID_Report_Element_t* const hidConfigurableElements[] = {
|
||||
&hidUsageByte0Bit0,
|
||||
&hidUsageByte0Bit1,
|
||||
&hidUsageByte0Bit2,
|
||||
@@ -75,25 +89,26 @@ static USB_HID_Short_Item_t* const hidConfigurableItems[] = {
|
||||
/*
|
||||
* List Usage pages in the HID Report descriptor, one per byte.
|
||||
*/
|
||||
static const USB_HID_Short_Item_t* const hidUsagePages[] = {
|
||||
static const USB_HID_Short_Item_t * const hidUsagePages[] = {
|
||||
&hidUsagePageConsumer
|
||||
};
|
||||
|
||||
/*
|
||||
* List all items in the HID Report descriptor.
|
||||
*/
|
||||
static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = {
|
||||
static const USB_HID_Short_Item_t * const hidReportDescriptorItems[] = {
|
||||
&(hidReportConsumer.item),
|
||||
&hidUsagePageConsumer,
|
||||
&hidUsageConsumerControl,
|
||||
&hidCollectionApplication,
|
||||
&hidLogicalMinimum0,
|
||||
&hidLogicalMaximum1,
|
||||
&hidUsageByte0Bit0,
|
||||
&hidUsageByte0Bit1,
|
||||
&hidUsageByte0Bit2,
|
||||
&hidUsageByte0Bit3,
|
||||
&hidUsageByte0Bit4,
|
||||
&hidUsageByte0Bit5,
|
||||
&(hidUsageByte0Bit0.item),
|
||||
&(hidUsageByte0Bit1.item),
|
||||
&(hidUsageByte0Bit2.item),
|
||||
&(hidUsageByte0Bit3.item),
|
||||
&(hidUsageByte0Bit4.item),
|
||||
&(hidUsageByte0Bit5.item),
|
||||
&hidReportSize1,
|
||||
&hidReportCount6,
|
||||
&hidInputDataVar,
|
||||
@@ -103,10 +118,15 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = {
|
||||
&hidCollectionEnd
|
||||
};
|
||||
|
||||
static const USB_HID_Report_Element_t* const hidReports[] = {
|
||||
&hidReportConsumer
|
||||
};
|
||||
|
||||
/*
|
||||
* Define the length of the HID Report.
|
||||
* This value must match the number of Report bytes defined by hidReportDescriptorItems.
|
||||
* Define the number of HID Reports
|
||||
* Due to XC not supporting designated initializers, this constant has a hard-coded value.
|
||||
* It must equal ( sizeof hidReports / sizeof ( USB_HID_Report_Element_t* ))
|
||||
*/
|
||||
#define HID_REPORT_LENGTH ( 1 )
|
||||
#define HID_REPORT_COUNT ( 1 )
|
||||
|
||||
#endif // __hid_report_descriptor_h__
|
||||
|
||||
@@ -66,7 +66,7 @@ enum USBInterfaceNumber
|
||||
INTERFACE_COUNT /* End marker */
|
||||
};
|
||||
|
||||
#if( 0 < HID_CONTROLS )
|
||||
#ifndef ENDPOINT_INT_INTERVAL_IN_HID
|
||||
#define ENDPOINT_INT_INTERVAL_IN_HID 0x08
|
||||
#endif
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ void hidCaptureReportTime( const unsigned id, const unsigned time )
|
||||
{
|
||||
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
||||
if( id == hidGetElementReportId( hidReports[ idx ]->location )) {
|
||||
s_hidNextReportTime[ idx ] = time;
|
||||
s_hidReportTime[ idx ] = time;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,7 +229,15 @@ size_t hidGetReportDescriptorLength( void )
|
||||
}
|
||||
|
||||
unsigned hidGetReportIdLimit ( void ) {
|
||||
return HID_REPORT_COUNT;
|
||||
unsigned retVal = 0U;
|
||||
|
||||
for( size_t idx = 0U; idx < HID_REPORT_COUNT; ++idx ) {
|
||||
unsigned reportId = hidGetElementReportId( hidReports[ idx ]->location );
|
||||
if( reportId >= retVal ) {
|
||||
retVal = reportId + 1;
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
#define HID_CONFIGURABLE_ELEMENT_COUNT ( sizeof hidConfigurableElements / sizeof ( USB_HID_Report_Element_t* ))
|
||||
|
||||
@@ -79,12 +79,10 @@ foreach( testsourcefile ${APP_SOURCES} )
|
||||
set_target_properties(${ITEM_NAME} PROPERTIES OUTPUT_NAME ${ITEM_NAME}.xe)
|
||||
target_compile_options(${ITEM_NAME} PRIVATE ${APP_COMPILER_FLAGS})
|
||||
|
||||
|
||||
|
||||
target_include_directories(${ITEM_NAME}
|
||||
PRIVATE ${APP_INCLUDES}
|
||||
PRIVATE ${XUA_INCLUDES_ALL}
|
||||
)
|
||||
target_include_directories(${ITEM_NAME}
|
||||
PRIVATE ${APP_INCLUDES}
|
||||
PRIVATE ${XUA_INCLUDES_ALL}
|
||||
)
|
||||
|
||||
target_sources(${ITEM_NAME}
|
||||
PRIVATE ${APP_SRCS}
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
// Copyright 2021 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#ifndef __hid_report_descriptor_h__
|
||||
#define __hid_report_descriptor_h__
|
||||
|
||||
#include "xua_hid_report_descriptor.h"
|
||||
|
||||
#define MAX_VALID_BIT ( 7 )
|
||||
#define MAX_VALID_BYTE ( 1 )
|
||||
|
||||
#define MIN_VALID_BIT ( 0 )
|
||||
#define MIN_VALID_BYTE ( 0 )
|
||||
|
||||
/*
|
||||
* Define non-configurable items in the HID Report descriptor.
|
||||
*/
|
||||
static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidCollectionLogical = { .header = 0xA1, .data = { 0x02, 0x00 }, .location = 0x00 };
|
||||
|
||||
static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }, .location = 0x00 };
|
||||
|
||||
static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }, .location = 0x00 };
|
||||
|
||||
static const USB_HID_Short_Item_t hidReportCount1 = { .header = 0x95, .data = { 0x01, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidReportCount7 = { .header = 0x95, .data = { 0x07, 0x00 }, .location = 0x00 };
|
||||
static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }, .location = 0x00 };
|
||||
|
||||
static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }, .location = 0x00 };
|
||||
|
||||
static const USB_HID_Short_Item_t hidUsagePageConsumer = { .header = 0x05, .data = { 0x0C, 0x00 }, .location = 0x00 };
|
||||
|
||||
/*
|
||||
* Define configurable items in the HID Report descriptor.
|
||||
*/
|
||||
static USB_HID_Short_Item_t hidUsageByte0Bit0 = { .header = 0x09, .data = { 0xE2, 0x00 }, .location = 0x00 }; // Mute
|
||||
|
||||
static USB_HID_Short_Item_t hidUsageByte1Bit7 = { .header = 0x09, .data = { 0xEA, 0x00 }, .location = 0x71 }; // Vol-
|
||||
static USB_HID_Short_Item_t hidUsageByte1Bit0 = { .header = 0x09, .data = { 0xE9, 0x00 }, .location = 0x01 }; // Vol+
|
||||
|
||||
/*
|
||||
* List the configurable items in the HID Report descriptor.
|
||||
*/
|
||||
static USB_HID_Short_Item_t* const hidConfigurableItems[] = {
|
||||
&hidUsageByte0Bit0,
|
||||
&hidUsageByte1Bit0,
|
||||
&hidUsageByte1Bit7
|
||||
};
|
||||
|
||||
/*
|
||||
* List Usage pages in the HID Report descriptor, one per byte.
|
||||
*/
|
||||
static const USB_HID_Short_Item_t* const hidUsagePages[] = {
|
||||
&hidUsagePageConsumer,
|
||||
&hidUsagePageConsumer
|
||||
};
|
||||
|
||||
/*
|
||||
* List all items in the HID Report descriptor.
|
||||
*/
|
||||
static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = {
|
||||
&hidUsagePageConsumer,
|
||||
&hidUsageConsumerControl,
|
||||
&hidCollectionApplication,
|
||||
&hidReportSize1,
|
||||
&hidLogicalMinimum0,
|
||||
&hidCollectionLogical, // Byte 0
|
||||
&hidLogicalMaximum1,
|
||||
&hidReportCount1,
|
||||
&hidUsageByte0Bit0,
|
||||
&hidInputDataVar,
|
||||
&hidLogicalMaximum0,
|
||||
&hidReportCount7,
|
||||
&hidInputConstArray,
|
||||
&hidCollectionEnd,
|
||||
&hidCollectionLogical, // Byte 1
|
||||
&hidLogicalMaximum1,
|
||||
&hidReportCount1,
|
||||
&hidUsageByte1Bit0,
|
||||
&hidInputDataVar,
|
||||
&hidLogicalMaximum0,
|
||||
&hidReportCount6,
|
||||
&hidInputConstArray,
|
||||
&hidLogicalMaximum1,
|
||||
&hidUsageByte1Bit7,
|
||||
&hidInputDataVar,
|
||||
&hidCollectionEnd,
|
||||
&hidCollectionEnd
|
||||
};
|
||||
|
||||
/*
|
||||
* Define the length of the HID Report.
|
||||
* This value must match the number of Report bytes defined by hidReportDescriptorItems.
|
||||
*/
|
||||
#define HID_REPORT_LENGTH ( 2 )
|
||||
|
||||
#endif // __hid_report_descriptor_h__
|
||||
@@ -0,0 +1,230 @@
|
||||
// Copyright 2021 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#ifndef __hid_report_descriptor_h__
|
||||
#define __hid_report_descriptor_h__
|
||||
|
||||
#include "xua_hid_report.h"
|
||||
|
||||
#define USB_HID_REPORT_ID_KEYBOARD ( 0x01 )
|
||||
#define USB_HID_REPORT_ID_CONSUMER ( 0x02 )
|
||||
#define USB_HID_REPORT_ID_TELEPHONY ( 0x03 )
|
||||
|
||||
#define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x0C )
|
||||
#define USB_HID_USAGE_PAGE_ID_KEYBOARD ( 0x07 )
|
||||
#define USB_HID_USAGE_PAGE_ID_TELEPHONY ( 0x0B )
|
||||
|
||||
/*
|
||||
* Define non-configurable items in the HID Report descriptor.
|
||||
* (These are short items as the location field isn't relevant for them)
|
||||
*/
|
||||
static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidCollectionLogical = { .header = 0xA1, .data = { 0x02, 0x00 }};
|
||||
|
||||
static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }};
|
||||
|
||||
static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }};
|
||||
|
||||
static const USB_HID_Short_Item_t hidReportCount1 = { .header = 0x95, .data = { 0x01, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidReportCount4 = { .header = 0x95, .data = { 0x04, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }};
|
||||
|
||||
static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }};
|
||||
|
||||
/*
|
||||
* Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report
|
||||
* For internal purposes, a report element with ID of 0 must be included if report IDs are not being used.
|
||||
*/
|
||||
static const USB_HID_Short_Item_t hidReportId1 = { .header = 0x85, .data = { USB_HID_REPORT_ID_KEYBOARD, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidReportId2 = { .header = 0x85, .data = { USB_HID_REPORT_ID_CONSUMER, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidReportId3 = { .header = 0x85, .data = { USB_HID_REPORT_ID_TELEPHONY, 0x00 }};
|
||||
|
||||
static const USB_HID_Report_Element_t hidReportKeyboard = {
|
||||
.item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_KEYBOARD, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 1, 0, 0 )
|
||||
};
|
||||
|
||||
static const USB_HID_Report_Element_t hidReportConsumer = {
|
||||
.item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 2, 0, 0 )
|
||||
};
|
||||
|
||||
static const USB_HID_Report_Element_t hidReportTelephony = {
|
||||
.item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_TELEPHONY, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_TELEPHONY, 1, 0, 0 )
|
||||
};
|
||||
|
||||
static USB_HID_Report_Element_t hidUsageReport1Byte0Bit0 = {
|
||||
.item = { .header = 0x09, .data = { 0x17, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 0, 0, 0 )
|
||||
}; // 't'
|
||||
|
||||
static USB_HID_Report_Element_t hidUsageReport1Byte0Bit2 = {
|
||||
.item = { .header = 0x09, .data = { 0x72, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 0, 0, 2 )
|
||||
}; // F23
|
||||
|
||||
static USB_HID_Report_Element_t hidUsageReport1Byte0Bit3 = {
|
||||
.item = { .header = 0x09, .data = { 0x73, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 0, 0, 3 )
|
||||
}; // F24
|
||||
|
||||
static USB_HID_Report_Element_t hidUsageReport2Byte0Bit0 = {
|
||||
.item = { .header = 0x0A, .data = { 0x26, 0x02 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 0 )
|
||||
}; // AC Stop
|
||||
|
||||
static USB_HID_Report_Element_t hidUsageReport2Byte0Bit1 = {
|
||||
.item = { .header = 0x0A, .data = { 0x21, 0x02 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 1 )
|
||||
}; // AC Search
|
||||
|
||||
static USB_HID_Report_Element_t hidUsageReport2Byte0Bit2 = {
|
||||
.item = { .header = 0x09, .data = { 0xE2, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 2 )
|
||||
}; // Mute
|
||||
|
||||
static USB_HID_Report_Element_t hidUsageReport2Byte0Bit4 = {
|
||||
.item = { .header = 0x09, .data = { 0xCF, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 4 )
|
||||
}; // Voice Command
|
||||
|
||||
static USB_HID_Report_Element_t hidUsageReport2Byte0Bit6 = {
|
||||
.item = { .header = 0x09, .data = { 0xE9, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 6 )
|
||||
}; // Vol+
|
||||
|
||||
static USB_HID_Report_Element_t hidUsageReport2Byte0Bit7 = {
|
||||
.item = { .header = 0x09, .data = { 0xEA, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 7 )
|
||||
}; // Vol-
|
||||
|
||||
static USB_HID_Report_Element_t hidUsageReport2Byte1Bit7 = {
|
||||
.item = { .header = 0x09, .data = { 0xE5, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 1, 7 )
|
||||
}; // Bass boost
|
||||
|
||||
static USB_HID_Report_Element_t hidUsageReport3Byte0Bit0 = {
|
||||
.item = { .header = 0x09, .data = { 0x20, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_TELEPHONY, 0, 0, 0 )
|
||||
}; // Hook Switch
|
||||
|
||||
static USB_HID_Report_Element_t hidUsageReport3Byte0Bit1 = {
|
||||
.item = { .header = 0x09, .data = { 0x2F, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_TELEPHONY, 0, 0, 1 )
|
||||
}; // Phone Mute
|
||||
|
||||
/*
|
||||
* List the configurable elements in the HID Report.
|
||||
*/
|
||||
static USB_HID_Report_Element_t* const hidConfigurableElements[] = {
|
||||
&hidUsageReport1Byte0Bit0,
|
||||
&hidUsageReport1Byte0Bit2,
|
||||
&hidUsageReport1Byte0Bit3,
|
||||
|
||||
&hidUsageReport2Byte0Bit0,
|
||||
&hidUsageReport2Byte0Bit1,
|
||||
&hidUsageReport2Byte0Bit2,
|
||||
&hidUsageReport2Byte0Bit4,
|
||||
&hidUsageReport2Byte0Bit6,
|
||||
&hidUsageReport2Byte0Bit7,
|
||||
&hidUsageReport2Byte1Bit7,
|
||||
|
||||
&hidUsageReport3Byte0Bit0,
|
||||
&hidUsageReport3Byte0Bit1
|
||||
};
|
||||
|
||||
/*
|
||||
* List HID Reports, one per Report ID. This should be a usage page item with the locator filled out with ID and size
|
||||
* If not using report IDs - still have one with report ID 0
|
||||
*/
|
||||
static const USB_HID_Report_Element_t* const hidReports[] = {
|
||||
&hidReportKeyboard,
|
||||
&hidReportConsumer,
|
||||
&hidReportTelephony
|
||||
};
|
||||
|
||||
/*
|
||||
* List all items in the HID Report descriptor.
|
||||
*/
|
||||
static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = {
|
||||
&(hidReportConsumer.item),
|
||||
&hidUsageConsumerControl,
|
||||
&hidCollectionApplication,
|
||||
&hidReportSize1,
|
||||
&hidLogicalMinimum0,
|
||||
&hidCollectionLogical, // Report 1
|
||||
&hidReportId1,
|
||||
&(hidReportKeyboard.item),
|
||||
&hidLogicalMaximum1,
|
||||
&hidReportCount1,
|
||||
&(hidUsageReport1Byte0Bit0.item),
|
||||
&hidInputDataVar,
|
||||
&hidLogicalMaximum0,
|
||||
&hidInputConstArray,
|
||||
&hidLogicalMaximum1,
|
||||
&(hidUsageReport1Byte0Bit2.item),
|
||||
&hidInputDataVar,
|
||||
&(hidUsageReport1Byte0Bit3.item),
|
||||
&hidInputDataVar,
|
||||
&hidLogicalMaximum0,
|
||||
&hidReportCount4,
|
||||
&hidInputConstArray,
|
||||
&hidCollectionEnd,
|
||||
&hidCollectionLogical, // Report 2
|
||||
&hidReportId2,
|
||||
&(hidReportConsumer.item),
|
||||
&hidLogicalMaximum1,
|
||||
&hidReportCount1,
|
||||
&(hidUsageReport2Byte0Bit0.item),
|
||||
&hidInputDataVar,
|
||||
&(hidUsageReport2Byte0Bit1.item),
|
||||
&hidInputDataVar,
|
||||
&(hidUsageReport2Byte0Bit2.item),
|
||||
&hidInputDataVar,
|
||||
&hidLogicalMaximum0,
|
||||
&hidInputConstArray,
|
||||
&hidLogicalMaximum1,
|
||||
&(hidUsageReport2Byte0Bit4.item),
|
||||
&hidInputDataVar,
|
||||
&hidLogicalMaximum0,
|
||||
&hidInputConstArray,
|
||||
&hidLogicalMaximum1,
|
||||
&(hidUsageReport2Byte0Bit6.item),
|
||||
&hidInputDataVar,
|
||||
&(hidUsageReport2Byte0Bit7.item),
|
||||
&hidInputDataVar,
|
||||
&hidLogicalMaximum0,
|
||||
&hidReportCount6,
|
||||
&hidInputConstArray,
|
||||
&hidLogicalMaximum1,
|
||||
&(hidUsageReport2Byte1Bit7.item),
|
||||
&hidInputDataVar,
|
||||
&hidCollectionEnd,
|
||||
&hidCollectionLogical, // Report 3
|
||||
&hidReportId3,
|
||||
&(hidReportTelephony.item),
|
||||
&(hidUsageReport3Byte0Bit0.item),
|
||||
&hidInputDataVar,
|
||||
&(hidUsageReport3Byte0Bit1.item),
|
||||
&hidInputDataVar,
|
||||
&hidLogicalMaximum0,
|
||||
&hidReportCount6,
|
||||
&hidInputConstArray,
|
||||
&hidCollectionEnd,
|
||||
&hidCollectionEnd
|
||||
};
|
||||
|
||||
/*
|
||||
* Define the number of HID Reports
|
||||
* Due to XC not supporting designated initializers, this constant has a hard-coded value.
|
||||
* It must equal ( sizeof hidReports / sizeof ( USB_HID_Report_Element_t* ))
|
||||
*/
|
||||
#define HID_REPORT_COUNT ( 3 )
|
||||
|
||||
#endif // __hid_report_descriptor_h__
|
||||
@@ -0,0 +1,736 @@
|
||||
// Copyright 2021 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "xua_unit_tests.h"
|
||||
#include "xua_hid_report.h"
|
||||
|
||||
// Test constants related to the report descriptor defined in hid_report_descriptor.h
|
||||
#define REPORT1_MAX_VALID_BIT ( 3 )
|
||||
#define REPORT1_MAX_VALID_BYTE ( 0 )
|
||||
#define REPORT1_MIN_VALID_BIT ( 0 )
|
||||
#define REPORT1_MIN_VALID_BYTE ( 0 )
|
||||
|
||||
#define REPORT2_MAX_VALID_BIT ( 7 )
|
||||
#define REPORT2_MAX_VALID_BYTE ( 1 )
|
||||
#define REPORT2_MIN_VALID_BIT ( 0 )
|
||||
#define REPORT2_MIN_VALID_BYTE ( 0 )
|
||||
|
||||
#define REPORT3_MAX_VALID_BIT ( 1 )
|
||||
#define REPORT3_MAX_VALID_BYTE ( 0 )
|
||||
#define REPORT3_MIN_VALID_BIT ( 0 )
|
||||
#define REPORT3_MIN_VALID_BYTE ( 0 )
|
||||
|
||||
#define HID_REPORT_LENGTH ( 3 )
|
||||
#define HID_REPORT_COUNT ( 3 )
|
||||
#define HID_REPORTID_LIMIT ( 4 )
|
||||
|
||||
// Constants from USB HID Usage Tables
|
||||
#define KEYBOARD_PAGE ( 0x07 )
|
||||
#define CONSUMER_PAGE ( 0x0C )
|
||||
#define TELEPHONY_DEVICE_PAGE ( 0x0B )
|
||||
#define LOUDNESS_CONTROL ( 0xE7 )
|
||||
#define PHONE_KEY_9 ( 0xB9 )
|
||||
#define KEYBOARD_X ( 0x1B )
|
||||
#define PHONE_HOST_HOLD ( 0x010A )
|
||||
|
||||
static unsigned construct_usage_header( unsigned size )
|
||||
{
|
||||
unsigned header = 0x00;
|
||||
|
||||
header |= ( HID_REPORT_ITEM_USAGE_TAG << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_MASK;
|
||||
header |= ( HID_REPORT_ITEM_USAGE_TYPE << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK;
|
||||
|
||||
header |= ( size << HID_REPORT_ITEM_HDR_SIZE_SHIFT ) & HID_REPORT_ITEM_HDR_SIZE_MASK;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
void setUp( void )
|
||||
{
|
||||
hidReportInit();
|
||||
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");
|
||||
}
|
||||
|
||||
// Basic report descriptor tests
|
||||
void test_unprepared_hidGetReportDescriptor( void )
|
||||
{
|
||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||
TEST_ASSERT_NULL( reportDescPtr );
|
||||
|
||||
for (unsigned reportId = 1; reportId <= HID_REPORT_COUNT; reportId++)
|
||||
{
|
||||
unsigned reportLength = hidGetReportLength( reportId );
|
||||
TEST_ASSERT_EQUAL_UINT( 0, reportLength );
|
||||
}
|
||||
}
|
||||
|
||||
void test_prepared_hidGetReportDescriptor( void )
|
||||
{
|
||||
hidPrepareReportDescriptor();
|
||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||
TEST_ASSERT_NOT_NULL( reportDescPtr );
|
||||
|
||||
unsigned reportId = 1;
|
||||
unsigned reportLength = hidGetReportLength( reportId );
|
||||
TEST_ASSERT_EQUAL_UINT( 1, reportLength );
|
||||
|
||||
reportId = 2;
|
||||
reportLength = hidGetReportLength( reportId );
|
||||
TEST_ASSERT_EQUAL_UINT( 2, reportLength );
|
||||
|
||||
reportId = 3;
|
||||
reportLength = hidGetReportLength( reportId );
|
||||
TEST_ASSERT_EQUAL_UINT( 1, reportLength );
|
||||
}
|
||||
|
||||
void test_reset_unprepared_hidGetReportDescriptor( void )
|
||||
{
|
||||
hidPrepareReportDescriptor();
|
||||
hidResetReportDescriptor();
|
||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||
TEST_ASSERT_NULL( reportDescPtr );
|
||||
}
|
||||
|
||||
void test_reset_prepared_hidGetReportDescriptor( void )
|
||||
{
|
||||
hidPrepareReportDescriptor();
|
||||
hidResetReportDescriptor();
|
||||
hidPrepareReportDescriptor();
|
||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||
TEST_ASSERT_NOT_NULL( reportDescPtr );
|
||||
}
|
||||
|
||||
void test_report_id_limit( void )
|
||||
{
|
||||
unsigned reportIdLimit = hidGetReportIdLimit();
|
||||
TEST_ASSERT_EQUAL_UINT( HID_REPORTID_LIMIT, reportIdLimit );
|
||||
}
|
||||
|
||||
// Basic item tests
|
||||
void test_max_loc_hidGetReportItem( void )
|
||||
{
|
||||
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ];
|
||||
unsigned char header;
|
||||
unsigned char page;
|
||||
|
||||
unsigned reportId = 1;
|
||||
unsigned bit = REPORT1_MAX_VALID_BIT;
|
||||
unsigned byte = REPORT1_MAX_VALID_BYTE;
|
||||
unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( KEYBOARD_PAGE, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x09, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x73, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]);
|
||||
|
||||
reportId = 2;
|
||||
bit = REPORT2_MAX_VALID_BIT;
|
||||
byte = REPORT2_MAX_VALID_BYTE;
|
||||
retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( CONSUMER_PAGE, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x09, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xE5, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]);
|
||||
|
||||
reportId = 3;
|
||||
bit = REPORT3_MAX_VALID_BIT;
|
||||
byte = REPORT3_MAX_VALID_BYTE;
|
||||
retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( TELEPHONY_DEVICE_PAGE, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x09, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x2F, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]);
|
||||
}
|
||||
|
||||
|
||||
void test_min_loc_hidGetReportItem( void )
|
||||
{
|
||||
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ];
|
||||
unsigned char header;
|
||||
unsigned char page;
|
||||
|
||||
unsigned reportId = 1;
|
||||
unsigned bit = REPORT1_MIN_VALID_BIT;
|
||||
unsigned byte = REPORT1_MIN_VALID_BYTE;
|
||||
unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( KEYBOARD_PAGE, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x09, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x17, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]);
|
||||
|
||||
reportId = 2;
|
||||
bit = REPORT2_MIN_VALID_BIT;
|
||||
byte = REPORT2_MIN_VALID_BYTE;
|
||||
retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( CONSUMER_PAGE, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x0A, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x26, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0x02, data[ 1 ]);
|
||||
|
||||
reportId = 3;
|
||||
bit = REPORT3_MIN_VALID_BIT;
|
||||
byte = REPORT3_MIN_VALID_BYTE;
|
||||
retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( TELEPHONY_DEVICE_PAGE, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x09, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x20, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]);
|
||||
}
|
||||
|
||||
void test_invalid_report_id( void )
|
||||
{
|
||||
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD2 };
|
||||
unsigned char header = 0x33;
|
||||
unsigned char page = 0x44;
|
||||
|
||||
unsigned reportId = 0;
|
||||
unsigned bit = REPORT1_MIN_VALID_BIT;
|
||||
unsigned byte = REPORT1_MIN_VALID_BYTE;
|
||||
unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_ID, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x33, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0xD2, data[ 1 ]);
|
||||
}
|
||||
|
||||
void test_unused_report_id( void )
|
||||
{
|
||||
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD2 };
|
||||
unsigned char header = 0x33;
|
||||
unsigned char page = 0x44;
|
||||
|
||||
unsigned reportId = 8;
|
||||
unsigned bit = REPORT1_MIN_VALID_BIT;
|
||||
unsigned byte = REPORT1_MIN_VALID_BYTE;
|
||||
unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_ID, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x33, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0xD2, data[ 1 ]);
|
||||
}
|
||||
|
||||
void test_overflow_bit_hidGetReportItem( void )
|
||||
{
|
||||
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 };
|
||||
unsigned char header = 0xAA;
|
||||
unsigned char page = 0x44;
|
||||
|
||||
unsigned reportId = 1;
|
||||
unsigned bit = REPORT1_MAX_VALID_BIT + 1;
|
||||
unsigned byte = REPORT1_MAX_VALID_BYTE;
|
||||
unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]);
|
||||
|
||||
reportId = 2;
|
||||
bit = REPORT2_MAX_VALID_BIT + 1;
|
||||
byte = REPORT2_MAX_VALID_BYTE;
|
||||
retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]);
|
||||
|
||||
reportId = 3;
|
||||
bit = REPORT3_MAX_VALID_BIT + 1;
|
||||
byte = REPORT3_MAX_VALID_BYTE;
|
||||
retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]);
|
||||
}
|
||||
|
||||
void test_overflow_byte_hidGetReportItem( void )
|
||||
{
|
||||
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 };
|
||||
unsigned char header = 0xAA;
|
||||
unsigned char page = 0x44;
|
||||
|
||||
unsigned reportId = 1;
|
||||
unsigned bit = REPORT1_MAX_VALID_BIT;
|
||||
unsigned byte = REPORT1_MAX_VALID_BYTE + 1;
|
||||
unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]);
|
||||
|
||||
reportId = 2;
|
||||
bit = REPORT2_MAX_VALID_BIT;
|
||||
byte = REPORT2_MAX_VALID_BYTE + 1;
|
||||
retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]);
|
||||
|
||||
reportId = 3;
|
||||
bit = REPORT3_MAX_VALID_BIT;
|
||||
byte = REPORT3_MAX_VALID_BYTE + 1;
|
||||
retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]);
|
||||
}
|
||||
|
||||
void test_underflow_bit_hidGetReportItem( void )
|
||||
{
|
||||
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 };
|
||||
unsigned char header = 0xAA;
|
||||
unsigned char page = 0x44;
|
||||
|
||||
unsigned reportId = 1;
|
||||
unsigned bit = REPORT1_MIN_VALID_BIT - 1;
|
||||
unsigned byte = REPORT1_MIN_VALID_BYTE;
|
||||
unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]);
|
||||
|
||||
reportId = 2;
|
||||
bit = REPORT2_MIN_VALID_BIT - 1;
|
||||
byte = REPORT2_MIN_VALID_BYTE;
|
||||
retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]);
|
||||
|
||||
reportId = 3;
|
||||
bit = REPORT3_MIN_VALID_BIT - 1;
|
||||
byte = REPORT3_MIN_VALID_BYTE;
|
||||
retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]);
|
||||
}
|
||||
|
||||
void test_underflow_byte_hidGetReportItem( void )
|
||||
{
|
||||
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 };
|
||||
unsigned char header = 0xAA;
|
||||
unsigned char page = 0x44;
|
||||
|
||||
unsigned reportId = 1;
|
||||
unsigned bit = REPORT1_MIN_VALID_BIT;
|
||||
unsigned byte = REPORT1_MIN_VALID_BYTE - 1;
|
||||
unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]);
|
||||
|
||||
reportId = 2;
|
||||
bit = REPORT2_MIN_VALID_BIT;
|
||||
byte = REPORT2_MIN_VALID_BYTE - 1;
|
||||
retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]);
|
||||
|
||||
reportId = 3;
|
||||
bit = REPORT3_MIN_VALID_BIT;
|
||||
byte = REPORT3_MIN_VALID_BYTE - 1;
|
||||
retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]);
|
||||
}
|
||||
|
||||
// Configurable and non-configurable item tests
|
||||
void test_configurable_item_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 1;
|
||||
const unsigned bit = REPORT1_MIN_VALID_BIT;
|
||||
const unsigned byte = REPORT1_MIN_VALID_BYTE;
|
||||
unsigned char data[ 1 ] = { KEYBOARD_X };
|
||||
unsigned char header = construct_usage_header( sizeof( data ) / sizeof( unsigned char ));
|
||||
unsigned char page = KEYBOARD_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
|
||||
retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( KEYBOARD_PAGE, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x09, header );
|
||||
TEST_ASSERT_EQUAL_UINT( KEYBOARD_X, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]);
|
||||
}
|
||||
|
||||
// Testing that the high byte of the report gets correctly cleared
|
||||
void test_configurable_item_hidSetReportItem_multibyte_orig( void )
|
||||
{
|
||||
const unsigned reportId = 2;
|
||||
const unsigned bit = 1; // This byte&bit combo is originally set be 2 bytes long in the header
|
||||
const unsigned byte = 0;
|
||||
unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
|
||||
unsigned char header = construct_usage_header( sizeof( data ) / sizeof( unsigned char ));
|
||||
unsigned char page = CONSUMER_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
|
||||
retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( CONSUMER_PAGE, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x09, header );
|
||||
TEST_ASSERT_EQUAL_UINT( LOUDNESS_CONTROL, data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]);
|
||||
}
|
||||
|
||||
void test_nonconfigurable_item_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 1;
|
||||
const unsigned bit = 1; // This bit and byte combination should not appear in the
|
||||
const unsigned byte = 0; // hidConfigurableElements list in hid_report_descriptors.c.
|
||||
const unsigned char data[ 1 ] = { KEYBOARD_X };
|
||||
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
|
||||
const unsigned char page = KEYBOARD_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
}
|
||||
|
||||
// Bit range tests
|
||||
void test_max_bit_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
|
||||
unsigned reportId = 1;
|
||||
unsigned bit = REPORT1_MAX_VALID_BIT; // See the hidConfigurableElements list in hid_report_descriptors.c.
|
||||
unsigned byte = REPORT1_MAX_VALID_BYTE;
|
||||
unsigned char page = KEYBOARD_PAGE;
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
|
||||
reportId = 2;
|
||||
bit = REPORT2_MAX_VALID_BIT;
|
||||
byte = REPORT2_MAX_VALID_BYTE;
|
||||
page = CONSUMER_PAGE;
|
||||
retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
|
||||
reportId = 3;
|
||||
bit = REPORT3_MAX_VALID_BIT;
|
||||
byte = REPORT3_MAX_VALID_BYTE;
|
||||
page = TELEPHONY_DEVICE_PAGE;
|
||||
retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
}
|
||||
|
||||
void test_min_bit_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
|
||||
unsigned reportId = 1;
|
||||
unsigned bit = REPORT1_MIN_VALID_BIT; // See the hidConfigurableElements list in hid_report_descriptors.c.
|
||||
unsigned byte = REPORT1_MIN_VALID_BYTE;
|
||||
unsigned char page = KEYBOARD_PAGE;
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
|
||||
reportId = 2;
|
||||
bit = REPORT2_MIN_VALID_BIT;
|
||||
byte = REPORT2_MIN_VALID_BYTE;
|
||||
page = CONSUMER_PAGE;
|
||||
retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
|
||||
reportId = 3;
|
||||
bit = REPORT3_MIN_VALID_BIT;
|
||||
byte = REPORT3_MIN_VALID_BYTE;
|
||||
page = TELEPHONY_DEVICE_PAGE;
|
||||
retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
}
|
||||
|
||||
void test_overflow_bit_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
|
||||
unsigned reportId = 1;
|
||||
unsigned bit = REPORT1_MAX_VALID_BIT + 1; // See the hidConfigurableElements list in hid_report_descriptors.c.
|
||||
unsigned byte = REPORT1_MAX_VALID_BYTE;
|
||||
unsigned char page = KEYBOARD_PAGE;
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
|
||||
reportId = 2;
|
||||
bit = REPORT2_MAX_VALID_BIT + 1;
|
||||
byte = REPORT2_MAX_VALID_BYTE;
|
||||
page = CONSUMER_PAGE;
|
||||
retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
|
||||
reportId = 3;
|
||||
bit = REPORT3_MAX_VALID_BIT + 1;
|
||||
byte = REPORT3_MAX_VALID_BYTE;
|
||||
page = TELEPHONY_DEVICE_PAGE;
|
||||
retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
}
|
||||
|
||||
void test_underflow_bit_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
|
||||
unsigned reportId = 1;
|
||||
unsigned bit = REPORT1_MIN_VALID_BIT - 1; // See the hidConfigurableElements list in hid_report_descriptors.c.
|
||||
unsigned byte = REPORT1_MIN_VALID_BYTE;
|
||||
unsigned char page = KEYBOARD_PAGE;
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
|
||||
reportId = 2;
|
||||
bit = REPORT2_MIN_VALID_BIT - 1;
|
||||
byte = REPORT2_MIN_VALID_BYTE;
|
||||
page = CONSUMER_PAGE;
|
||||
retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
|
||||
reportId = 3;
|
||||
bit = REPORT3_MIN_VALID_BIT - 1;
|
||||
byte = REPORT3_MIN_VALID_BYTE;
|
||||
page = TELEPHONY_DEVICE_PAGE;
|
||||
retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
}
|
||||
|
||||
void test_overflow_byte_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
|
||||
unsigned reportId = 1;
|
||||
unsigned bit = REPORT1_MAX_VALID_BIT; // See the hidConfigurableElements list in hid_report_descriptors.c.
|
||||
unsigned byte = REPORT1_MAX_VALID_BYTE + 1;
|
||||
unsigned char page = KEYBOARD_PAGE;
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
|
||||
reportId = 2;
|
||||
bit = REPORT2_MAX_VALID_BIT;
|
||||
byte = REPORT2_MAX_VALID_BYTE + 1;
|
||||
page = CONSUMER_PAGE;
|
||||
retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
|
||||
reportId = 3;
|
||||
bit = REPORT3_MAX_VALID_BIT;
|
||||
byte = REPORT3_MAX_VALID_BYTE + 1;
|
||||
page = TELEPHONY_DEVICE_PAGE;
|
||||
retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
}
|
||||
|
||||
void test_underflow_byte_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
|
||||
unsigned reportId = 1;
|
||||
unsigned bit = REPORT1_MIN_VALID_BIT; // See the hidConfigurableElements list in hid_report_descriptors.c.
|
||||
unsigned byte = REPORT1_MIN_VALID_BYTE - 1;
|
||||
unsigned char page = KEYBOARD_PAGE;
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
|
||||
reportId = 2;
|
||||
bit = REPORT2_MIN_VALID_BIT;
|
||||
byte = REPORT2_MIN_VALID_BYTE - 1;
|
||||
page = CONSUMER_PAGE;
|
||||
retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
|
||||
reportId = 3;
|
||||
bit = REPORT3_MIN_VALID_BIT;
|
||||
byte = REPORT3_MIN_VALID_BYTE - 1;
|
||||
page = TELEPHONY_DEVICE_PAGE;
|
||||
retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
}
|
||||
|
||||
// Size range tests
|
||||
void test_max_size_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 1;
|
||||
const unsigned bit = REPORT1_MIN_VALID_BIT;
|
||||
const unsigned byte = REPORT1_MIN_VALID_BYTE;
|
||||
const unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0x00 };
|
||||
const unsigned char header = construct_usage_header( HID_REPORT_ITEM_MAX_SIZE );
|
||||
const unsigned char page = KEYBOARD_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
}
|
||||
|
||||
void test_min_size_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 1;
|
||||
const unsigned bit = REPORT1_MIN_VALID_BIT;
|
||||
const unsigned byte = REPORT1_MIN_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0x00 );
|
||||
const unsigned char page = KEYBOARD_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
}
|
||||
|
||||
void test_unsupported_size_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = REPORT1_MIN_VALID_BIT;
|
||||
const unsigned byte = REPORT1_MIN_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0x03 );
|
||||
const unsigned char page = KEYBOARD_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
|
||||
}
|
||||
|
||||
// Combined function tests
|
||||
void test_initial_modification_without_subsequent_preparation( void )
|
||||
{
|
||||
const unsigned reportId = 2;
|
||||
const unsigned bit = REPORT2_MIN_VALID_BIT;
|
||||
const unsigned byte = REPORT2_MIN_VALID_BYTE;
|
||||
const unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
|
||||
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
|
||||
const unsigned char page = CONSUMER_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
|
||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||
TEST_ASSERT_NULL( reportDescPtr );
|
||||
}
|
||||
|
||||
void test_initial_modification_with_subsequent_preparation( void )
|
||||
{
|
||||
const unsigned reportId = 2;
|
||||
const unsigned bit = REPORT2_MIN_VALID_BIT;
|
||||
const unsigned byte = REPORT2_MIN_VALID_BYTE;
|
||||
const unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
|
||||
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
|
||||
const unsigned char page = CONSUMER_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
|
||||
hidPrepareReportDescriptor();
|
||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||
TEST_ASSERT_NOT_NULL( reportDescPtr );
|
||||
}
|
||||
|
||||
void test_initial_modification_with_subsequent_verification_1( void )
|
||||
{
|
||||
const unsigned reportId = 2;
|
||||
const unsigned bit = REPORT2_MIN_VALID_BIT;
|
||||
const unsigned byte = REPORT2_MIN_VALID_BYTE;
|
||||
|
||||
unsigned char get_data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xFF, 0xFF };
|
||||
unsigned char get_header = 0xFF;
|
||||
unsigned char get_page = 0xFF;
|
||||
|
||||
const unsigned char set_data[ 1 ] = { LOUDNESS_CONTROL };
|
||||
const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char ));
|
||||
const unsigned char set_page = CONSUMER_PAGE;
|
||||
|
||||
unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal );
|
||||
|
||||
unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal );
|
||||
TEST_ASSERT_EQUAL_UINT( set_page, get_page );
|
||||
TEST_ASSERT_EQUAL_UINT( set_header, get_header );
|
||||
TEST_ASSERT_EQUAL_UINT( set_data[ 0 ], get_data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0, get_data[ 1 ]); // Should be MSB of data from hidUsageByte0Bit0 in hid_report_descriptor.h
|
||||
}
|
||||
|
||||
void test_initial_modification_with_subsequent_verification_2( void )
|
||||
{
|
||||
const unsigned reportId = 3;
|
||||
const unsigned bit = REPORT3_MIN_VALID_BIT;
|
||||
const unsigned byte = REPORT3_MIN_VALID_BYTE;
|
||||
|
||||
{
|
||||
unsigned char get_data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xFF, 0xFF };
|
||||
unsigned char get_header = 0xFF;
|
||||
unsigned char get_page = 0xFF;
|
||||
|
||||
const unsigned char set_data[ 2 ] = {( PHONE_HOST_HOLD & 0x00FF ), (( PHONE_HOST_HOLD & 0xFF00 ) >> 8 )};
|
||||
const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char ));
|
||||
const unsigned char set_page = TELEPHONY_DEVICE_PAGE;
|
||||
|
||||
unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal );
|
||||
|
||||
unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal );
|
||||
TEST_ASSERT_EQUAL_UINT( set_page, get_page );
|
||||
TEST_ASSERT_EQUAL_UINT( set_header, get_header );
|
||||
TEST_ASSERT_EQUAL_UINT( set_data[ 0 ], get_data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( set_data[ 1 ], get_data[ 1 ]);
|
||||
}
|
||||
|
||||
{
|
||||
unsigned char get_data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xFF, 0xFF };
|
||||
unsigned char get_header = 0xFF;
|
||||
unsigned char get_page = 0xFF;
|
||||
|
||||
const unsigned char set_data[ 1 ] = { PHONE_KEY_9 };
|
||||
const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char ));
|
||||
const unsigned char set_page = TELEPHONY_DEVICE_PAGE;
|
||||
|
||||
unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal );
|
||||
|
||||
unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal );
|
||||
TEST_ASSERT_EQUAL_UINT( set_page, get_page );
|
||||
TEST_ASSERT_EQUAL_UINT( set_header, get_header );
|
||||
TEST_ASSERT_EQUAL_UINT( set_data[ 0 ], get_data[ 0 ]);
|
||||
TEST_ASSERT_EQUAL_UINT( 0, get_data[ 1 ]); // The call to hidSetReportItem with size 1 in the header should return the MSB to zero
|
||||
}
|
||||
}
|
||||
116
tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h
Normal file
116
tests/xua_unit_tests/src/test_simple/hid_report_descriptor.h
Normal file
@@ -0,0 +1,116 @@
|
||||
// Copyright 2021 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
#ifndef __hid_report_descriptor_h__
|
||||
#define __hid_report_descriptor_h__
|
||||
|
||||
#include "xua_hid_report.h"
|
||||
|
||||
#define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x0C )
|
||||
|
||||
/*
|
||||
* Define non-configurable items in the HID Report descriptor.
|
||||
* (These are short items as the location field isn't relevant for them)
|
||||
*/
|
||||
static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidCollectionLogical = { .header = 0xA1, .data = { 0x02, 0x00 }};
|
||||
|
||||
static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }};
|
||||
|
||||
static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }};
|
||||
|
||||
static const USB_HID_Short_Item_t hidReportCount1 = { .header = 0x95, .data = { 0x01, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidReportCount7 = { .header = 0x95, .data = { 0x07, 0x00 }};
|
||||
static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }};
|
||||
|
||||
static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }};
|
||||
|
||||
/*
|
||||
* Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report
|
||||
* For internal purposes, a report element with ID of 0 must be included if report IDs are not being used.
|
||||
*/
|
||||
static const USB_HID_Report_Element_t hidReportPageConsumer = {
|
||||
.item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC( 0, 2, 0, 0 )
|
||||
};
|
||||
|
||||
/*
|
||||
* Define configurable items in the HID Report descriptor.
|
||||
*/
|
||||
static USB_HID_Report_Element_t hidUsageByte0Bit0 = {
|
||||
.item = { .header = 0x09, .data = { 0xE2, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC(0, 0, 0, 0)
|
||||
}; // Mute
|
||||
|
||||
static USB_HID_Report_Element_t hidUsageByte1Bit7 = {
|
||||
.item = { .header = 0x09, .data = { 0xEA, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC(0, 0, 1, 7)
|
||||
}; // Vol-
|
||||
static USB_HID_Report_Element_t hidUsageByte1Bit0 = {
|
||||
.item = { .header = 0x09, .data = { 0xE9, 0x00 }},
|
||||
.location = HID_REPORT_SET_LOC(0, 0, 1, 0)
|
||||
}; // Vol+
|
||||
|
||||
/*
|
||||
* List the configurable elements in the HID Report descriptor.
|
||||
*/
|
||||
static USB_HID_Report_Element_t* const hidConfigurableElements[] = {
|
||||
&hidUsageByte0Bit0,
|
||||
&hidUsageByte1Bit0,
|
||||
&hidUsageByte1Bit7
|
||||
};
|
||||
|
||||
/*
|
||||
* List HID Reports, one per Report ID. This should be a usage page item with the relevant
|
||||
* If not using report IDs - still have one with report ID 0
|
||||
*/
|
||||
static const USB_HID_Report_Element_t* const hidReports[] = {
|
||||
&hidReportPageConsumer
|
||||
};
|
||||
|
||||
/*
|
||||
* List all items in the HID Report descriptor.
|
||||
*/
|
||||
static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = {
|
||||
&(hidReportPageConsumer.item),
|
||||
&hidUsageConsumerControl,
|
||||
&hidCollectionApplication,
|
||||
&hidReportSize1,
|
||||
&hidLogicalMinimum0,
|
||||
&hidCollectionLogical, // Byte 0
|
||||
&hidLogicalMaximum1,
|
||||
&hidReportCount1,
|
||||
&(hidUsageByte0Bit0.item),
|
||||
&hidInputDataVar,
|
||||
&hidLogicalMaximum0,
|
||||
&hidReportCount7,
|
||||
&hidInputConstArray,
|
||||
&hidCollectionEnd,
|
||||
&hidCollectionLogical, // Byte 1
|
||||
&hidLogicalMaximum1,
|
||||
&hidReportCount1,
|
||||
&(hidUsageByte1Bit0.item),
|
||||
&hidInputDataVar,
|
||||
&hidLogicalMaximum0,
|
||||
&hidReportCount6,
|
||||
&hidInputConstArray,
|
||||
&hidLogicalMaximum1,
|
||||
&(hidUsageByte1Bit7.item),
|
||||
&hidInputDataVar,
|
||||
&hidCollectionEnd,
|
||||
&hidCollectionEnd
|
||||
};
|
||||
|
||||
/*
|
||||
* Define the number of HID Reports
|
||||
* Due to XC not supporting designated initializers, this constant has a hard-coded value.
|
||||
* It must equal ( sizeof hidReports / sizeof ( USB_HID_Report_Element_t* ))
|
||||
*/
|
||||
#define HID_REPORT_COUNT ( 1 )
|
||||
|
||||
#endif // __hid_report_descriptor_h__
|
||||
@@ -5,17 +5,29 @@
|
||||
|
||||
#include "xua_unit_tests.h"
|
||||
#include "xua_hid_report.h"
|
||||
#include "hid_report_descriptor.h"
|
||||
|
||||
#define HID_REPORT_ITEM_TYPE_GLOBAL ( 0x01 )
|
||||
#define HID_REPORT_ITEM_TYPE_LOCAL ( 0x02 )
|
||||
#define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 )
|
||||
#define HID_REPORT_ITEM_TYPE_RESERVED ( 0x03 )
|
||||
// Test constants related to the report descriptor defined in hid_report_descriptor.h
|
||||
#define MAX_VALID_BIT ( 7 )
|
||||
#define MAX_VALID_BYTE ( 1 )
|
||||
|
||||
#define MIN_VALID_BIT ( 0 )
|
||||
#define MIN_VALID_BYTE ( 0 )
|
||||
|
||||
#define HID_REPORT_LENGTH ( 2 )
|
||||
#define HID_REPORT_COUNT ( 1 )
|
||||
#define HID_REPORTID_LIMIT ( 1 )
|
||||
|
||||
// Constants from the USB HID Usage Tables
|
||||
#define CONSUMER_CONTROL_PAGE ( 0x0C )
|
||||
#define LOUDNESS_CONTROL ( 0xE7 )
|
||||
#define AL_CONTROL_PANEL ( 0x019F )
|
||||
|
||||
// Constants from the USB Device Class Definition for HID
|
||||
#define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 )
|
||||
#define HID_REPORT_ITEM_TYPE_GLOBAL ( 0x01 )
|
||||
#define HID_REPORT_ITEM_TYPE_LOCAL ( 0x02 )
|
||||
#define HID_REPORT_ITEM_TYPE_RESERVED ( 0x03 )
|
||||
|
||||
static unsigned construct_usage_header( unsigned size )
|
||||
{
|
||||
unsigned header = 0x00;
|
||||
@@ -30,33 +42,35 @@ static unsigned construct_usage_header( unsigned size )
|
||||
|
||||
void setUp( void )
|
||||
{
|
||||
hidReportInit();
|
||||
hidResetReportDescriptor();
|
||||
}
|
||||
|
||||
// Basic report descriptor tests
|
||||
void test_unprepared_hidGetReportDescriptor( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||
TEST_ASSERT_NULL( reportDescPtr );
|
||||
|
||||
unsigned reportLength = hidGetReportLength();
|
||||
unsigned reportLength = hidGetReportLength( reportId );
|
||||
TEST_ASSERT_EQUAL_UINT( 0, reportLength );
|
||||
}
|
||||
|
||||
void test_prepared_hidGetReportDescriptor( void )
|
||||
{
|
||||
hidReportInit();
|
||||
const unsigned reportId = 0;
|
||||
|
||||
hidPrepareReportDescriptor();
|
||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||
TEST_ASSERT_NOT_NULL( reportDescPtr );
|
||||
|
||||
unsigned reportLength = hidGetReportLength();
|
||||
unsigned reportLength = hidGetReportLength( reportId );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_REPORT_LENGTH, reportLength );
|
||||
}
|
||||
|
||||
void test_reset_unprepared_hidGetReportDescriptor( void )
|
||||
{
|
||||
hidReportInit();
|
||||
hidPrepareReportDescriptor();
|
||||
hidResetReportDescriptor();
|
||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||
@@ -65,7 +79,6 @@ void test_reset_unprepared_hidGetReportDescriptor( void )
|
||||
|
||||
void test_reset_prepared_hidGetReportDescriptor( void )
|
||||
{
|
||||
hidReportInit();
|
||||
hidPrepareReportDescriptor();
|
||||
hidResetReportDescriptor();
|
||||
hidPrepareReportDescriptor();
|
||||
@@ -73,16 +86,23 @@ void test_reset_prepared_hidGetReportDescriptor( void )
|
||||
TEST_ASSERT_NOT_NULL( reportDescPtr );
|
||||
}
|
||||
|
||||
void test_report_id_limit( void )
|
||||
{
|
||||
unsigned reportIdLimit = hidGetReportIdLimit();
|
||||
TEST_ASSERT_EQUAL_UINT( HID_REPORTID_LIMIT, reportIdLimit );
|
||||
}
|
||||
|
||||
// Basic item tests
|
||||
void test_max_loc_hidGetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MAX_VALID_BIT;
|
||||
const unsigned byte = MAX_VALID_BYTE;
|
||||
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ];
|
||||
unsigned char header;
|
||||
unsigned char page;
|
||||
|
||||
unsigned retVal = hidGetReportItem( byte, bit, &page, &header, data );
|
||||
unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( CONSUMER_CONTROL_PAGE, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x09, header );
|
||||
@@ -92,13 +112,14 @@ void test_max_loc_hidGetReportItem( void )
|
||||
|
||||
void test_min_loc_hidGetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ];
|
||||
unsigned char header;
|
||||
unsigned char page;
|
||||
|
||||
unsigned retVal = hidGetReportItem( byte, bit, &page, &header, data );
|
||||
unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( CONSUMER_CONTROL_PAGE, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x09, header );
|
||||
@@ -108,13 +129,14 @@ void test_min_loc_hidGetReportItem( void )
|
||||
|
||||
void test_overflow_bit_hidGetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MAX_VALID_BIT + 1;
|
||||
const unsigned byte = MAX_VALID_BYTE;
|
||||
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 };
|
||||
unsigned char header = 0xAA;
|
||||
unsigned char page = 0x44;
|
||||
|
||||
unsigned retVal = hidGetReportItem( byte, bit, &page, &header, data );
|
||||
unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
@@ -124,13 +146,14 @@ void test_overflow_bit_hidGetReportItem( void )
|
||||
|
||||
void test_overflow_byte_hidGetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MAX_VALID_BIT;
|
||||
const unsigned byte = MAX_VALID_BYTE + 1;
|
||||
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 };
|
||||
unsigned char header = 0xAA;
|
||||
unsigned char page = 0x44;
|
||||
|
||||
unsigned retVal = hidGetReportItem( byte, bit, &page, &header, data );
|
||||
unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
@@ -140,13 +163,14 @@ void test_overflow_byte_hidGetReportItem( void )
|
||||
|
||||
void test_underflow_bit_hidGetReportItem( void )
|
||||
{
|
||||
const int bit = MIN_VALID_BIT - 1;
|
||||
const unsigned reportId = 0;
|
||||
const int bit = MIN_VALID_BIT - 1;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 };
|
||||
unsigned char header = 0xAA;
|
||||
unsigned char page = 0x44;
|
||||
|
||||
unsigned retVal = hidGetReportItem( byte, ( unsigned ) bit, &page, &header, data );
|
||||
unsigned retVal = hidGetReportItem( reportId, byte, ( unsigned ) bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
@@ -156,13 +180,14 @@ void test_underflow_bit_hidGetReportItem( void )
|
||||
|
||||
void test_underflow_byte_hidGetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const int byte = MIN_VALID_BYTE - 1;
|
||||
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 };
|
||||
unsigned char header = 0xAA;
|
||||
unsigned char page = 0x44;
|
||||
|
||||
unsigned retVal = hidGetReportItem(( unsigned ) byte, bit, &page, &header, data );
|
||||
unsigned retVal = hidGetReportItem( reportId, ( unsigned ) byte, bit, &page, &header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
TEST_ASSERT_EQUAL_UINT( 0x44, page );
|
||||
TEST_ASSERT_EQUAL_UINT( 0xAA, header );
|
||||
@@ -173,226 +198,245 @@ void test_underflow_byte_hidGetReportItem( void )
|
||||
// Configurable and non-configurable item tests
|
||||
void test_configurable_item_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
|
||||
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, data );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
}
|
||||
|
||||
void test_nonconfigurable_item_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MAX_VALID_BIT; // This bit and byte combination should not appear in the
|
||||
const unsigned byte = MIN_VALID_BYTE; // hidConfigurableItems list in hid_report_descriptors.c.
|
||||
const unsigned byte = MIN_VALID_BYTE; // hidConfigurableElements list in hid_report_descriptors.c.
|
||||
const unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
|
||||
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, data );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
}
|
||||
|
||||
// Bit range tests
|
||||
void test_max_bit_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MAX_VALID_BIT; // Only byte 1 has bit 7 not reserved, See the
|
||||
const unsigned byte = MAX_VALID_BYTE; // hidConfigurableItems list in hid_report_descriptors.c.
|
||||
const unsigned byte = MAX_VALID_BYTE; // hidConfigurableElements list in hid_report_descriptors.c.
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
}
|
||||
|
||||
void test_min_bit_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
}
|
||||
|
||||
void test_overflow_bit_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MAX_VALID_BIT + 1;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
}
|
||||
|
||||
void test_underflow_bit_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const int bit = MIN_VALID_BIT - 1;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, ( unsigned ) bit, page, header, NULL );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, ( unsigned ) bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
}
|
||||
|
||||
// Byte range tests
|
||||
void test_max_byte_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MAX_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
}
|
||||
|
||||
void test_min_byte_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
}
|
||||
|
||||
void test_overflow_byte_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MAX_VALID_BYTE + 1;
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
}
|
||||
|
||||
void test_underflow_byte_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const int byte = MIN_VALID_BYTE - 1;
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( ( unsigned ) byte, bit, page, header, NULL );
|
||||
unsigned retVal = hidSetReportItem( reportId, ( unsigned ) byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||
}
|
||||
|
||||
// Size range tests
|
||||
void test_max_size_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0x00 };
|
||||
const unsigned char header = construct_usage_header( HID_REPORT_ITEM_MAX_SIZE );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, data );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
}
|
||||
|
||||
void test_min_size_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0x00 );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
}
|
||||
|
||||
void test_unsupported_size_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0x03 );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
|
||||
}
|
||||
|
||||
// Header tag and type tests
|
||||
void test_bad_tag_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char good_header = construct_usage_header( 0x00 );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
for( unsigned tag = 0x01; tag <= 0x0F; ++tag ) {
|
||||
unsigned char bad_header = good_header | (( 0x0F << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_MASK );
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, bad_header, NULL );
|
||||
unsigned char bad_header = good_header | (( tag << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_MASK );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, bad_header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
|
||||
}
|
||||
}
|
||||
|
||||
void test_global_type_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) |
|
||||
(( HID_REPORT_ITEM_TYPE_GLOBAL << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
|
||||
}
|
||||
|
||||
void test_local_type_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) |
|
||||
(( HID_REPORT_ITEM_TYPE_LOCAL << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
}
|
||||
|
||||
void test_main_type_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) |
|
||||
(( HID_REPORT_ITEM_TYPE_MAIN << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
|
||||
}
|
||||
|
||||
void test_reserved_type_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) |
|
||||
(( HID_REPORT_ITEM_TYPE_RESERVED << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK );
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
|
||||
}
|
||||
|
||||
// Combined function tests
|
||||
void test_initial_modification_without_subsequent_preparation( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
|
||||
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, data );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
|
||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||
@@ -401,14 +445,14 @@ void test_initial_modification_without_subsequent_preparation( void )
|
||||
|
||||
void test_initial_modification_with_subsequent_preparation( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
|
||||
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
hidReportInit();
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, data );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
|
||||
hidPrepareReportDescriptor();
|
||||
@@ -418,6 +462,7 @@ void test_initial_modification_with_subsequent_preparation( void )
|
||||
|
||||
void test_initial_modification_with_subsequent_verification_1( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
|
||||
@@ -429,10 +474,10 @@ void test_initial_modification_with_subsequent_verification_1( void )
|
||||
const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char ));
|
||||
const unsigned char set_page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned setRetVal = hidSetReportItem( byte, bit, set_page, set_header, set_data );
|
||||
unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal );
|
||||
|
||||
unsigned getRetVal = hidGetReportItem( byte, bit, &get_page, &get_header, get_data );
|
||||
unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal );
|
||||
TEST_ASSERT_EQUAL_UINT( set_page, get_page );
|
||||
TEST_ASSERT_EQUAL_UINT( set_header, get_header );
|
||||
@@ -442,6 +487,7 @@ void test_initial_modification_with_subsequent_verification_1( void )
|
||||
|
||||
void test_initial_modification_with_subsequent_verification_2( void )
|
||||
{
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
|
||||
@@ -454,10 +500,10 @@ void test_initial_modification_with_subsequent_verification_2( void )
|
||||
const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char ));
|
||||
const unsigned char set_page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned setRetVal = hidSetReportItem( byte, bit, set_page, set_header, set_data );
|
||||
unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal );
|
||||
|
||||
unsigned getRetVal = hidGetReportItem( byte, bit, &get_page, &get_header, get_data );
|
||||
unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal );
|
||||
TEST_ASSERT_EQUAL_UINT( set_page, get_page );
|
||||
TEST_ASSERT_EQUAL_UINT( set_header, get_header );
|
||||
@@ -474,10 +520,10 @@ void test_initial_modification_with_subsequent_verification_2( void )
|
||||
const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char ));
|
||||
const unsigned char set_page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
unsigned setRetVal = hidSetReportItem( byte, bit, set_page, set_header, set_data );
|
||||
unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal );
|
||||
|
||||
unsigned getRetVal = hidGetReportItem( byte, bit, &get_page, &get_header, get_data );
|
||||
unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal );
|
||||
TEST_ASSERT_EQUAL_UINT( set_page, get_page );
|
||||
TEST_ASSERT_EQUAL_UINT( set_header, get_header );
|
||||
@@ -488,11 +534,11 @@ void test_initial_modification_with_subsequent_verification_2( void )
|
||||
|
||||
void test_modification_without_subsequent_preparation( void )
|
||||
{
|
||||
hidReportInit();
|
||||
hidPrepareReportDescriptor();
|
||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||
TEST_ASSERT_NOT_NULL( reportDescPtr );
|
||||
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
|
||||
@@ -500,7 +546,7 @@ void test_modification_without_subsequent_preparation( void )
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
hidResetReportDescriptor();
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, data );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
|
||||
reportDescPtr = hidGetReportDescriptor();
|
||||
@@ -509,11 +555,11 @@ void test_modification_without_subsequent_preparation( void )
|
||||
|
||||
void test_modification_with_subsequent_preparation( void )
|
||||
{
|
||||
hidReportInit();
|
||||
hidPrepareReportDescriptor();
|
||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||
TEST_ASSERT_NOT_NULL( reportDescPtr );
|
||||
|
||||
const unsigned reportId = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
|
||||
@@ -521,7 +567,7 @@ void test_modification_with_subsequent_preparation( void )
|
||||
const unsigned char page = CONSUMER_CONTROL_PAGE;
|
||||
|
||||
hidResetReportDescriptor();
|
||||
unsigned retVal = hidSetReportItem( byte, bit, page, header, data );
|
||||
unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||
|
||||
hidPrepareReportDescriptor();
|
||||
@@ -95,6 +95,7 @@ def add_unity_runner_build_config(waf_conf, project_root_path, unity_test_path,
|
||||
|
||||
def prepare_unity_test_for_build(waf_conf, project_root_path, unity_test_path,
|
||||
unity_runner_dir, unity_runner_suffix, target):
|
||||
print("unity_test_path: " + str(unity_test_path))
|
||||
generate_unity_runner(project_root_path, unity_test_path,
|
||||
unity_runner_dir, unity_runner_suffix)
|
||||
runner_build_flags = '' # Could extract flags from the test name
|
||||
@@ -107,7 +108,12 @@ def find_unity_test_paths(unity_test_dir, unity_test_prefix):
|
||||
Return a list of all file paths with the unity_test_prefix found in the
|
||||
unity_test_dir.
|
||||
"""
|
||||
return glob.glob(os.path.join(unity_test_dir, unity_test_prefix+'*'))
|
||||
file_list = []
|
||||
for root, dirs, files in os.walk(unity_test_dir):
|
||||
for f in files:
|
||||
if f.startswith(unity_test_prefix):
|
||||
file_list.append(os.path.join(root,f))
|
||||
return file_list
|
||||
|
||||
|
||||
def find_unity_tests(unity_test_dir, unity_test_prefix):
|
||||
@@ -116,7 +122,7 @@ def find_unity_tests(unity_test_dir, unity_test_prefix):
|
||||
unity_test_prefix found in the unity_test_dir.
|
||||
"""
|
||||
unity_test_paths = find_unity_test_paths(unity_test_dir, unity_test_prefix)
|
||||
return {get_test_name(path): get_file_type(path)
|
||||
return {get_test_name(path): {"language": get_file_type(path), "dir": os.path.dirname(path)}
|
||||
for path in unity_test_paths}
|
||||
|
||||
|
||||
@@ -139,8 +145,8 @@ def generate_all_unity_runners(waf_conf, project_root_path,
|
||||
# TODO: can the xwaf boilerplate help here?
|
||||
def create_waf_contexts(configs):
|
||||
for trgt in TARGETS:
|
||||
for test_name, test_language in configs.items():
|
||||
print(f"test_name {test_name}, test_language {test_language}")
|
||||
for test_name, params in configs.items():
|
||||
print(f"test_name {test_name}, test_language {params['language']}")
|
||||
for ctx in (BuildContext, CleanContext):
|
||||
raw_context = ctx.__name__.replace('Context', '').lower()
|
||||
|
||||
@@ -149,9 +155,10 @@ def create_waf_contexts(configs):
|
||||
variant = test_name + '_' + trgt
|
||||
#cmd = raw_context + '_' + test_name
|
||||
#variant = test_name
|
||||
language = test_language
|
||||
language = params["language"]
|
||||
target = trgt
|
||||
runner = test_name
|
||||
directory = params["dir"]
|
||||
print(f"cmd {cmd}, variant {variant}, language {language}")
|
||||
|
||||
|
||||
@@ -161,6 +168,8 @@ UNITY_RUNNER_DIR = 'runners'
|
||||
UNITY_RUNNER_SUFFIX = '_Runner'
|
||||
UNITY_TESTS = find_unity_tests(UNITY_TEST_DIR, UNITY_TEST_PREFIX)
|
||||
|
||||
print("UNITY_TESTS: " + str(UNITY_TESTS))
|
||||
|
||||
create_waf_contexts(UNITY_TESTS)
|
||||
|
||||
def options(opt):
|
||||
@@ -175,7 +184,6 @@ def configure(conf):
|
||||
UNITY_RUNNER_DIR, UNITY_RUNNER_SUFFIX)
|
||||
conf.load('xwaf.xcommon')
|
||||
|
||||
|
||||
def build(bld):
|
||||
if not bld.variant:
|
||||
print('Adding test runners to build queue')
|
||||
@@ -204,7 +212,7 @@ def build(bld):
|
||||
'Unity']
|
||||
|
||||
makefile_opts = {}
|
||||
makefile_opts['SOURCE_DIRS'] = ['src', os.path.join('runners',bld.runner)]
|
||||
makefile_opts['SOURCE_DIRS'] = ['src', bld.directory, os.path.join('runners',bld.runner)]
|
||||
if(bld.target == 'xcoreai'):
|
||||
print('TARGET XCOREAI')
|
||||
makefile_opts['TARGET'] = ['XCORE-AI-EXPLORER']
|
||||
@@ -213,6 +221,7 @@ def build(bld):
|
||||
makefile_opts['TARGET'] = ['XCORE-200-EXPLORER']
|
||||
|
||||
makefile_opts['INCLUDE_DIRS'] = ['src',
|
||||
bld.directory,
|
||||
'../../lib_xua/api',
|
||||
'../../lib_xua/src/core/pdm_mics',
|
||||
'../../lib_xua/src/hid',
|
||||
|
||||
Reference in New Issue
Block a user