Skip to content

Commit 97df251

Browse files
committed
add test
Update demo_device_hid_mouse_rtos.c Update regression_test.yml
1 parent 9385bc6 commit 97df251

12 files changed

Lines changed: 939 additions & 290 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

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: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ static VOID ux_demo_error_callback(UINT system_level, UINT system_context, UINT
101101
/************************************************************/
102102
/** usbx device hid demo mouse */
103103
/************************************************************/
104-
UINT usbx_demo_init(VOID);
105-
UINT usbx_demo_uninit(VOID);
104+
UINT ux_demo_device_hid_init(VOID);
105+
UINT ux_demo_device_hid_uninit(VOID);
106106
UINT ux_device_hid_init(VOID);
107107
UINT ux_device_hid_uninit(VOID);
108108
UINT ux_device_hid_mouse_cursor_move(UX_SLAVE_CLASS_HID *device_hid);
@@ -377,17 +377,17 @@ VOID tx_application_define(VOID *first_unused_memory)
377377
{
378378
UX_PARAMETER_NOT_USED(first_unused_memory);
379379

380-
usbx_demo_init();
380+
ux_demo_device_hid_init();
381381
}
382382
#endif /* DEMO_TEST */
383383

384384
/********************************************************************/
385-
/** usbx_demo_init */
385+
/** ux_demo_device_hid_init */
386386
/** */
387387
/** Create the demo threads and initialize the USBX HID device */
388388
/** stack used by this sample. */
389389
/********************************************************************/
390-
UINT usbx_demo_init(VOID)
390+
UINT ux_demo_device_hid_init(VOID)
391391
{
392392
UINT status;
393393

@@ -427,12 +427,13 @@ UINT ux_device_hid_init(VOID)
427427
UINT status;
428428
UX_SLAVE_CLASS_HID_PARAMETER hid_mouse_parameter = {UX_NULL};
429429

430-
430+
#ifndef DEMO_TEST
431431
/* Initialize USBX Memory. */
432432
status = ux_system_initialize(ux_system_memory_pool, UX_DEVICE_MEMORY_STACK_SIZE, UX_NULL, 0);
433433

434434
if(status != UX_SUCCESS)
435435
return status;
436+
#endif /* DEMO_TEST */
436437

437438
/* Install the device portion of USBX. */
438439
status = ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
@@ -467,12 +468,12 @@ UX_SLAVE_CLASS_HID_PARAMETER hid_mouse_parameter = {UX_NULL};
467468
}
468469

469470
/********************************************************************/
470-
/** usbx_demo_uninit */
471+
/** ux_demo_device_hid_uninit */
471472
/** */
472-
/** Stop the demo worker threads created by usbx_demo_init so the */
473-
/** RTOS sample can be shut down cleanly. */
473+
/** Stop the demo worker threads created by ux_demo_device_hid_init*/
474+
/** so the RTOS sample can be shut down cleanly. */
474475
/********************************************************************/
475-
UINT usbx_demo_uninit(VOID)
476+
UINT ux_demo_device_hid_uninit(VOID)
476477
{
477478

478479
UINT status;
@@ -581,15 +582,15 @@ VOID ux_demo_thread_entry(ULONG thread_input)
581582

582583
UX_PARAMETER_NOT_USED(thread_input);
583584

584-
#ifndef EXTERNAL_DCD_INITIALIZE
585+
#ifndef DEMO_TEST
585586

586587
/* Register the USB device simulator controllers for testing */
587588
ux_dcd_sim_slave_initialize();
588-
#else /* EXTERNAL_DCD_INITIALIZE */
589+
#else /* DEMO_TEST */
589590

590591
/* Register the USB device controllers available in this system */
591592
usb_device_dcd_initialize(UX_NULL);
592-
#endif /* EXTERNAL_DCD_INITIALIZE */
593+
#endif /* DEMO_TEST */
593594

594595
}
595596

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+

0 commit comments

Comments
 (0)