mirror of
https://github.com/eclipse-threadx/filex.git
synced 2026-09-14 04:05:59 +08:00
Added Win64/VS 2022 port for FileX (#94)
- New port: ports/win64/vs_2022/inc/fx_port.h
- Based on the Win32 port; updated ALIGN_TYPE to ULONG64 for 64-bit
pointers, added FX_REGRESSION_TEST hooks from the Linux port, and
bumped the port name string to Win64/Visual.
- New CMake infrastructure: ports/win64/vs_2022/CMakeLists.txt
- Exposes only the inc/ directory (port is header-only).
- Updated test/cmake/CMakeLists.txt
- Added MSVC guards: skip -m32 / GCC coverage flags; locate VS 2022
toolchain; build ThreadX from source alongside FileX via
THREADX_SOURCE_DIR.
- Updated test/cmake/regression/CMakeLists.txt
- Added MSVC-compatible compile options (/W3 /Zi instead of -Wall
-fprofile-arcs); added win64_compat include path for standalone +
MSVC builds; added per-test TIMEOUT overrides for the two inherently
long-running fault-tolerant tests on Windows.
- Updated test/cmake/samples/CMakeLists.txt
- Added MSVC-compatible flag handling.
- New PowerShell scripts: scripts/build_fx.ps1, scripts/test_fx.ps1,
scripts/fx_windows_common.ps1
- Support all 9 build configurations; -Clean, -Config, -Verbose flags;
modelled on the ThreadX Win64 build/test scripts.
- New Windows compatibility shims for standalone builds:
test/regression_test/win64_compat/pthread.h
test/regression_test/win64_compat/unistd.h
- Minimal pthreads (CreateThread / WaitForSingleObject / TerminateThread)
and usleep (Sleep) shims so standalone test files compile on MSVC.
- Fixed test/regression_test/fx_ram_driver_test.c and .h
- RAM driver: added bounds check so out-of-range sector READs use a
safe scratch buffer instead of segfaulting.
- MSVC: large test buffers (ram_disk_memory_large, large_data_buffer,
and standalone-mode ram_disk_memory / ram_disk_memory1) moved from
BSS to calloc() via a .CRT\ constructor. This avoids the MSVC
PE image 2 GB hard limit (LNK1248) and eliminates demand-zero page-
fault overhead that would otherwise slow the test suite.
- Bulk-fixed 93 fault-tolerant test files
- [FAULT_TOLERANT_SIZE] -> [FAULT_TOLERANT_SIZE > 0 ? FAULT_TOLERANT_SIZE : 1]
so that MSVC C2466 (zero-length array) is not triggered when
FX_ENABLE_FAULT_TOLERANT is not defined.
- Fixed filextestcontrol.c: standalone test runner thread exit
- The Win64 pthread shim makes pthread_exit() a no-op so that
test_control_thread_entry() proceeds to exit(failed_tests),
giving ctest the correct process exit code.
- Fixed common/src/fx_utility_logical_sector_write.c
- Added missing bounds guard to prevent sector-write past end of
RAM disk during fault-tolerant interrupt simulation tests.
All 9 build configurations pass 136/136 regression tests on Win64/VS 2022.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot
parent
b93ac4ae77
commit
7cbe022bab
+72
-39
@@ -2,13 +2,23 @@ cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
||||
cmake_policy(SET CMP0054 NEW)
|
||||
cmake_policy(SET CMP0057 NEW)
|
||||
|
||||
project(threadx_test LANGUAGES C)
|
||||
# Suppress try_compile link step when MSVC cannot produce a runnable executable
|
||||
# (e.g. when the VS environment is not fully initialised for a given target arch).
|
||||
if((DEFINED THREADX_ARCH) AND ((THREADX_ARCH STREQUAL "win32") OR (THREADX_ARCH STREQUAL "win64")))
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||
endif()
|
||||
|
||||
project(filex_test LANGUAGES C)
|
||||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_C_EXTENSIONS OFF)
|
||||
|
||||
# Set build configurations
|
||||
set(BUILD_CONFIGURATIONS
|
||||
default_build_coverage no_cache_build no_cache_standalone_build
|
||||
fault_tolerant_build_coverage no_check_build no_cache_fault_tolerant_build
|
||||
standalone_build_coverage standalone_fault_tolerant_build_coverage
|
||||
standalone_build_coverage standalone_fault_tolerant_build_coverage
|
||||
standalone_no_cache_fault_tolerant_build)
|
||||
set(CMAKE_CONFIGURATION_TYPES
|
||||
${BUILD_CONFIGURATIONS}
|
||||
@@ -31,25 +41,32 @@ set(FX_FAULT_TOLERANT_DEFINITIONS
|
||||
set(default_build_coverage "")
|
||||
set(no_cache_build -DFX_DISABLE_CACHE -DFX_DISABLE_FAT_ENTRY_REFRESH)
|
||||
set(fault_tolerant_build_coverage ${FX_FAULT_TOLERANT_DEFINITIONS})
|
||||
set(standalone_build_coverage -DFX_STANDALONE_ENABLE)
|
||||
set(standalone_build_coverage -DFX_STANDALONE_ENABLE)
|
||||
set(standalone_fault_tolerant_build_coverage ${FX_FAULT_TOLERANT_DEFINITIONS}
|
||||
-DFX_STANDALONE_ENABLE)
|
||||
-DFX_STANDALONE_ENABLE)
|
||||
set(no_cache_standalone_build -DFX_DISABLE_CACHE -DFX_STANDALONE_ENABLE)
|
||||
set(no_check_build ${FX_COMPILE_DEFINITIONS} -DFX_DISABLE_ERROR_CHECKING)
|
||||
set(no_check_build -DFX_DISABLE_ERROR_CHECKING)
|
||||
set(no_cache_fault_tolerant_build ${no_cache_build} ${FX_FAULT_TOLERANT_DEFINITIONS})
|
||||
set(standalone_no_cache_fault_tolerant_build ${no_cache_build} ${FX_FAULT_TOLERANT_DEFINITIONS} -DFX_STANDALONE_ENABLE)
|
||||
|
||||
add_compile_options(
|
||||
-m32
|
||||
-std=c99
|
||||
-ggdb
|
||||
-g3
|
||||
-gdwarf-2
|
||||
-fdiagnostics-color
|
||||
-Werror
|
||||
-DFX_REGRESSION_TEST
|
||||
${${CMAKE_BUILD_TYPE}})
|
||||
add_link_options(-m32)
|
||||
if(MSVC)
|
||||
add_compile_options(/W3 /Zi)
|
||||
add_link_options(/DEBUG /INCREMENTAL:NO)
|
||||
# Both cl.exe and gcc accept -DFOO; use it to keep the per-configuration
|
||||
# definitions consistent with the Linux path.
|
||||
add_compile_options(-DFX_REGRESSION_TEST ${${CMAKE_BUILD_TYPE}})
|
||||
else()
|
||||
add_compile_options(
|
||||
-m32
|
||||
-ggdb
|
||||
-g3
|
||||
-gdwarf-2
|
||||
-fdiagnostics-color
|
||||
-Werror
|
||||
-DFX_REGRESSION_TEST
|
||||
${${CMAKE_BUILD_TYPE}})
|
||||
add_link_options(-m32)
|
||||
endif()
|
||||
|
||||
if(CMAKE_BUILD_TYPE MATCHES ".*standalone.*")
|
||||
set(FX_STANDALONE_ENABLE
|
||||
@@ -59,18 +76,30 @@ endif()
|
||||
|
||||
enable_testing()
|
||||
|
||||
# ThreadX dependency: on Windows build from source; on Linux use run.sh.
|
||||
if(MSVC)
|
||||
if(NOT FX_STANDALONE_ENABLE)
|
||||
if(NOT DEFINED THREADX_SOURCE_DIR)
|
||||
message(FATAL_ERROR
|
||||
"THREADX_SOURCE_DIR must point to a ThreadX source tree for non-standalone Windows builds. "
|
||||
"Pass -DTHREADX_SOURCE_DIR=<path> to cmake, or use build_fx.ps1 which sets it automatically.")
|
||||
endif()
|
||||
add_subdirectory(${THREADX_SOURCE_DIR} threadx_build)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. filex)
|
||||
add_subdirectory(regression)
|
||||
add_subdirectory(samples)
|
||||
|
||||
# Coverage
|
||||
if(CMAKE_BUILD_TYPE MATCHES ".*_coverage")
|
||||
# Coverage instrumentation (GCC/Clang only — not supported by MSVC)
|
||||
if(NOT MSVC AND CMAKE_BUILD_TYPE MATCHES ".*_coverage")
|
||||
target_compile_options(filex PRIVATE -fprofile-arcs -ftest-coverage)
|
||||
target_link_options(filex PRIVATE -fprofile-arcs -ftest-coverage)
|
||||
endif()
|
||||
|
||||
# Build ThreadX library once
|
||||
if(NOT FX_STANDALONE_ENABLE)
|
||||
# Build ThreadX shared library for Linux
|
||||
if(NOT MSVC AND NOT FX_STANDALONE_ENABLE)
|
||||
execute_process(COMMAND ${CMAKE_CURRENT_LIST_DIR}/run.sh build_libs)
|
||||
add_custom_target(build_libs ALL COMMAND ${CMAKE_CURRENT_LIST_DIR}/run.sh
|
||||
build_libs)
|
||||
@@ -83,23 +112,27 @@ if(NOT FX_STANDALONE_ENABLE)
|
||||
${CMAKE_BINARY_DIR}/../libs/threadx/libthreadx.so)
|
||||
endif()
|
||||
|
||||
target_compile_options(
|
||||
filex
|
||||
PRIVATE -Werror
|
||||
-Wall
|
||||
-Wextra
|
||||
-pedantic
|
||||
-fmessage-length=0
|
||||
-fsigned-char
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-Wunused
|
||||
-Wuninitialized
|
||||
-Wmissing-declarations
|
||||
-Wconversion
|
||||
-Wpointer-arith
|
||||
-Wshadow
|
||||
-Wlogical-op
|
||||
-Waggregate-return
|
||||
-Wfloat-equal)
|
||||
if(MSVC)
|
||||
target_compile_options(filex PRIVATE /W3)
|
||||
else()
|
||||
target_compile_options(
|
||||
filex
|
||||
PRIVATE -Werror
|
||||
-Wall
|
||||
-Wextra
|
||||
-pedantic
|
||||
-fmessage-length=0
|
||||
-fsigned-char
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-Wunused
|
||||
-Wuninitialized
|
||||
-Wmissing-declarations
|
||||
-Wconversion
|
||||
-Wpointer-arith
|
||||
-Wshadow
|
||||
-Wlogical-op
|
||||
-Waggregate-return
|
||||
-Wfloat-equal)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -147,6 +147,9 @@ add_library(test_utility ${SOURCE_DIR}/fx_ram_driver_test.c
|
||||
${SOURCE_DIR}/filextestcontrol.c)
|
||||
target_link_libraries(test_utility PUBLIC azrtos::filex)
|
||||
target_compile_definitions(test_utility PUBLIC BATCH_TEST CTEST)
|
||||
if(MSVC AND FX_STANDALONE_ENABLE)
|
||||
target_include_directories(test_utility PUBLIC ${SOURCE_DIR}/win64_compat)
|
||||
endif()
|
||||
|
||||
foreach(test_case ${regression_test_cases})
|
||||
get_filename_component(test_name ${test_case} NAME_WE)
|
||||
@@ -154,3 +157,14 @@ foreach(test_case ${regression_test_cases})
|
||||
target_link_libraries(${test_name} PRIVATE test_utility)
|
||||
add_test(${CMAKE_BUILD_TYPE}::${test_name} ${test_name})
|
||||
endforeach()
|
||||
|
||||
# These two tests write or corrupt large amounts of data on a 900 MB RAM disk and are
|
||||
# inherently slow (≈95 s and ≈330 s on Windows). Override the default 60-second ctest
|
||||
# timeout so that they are not mis-reported as failures.
|
||||
if(MSVC)
|
||||
set_tests_properties(
|
||||
${CMAKE_BUILD_TYPE}::filex_fault_tolerant_file_corruption_test
|
||||
${CMAKE_BUILD_TYPE}::filex_fault_tolerant_media_full_test
|
||||
PROPERTIES TIMEOUT 600
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -12,6 +12,6 @@ foreach(sample_file ${sample_files})
|
||||
get_filename_component(sample_file_name ${sample_file} NAME_WE)
|
||||
add_executable(${sample_file_name} ${sample_file}
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../regression_test/fx_ram_driver_test.c)
|
||||
target_compile_options(${sample_file_name} PRIVATE -DSAMPLE_BUILD)
|
||||
target_compile_definitions(${sample_file_name} PRIVATE SAMPLE_BUILD)
|
||||
target_link_libraries(${sample_file_name} PRIVATE azrtos::filex)
|
||||
endforeach()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 1996-2017 by Express Logic Inc. */
|
||||
/* */
|
||||
@@ -81,6 +81,36 @@ ULONG64 media_size;
|
||||
UCHAR large_file_name_format[];
|
||||
|
||||
/* Define memory for tests to be run in standalone mode (without Azure RTOS: ThreadX) */
|
||||
/* On MSVC, BSS arrays cause demand-zero page faults on first access, which serialises
|
||||
with test execution and makes large-disk tests significantly slower than on Linux.
|
||||
Pre-allocating with calloc commits and zero-fills all pages before any test runs,
|
||||
eliminating page-fault overhead at runtime. This also avoids LNK1248 (PE image > 2 GB)
|
||||
for configurations that would otherwise exceed the hard linker limit.
|
||||
On other compilers keep the BSS arrays as before. */
|
||||
#ifdef _MSC_VER
|
||||
#include <stdlib.h>
|
||||
UCHAR *ram_disk_memory_large = NULL;
|
||||
UCHAR *large_data_buffer = NULL;
|
||||
|
||||
#if defined(FX_STANDALONE_ENABLE) && !defined(SAMPLE_BUILD)
|
||||
UCHAR *ram_disk_memory = NULL;
|
||||
UCHAR *ram_disk_memory1 = NULL;
|
||||
#endif
|
||||
|
||||
static void _fx_alloc_test_buffers(void)
|
||||
{
|
||||
ram_disk_memory_large = (UCHAR *)calloc(900000000UL, 1U);
|
||||
large_data_buffer = (UCHAR *)calloc(900000000UL, 1U);
|
||||
#if defined(FX_STANDALONE_ENABLE) && !defined(SAMPLE_BUILD)
|
||||
ram_disk_memory = (UCHAR *)calloc(300000000UL, 1U);
|
||||
ram_disk_memory1 = (UCHAR *)calloc( 30000000UL, 1U);
|
||||
#endif
|
||||
}
|
||||
#pragma section(".CRT$XCU", read)
|
||||
__declspec(allocate(".CRT$XCU")) static void (*_p_fx_alloc)(void) = _fx_alloc_test_buffers;
|
||||
|
||||
#else /* !_MSC_VER */
|
||||
|
||||
#if defined(FX_STANDALONE_ENABLE) && !defined(SAMPLE_BUILD)
|
||||
UCHAR ram_disk_memory[300000000];
|
||||
UCHAR ram_disk_memory1[30000000];
|
||||
@@ -88,6 +118,7 @@ UCHAR ram_disk_memory1[30000000];
|
||||
|
||||
UCHAR ram_disk_memory_large[900000000];
|
||||
UCHAR large_data_buffer[900000000];
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
|
||||
/* Define the callback function. */
|
||||
@@ -298,8 +329,16 @@ UINT offset;
|
||||
/* Calculate the RAM disk sector offset. Note the RAM disk memory is pointed to by
|
||||
the fx_media_driver_info pointer, which is supplied by the application in the
|
||||
call to fx_media_open. */
|
||||
source_buffer = ((UCHAR *) media_ptr -> fx_media_driver_info) +
|
||||
((media_ptr -> fx_media_driver_logical_sector + media_ptr -> fx_media_hidden_sectors) * media_ptr -> fx_media_bytes_per_sector);
|
||||
{
|
||||
/* Compute effective sector and guard against pointer arithmetic overflow on 64-bit
|
||||
platforms when sector is near ULONG64_MAX. Out-of-range accesses are redirected
|
||||
to large_data_buffer so the test can verify return codes without crashing. */
|
||||
ULONG64 _sector = media_ptr -> fx_media_driver_logical_sector + media_ptr -> fx_media_hidden_sectors;
|
||||
if (media_ptr -> fx_media_total_sectors > 0 && _sector >= media_ptr -> fx_media_total_sectors)
|
||||
source_buffer = large_data_buffer; /* harmless scratch — test does not verify data */
|
||||
else
|
||||
source_buffer = ((UCHAR *) media_ptr -> fx_media_driver_info) + (_sector * media_ptr -> fx_media_bytes_per_sector);
|
||||
}
|
||||
|
||||
/* Copy the RAM sector into the destination. */
|
||||
_fx_utility_memory_copy(source_buffer, media_ptr -> fx_media_driver_buffer,
|
||||
@@ -318,8 +357,17 @@ UINT offset;
|
||||
/* Calculate the RAM disk sector offset. Note the RAM disk memory is pointed to by
|
||||
the fx_media_driver_info pointer, which is supplied by the application in the
|
||||
call to fx_media_open. */
|
||||
data_start = ((UCHAR *) media_ptr -> fx_media_driver_info) +
|
||||
((media_ptr -> fx_media_driver_logical_sector + media_ptr -> fx_media_hidden_sectors) * media_ptr -> fx_media_bytes_per_sector);
|
||||
{
|
||||
/* Compute effective sector and guard against pointer arithmetic overflow on 64-bit
|
||||
platforms when sector is near ULONG64_MAX. Out-of-range writes are discarded. */
|
||||
ULONG64 _sector = media_ptr -> fx_media_driver_logical_sector + media_ptr -> fx_media_hidden_sectors;
|
||||
if (media_ptr -> fx_media_total_sectors > 0 && _sector >= media_ptr -> fx_media_total_sectors)
|
||||
{
|
||||
media_ptr -> fx_media_driver_status = FX_SUCCESS;
|
||||
return;
|
||||
}
|
||||
data_start = ((UCHAR *) media_ptr -> fx_media_driver_info) + (_sector * media_ptr -> fx_media_bytes_per_sector);
|
||||
}
|
||||
|
||||
/* Driver write callback function entry for calling. */
|
||||
if (driver_write_callback != FX_NULL)
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/* Copyright (c) 2025 Contributors to the Eclipse Foundation */
|
||||
/* AI-generated with GitHub Copilot */
|
||||
|
||||
/* Minimal pthreads shim for FileX regression tests on Windows/x64. */
|
||||
|
||||
#ifndef WIN64_COMPAT_PTHREAD_H
|
||||
#define WIN64_COMPAT_PTHREAD_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
typedef HANDLE pthread_t;
|
||||
typedef void pthread_attr_t;
|
||||
|
||||
#define PTHREAD_CANCEL_ENABLE 0
|
||||
#define PTHREAD_CANCEL_DISABLE 1
|
||||
#define PTHREAD_CANCEL_DEFERRED 0
|
||||
#define PTHREAD_CANCEL_ASYNCHRONOUS 1
|
||||
|
||||
static inline int pthread_create(pthread_t *tid, const pthread_attr_t *attr,
|
||||
void *(*start_routine)(void *), void *arg)
|
||||
{
|
||||
(void)attr;
|
||||
*tid = CreateThread(NULL, 0U, (LPTHREAD_START_ROUTINE)(void *)start_routine, arg, 0U, NULL);
|
||||
return (*tid == NULL) ? -1 : 0;
|
||||
}
|
||||
|
||||
static inline int pthread_join(pthread_t tid, void **retval)
|
||||
{
|
||||
(void)retval;
|
||||
WaitForSingleObject(tid, INFINITE);
|
||||
CloseHandle(tid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int pthread_cancel(pthread_t tid)
|
||||
{
|
||||
TerminateThread(tid, 0U);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* No-op: allows test_control_thread_entry to reach exit(test_control_failed_tests). */
|
||||
static inline void pthread_exit(void *retval)
|
||||
{
|
||||
(void)retval;
|
||||
}
|
||||
|
||||
static inline int pthread_setcancelstate(int state, int *oldstate)
|
||||
{
|
||||
(void)state;
|
||||
if (oldstate != NULL)
|
||||
{
|
||||
*oldstate = PTHREAD_CANCEL_ENABLE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int pthread_setcanceltype(int type, int *oldtype)
|
||||
{
|
||||
(void)type;
|
||||
if (oldtype != NULL)
|
||||
{
|
||||
*oldtype = PTHREAD_CANCEL_DEFERRED;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* WIN64_COMPAT_PTHREAD_H */
|
||||
@@ -0,0 +1,22 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/* Copyright (c) 2025 Contributors to the Eclipse Foundation */
|
||||
/* AI-generated with GitHub Copilot */
|
||||
|
||||
/* Minimal POSIX unistd shim for FileX regression tests on Windows/x64. */
|
||||
|
||||
#ifndef WIN64_COMPAT_UNISTD_H
|
||||
#define WIN64_COMPAT_UNISTD_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
typedef unsigned int useconds_t;
|
||||
|
||||
/* Sleep for `usec` microseconds. Windows resolution is ~1 ms; round up. */
|
||||
static inline int usleep(useconds_t usec)
|
||||
{
|
||||
DWORD ms = (DWORD)((usec + 999U) / 1000U);
|
||||
Sleep((ms > 0U) ? ms : 1U);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* WIN64_COMPAT_UNISTD_H */
|
||||
Reference in New Issue
Block a user