Skip to content

Commit bbfaf8e

Browse files
committed
add test
1 parent 9385bc6 commit bbfaf8e

13 files changed

Lines changed: 958 additions & 279 deletions
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: USBX Samples Regression Test
2+
3+
# Runs sample-based regression tests (samples_rtos_build) on push / pull
4+
# request to master, or on manual dispatch.
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
skip_coverage:
9+
required: false
10+
type: boolean
11+
default: true
12+
coverage_name:
13+
required: false
14+
default: 'samples_rtos_build'
15+
push:
16+
branches: [ master ]
17+
pull_request:
18+
branches: [ master ]
19+
20+
jobs:
21+
22+
manual_tests:
23+
if: github.event_name == 'workflow_dispatch'
24+
permissions:
25+
contents: read
26+
issues: read
27+
checks: write
28+
pull-requests: write
29+
pages: write
30+
id-token: write
31+
32+
uses: eclipse-threadx/threadx/.github/workflows/regression_template.yml@master
33+
with:
34+
cmake_path: ./test/cmake/usbx
35+
build_script: ./scripts/build.sh samples_rtos_build
36+
test_script: ./scripts/test.sh samples_rtos_build
37+
coverage_name: ${{ inputs.coverage_name }}
38+
skip_coverage: ${{ !!inputs.skip_coverage }}
39+
40+
auto_tests:
41+
if: github.event_name != 'workflow_dispatch'
42+
permissions:
43+
contents: read
44+
issues: read
45+
checks: write
46+
pull-requests: write
47+
pages: write
48+
id-token: write
49+
50+
uses: eclipse-threadx/threadx/.github/workflows/regression_template.yml@master
51+
with:
52+
cmake_path: ./test/cmake/usbx
53+
build_script: ./scripts/build.sh samples_rtos_build
54+
test_script: ./scripts/test.sh samples_rtos_build
55+
coverage_name: samples_rtos_build
56+
skip_coverage: true

.github/workflows/regression_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
workflow_dispatch:
77
inputs:
88
tests_to_run:
9-
description: 'all, single or multiple of default_build_coverage error_check_build_full_coverage tracex_enable_build device_buffer_owner_build device_zero_copy_build nofx_build_coverage optimized_build standalone_device_build_coverage standalone_device_buffer_owner_build standalone_device_zero_copy_build standalone_host_build_coverage standalone_build_coverage generic_build otg_support_build memory_management_build_coverage msrc_rtos_build msrc_standalone_build'
9+
description: 'all, single or multiple of default_build_coverage error_check_build_full_coverage tracex_enable_build device_buffer_owner_build device_zero_copy_build nofx_build_coverage optimized_build standalone_device_build_coverage standalone_device_buffer_owner_build standalone_device_zero_copy_build standalone_host_build_coverage standalone_build_coverage generic_build otg_support_build memory_management_build_coverage msrc_rtos_build msrc_standalone_build samples_rtos_build'
1010
required: false
1111
default: 'all'
1212
skip_coverage:

samples/demo_device_hid_keyboard_rtos.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,36 @@ VOID tx_application_define(VOID *first_unused_memory)
380380
}
381381
#endif /* DEMO_TEST */
382382

383+
#ifdef DEMO_TEST
384+
/********************************************************************/
385+
/** ux_demo_device_hid_init */
386+
/** */
387+
/** Entry point called by the regression test harness. */
388+
/** Assumes ux_system_initialize() was already called by the test. */
389+
/** Sets up the device stack, registers the DCD, and starts the */
390+
/** HID worker thread. The test then registers the host stack and */
391+
/** HCD to complete the USB connection. */
392+
/********************************************************************/
393+
UINT ux_demo_device_hid_init(VOID)
394+
{
395+
UINT status;
396+
397+
/* Set up device stack and HID class (no ux_system_initialize, test did it). */
398+
status = ux_device_hid_init();
399+
if (status != UX_SUCCESS)
400+
return status;
401+
402+
/* Register DCD synchronously so HCD registration can follow immediately. */
403+
ux_dcd_sim_slave_initialize();
404+
405+
/* Start the device HID worker thread that sends periodic keyboard reports. */
406+
status = ux_utility_thread_create(&ux_device_hid_thread, "usbx_hid_app_thread_entry",
407+
ux_device_hid_thread_entry, 0, ux_device_hid_thread_stack,
408+
ux_device_hid_thread_size, 20, 20, 1, UX_AUTO_START);
409+
return status;
410+
}
411+
#endif /* DEMO_TEST */
412+
383413
/********************************************************************/
384414
/** usbx_demo_init */
385415
/** */
@@ -428,11 +458,13 @@ UINT ux_device_hid_init(VOID)
428458
UINT status;
429459
UX_SLAVE_CLASS_HID_PARAMETER hid_keyboard_parameter = {UX_NULL};
430460

