Skip to content

Commit 1040a61

Browse files
committed
add test
add test add test Update demo_device_hid_mouse_rtos.c Update regression_test.yml Delete nx_user.h
1 parent 9385bc6 commit 1040a61

13 files changed

Lines changed: 883 additions & 290 deletions
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
install_script: ./scripts/install_samples_rtos.sh
36+
build_script: ./scripts/build_samples_rtos.sh
37+
test_script: ./scripts/test_samples_rtos.sh
38+
coverage_name: ${{ inputs.coverage_name }}
39+
skip_coverage: ${{ !!inputs.skip_coverage }}
40+
41+
auto_tests:
42+
if: github.event_name != 'workflow_dispatch'
43+
permissions:
44+
contents: read
45+
issues: read
46+
checks: write
47+
pull-requests: write
48+
pages: write
49+
id-token: write
50+
51+
uses: eclipse-threadx/threadx/.github/workflows/regression_template.yml@master
52+
with:
53+
cmake_path: ./test/cmake/usbx
54+
install_script: ./scripts/install_samples_rtos.sh
55+
build_script: ./scripts/build_samples_rtos.sh
56+
test_script: ./scripts/test_samples_rtos.sh
57+
coverage_name: samples_rtos_build
58+
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

scripts/build_samples_rtos.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
$(dirname `realpath $0`)/../test/cmake/usbx/run.sh build samples_rtos_build

scripts/install_samples_rtos.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
#
3+
# Install necessary softwares for Ubuntu (samples RTOS regression tests).
4+
# Coverage tools are not required as coverage is not collected for this build.
5+
6+
sudo apt-get update
7+
sudo apt-get install -y \
8+
gcc-multilib \
9+
git \
10+
g++ \
11+
python3-pip \
12+
ninja-build \
13+
unifdef \
14+
p7zip-full \
15+
tofrodos \
16+
gawk \
17+
software-properties-common
18+
19+
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -
20+
CODENAME=$(lsb_release -c | cut -f2 -d':' | sed 's/\t//')
21+
sudo apt-add-repository -y "deb https://apt.kitware.com/ubuntu/ $CODENAME main"
22+
sudo apt-get -y install cmake
23+
24+
python3 -m pip install --upgrade pip
25+
pip3 install --upgrade cmake

scripts/test_samples_rtos.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
CTEST_PARALLEL_LEVEL=4 $(dirname `realpath $0`)/../test/cmake/usbx/run.sh test samples_rtos_build

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
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()
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)