diff --git a/tests/xua_unit_tests/CMakeLists.txt b/tests/xua_unit_tests/CMakeLists.txt index a457c644..da0b80a9 100644 --- a/tests/xua_unit_tests/CMakeLists.txt +++ b/tests/xua_unit_tests/CMakeLists.txt @@ -1,12 +1,7 @@ cmake_minimum_required(VERSION 3.21) include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake) -## App name -set( APP_NAME xua_unit_tests ) - - # Auto-generate schedule and top level config files - if( NOT ${Python3_FOUND} ) message(FATAL_ERROR "Python3 not found for running . ") endif() @@ -24,35 +19,28 @@ set( GEN_RUNNER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/generate_unity_runner.py ) set( RUNNERS_DIR ${CMAKE_CURRENT_BINARY_DIR}/src.runners ) file( MAKE_DIRECTORY ${RUNNERS_DIR} ) +# Find unit test files file( GLOB_RECURSE TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/test_*/*.c ) -message(STATUS "HERE: ${TEST_SOURCES}") - - # For every source file in xua_unit_tests/ -foreach(testfile ${TEST_SOURCES}) - message(STATUS "Processing: ${testfile}") - - # Get test name - #cmake_path( GET testfile STEM TESTNAME ) - get_filename_component(TESTNAME ${testfile} NAME_WLE) - - message(STATUS "Unit test name: ${TESTNAME}") +foreach(TESTFILE ${TEST_SOURCES}) + # Get test name from C file stem + cmake_path(GET TESTFILE STEM TESTNAME) project(${TESTNAME}) + message(STATUS "Processing unit test: ${TESTNAME}") - - # Create runner file directory - file(MAKE_DIRECTORY ${RUNNERS_DIR}/${TESTNAME} ) + file(MAKE_DIRECTORY ${RUNNERS_DIR}/${TESTNAME}) - ######### + ##################### ## Create runner file + ##################### set( RUNNER_FILE ${RUNNERS_DIR}/${TESTNAME}/${TESTNAME}_Runner.c ) - set( GEN_RUNNER_SCRIPT_BYPRODUCTS ${RUNNER_FILE} ) + set( GEN_RUNNER_SCRIPT_BYPRODUCTS ${RUNNER_FILE}) unset(GEN_RUNNER_SCRIPT_ARGS) - list(APPEND GEN_RUNNER_SCRIPT_ARGS --project-root ${UNITY_PATH}/.. ) - list(APPEND GEN_RUNNER_SCRIPT_ARGS --source-file ${testfile} ) + list(APPEND GEN_RUNNER_SCRIPT_ARGS --project-root ${UNITY_PATH}/..) + list(APPEND GEN_RUNNER_SCRIPT_ARGS --source-file ${TESTFILE}) list(APPEND GEN_RUNNER_SCRIPT_ARGS --runner-file ${RUNNER_FILE}) ## Add command to generate runner file @@ -64,23 +52,43 @@ foreach(testfile ${TEST_SOURCES}) ########################## ## Do xcommon cmake build ########################## - set(XMOS_SANDBOX_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..) - set(APP_HW_TARGET XK-EVK-XU316) set(APP_DEPENDENT_MODULES "lib_xua") - set(APP_PCA_ENABLE ON) + # set(APP_PCA_ENABLE ON) set(APP_COMPILER_FLAGS ${EXTRA_BUILD_FLAGS} -fcomment-asm -Wall - -O3 + -O2 -report -g -fxscope -DUSB_TILE=tile[0] + -DUNITY_SUPPORT_64 + -DUNITY_INCLUDE_DOUBLE + -DXUD_CORE_CLOCK=600 + -DXUD_SERIES_SUPPORT=4 ) + # For HID tests only enable HID + if(${TESTFILE} MATCHES ".+hid.*") + list(APPEND APP_COMPILER_FLAGS "-DHID_CONTROLS=1") + endif() + + + # Workaround for xcommon cmake pre-pending CMAKE_CURRENT_LIST_DIR + string(REPLACE ${CMAKE_CURRENT_LIST_DIR} "" UNIT_TEST_SOURCE_RELATIVE ${TESTFILE}) + + set(APP_C_SRCS runners/${TESTNAME}/${TESTNAME}_Runner.c + ${UNIT_TEST_SOURCE_RELATIVE} + ../../../Unity/src/unity.c + ) + + + get_filename_component(TEST_FILE_DIR ${TESTFILE} DIRECTORY) set(APP_INCLUDES ${CMAKE_CURRENT_LIST_DIR}/src - ${CMAKE_CURRENT_LIST_DIR}/../../../Unity/src) + ${TEST_FILE_DIR} + ${XMOS_SANDBOX_DIR}/Unity/src + ${XMOS_SANDBOX_DIR}/lib_xud/lib_xud/src/user/class) XMOS_REGISTER_APP() diff --git a/tests/xua_unit_tests/src/test_midi_parse/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_midi_parse/hid_report_descriptor.h deleted file mode 100644 index 3824814e..00000000 --- a/tests/xua_unit_tests/src/test_midi_parse/hid_report_descriptor.h +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2021-2024 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 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 = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), - .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidCollectionEnd = { - .header = HID_REPORT_SET_HEADER(0, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_END_COLLECTION), - .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidCollectionLogical = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), - .data = { 0x02, 0x00 } }; - -static const USB_HID_Short_Item_t hidInputConstArray = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), - .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidInputDataVar = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), - .data = { 0x02, 0x00 } }; - -static const USB_HID_Short_Item_t hidLogicalMaximum0 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), - .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMaximum1 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), - .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMinimum0 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM), - .data = { 0x00, 0x00 } }; - -static const USB_HID_Short_Item_t hidReportCount1 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), - .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidReportCount6 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), - .data = { 0x06, 0x00 } }; -static const USB_HID_Short_Item_t hidReportCount7 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), - .data = { 0x07, 0x00 } }; -static const USB_HID_Short_Item_t hidReportSize1 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), - .data = { 0x01, 0x00 } }; - -static const USB_HID_Short_Item_t hidUsageConsumerControl = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), - .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 = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), - .item.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 = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), - .item.data = { 0xE2, 0x00 }, - .location = HID_REPORT_SET_LOC(0, 0, 0, 0) -}; // Mute - -static USB_HID_Report_Element_t hidUsageByte1Bit7 = { - .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), - .item.data = { 0xEA, 0x00 }, - .location = HID_REPORT_SET_LOC(0, 0, 1, 7) -}; // Vol- -static USB_HID_Report_Element_t hidUsageByte1Bit0 = { - .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), - .item.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, - &hidReportCount1, - &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__ diff --git a/tests/xua_unit_tests/src/test_midi_queue/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_midi_queue/hid_report_descriptor.h deleted file mode 100644 index 3824814e..00000000 --- a/tests/xua_unit_tests/src/test_midi_queue/hid_report_descriptor.h +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2021-2024 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 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 = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), - .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidCollectionEnd = { - .header = HID_REPORT_SET_HEADER(0, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_END_COLLECTION), - .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidCollectionLogical = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_COLLECTION), - .data = { 0x02, 0x00 } }; - -static const USB_HID_Short_Item_t hidInputConstArray = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), - .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidInputDataVar = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_MAIN, HID_REPORT_ITEM_TAG_INPUT), - .data = { 0x02, 0x00 } }; - -static const USB_HID_Short_Item_t hidLogicalMaximum0 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), - .data = { 0x00, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMaximum1 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM), - .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidLogicalMinimum0 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM), - .data = { 0x00, 0x00 } }; - -static const USB_HID_Short_Item_t hidReportCount1 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), - .data = { 0x01, 0x00 } }; -static const USB_HID_Short_Item_t hidReportCount6 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), - .data = { 0x06, 0x00 } }; -static const USB_HID_Short_Item_t hidReportCount7 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_COUNT), - .data = { 0x07, 0x00 } }; -static const USB_HID_Short_Item_t hidReportSize1 = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_REPORT_SIZE), - .data = { 0x01, 0x00 } }; - -static const USB_HID_Short_Item_t hidUsageConsumerControl = { - .header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), - .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 = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_GLOBAL, HID_REPORT_ITEM_TAG_USAGE_PAGE), - .item.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 = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), - .item.data = { 0xE2, 0x00 }, - .location = HID_REPORT_SET_LOC(0, 0, 0, 0) -}; // Mute - -static USB_HID_Report_Element_t hidUsageByte1Bit7 = { - .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), - .item.data = { 0xEA, 0x00 }, - .location = HID_REPORT_SET_LOC(0, 0, 1, 7) -}; // Vol- -static USB_HID_Report_Element_t hidUsageByte1Bit0 = { - .item.header = HID_REPORT_SET_HEADER(1, HID_REPORT_ITEM_TYPE_LOCAL, HID_REPORT_ITEM_TAG_USAGE), - .item.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, - &hidReportCount1, - &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__