461+
#ifndef DEMO_TEST
431462
/* Initialize USBX Memory. */
432463
status = ux_system_initialize(ux_system_memory_pool, UX_DEVICE_MEMORY_STACK_SIZE, UX_NULL, 0);
433464

434465
if(status != UX_SUCCESS)
435466
return status;
467+
#endif /* DEMO_TEST */
436468

437469
/* Install the device portion of USBX. */
438470
status = ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,

samples/demo_device_hid_mouse_rtos.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,36 @@ VOID tx_application_define(VOID *first_unused_memory)
381381
}
382382
#endif /* DEMO_TEST */
383383

384+
#ifdef DEMO_TEST
385+
/********************************************************************/
386+
/** ux_demo_device_hid_init */
387+
/** */
388+
/** Entry point called by the regression test harness. */
389+
/** Assumes ux_system_initialize() was already called by the test. */
390+
/** Sets up the device stack, registers the DCD, and starts the */
391+
/** HID worker thread. The test then registers the host stack and */
392+
/** HCD to complete the USB connection. */
393+
/********************************************************************/
394+
UINT ux_demo_device_hid_init(VOID)
395+
{
396+
UINT status;
397+
398+
/* Set up device stack and HID class (no ux_system_initialize, test did it). */
399+
status = ux_device_hid_init();
400+
if (status != UX_SUCCESS)
401+
return status;
402+
403+
/* Register DCD synchronously so HCD registration can follow immediately. */
404+
ux_dcd_sim_slave_initialize();
405+
406+
/* Start the device HID worker thread that sends periodic mouse reports. */
407+
status = ux_utility_thread_create(&ux_device_hid_thread, "usbx_hid_app_thread_entry",
408+
ux_device_hid_thread_entry, 0, ux_device_hid_thread_stack,
409+
ux_device_hid_thread_size, 20, 20, 1, UX_AUTO_START);
410+
return status;
411+
}
412+
#endif /* DEMO_TEST */
413+
384414
/********************************************************************/
385415
/** usbx_demo_init */
386416
/** */
@@ -427,12 +457,13 @@ UINT ux_device_hid_init(VOID)
427457
UINT status;
428458
UX_SLAVE_CLASS_HID_PARAMETER hid_mouse_parameter = {UX_NULL};
429459

430-
460+
#ifndef DEMO_TEST
431461
/* Initialize USBX Memory. */
432462
status = ux_system_initialize(ux_system_memory_pool, UX_DEVICE_MEMORY_STACK_SIZE, UX_NULL, 0);
433463

434464
if(status != UX_SUCCESS)
435465
return status;
466+
#endif /* DEMO_TEST */
436467

437468
/* Install the device portion of USBX. */
438469
status = ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,

test/cmake/usbx/.run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../externals/threadx/scripts/cmake_bootstrap.sh

test/cmake/usbx/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ set(BUILD_CONFIGURATIONS
3636
memory_management_build_coverage
3737
msrc_rtos_build
3838
msrc_standalone_build
39+
samples_rtos_build
3940
)
4041

4142
set(CMAKE_CONFIGURATION_TYPES
@@ -207,6 +208,9 @@ set(memory_management_build_coverage
207208
-DUX_ENABLE_MEMORY_STATISTICS
208209
-DUX_ENABLE_MEMORY_POOL_SANITY_CHECK
209210
)
211+
set(samples_rtos_build
212+
${default_build_coverage}
213+
)
210214
# Control if USBX is static or shared
211215
if($ENV{USBX_STATIC})
212216
message(STATUS "Building STATIC usbx")
@@ -245,6 +249,8 @@ enable_testing()
245249
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../../ usbx)
246250
if(CMAKE_BUILD_TYPE STREQUAL "generic_build")
247251
add_test(fake_test true)
252+
elseif(CMAKE_BUILD_TYPE STREQUAL "samples_rtos_build")
253+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/regression_samples_rtos regression_samples_rtos)
248254
else()
249255
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/regression regression)
250256
endif()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
2+
3+
project(libs LANGUAGES C)
4+
5+
if($ENV{ENABLE_64})
6+
message(STATUS "Building for 64bit")
7+
set(NX_USER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/nx_user.h)
8+
else()
9+
add_compile_options(-m32)
10+
add_link_options(-m32)
11+
message(STATUS "Building for 32bit")
12+
endif()
13+
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")
14+
15+
get_filename_component(externals ${CMAKE_CURRENT_SOURCE_DIR}/../../../externals
16+
ABSOLUTE)
17+
add_subdirectory(${externals}/threadx threadx)
18+
add_subdirectory(${externals}/netxduo netxduo)
19+
add_subdirectory(${externals}/filex filex)
20+
target_compile_options(threadx PRIVATE -DTX_ENABLE_EVENT_TRACE)
21+
if(NOT DEFINED ENV{ENABLE_IDLE})
22+
target_compile_options(threadx PRIVATE -DTX_LINUX_NO_IDLE_ENABLE)
23+
endif()
24+
target_compile_options(filex PRIVATE -DFX_ENABLE_EXFAT)
25+
26+
target_compile_options(netxduo PRIVATE -DTX_ENABLE_EVENT_TRACE -DNX_PHYSICAL_HEADER=20)
27+
28+
foreach(lib threadx netxduo filex)
29+
get_target_property(dirs ${lib} INCLUDE_DIRECTORIES)
30+
execute_process(COMMAND mkdir -p ${CMAKE_BINARY_DIR}/inc)
31+
foreach(dir ${dirs})
32+
file(GLOB header_files ${dir}/*.h)
33+
foreach(header_file ${header_files})
34+
execute_process(COMMAND ln -sf ${header_file} ${CMAKE_BINARY_DIR}/inc)
35+
endforeach()
36+
endforeach()
37+
endforeach()

test/cmake/usbx/libs/nx_user.h

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/***************************************************************************
2+
* Copyright (c) 2024 Microsoft Corporation
3+
* Copyright (c) 2026-present Eclipse ThreadX contributors
4+
*
5+
* This program and the accompanying materials are made available under the
6+
* terms of the MIT License which is available at
7+
* https://opensource.org/licenses/MIT.
8+
*
9+
* SPDX-License-Identifier: MIT
10+
**************************************************************************/
11+
12+
13+
/**************************************************************************/
14+
/**************************************************************************/
15+
/** */
16+
/** NetX Component */
17+
/** */
18+
/** User Specific */
19+
/** */
20+
/**************************************************************************/
21+
/**************************************************************************/
22+
23+
24+
/**************************************************************************/
25+
/* */
26+
/* PORT SPECIFIC C INFORMATION RELEASE */
27+
/* */
28+
/* nx_user.h PORTABLE C */
29+
/* 6.0 */
30+
/* */
31+
/* AUTHOR */
32+
/* */
33+
/* Yuxin Zhou, Microsoft Corporation */
34+
/* */
35+
/* DESCRIPTION */
36+
/* */
37+
/* This file contains user defines for configuring NetX in specific */
38+
/* ways. This file will have an effect only if the application and */
39+
/* NetX library are built with NX_INCLUDE_USER_DEFINE_FILE defined. */
40+
/* Note that all the defines in this file may also be made on the */
41+
/* command line when building NetX library and application objects. */
42+
/* */
43+
/**************************************************************************/
44+
45+
#ifndef NX_USER_H
46+
#define NX_USER_H
47+
48+
/* Define the extension to hold the control block for 64-bit mode. */
49+
#define NX_THREAD_EXTENSION_PTR_SET(a, b) { \
50+
TX_THREAD *thread_ptr; \
51+
thread_ptr = (TX_THREAD *) (a); \
52+
(thread_ptr -> tx_thread_extension_ptr) = (VOID *)(b); \
53+
}
54+
#define NX_THREAD_EXTENSION_PTR_GET(a, b, c) { \
55+
NX_PARAMETER_NOT_USED(c); \
56+
TX_THREAD *thread_ptr; \
57+
thread_ptr = tx_thread_identify(); \
58+
while(1)\
59+
{ \
60+
if (thread_ptr -> tx_thread_extension_ptr) \
61+
{ \
62+
(a) = (b *)(thread_ptr -> tx_thread_extension_ptr); \
63+
break; \
64+
} \
65+
tx_thread_sleep(1); \
66+
} \
67+
}
68+
#define NX_TIMER_EXTENSION_PTR_SET(a, b) { \
69+
TX_TIMER *timer_ptr; \
70+
timer_ptr = (TX_TIMER *) (a); \
71+
(timer_ptr -> tx_timer_internal.tx_timer_internal_extension_ptr) = (VOID *)(b); \
72+
}
73+
#define NX_TIMER_EXTENSION_PTR_GET(a, b, c) { \
74+
NX_PARAMETER_NOT_USED(c); \
75+
if (!_tx_timer_expired_timer_ptr -> tx_timer_internal_extension_ptr) \
76+
return; \
77+
(a) = (b *)(_tx_timer_expired_timer_ptr -> tx_timer_internal_extension_ptr); \
78+
}
79+
80+
#endif
81+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
2+
cmake_policy(SET CMP0057 NEW)
3+
4+
project(regression_samples_rtos_test LANGUAGES C)
5+
6+
# Paths
7+
get_filename_component(REG_DIR
8+
${CMAKE_CURRENT_LIST_DIR}/../../../regression_samples_rtos ABSOLUTE)
9+
get_filename_component(SIM_DIR
10+
${CMAKE_CURRENT_LIST_DIR}/../../../regression ABSOLUTE)
11+
get_filename_component(SAMPLE_DIR
12+
${CMAKE_CURRENT_LIST_DIR}/../../../../samples ABSOLUTE)
13+
14+
# ---------------------------------------------------------------------------
15+
# test_utility_samples — shared support library for all sample regression tests
16+
#
17+
# Unlike the full regression test_utility, this library:
18+
# * does NOT include ux_test.c (error injection not needed for samples)
19+
# * uses ux_test_utility_sim_stubs.c (no-op stubs) instead of the real
20+
# ux_test_utility_sim.c, so no OS API overriding takes place
21+
# ---------------------------------------------------------------------------
22+
set(test_utility_samples_files
23+
${REG_DIR}/usbxtestcontrol.c
24+
${SIM_DIR}/ux_test_dcd_sim_slave.c
25+
${SIM_DIR}/ux_test_hcd_sim_host.c
26+
${REG_DIR}/ux_test_utility_sim_stubs.c
27+
)
28+
29+
add_library(test_utility_samples ${test_utility_samples_files})
30+
target_link_libraries(test_utility_samples
31+
PUBLIC azrtos::usbx azrtos::threadx azrtos::netxduo azrtos::filex)
32+
target_compile_definitions(test_utility_samples PUBLIC CTEST)
33+
34+
# Regression dir must come first so ux_test.h / ux_test_utility_sim.h resolve
35+
target_include_directories(test_utility_samples PUBLIC ${SIM_DIR})
36+
37+
# ---------------------------------------------------------------------------
38+
# Helper macro — builds one sample test executable
39+
#
40+
# Usage:
41+
# add_sample_test(<test_name> <test_source> <sample_source>)
42+
#
43+
# The sample source file is compiled with DEMO_TEST and EXTERNAL_MAIN so that:
44+
# DEMO_TEST — suppresses tx_application_define and exposes the
45+
# ux_demo_device_hid_init() wrapper function
46+
# EXTERNAL_MAIN — suppresses the sample's own main() entry point
47+
# UX_DEVICE_SIDE_ONLY is applied only to the sample translation unit so
48+
# that the USBX library itself is not restricted to device-only mode.
49+
# ---------------------------------------------------------------------------
50+
macro(add_sample_test test_name test_source sample_source)
51+
add_executable(${test_name} ${test_source} ${sample_source})
52+
53+
set_source_files_properties(${sample_source}
54+
PROPERTIES COMPILE_DEFINITIONS
55+
"UX_DEVICE_SIDE_ONLY;DEMO_TEST;EXTERNAL_MAIN")
56+
57+
target_link_libraries(${test_name} PRIVATE test_utility_samples)
58+
add_test(${CMAKE_BUILD_TYPE}::${test_name} ${test_name})
59+
endmacro()
60+
61+
# ---------------------------------------------------------------------------
62+
# Test cases
63+
# ---------------------------------------------------------------------------
64+
65+
add_sample_test(
66+
usbx_hid_mouse_demo_device_rtos_test
67+
${REG_DIR}/usbx_hid_mouse_demo_device_rtos_test.c
68+
${SAMPLE_DIR}/demo_device_hid_mouse_rtos.c
69+
)
70+
71+
add_sample_test(
72+
usbx_hid_keyboard_demo_device_rtos_test
73+
${REG_DIR}/usbx_hid_keyboard_demo_device_rtos_test.c
74+
${SAMPLE_DIR}/demo_device_hid_keyboard_rtos.c
75+
)

0 commit comments

Comments
 (0)