Merge pull request #244 from azure-rtos/tizho/test

Release ThreadX regression system
This commit is contained in:
TiejunZhou
2023-04-13 16:57:35 +08:00
committed by GitHub
233 changed files with 87402 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
{
"image": "tizho/azurertos-regression",
"runArgs": [ "--cap-add=NET_ADMIN"]
}

59
.pipelines/smp.yml Normal file
View File

@@ -0,0 +1,59 @@
trigger:
- master
pr:
- master
pool:
vmImage: "ubuntu-22.04"
steps:
- bash: sudo $(Build.SourcesDirectory)/scripts/install.sh
displayName: 'Install softwares'
env:
INDEX_URL: $(INDEX_URL)
- task: Bash@3
displayName: 'SDL check'
inputs:
filePath: '$(Build.SourcesDirectory)/scripts/sdl_check.sh'
- task: Bash@3
displayName: 'Build SMP'
inputs:
filePath: '$(Build.SourcesDirectory)/scripts/build_smp.sh'
- task: Bash@3
displayName: 'Test SMP'
inputs:
filePath: '$(Build.SourcesDirectory)/scripts/test_smp.sh'
- task: PublishTestResults@2
condition: succeededOrFailed()
displayName: 'Test SMP (PublishTestResults)'
inputs:
testResultsFormat: 'cTest'
testResultsFiles: '*/Testing/**/*.xml'
searchFolder: '$(Build.SourcesDirectory)/test/smp/cmake/build'
testRunTitle: 'SMP-Tests'
buildConfiguration: 'Release'
- task: CopyFiles@2
condition: succeededOrFailed()
displayName: 'Test SMP (PublishTestReports)'
inputs:
SourceFolder: '$(Build.SourcesDirectory)/test/smp/cmake'
Contents: |
build/*.txt
build/*/Testing/**/*.xml
coverage_report/**/*
TargetFolder: '$(ob_outputDirectory)/test_reports_SMP'
- task: PublishCodeCoverageResults@1
condition: succeededOrFailed()
displayName: 'Test SMP (PublishCodeCoverageResults)'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Build.SourcesDirectory)/test/smp/cmake/coverage_report/default_build_coverage.xml'
pathToSources: '$(Build.SourcesDirectory)/test/smp/cmake'
reportDirectory: '$(Build.SourcesDirectory)/test/smp/cmake/coverage_report/default_build_coverage'

59
.pipelines/tx.yml Normal file
View File

@@ -0,0 +1,59 @@
trigger:
- master
pr:
- master
pool:
vmImage: "ubuntu-22.04"
steps:
- bash: sudo $(Build.SourcesDirectory)/scripts/install.sh
displayName: 'Install softwares'
env:
INDEX_URL: $(INDEX_URL)
- task: Bash@3
displayName: 'SDL check'
inputs:
filePath: '$(Build.SourcesDirectory)/scripts/sdl_check.sh'
- task: Bash@3
displayName: 'Build TX'
inputs:
filePath: '$(Build.SourcesDirectory)/scripts/build_tx.sh'
- task: Bash@3
displayName: 'Test TX'
inputs:
filePath: '$(Build.SourcesDirectory)/scripts/test_tx.sh'
- task: PublishTestResults@2
condition: succeededOrFailed()
displayName: 'Test TX (PublishTestResults)'
inputs:
testResultsFormat: 'cTest'
testResultsFiles: '*/Testing/**/*.xml'
searchFolder: '$(Build.SourcesDirectory)/test/tx/cmake/build'
testRunTitle: 'TX-Tests'
buildConfiguration: 'Release'
- task: CopyFiles@2
condition: succeededOrFailed()
displayName: 'Test TX (PublishTestReports)'
inputs:
SourceFolder: '$(Build.SourcesDirectory)/test/tx/cmake'
Contents: |
build/*.txt
build/*/Testing/**/*.xml
coverage_report/**/*
TargetFolder: '$(ob_outputDirectory)/test_reports_TX'
- task: PublishCodeCoverageResults@1
condition: succeededOrFailed()
displayName: 'Test TX (PublishCodeCoverageResults)'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Build.SourcesDirectory)/test/tx/cmake/coverage_report/default_build_coverage.xml'
pathToSources: '$(Build.SourcesDirectory)/test/tx/cmake'
reportDirectory: '$(Build.SourcesDirectory)/test/tx/cmake/coverage_report/default_build_coverage'

2
scripts/build_smp.sh Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
$(dirname `realpath $0`)/../test/smp/cmake/run.sh build all

2
scripts/build_tx.sh Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
$(dirname `realpath $0`)/../test/tx/cmake/run.sh build all

120
scripts/cmake_bootstrap.sh Executable file
View File

@@ -0,0 +1,120 @@
#!/bin/bash
set -e
function help() {
echo "Usage: $0 [build|test] [all|<build_configuration> <build_configuration>...]"
echo "Available build_configuration:"
for build in ${build_configurations[*]}; do
echo " $build"
done
exit 1
}
function validate() {
for build in ${build_configurations[*]}; do
if [ "$1" == "$build" ]; then
return
fi
done
help
}
function generate() {
build=$1
cmake -Bbuild/$build -GNinja -DBUILD_SHARED_LIBS=ON -DCMAKE_TOOLCHAIN_FILE=$(dirname $(realpath $0))/../cmake/linux.cmake -DCMAKE_BUILD_TYPE=$build .
}
function build() {
cmake --build build/$1
}
function build_libs() {
cmake -Bbuild/libs -GNinja -DBUILD_SHARED_LIBS=ON -DCMAKE_TOOLCHAIN_FILE=$(dirname $(realpath $0))/../cmake/linux.cmake libs
cmake --build build/libs
}
function test() {
pushd build/$1
[ -z "${CTEST_PARALLEL_LEVEL}" ] && parallel="-j$2"
if [ -z "${CTEST_REPEAT_FAIL}" ];
then
repeat_fail=2
else
repeat_fail=${CTEST_REPEAT_FAIL}
fi
ctest $parallel --timeout 1000 -O $1.txt -T test --no-compress-output --test-output-size-passed 4194304 --test-output-size-failed 4194304 --output-on-failure --repeat until-pass:${repeat_fail}
popd
grep -E "^(\s*[0-9]+|Total)" build/$1/$1.txt >build/$1.txt
sed -i "s/\x1B\[[0-9;]*[JKmsu]//g" build/$1.txt
if [[ $1 = *"_coverage" ]]; then
./coverage.sh $1
fi
}
cd $(dirname $0)
result=$(sed -n "/(BUILD_CONFIGURATIONS/,/)/p" CMakeLists.txt|sed ':label;N;s/\n/ /;b label'|grep -Pzo "[a-zA-Z0-9_]*build[a-zA-Z0-9_]*\s*"| tr -d '\0')
IFS=' '
read -ra build_configurations <<< "$result"
if [ $# -lt 1 ]; then
help
fi
command=$1
shift
if [ "$#" == "0" ]; then
builds=${build_configurations[0]}
elif [ "$*" == "all" ]; then
builds=${build_configurations[@]}
else
for item in $*; do
validate $item
done
builds=$*
fi
if [ "$command" == "build" ]; then
for item in $builds; do
generate $item
echo ""
done
for item in $builds; do
echo "Building $item"
build $item
echo ""
done
elif [ "$command" == "test" ]; then
cores=$(nproc)
if [ -z "${CTEST_PARALLEL_LEVEL}" ];
then
# Run builds in parallel
build_counts=$(echo $builds | wc -w)
parallel_jobs=$(($cores / $build_counts))
parallel_jobs=$(($parallel_jobs + 2))
pids=""
for item in $builds; do
echo "Testing $item"
test $item $parallel_jobs &
pids+=" $!"
done
exit_code=0
for p in $pids; do
wait $p || exit_code=$?
done
exit $exit_code
else
# Run builds in serial
for item in $builds; do
echo "Testing $item"
test $item $parallel_jobs
done
fi
elif [ "$command" == "build_libs" ]; then
build_libs
else
help
fi

22
scripts/install.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
#
# Install necessary softwares for Ubuntu.
apt-get update
apt-get install -y \
gcc-multilib \
git \
g++ \
python3-pip \
ninja-build \
unifdef \
p7zip-full \
tofrodos \
gawk \
cmake \
software-properties-common
python3 -m pip install --upgrade pip
pip3 install artifacts-keyring
pip3 install gcovr==4.1 $INDEX_URL

19
scripts/sdl_check.sh Executable file
View File

@@ -0,0 +1,19 @@
# !/bin/bash
dir_list="common common_smp common_modules ports ports_module ports_smp samples"
exclude_list="-path TX"
file_list=$(find $dir_list \( $exclude_list \) -prune -o -type f -name '*.[ch]' -print)
cd $(dirname `realpath $0`)/..
echo "Checking for unexpected usage of memcpy..."
echo ""
echo "Excluding:"
echo $exclude_list | grep -P "[^\s]*/[^\s]*" -o
echo ""
echo "Result:"
grep -i "memcpy(" -i $file_list -n | grep -i "use case of .* is verified" -v
if [ "$?" -eq "1" ];
then
echo "CLEAN"
exit 0
else
exit 1
fi

3
scripts/test_smp.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
CTEST_PARALLEL_LEVEL=4 $(dirname `realpath $0`)/../test/smp/cmake/run.sh test all

3
scripts/test_tx.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
CTEST_PARALLEL_LEVEL=4 $(dirname `realpath $0`)/../test/tx/cmake/run.sh test all

2
test/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
tx_initialize_low_level.c
coverage_report/

View File

@@ -0,0 +1,76 @@
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0057 NEW)
project(threadx_smp_test LANGUAGES C)
# Set build configurations
set(BUILD_CONFIGURATIONS default_build_coverage
disable_notify_callbacks_build stack_checking_build
trace_build)
set(CMAKE_CONFIGURATION_TYPES
${BUILD_CONFIGURATIONS}
CACHE STRING "list of supported configuration types" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
${CMAKE_CONFIGURATION_TYPES})
list(GET CMAKE_CONFIGURATION_TYPES 0 BUILD_TYPE)
if((NOT CMAKE_BUILD_TYPE) OR (NOT ("${CMAKE_BUILD_TYPE}" IN_LIST
CMAKE_CONFIGURATION_TYPES)))
set(CMAKE_BUILD_TYPE
"${BUILD_TYPE}"
CACHE STRING "Build Type of the project" FORCE)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")
set(default_build_coverage "")
set(disable_notify_callbacks_build -DTX_DISABLE_NOTIFY_CALLBACKS)
set(stack_checking_build -DTX_ENABLE_STACK_CHECKING)
set(trace_build -DTX_ENABLE_EVENT_TRACE)
add_compile_options(
-m32
-std=c99
-ggdb
-g3
-gdwarf-2
-fdiagnostics-color
# -Werror
-DTX_THREAD_SMP_ONLY_CORE_0_DEFAULT
-DTX_SMP_NOT_POSSIBLE
-DTX_REGRESSION_TEST
-DTEST_STACK_SIZE_PRINTF=4096
${${CMAKE_BUILD_TYPE}})
add_link_options(-m32)
enable_testing()
add_subdirectory(threadx_smp)
add_subdirectory(regression)
add_subdirectory(samples)
# Coverage
if(CMAKE_BUILD_TYPE MATCHES ".*_coverage")
target_compile_options(threadx_smp PRIVATE -fprofile-arcs -ftest-coverage)
target_link_options(threadx_smp PRIVATE -fprofile-arcs -ftest-coverage)
endif()
target_compile_options(
threadx_smp
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)

9
test/smp/cmake/coverage.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
set -e
cd $(dirname $0)
threadx_smp=$(realpath ../../../common_smp/src)
mkdir -p coverage_report/$1
gcovr --object-directory=build/$1/threadx_smp/CMakeFiles/threadx_smp.dir/$threadx_smp -r build/$1 -f ../../../common_smp/src --xml-pretty --output coverage_report/$1.xml
gcovr --object-directory=build/$1/threadx_smp/CMakeFiles/threadx_smp.dir/$threadx_smp -r build/$1 -f ../../../common_smp/src --html --html-details --output coverage_report/$1/index.html

View File

@@ -0,0 +1,133 @@
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
cmake_policy(SET CMP0057 NEW)
project(regression_test LANGUAGES C)
set(SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../regression)
set(regression_test_cases
${SOURCE_DIR}/threadx_block_memory_basic_test.c
${SOURCE_DIR}/threadx_block_memory_error_detection_test.c
${SOURCE_DIR}/threadx_block_memory_information_test.c
${SOURCE_DIR}/threadx_block_memory_prioritize_test.c
${SOURCE_DIR}/threadx_block_memory_suspension_test.c
${SOURCE_DIR}/threadx_block_memory_suspension_timeout_test.c
${SOURCE_DIR}/threadx_block_memory_thread_terminate_test.c
${SOURCE_DIR}/threadx_byte_memory_basic_test.c
${SOURCE_DIR}/threadx_byte_memory_information_test.c
${SOURCE_DIR}/threadx_byte_memory_prioritize_test.c
${SOURCE_DIR}/threadx_byte_memory_suspension_test.c
${SOURCE_DIR}/threadx_byte_memory_suspension_timeout_test.c
${SOURCE_DIR}/threadx_byte_memory_thread_contention_test.c
${SOURCE_DIR}/threadx_byte_memory_thread_terminate_test.c
${SOURCE_DIR}/threadx_event_flag_basic_test.c
${SOURCE_DIR}/threadx_event_flag_information_test.c
${SOURCE_DIR}/threadx_event_flag_isr_set_clear_test.c
${SOURCE_DIR}/threadx_event_flag_isr_wait_abort_test.c
${SOURCE_DIR}/threadx_event_flag_single_thread_terminate_test.c
${SOURCE_DIR}/threadx_event_flag_suspension_consume_test.c
${SOURCE_DIR}/threadx_event_flag_suspension_different_bits_consume_test.c
${SOURCE_DIR}/threadx_event_flag_suspension_different_bits_test.c
${SOURCE_DIR}/threadx_event_flag_suspension_test.c
${SOURCE_DIR}/threadx_event_flag_suspension_timeout_test.c
${SOURCE_DIR}/threadx_event_flag_thread_terminate_test.c
${SOURCE_DIR}/threadx_interrupt_control_test.c
${SOURCE_DIR}/threadx_mutex_basic_test.c
${SOURCE_DIR}/threadx_mutex_delete_test.c
${SOURCE_DIR}/threadx_mutex_information_test.c
${SOURCE_DIR}/threadx_mutex_nested_priority_inheritance_test.c
${SOURCE_DIR}/threadx_mutex_no_preemption_test.c
${SOURCE_DIR}/threadx_mutex_preemption_test.c
${SOURCE_DIR}/threadx_mutex_priority_inheritance_test.c
${SOURCE_DIR}/threadx_mutex_proritize_test.c
${SOURCE_DIR}/threadx_mutex_suspension_timeout_test.c
${SOURCE_DIR}/threadx_mutex_thread_terminate_test.c
${SOURCE_DIR}/threadx_queue_basic_eight_word_test.c
${SOURCE_DIR}/threadx_queue_basic_four_word_test.c
${SOURCE_DIR}/threadx_queue_basic_one_word_test.c
${SOURCE_DIR}/threadx_queue_basic_sixteen_word_test.c
${SOURCE_DIR}/threadx_queue_basic_two_word_test.c
${SOURCE_DIR}/threadx_queue_empty_suspension_test.c
${SOURCE_DIR}/threadx_queue_flush_no_suspension_test.c
${SOURCE_DIR}/threadx_queue_flush_test.c
${SOURCE_DIR}/threadx_queue_front_send_test.c
${SOURCE_DIR}/threadx_queue_full_suspension_test.c
${SOURCE_DIR}/threadx_queue_information_test.c
${SOURCE_DIR}/threadx_queue_prioritize.c
${SOURCE_DIR}/threadx_queue_suspension_timeout_test.c
${SOURCE_DIR}/threadx_queue_thread_terminate_test.c
${SOURCE_DIR}/threadx_semaphore_basic_test.c
${SOURCE_DIR}/threadx_semaphore_ceiling_put_test.c
${SOURCE_DIR}/threadx_semaphore_delete_test.c
${SOURCE_DIR}/threadx_semaphore_information_test.c
${SOURCE_DIR}/threadx_semaphore_non_preemption_test.c
${SOURCE_DIR}/threadx_semaphore_preemption_test.c
${SOURCE_DIR}/threadx_semaphore_prioritize.c
${SOURCE_DIR}/threadx_semaphore_thread_terminate_test.c
${SOURCE_DIR}/threadx_semaphore_timeout_test.c
${SOURCE_DIR}/threadx_smp_multiple_threads_one_core_test.c
${SOURCE_DIR}/threadx_smp_non_trivial_scheduling_test.c
${SOURCE_DIR}/threadx_smp_one_thread_dynamic_exclusion_test.c
${SOURCE_DIR}/threadx_smp_preemption_threshold_test.c
${SOURCE_DIR}/threadx_smp_random_resume_suspend_exclusion_pt_test.c
${SOURCE_DIR}/threadx_smp_random_resume_suspend_exclusion_test.c
${SOURCE_DIR}/threadx_smp_random_resume_suspend_test.c
${SOURCE_DIR}/threadx_smp_rebalance_exclusion_test.c
${SOURCE_DIR}/threadx_smp_relinquish_test.c
${SOURCE_DIR}/threadx_smp_resume_suspend_accending_order_test.c
${SOURCE_DIR}/threadx_smp_resume_suspend_decending_order_test.c
${SOURCE_DIR}/threadx_smp_time_slice_test.c
${SOURCE_DIR}/threadx_smp_two_threads_one_core_test.c
${SOURCE_DIR}/threadx_thread_basic_execution_test.c
${SOURCE_DIR}/threadx_thread_basic_time_slice_test.c
${SOURCE_DIR}/threadx_thread_completed_test.c
${SOURCE_DIR}/threadx_thread_create_preemption_threshold_test.c
${SOURCE_DIR}/threadx_thread_delayed_suspension_test.c
${SOURCE_DIR}/threadx_thread_information_test.c
${SOURCE_DIR}/threadx_thread_multi_level_preemption_threshold_test.c
${SOURCE_DIR}/threadx_thread_multiple_non_current_test.c
${SOURCE_DIR}/threadx_thread_multiple_sleep_test.c
${SOURCE_DIR}/threadx_thread_multiple_suspension_test.c
${SOURCE_DIR}/threadx_thread_multiple_time_slice_test.c
${SOURCE_DIR}/threadx_thread_preemptable_suspension_test.c
${SOURCE_DIR}/threadx_thread_preemption_change_test.c
${SOURCE_DIR}/threadx_thread_priority_change.c
${SOURCE_DIR}/threadx_thread_relinquish_test.c
${SOURCE_DIR}/threadx_thread_reset_test.c
${SOURCE_DIR}/threadx_thread_simple_sleep_non_clear_test.c
${SOURCE_DIR}/threadx_thread_simple_sleep_test.c
${SOURCE_DIR}/threadx_thread_simple_suspend_test.c
${SOURCE_DIR}/threadx_thread_sleep_for_100ticks_test.c
${SOURCE_DIR}/threadx_thread_sleep_terminate_test.c
${SOURCE_DIR}/threadx_thread_stack_checking_test.c
${SOURCE_DIR}/threadx_thread_terminate_delete_test.c
${SOURCE_DIR}/threadx_thread_time_slice_change_test.c
${SOURCE_DIR}/threadx_thread_wait_abort_and_isr_test.c
${SOURCE_DIR}/threadx_thread_wait_abort_test.c
${SOURCE_DIR}/threadx_time_get_set_test.c
${SOURCE_DIR}/threadx_timer_activate_deactivate_test.c
${SOURCE_DIR}/threadx_timer_deactivate_accuracy_test.c
${SOURCE_DIR}/threadx_timer_information_test.c
${SOURCE_DIR}/threadx_timer_large_timer_accuracy_test.c
${SOURCE_DIR}/threadx_timer_multiple_accuracy_test.c
${SOURCE_DIR}/threadx_timer_multiple_test.c
${SOURCE_DIR}/threadx_timer_simple_test.c
${SOURCE_DIR}/threadx_trace_basic_test.c
${SOURCE_DIR}/threadx_initialize_kernel_setup_test.c)
add_custom_command(
OUTPUT ${SOURCE_DIR}/tx_initialize_low_level.c
COMMAND bash ${CMAKE_CURRENT_LIST_DIR}/generate_test_file.sh
COMMENT "Generating tx_initialize_low_level.c for test")
add_library(test_utility ${SOURCE_DIR}/tx_initialize_low_level.c
${SOURCE_DIR}/testcontrol.c)
target_link_libraries(test_utility PUBLIC azrtos::threadx_smp)
target_compile_definitions(test_utility PUBLIC CTEST BATCH_TEST)
foreach(test_case ${regression_test_cases})
get_filename_component(test_name ${test_case} NAME_WE)
add_executable(${test_name} ${test_case})
target_link_libraries(${test_name} PRIVATE test_utility)
add_test(${CMAKE_BUILD_TYPE}::${test_name} ${test_name})
endforeach()

View File

@@ -0,0 +1,10 @@
#!/bin/bash
dst=$(dirname $0)/../../regression/tx_initialize_low_level.c
src=$(dirname $0)/../../../../ports_smp/linux/gnu/src/tx_initialize_low_level.c
line=`sed -n '/_tx_linux_timer_interrupt/=' $src | tail -n 1`
sed "${line}iVOID test_interrupt_dispatch(VOID);" $src > tmp1
line=`sed -n '/_tx_timer_interrupt/=' $src | tail -n 1`
sed "${line}itest_interrupt_dispatch();" tmp1 > $dst
rm tmp1

1
test/smp/cmake/run.sh Symbolic link
View File

@@ -0,0 +1 @@
../../../scripts/cmake_bootstrap.sh

View File

@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
cmake_policy(SET CMP0057 NEW)
project(samples LANGUAGES C)
set(SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../ports_smp/linux/gnu/example_build)
set(sample_files
${SOURCE_DIR}/sample_threadx.c)
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}/fake.c)
target_link_libraries(${sample_file_name} PRIVATE azrtos::threadx_smp)
endforeach()

View File

@@ -0,0 +1,22 @@
#include "tx_api.h"
typedef unsigned int TEST_FLAG;
TEST_FLAG threadx_byte_allocate_loop_test;
TEST_FLAG threadx_byte_release_loop_test;
TEST_FLAG threadx_mutex_suspension_put_test;
TEST_FLAG threadx_mutex_suspension_priority_test;
#ifndef TX_TIMER_PROCESS_IN_ISR
TEST_FLAG threadx_delete_timer_thread;
#endif
void abort_and_resume_byte_allocating_thread(void){}
void abort_all_threads_suspended_on_mutex(void){}
void suspend_lowest_priority(void){}
#ifndef TX_TIMER_PROCESS_IN_ISR
void delete_timer_thread(void){}
#endif
TEST_FLAG test_stack_analyze_flag;
TEST_FLAG test_initialize_flag;
TEST_FLAG test_forced_mutex_timeout;
UINT mutex_priority_change_extension_selection;
UINT priority_change_extension_selection;

View File

@@ -0,0 +1,60 @@
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
# Set up the project
project(threadx_smp
VERSION 6.0.0
LANGUAGES C ASM
)
if(NOT DEFINED THREADX_ARCH)
message(FATAL_ERROR "Error: THREADX_ARCH not defined")
endif()
if(NOT DEFINED THREADX_TOOLCHAIN)
message(FATAL_ERROR "Error: THREADX_TOOLCHAIN not defined")
endif()
set(PROJECT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../..)
# Define our target library and an alias for consumers
add_library(${PROJECT_NAME})
add_library("azrtos::${PROJECT_NAME}" ALIAS ${PROJECT_NAME})
# A place for generated/copied include files (no need to change)
set(CUSTOM_INC_DIR ${CMAKE_CURRENT_BINARY_DIR}/custom_inc)
# Pick up the port specific variables and apply them
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/ports_smp/${THREADX_ARCH}/${THREADX_TOOLCHAIN})
# Pick up the common stuff
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/common_smp)
# If the user provided an override, copy it to the custom directory
if (NOT TX_USER_FILE)
message(STATUS "Using default tx_user.h file")
set(TX_USER_FILE ${PROJECT_DIR}/common_smp/inc/tx_user_sample.h)
else()
message(STATUS "Using custom tx_user.h file from ${TX_USER_FILE}")
endif()
configure_file(${TX_USER_FILE} ${CUSTOM_INC_DIR}/tx_user.h COPYONLY)
target_include_directories(${PROJECT_NAME}
PUBLIC
${CUSTOM_INC_DIR}
)
target_compile_definitions(${PROJECT_NAME} PUBLIC "TX_INCLUDE_USER_DEFINE_FILE" )
# Enable a build target that produces a ZIP file of all sources
set(CPACK_SOURCE_GENERATOR "ZIP")
set(CPACK_SOURCE_IGNORE_FILES
\\.git/
\\.github/
_build/
\\.git
\\.gitattributes
\\.gitignore
".*~$"
)
set(CPACK_VERBATIM_VARIABLES YES)
include(CPack)

View File

@@ -0,0 +1,220 @@
set(CURRENT_DIR ${PROJECT_DIR}/common_smp)
function(target_sources_if_not_overridden filename)
list(FIND TX_SRC_OVERRIDES ${filename} OVERRIDE_FOUND)
if( OVERRIDE_FOUND EQUAL -1 )
# message(STATUS "** Using original ${filename} from common/src **")
target_sources(${PROJECT_NAME} PRIVATE ${CURRENT_DIR}/src/${filename})
endif()
endfunction()
# These files can be overridden by setting them in the variable list named TX_SRC_OVERRIDES
target_sources_if_not_overridden("tx_thread_delete.c")
target_sources_if_not_overridden("tx_thread_reset.c")
target_sources(${PROJECT_NAME}
PRIVATE
# {{BEGIN_TARGET_SOURCES}}
${CURRENT_DIR}/src/tx_block_allocate.c
${CURRENT_DIR}/src/tx_block_allocate.c
${CURRENT_DIR}/src/tx_block_pool_cleanup.c
${CURRENT_DIR}/src/tx_block_pool_create.c
${CURRENT_DIR}/src/tx_block_pool_delete.c
${CURRENT_DIR}/src/tx_block_pool_info_get.c
${CURRENT_DIR}/src/tx_block_pool_initialize.c
${CURRENT_DIR}/src/tx_block_pool_performance_info_get.c
${CURRENT_DIR}/src/tx_block_pool_performance_system_info_get.c
${CURRENT_DIR}/src/tx_block_pool_prioritize.c
${CURRENT_DIR}/src/tx_block_release.c
${CURRENT_DIR}/src/tx_byte_allocate.c
${CURRENT_DIR}/src/tx_byte_pool_cleanup.c
${CURRENT_DIR}/src/tx_byte_pool_create.c
${CURRENT_DIR}/src/tx_byte_pool_delete.c
${CURRENT_DIR}/src/tx_byte_pool_info_get.c
${CURRENT_DIR}/src/tx_byte_pool_initialize.c
${CURRENT_DIR}/src/tx_byte_pool_performance_info_get.c
${CURRENT_DIR}/src/tx_byte_pool_performance_system_info_get.c
${CURRENT_DIR}/src/tx_byte_pool_prioritize.c
${CURRENT_DIR}/src/tx_byte_pool_search.c
${CURRENT_DIR}/src/tx_byte_release.c
${CURRENT_DIR}/src/txe_block_allocate.c
${CURRENT_DIR}/src/txe_block_pool_create.c
${CURRENT_DIR}/src/txe_block_pool_delete.c
${CURRENT_DIR}/src/txe_block_pool_info_get.c
${CURRENT_DIR}/src/txe_block_pool_prioritize.c
${CURRENT_DIR}/src/txe_block_release.c
${CURRENT_DIR}/src/txe_byte_allocate.c
${CURRENT_DIR}/src/txe_byte_pool_create.c
${CURRENT_DIR}/src/txe_byte_pool_delete.c
${CURRENT_DIR}/src/txe_byte_pool_info_get.c
${CURRENT_DIR}/src/txe_byte_pool_prioritize.c
${CURRENT_DIR}/src/txe_byte_release.c
${CURRENT_DIR}/src/txe_event_flags_create.c
${CURRENT_DIR}/src/txe_event_flags_delete.c
${CURRENT_DIR}/src/txe_event_flags_get.c
${CURRENT_DIR}/src/txe_event_flags_info_get.c
${CURRENT_DIR}/src/txe_event_flags_set.c
${CURRENT_DIR}/src/txe_event_flags_set_notify.c
${CURRENT_DIR}/src/txe_mutex_create.c
${CURRENT_DIR}/src/txe_mutex_delete.c
${CURRENT_DIR}/src/txe_mutex_get.c
${CURRENT_DIR}/src/txe_mutex_info_get.c
${CURRENT_DIR}/src/txe_mutex_prioritize.c
${CURRENT_DIR}/src/txe_mutex_put.c
${CURRENT_DIR}/src/txe_queue_create.c
${CURRENT_DIR}/src/txe_queue_delete.c
${CURRENT_DIR}/src/txe_queue_flush.c
${CURRENT_DIR}/src/txe_queue_front_send.c
${CURRENT_DIR}/src/txe_queue_info_get.c
${CURRENT_DIR}/src/txe_queue_prioritize.c
${CURRENT_DIR}/src/txe_queue_receive.c
${CURRENT_DIR}/src/txe_queue_send.c
${CURRENT_DIR}/src/txe_queue_send_notify.c
${CURRENT_DIR}/src/txe_semaphore_ceiling_put.c
${CURRENT_DIR}/src/txe_semaphore_create.c
${CURRENT_DIR}/src/txe_semaphore_delete.c
${CURRENT_DIR}/src/txe_semaphore_get.c
${CURRENT_DIR}/src/txe_semaphore_info_get.c
${CURRENT_DIR}/src/txe_semaphore_prioritize.c
${CURRENT_DIR}/src/txe_semaphore_put.c
${CURRENT_DIR}/src/txe_semaphore_put_notify.c
${CURRENT_DIR}/src/txe_thread_create.c
${CURRENT_DIR}/src/txe_thread_delete.c
${CURRENT_DIR}/src/txe_thread_entry_exit_notify.c
${CURRENT_DIR}/src/txe_thread_info_get.c
${CURRENT_DIR}/src/txe_thread_preemption_change.c
${CURRENT_DIR}/src/txe_thread_priority_change.c
${CURRENT_DIR}/src/txe_thread_relinquish.c
${CURRENT_DIR}/src/txe_thread_reset.c
${CURRENT_DIR}/src/txe_thread_resume.c
${CURRENT_DIR}/src/txe_thread_suspend.c
${CURRENT_DIR}/src/txe_thread_terminate.c
${CURRENT_DIR}/src/txe_thread_time_slice_change.c
${CURRENT_DIR}/src/txe_thread_wait_abort.c
${CURRENT_DIR}/src/txe_timer_activate.c
${CURRENT_DIR}/src/txe_timer_change.c
${CURRENT_DIR}/src/txe_timer_create.c
${CURRENT_DIR}/src/txe_timer_deactivate.c
${CURRENT_DIR}/src/txe_timer_delete.c
${CURRENT_DIR}/src/txe_timer_info_get.c
${CURRENT_DIR}/src/tx_event_flags_cleanup.c
${CURRENT_DIR}/src/tx_event_flags_create.c
${CURRENT_DIR}/src/tx_event_flags_delete.c
${CURRENT_DIR}/src/tx_event_flags_get.c
${CURRENT_DIR}/src/tx_event_flags_info_get.c
${CURRENT_DIR}/src/tx_event_flags_initialize.c
${CURRENT_DIR}/src/tx_event_flags_performance_info_get.c
${CURRENT_DIR}/src/tx_event_flags_performance_system_info_get.c
${CURRENT_DIR}/src/tx_event_flags_set.c
${CURRENT_DIR}/src/tx_event_flags_set_notify.c
${CURRENT_DIR}/src/tx_initialize_high_level.c
${CURRENT_DIR}/src/tx_initialize_kernel_enter.c
${CURRENT_DIR}/src/tx_initialize_kernel_setup.c
${CURRENT_DIR}/src/tx_misra.c
${CURRENT_DIR}/src/tx_mutex_cleanup.c
${CURRENT_DIR}/src/tx_mutex_create.c
${CURRENT_DIR}/src/tx_mutex_delete.c
${CURRENT_DIR}/src/tx_mutex_get.c
${CURRENT_DIR}/src/tx_mutex_info_get.c
${CURRENT_DIR}/src/tx_mutex_initialize.c
${CURRENT_DIR}/src/tx_mutex_performance_info_get.c
${CURRENT_DIR}/src/tx_mutex_performance_system_info_get.c
${CURRENT_DIR}/src/tx_mutex_prioritize.c
${CURRENT_DIR}/src/tx_mutex_priority_change.c
${CURRENT_DIR}/src/tx_mutex_put.c
${CURRENT_DIR}/src/tx_queue_cleanup.c
${CURRENT_DIR}/src/tx_queue_create.c
${CURRENT_DIR}/src/tx_queue_delete.c
${CURRENT_DIR}/src/tx_queue_flush.c
${CURRENT_DIR}/src/tx_queue_front_send.c
${CURRENT_DIR}/src/tx_queue_info_get.c
${CURRENT_DIR}/src/tx_queue_initialize.c
${CURRENT_DIR}/src/tx_queue_performance_info_get.c
${CURRENT_DIR}/src/tx_queue_performance_system_info_get.c
${CURRENT_DIR}/src/tx_queue_prioritize.c
${CURRENT_DIR}/src/tx_queue_receive.c
${CURRENT_DIR}/src/tx_queue_send.c
${CURRENT_DIR}/src/tx_queue_send_notify.c
${CURRENT_DIR}/src/tx_semaphore_ceiling_put.c
${CURRENT_DIR}/src/tx_semaphore_cleanup.c
${CURRENT_DIR}/src/tx_semaphore_create.c
${CURRENT_DIR}/src/tx_semaphore_delete.c
${CURRENT_DIR}/src/tx_semaphore_get.c
${CURRENT_DIR}/src/tx_semaphore_info_get.c
${CURRENT_DIR}/src/tx_semaphore_initialize.c
${CURRENT_DIR}/src/tx_semaphore_performance_info_get.c
${CURRENT_DIR}/src/tx_semaphore_performance_system_info_get.c
${CURRENT_DIR}/src/tx_semaphore_prioritize.c
${CURRENT_DIR}/src/tx_semaphore_put.c
${CURRENT_DIR}/src/tx_semaphore_put_notify.c
${CURRENT_DIR}/src/tx_thread_create.c
${CURRENT_DIR}/src/tx_thread_entry_exit_notify.c
${CURRENT_DIR}/src/tx_thread_identify.c
${CURRENT_DIR}/src/tx_thread_info_get.c
${CURRENT_DIR}/src/tx_thread_initialize.c
${CURRENT_DIR}/src/tx_thread_performance_info_get.c
${CURRENT_DIR}/src/tx_thread_performance_system_info_get.c
${CURRENT_DIR}/src/tx_thread_preemption_change.c
${CURRENT_DIR}/src/tx_thread_priority_change.c
${CURRENT_DIR}/src/tx_thread_relinquish.c
${CURRENT_DIR}/src/tx_thread_resume.c
${CURRENT_DIR}/src/tx_thread_shell_entry.c
${CURRENT_DIR}/src/tx_thread_sleep.c
${CURRENT_DIR}/src/tx_thread_smp_utilities.c
${CURRENT_DIR}/src/tx_thread_stack_analyze.c
${CURRENT_DIR}/src/tx_thread_stack_error_handler.c
${CURRENT_DIR}/src/tx_thread_stack_error_notify.c
${CURRENT_DIR}/src/tx_thread_suspend.c
${CURRENT_DIR}/src/tx_thread_system_preempt_check.c
${CURRENT_DIR}/src/tx_thread_system_resume.c
${CURRENT_DIR}/src/tx_thread_system_suspend.c
${CURRENT_DIR}/src/tx_thread_terminate.c
${CURRENT_DIR}/src/tx_thread_timeout.c
${CURRENT_DIR}/src/tx_thread_time_slice.c
${CURRENT_DIR}/src/tx_thread_time_slice_change.c
${CURRENT_DIR}/src/tx_thread_wait_abort.c
${CURRENT_DIR}/src/tx_time_get.c
${CURRENT_DIR}/src/tx_timer_activate.c
${CURRENT_DIR}/src/tx_timer_change.c
${CURRENT_DIR}/src/tx_timer_create.c
${CURRENT_DIR}/src/tx_timer_deactivate.c
${CURRENT_DIR}/src/tx_timer_delete.c
${CURRENT_DIR}/src/tx_timer_expiration_process.c
${CURRENT_DIR}/src/tx_timer_info_get.c
${CURRENT_DIR}/src/tx_timer_initialize.c
${CURRENT_DIR}/src/tx_timer_performance_info_get.c
${CURRENT_DIR}/src/tx_timer_performance_system_info_get.c
${CURRENT_DIR}/src/tx_timer_system_activate.c
${CURRENT_DIR}/src/tx_timer_system_deactivate.c
${CURRENT_DIR}/src/tx_timer_thread_entry.c
${CURRENT_DIR}/src/tx_time_set.c
${CURRENT_DIR}/src/tx_trace_buffer_full_notify.c
${CURRENT_DIR}/src/tx_trace_disable.c
${CURRENT_DIR}/src/tx_trace_enable.c
${CURRENT_DIR}/src/tx_trace_event_filter.c
${CURRENT_DIR}/src/tx_trace_event_unfilter.c
${CURRENT_DIR}/src/tx_trace_initialize.c
${CURRENT_DIR}/src/tx_trace_interrupt_control.c
${CURRENT_DIR}/src/tx_trace_isr_enter_insert.c
${CURRENT_DIR}/src/tx_trace_isr_exit_insert.c
${CURRENT_DIR}/src/tx_trace_object_register.c
${CURRENT_DIR}/src/tx_trace_object_unregister.c
${CURRENT_DIR}/src/tx_trace_user_event_insert.c
${CURRENT_DIR}/src/tx_thread_smp_core_exclude.c
${CURRENT_DIR}/src/tx_thread_smp_core_exclude_get.c
${CURRENT_DIR}/src/tx_thread_smp_current_state_set.c
${CURRENT_DIR}/src/tx_thread_smp_debug_entry_insert.c
${CURRENT_DIR}/src/tx_thread_smp_high_level_initialize.c
${CURRENT_DIR}/src/tx_thread_smp_rebalance_execute_list.c
${CURRENT_DIR}/src/tx_timer_smp_core_exclude.c
${CURRENT_DIR}/src/tx_timer_smp_core_exclude_get.c
# {{END_TARGET_SOURCES}}
)
# Add the Common/inc directory to the project include list
target_include_directories(${PROJECT_NAME}
PUBLIC
${CURRENT_DIR}/inc
)

View File

@@ -0,0 +1,32 @@
set(CURRENT_DIR ${PROJECT_DIR}/ports_smp/linux/gnu)
target_sources(${PROJECT_NAME}
PRIVATE
# {{BEGIN_TARGET_SOURCES}}
${CURRENT_DIR}/src/tx_initialize_low_level.c
${CURRENT_DIR}/src/tx_thread_context_restore.c
${CURRENT_DIR}/src/tx_thread_context_save.c
${CURRENT_DIR}/src/tx_thread_interrupt_control.c
${CURRENT_DIR}/src/tx_thread_schedule.c
${CURRENT_DIR}/src/tx_thread_smp_core_get.c
${CURRENT_DIR}/src/tx_thread_smp_core_preempt.c
${CURRENT_DIR}/src/tx_thread_smp_current_state_get.c
${CURRENT_DIR}/src/tx_thread_smp_current_thread_get.c
${CURRENT_DIR}/src/tx_thread_smp_initialize_wait.c
${CURRENT_DIR}/src/tx_thread_smp_low_level_initialize.c
${CURRENT_DIR}/src/tx_thread_smp_protect.c
${CURRENT_DIR}/src/tx_thread_smp_time_get.c
${CURRENT_DIR}/src/tx_thread_smp_unprotect.c
${CURRENT_DIR}/src/tx_thread_stack_build.c
${CURRENT_DIR}/src/tx_thread_system_return.c
${CURRENT_DIR}/src/tx_timer_interrupt.c
# {{END_TARGET_SOURCES}}
)
target_include_directories(${PROJECT_NAME}
PUBLIC
${CURRENT_DIR}/inc
)
target_compile_definitions(${PROJECT_NAME} PUBLIC "-D_GNU_SOURCE -DTX_LINUX_DEBUG_ENABLE")

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,387 @@
/* This test is designed to test error detection for simple memory block operations. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static TX_BLOCK_POOL pool_0;
static TX_BLOCK_POOL pool_1;
static TX_BLOCK_POOL pool_2;
static CHAR *pointer;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
UINT _txe_block_pool_create(TX_BLOCK_POOL *pool_ptr, CHAR *name_ptr, ULONG block_size,
VOID *pool_start, ULONG pool_size, UINT pool_control_block_size);
/* Prototype for test control return. */
void test_control_return(UINT status);
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_block_memory_error_detection_application_define(void *first_unused_memory)
#endif
{
INT status;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Create block pool 0. */
status = tx_block_pool_create(&pool_0, "pool 0", 100, pointer, 320);
pointer = pointer + 320;
#ifndef TX_DISABLE_ERROR_CHECKING /* skip this test and pretend it passed */
/* Create block pool again to get pool_ptr error. */
status = tx_block_pool_create(&pool_0, "pool 0", 100, pointer, 320);
if (status != TX_POOL_ERROR)
return;
/* Create block pool with NULL pointer. */
status = tx_block_pool_create(TX_NULL, "pool 0", 100, pointer, 320);
if (status != TX_POOL_ERROR)
{
printf("Running Block Memory Error Detection Test........................... ERROR #1\n");
test_control_return(1);
}
/* Create block pool pointer if NULL start. */
status = tx_block_pool_create(&pool_1, "pool 0", 100, NULL, 320);
if (status != TX_PTR_ERROR)
{
printf("Running Block Memory Error Detection Test........................... ERROR #2\n");
test_control_return(1);
}
/* Create block pool pointer with invalid size. */
status = tx_block_pool_create(&pool_1, "pool 0", 100, pointer, 100);
if (status != TX_SIZE_ERROR)
{
printf("Running Block Memory Error Detection Test........................... ERROR #3\n");
test_control_return(1);
}
/* Attempt of allocate block with NULL dest. */
status = tx_block_allocate(&pool_0, (VOID **) TX_NULL, TX_NO_WAIT);
if (status != TX_PTR_ERROR)
{
printf("Running Block Memory Error Detection Test........................... ERROR #4\n");
test_control_return(1);
}
/* Delete null pointer. */
status = tx_block_pool_delete(TX_NULL);
if (status != TX_POOL_ERROR)
{
printf("Running Block Memory Error Detection Test........................... ERROR #5\n");
test_control_return(1);
}
#endif /* TX_DISABLE_ERROR_CHECKING */
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
#ifndef TX_DISABLE_ERROR_CHECKING
UINT status;
CHAR *pointer_1;
CHAR *pointer_2;
CHAR *pointer_3;
CHAR *pointer_4;
INT i;
#endif
/* Inform user. */
printf("Running Block Memory Error Detection Test........................... ");
#ifndef TX_DISABLE_ERROR_CHECKING /* skip this test and pretend it passed */
status = tx_block_pool_create(&pool_1, "pool 1", 100, pointer, 320);
pointer = pointer + 320;
/* Attempt to create a pool with an invalid size. */
status = _txe_block_pool_create(&pool_2, "pool 2", 100, pointer, 320, 777777);
if (status != TX_POOL_ERROR)
{
/* Error! */
printf("ERROR #6\n");
test_control_return(1);
}
/* Allocate with a NULL destination pointer. */
status = tx_block_allocate(&pool_0, (VOID **) TX_NULL, TX_NO_WAIT);
if (status != TX_PTR_ERROR)
{
/* Error! */
printf("ERROR #7\n");
test_control_return(1);
}
/* Allocate with a NULL pool pointer. */
status = tx_block_allocate(TX_NULL, (VOID **) TX_NULL, TX_NO_WAIT);
if (status != TX_POOL_ERROR)
{
/* Error! */
printf("ERROR #8\n");
test_control_return(1);
}
/* Allocate with bad pool pointer. */
pool_2.tx_block_pool_id = 0;
status = tx_block_allocate(&pool_2, (VOID **) TX_NULL, TX_NO_WAIT);
if (status != TX_POOL_ERROR)
{
/* Error! */
printf("ERROR #9\n");
test_control_return(1);
}
/* Release bad pool ptr. */
status = tx_block_release(TX_NULL);
if (status != TX_PTR_ERROR)
{
/* Error! */
printf("ERROR #10\n");
test_control_return(1);
}
/* Allocate first block from the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_1, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Error! */
printf("ERROR #11\n");
test_control_return(1);
}
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_1, (CHAR) 0xEF, 100);
/* Allocate second block from the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_2, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Error! */
printf("ERROR #12\n");
test_control_return(1);
}
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_2, (CHAR) 0xEF, 100);
/* Allocate third block from the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_3, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Error! */
printf("ERROR #13\n");
test_control_return(1);
}
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_3, (CHAR) 0xEF, 100);
/* Attempt to allocate fourth block from the pool. This should fail because
there should be no more blocks in the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_4, TX_NO_WAIT);
/* Check status. */
if (status != TX_NO_MEMORY)
{
/* Error! */
printf("ERROR #14\n");
test_control_return(1);
}
/* Set the memory of all of the allocated blocks. */
for (i =0; i < 100; i++)
{
pointer_1[i] = (CHAR) 0xFF;
pointer_2[i] = (CHAR) 0xFF;
pointer_3[i] = (CHAR) 0xFF;
}
/* Now release each of the blocks. */
status = tx_block_release(pointer_1);
/* Check for status. */
if (status != TX_SUCCESS)
{
/* Error! */
printf("ERROR #15\n");
test_control_return(1);
}
/* Release the second block. */
status = tx_block_release(pointer_2);
/* Check for status. */
if (status != TX_SUCCESS)
{
/* Error! */
printf("ERROR #16\n");
test_control_return(1);
}
/* Release the third block. */
status = tx_block_release(pointer_3);
/* Check for status. */
if (status != TX_SUCCESS)
{
/* Error! */
printf("ERROR #17\n");
test_control_return(1);
}
/* Allocate each block again to make sure everything still
works. The block addresses should come out in reverse
order, because a released block is placed at the head of
the list. */
/* Allocate first block from the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_1, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Error! */
printf("ERROR #18\n");
test_control_return(1);
}
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_1, (CHAR) 0xEF, 100);
/* Allocate second block from the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_2, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Error! */
printf("ERROR #19\n");
test_control_return(1);
}
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_2, (CHAR) 0xEF, 100);
/* Allocate third block from the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_3, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Error! */
printf("ERROR #20\n");
test_control_return(1);
}
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_3, (CHAR) 0xEF, 100);
/* Attempt to allocate fourth block from the pool. This should fail because
there should be no more blocks in the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_4, TX_NO_WAIT);
/* Check status. */
if (status != TX_NO_MEMORY)
{
/* Error! */
printf("ERROR #21\n");
test_control_return(1);
}
/* Delete both block pools. */
status = tx_block_pool_delete(&pool_0);
if (status != TX_SUCCESS)
{
/* Error! */
printf("ERROR #22\n");
test_control_return(1);
}
status = tx_block_pool_delete(&pool_1);
if (status != TX_SUCCESS)
{
/* Error! */
printf("ERROR #23\n");
test_control_return(1);
}
/* Attempt to delete again. */
status = tx_block_pool_delete(&pool_1);
if (status != TX_POOL_ERROR)
{
/* Error! */
printf("ERROR #24\n");
test_control_return(1);
}
thread_0_counter++;
#endif /* TX_DISABLE_ERROR_CHECKING */
/* All is good! */
printf("SUCCESS!\n");
test_control_return(0);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,311 @@
/* This test is designed to test suspension on memory block pools. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
static TX_BLOCK_POOL pool_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_block_memory_suspension_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Block Memory Suspension Test................................ ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Block Memory Suspension Test................................ ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_DONT_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Block Memory Suspension Test................................ ERROR #3\n");
test_control_return(1);
}
/* Create block pool. */
status = tx_block_pool_create(&pool_0, "pool 0", 100, pointer, 320);
pointer = pointer + 320;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Block Memory Suspension Test................................ ERROR #4\n");
test_control_return(1);
}
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer_1;
CHAR *pointer_2;
CHAR *pointer_3;
/* Inform user. */
printf("Running Block Memory Suspension Test................................ ");
/* Increment the run counter. */
thread_0_counter++;
/* Allocate all blocks from the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_1, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Block memory error. */
printf("ERROR #5\n");
test_control_return(1);
}
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_1, (CHAR) 0xEF, 100);
status = tx_block_allocate(&pool_0, (VOID **) &pointer_2, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Block memory error. */
printf("ERROR #6\n");
test_control_return(1);
}
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_2, (CHAR) 0xEF, 100);
/* Get the last block. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_3, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Block memory error. */
printf("ERROR #6\n");
test_control_return(1);
}
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_3, (CHAR) 0xEF, 100);
/* Let the other thread suspend on the pool. */
tx_thread_relinquish();
/* Now release the block to lift the suspension on the other thread. */
status = tx_block_release(pointer_3);
/* Check status and run counter. */
if ((status != TX_SUCCESS) || (thread_1_counter != 0))
{
/* Block memory error. */
printf("ERROR #7\n");
test_control_return(1);
}
/* Let the other thread run again. */
tx_thread_relinquish();
/* Check the run counter of the other thread. */
if (thread_1_counter != 1)
{
/* Block memory error. */
printf("ERROR #8\n");
test_control_return(1);
}
/* At this point the other thread has run and there is one block free. */
/* Get the last block again. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_3, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Block memory error. */
printf("ERROR #9\n");
test_control_return(1);
}
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_3, (CHAR) 0xEF, 100);
/* Resume the second thread. */
tx_thread_resume(&thread_2);
/* Let both threads suspend on the block pool via relinquish. */
tx_thread_relinquish();
/* Now release the block. */
status = tx_block_release(pointer_3);
/* Check status and run counter. */
if ((status != TX_SUCCESS) || (thread_1_counter != 1) || (thread_2_counter != 0))
{
/* Block memory error. */
printf("ERROR #10\n");
test_control_return(1);
}
/* Let thread 1 release the block. */
tx_thread_relinquish();
/* Let thread 2 get the block and release the block. */
tx_thread_relinquish();
/* Check status and run counter. */
if ((thread_1_counter != 3) || (thread_2_counter != 1))
{
/* Block memory error. */
printf("ERROR #11\n");
test_control_return(1);
}
else
{
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer_1;
/* Attempt to get a block from the pool. */
while(1)
{
/* Allocate a block from the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_1, TX_WAIT_FOREVER);
/* Determine if the allocate was successful. */
if (status != TX_SUCCESS)
return;
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_1, (CHAR) 0xEF, 100);
/* Increment the thread counter. */
thread_1_counter++;
/* Release the block. */
tx_block_release(pointer_1);
/* Switch back to other thread. */
tx_thread_relinquish();
}
}
static void thread_2_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer_1;
/* Attempt to get a block from the pool. */
while(1)
{
/* Allocate a block from the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_1, TX_WAIT_FOREVER);
/* Determine if the allocate was successful. */
if (status != TX_SUCCESS)
return;
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_1, (CHAR) 0xEF, 100);
/* Increment the thread counter. */
thread_2_counter++;
/* Release the block. */
tx_block_release(pointer_1);
/* Switch back to other thread. */
tx_thread_relinquish();
}
}

View File

@@ -0,0 +1,212 @@
/* This test is designed to test timeouts on suspension on memory block pools. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
static TX_BLOCK_POOL pool_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_block_memory_suspension_timeout_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Block Memory Suspension Timeout Test........................ ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Block Memory Suspension Timeout Test........................ ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Block Memory Suspension Timeout Test........................ ERROR #3\n");
test_control_return(1);
}
/* Create block pool. */
status = tx_block_pool_create(&pool_0, "pool 0", 100, pointer, 320);
pointer = pointer + 320;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Block Memory Suspension Timeout Test........................ ERROR #4\n");
test_control_return(1);
}
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer_1;
CHAR *pointer_2;
CHAR *pointer_3;
/* Inform user. */
printf("Running Block Memory Suspension Timeout Test........................ ");
/* Allocate all blocks from the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_1, TX_NO_WAIT);
status += tx_block_allocate(&pool_0, (VOID **) &pointer_2, TX_NO_WAIT);
status += tx_block_allocate(&pool_0, (VOID **) &pointer_3, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Block memory error. */
printf("ERROR #5\n");
test_control_return(1);
}
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_1, (CHAR) 0xEF, 100);
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_2, (CHAR) 0xEF, 100);
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_3, (CHAR) 0xEF, 100);
/* Sleep for 64 ticks to allow the other thread 6 timeouts on the block
pool. */
tx_thread_sleep(64);
/* Incrment the run counter. */
thread_0_counter++;
/* Check the counter of the other thread. */
if ((thread_1_counter != 6) || (thread_2_counter != 3))
{
/* Block memory error. */
printf("ERROR #6\n");
test_control_return(1);
}
else
{
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer_1;
/* Attempt to get a block from the pool. */
while(1)
{
/* Allocate a block from the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_1, 10);
/* Determine if the allocate was successful. */
if (status != TX_NO_MEMORY)
return;
/* Increment the thread counter. */
thread_1_counter++;
}
}
static void thread_2_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer_1;
/* Delay so we get some single suspension timeouts as well. */
tx_thread_sleep(32);
/* Attempt to get a block from the pool. */
while(1)
{
/* Allocate a block from the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_1, 10);
/* Determine if the allocate was successful. */
if (status != TX_NO_MEMORY)
return;
/* Increment the thread counter. */
thread_2_counter++;
}
}

View File

@@ -0,0 +1,185 @@
/* This test is designed to test thread termination on a thread suspended on a block
memory pool. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static TX_BLOCK_POOL pool_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_block_memory_thread_terminate_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Block Memory Thread Terminate Test.......................... ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Block Memory Thread Terminate Test.......................... ERROR #2\n");
test_control_return(1);
}
/* Create block pool. */
status = tx_block_pool_create(&pool_0, "pool 0", 100, pointer, 320);
pointer = pointer + 320;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Block Memory Thread Terminate Test.......................... ERROR #3\n");
test_control_return(1);
}
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer_1;
CHAR *pointer_2;
CHAR *pointer_3;
/* Inform user. */
printf("Running Block Memory Thread Terminate Test.......................... ");
/* Allocate all blocks from the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_1, TX_NO_WAIT);
status += tx_block_allocate(&pool_0, (VOID **) &pointer_2, TX_NO_WAIT);
status += tx_block_allocate(&pool_0, (VOID **) &pointer_3, TX_NO_WAIT);
/* Increment the run counter. */
thread_0_counter++;
/* Check status. */
if (status != TX_SUCCESS)
{
/* Block memory error. */
printf("ERROR #4\n");
test_control_return(1);
}
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_1, (CHAR) 0xEF, 100);
TX_MEMSET(pointer_2, (CHAR) 0xEF, 100);
TX_MEMSET(pointer_3, (CHAR) 0xEF, 100);
/* Let other thread suspend on block pool. */
tx_thread_relinquish();
/* Terminate the other thread. */
status = tx_thread_terminate(&thread_1);
/* Check status. */
if ((status != TX_SUCCESS) || (thread_1.tx_thread_state != TX_TERMINATED) ||
(thread_1_counter != 0))
{
/* Block memory error. */
printf("ERROR #5\n");
test_control_return(1);
}
/* Release all the blocks. */
status = tx_block_release(pointer_1);
status += tx_block_release(pointer_2);
status += tx_block_release(pointer_3);
/* Check status. */
if ((status != TX_SUCCESS) || (thread_1.tx_thread_state != TX_TERMINATED) ||
(thread_1_counter != 0))
{
/* Block memory error. */
printf("ERROR #6\n");
test_control_return(1);
}
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer_1;
/* Attempt to get a block from the pool. */
while(1)
{
/* Allocate a block from the pool. */
status = tx_block_allocate(&pool_0, (VOID **) &pointer_1, 10);
/* Determine if the allocate was successful. */
if (status != TX_NO_MEMORY)
return;
/* Set all the memory of the blocks. */
TX_MEMSET(pointer_1, (CHAR) 0xEF, 100);
/* Increment the thread counter. */
thread_1_counter++;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,498 @@
/* This test is designed to test byte memory prioritize. */
#include <stdio.h>
#include "tx_api.h"
/* Define the ISR dispatch. */
extern VOID (*test_isr_dispatch)(void);
/* Define the external reference for the preempt disable flag. */
extern volatile UINT _tx_thread_preempt_disable;
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
static unsigned long thread_3_counter = 0;
static TX_THREAD thread_3;
static unsigned long thread_4_counter = 0;
static TX_THREAD thread_4;
static unsigned long thread_5_counter = 0;
static TX_THREAD thread_5;
static unsigned long thread_6_counter = 0;
static TX_THREAD thread_6;
static TX_BYTE_POOL byte_pool_0;
static TX_BYTE_POOL byte_pool_1;
static int test_status;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
static void thread_3_entry(ULONG thread_input);
static void thread_4_entry(ULONG thread_input);
static void thread_5_entry(ULONG thread_input);
static void thread_6_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
/* Define the ISR dispatch routine. */
static void test_isr(void)
{
/* Determine if the test case we are looking for is present. */
if ((_tx_thread_preempt_disable) && (test_status == 1))
{
/* Determine if thread 3 is at the front of the suspension list. */
if (byte_pool_0.tx_byte_pool_suspension_list == &thread_3)
{
/* Abort the wait of thread 3. */
tx_thread_wait_abort(&thread_3);
}
else
{
/* Abort the wait of thread 5. */
tx_thread_wait_abort(&thread_5);
/* End the ISR processing. */
test_status = 2;
test_isr_dispatch = TX_NULL;
}
}
}
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_byte_memory_prioritize_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Prioritize Test................................. ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_DONT_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Prioritize Test................................. ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,
pointer, TEST_STACK_SIZE_PRINTF,
15, 15, 100, TX_DONT_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Prioritize Test................................. ERROR #3\n");
test_control_return(1);
}
status = tx_thread_create(&thread_3, "thread 3", thread_3_entry, 3,
pointer, TEST_STACK_SIZE_PRINTF,
3, 3, 100, TX_DONT_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Prioritize Test................................. ERROR #4\n");
test_control_return(1);
}
status = tx_thread_create(&thread_4, "thread 4", thread_4_entry, 4,
pointer, TEST_STACK_SIZE_PRINTF,
4, 4, 100, TX_DONT_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Prioritize Test................................. ERROR #5\n");
test_control_return(1);
}
status = tx_thread_create(&thread_5, "thread 5", thread_5_entry, 5,
pointer, TEST_STACK_SIZE_PRINTF,
5, 5, 100, TX_DONT_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Prioritize Test................................. ERROR #6\n");
test_control_return(1);
}
status = tx_thread_create(&thread_6, "thread 6", thread_6_entry, 6,
pointer, TEST_STACK_SIZE_PRINTF,
6, 6, 100, TX_DONT_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Prioritize Test................................. ERROR #7\n");
test_control_return(1);
}
/* Create the byte_pool with one byte. */
status = tx_byte_pool_create(&byte_pool_0, "byte_pool 0", pointer, 100);
pointer = pointer + 100;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Prioritize Test................................. ERROR #8\n");
test_control_return(1);
}
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
VOID *pointer;
/* Inform user. */
printf("Running Byte Memory Prioritize Test................................. ");
/* Allocate the one byte. */
tx_byte_allocate(&byte_pool_0, &pointer, 80, TX_NO_WAIT);
#ifndef TX_DISABLE_ERROR_CHECKING
/* Call byte pool prioritize with a NULL pointer. */
status = tx_byte_pool_prioritize(TX_NULL);
/* Check for error. */
if (status != TX_POOL_ERROR)
{
/* Byte Pool error. */
printf("ERROR #9\n");
test_control_return(1);
}
/* Call byte pool info with an non-created pool pointer. */
byte_pool_1.tx_byte_pool_id = 0;
status = tx_byte_pool_prioritize(&byte_pool_1);
/* Check for error. */
if (status != TX_POOL_ERROR)
{
/* Byte Pool error. */
printf("ERROR #10\n");
test_control_return(1);
}
#endif
/* Nothing to do here, but check prioritization with no suspended threads. */
status = tx_byte_pool_prioritize(&byte_pool_0);
/* Check status and make sure thread 1 is terminated. */
if (status != TX_SUCCESS)
{
/* Byte Pool error. */
printf("ERROR #11\n");
test_control_return(1);
}
tx_thread_resume(&thread_1);
tx_thread_resume(&thread_2);
/* Increment the thread counter. */
thread_0_counter++;
/* Make sure thread 1 and 2 are suspended on the byte_pool. */
if ((thread_1.tx_thread_state != TX_BYTE_MEMORY) || (thread_2.tx_thread_state != TX_BYTE_MEMORY) ||
(byte_pool_0.tx_byte_pool_suspension_list != &thread_1))
{
/* Byte Pool error. */
printf("ERROR #12\n");
test_control_return(1);
}
/* Prioritize the byte pool suspension list. */
status = tx_byte_pool_prioritize(&byte_pool_0);
/* Check status and make sure thread 2 is now at the front of the suspension list. */
if ((status != TX_SUCCESS) || (byte_pool_0.tx_byte_pool_suspension_list != &thread_2))
{
/* Byte Pool error. */
printf("ERROR #13\n");
test_control_return(1);
}
/* Call byte pool prioritize again to test the don't-do-anything path in tx_byte_pool_prioritize. */
status += tx_byte_pool_prioritize(&byte_pool_0);
/* At this point we are going to get more than 2 threads suspended. */
tx_thread_resume(&thread_1);
tx_thread_resume(&thread_2);
tx_thread_resume(&thread_3);
tx_thread_resume(&thread_4);
tx_thread_resume(&thread_5);
tx_thread_resume(&thread_6);
/* Prioritize the byte pool suspension list. */
status = tx_byte_pool_prioritize(&byte_pool_0);
/* Check status and make sure thread 3 is now at the front of the suspension list. */
if ((status != TX_SUCCESS) || (byte_pool_0.tx_byte_pool_suspension_list != &thread_3))
{
/* Byte Pool error. */
printf("ERROR #14\n");
test_control_return(1);
}
/* Now loop to test the interrupt of the prioritize loop logic. */
test_status = 1;
test_isr_dispatch = test_isr;
do
{
/* Prioritize the byte pool suspension list. */
status = tx_byte_pool_prioritize(&byte_pool_0);
/* Check status and make sure thread 1 is terminated. */
if (status != TX_SUCCESS)
{
/* Block Pool error. */
printf("ERROR #15\n");
test_control_return(1);
}
} while (test_status == 1);
/* Check status and make sure thread 3 is now at the front of the suspension list. */
if ((status != TX_SUCCESS) || (byte_pool_0.tx_byte_pool_suspension_list != &thread_4))
{
/* Byte Pool error. */
printf("ERROR #16\n");
test_control_return(1);
}
else
{
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
VOID *pointer;
/* Loop forever! */
while(1)
{
/* Get byte from pool. */
status = tx_byte_allocate(&byte_pool_0, &pointer, 25, TX_WAIT_FOREVER);
if (status != TX_SUCCESS)
break;
/* Increment the thread counter. */
thread_1_counter++;
}
}
static void thread_2_entry(ULONG thread_input)
{
UINT status;
VOID *pointer;
/* Loop forever! */
while(1)
{
/* Get byte from pool. */
status = tx_byte_allocate(&byte_pool_0, &pointer, 25, TX_WAIT_FOREVER);
if (status != TX_SUCCESS)
break;
/* Increment the thread counter. */
thread_2_counter++;
}
}
static void thread_3_entry(ULONG thread_input)
{
UINT status;
VOID *pointer;
/* Loop forever! */
while(1)
{
/* Get byte from pool. */
status = tx_byte_allocate(&byte_pool_0, &pointer, 25, TX_WAIT_FOREVER);
if (status != TX_SUCCESS)
break;
/* Increment the thread counter. */
thread_3_counter++;
}
}
static void thread_4_entry(ULONG thread_input)
{
UINT status;
VOID *pointer;
/* Loop forever! */
while(1)
{
/* Get byte from pool. */
status = tx_byte_allocate(&byte_pool_0, &pointer, 25, TX_WAIT_FOREVER);
if (status != TX_SUCCESS)
break;
/* Increment the thread counter. */
thread_4_counter++;
}
}
static void thread_5_entry(ULONG thread_input)
{
UINT status;
VOID *pointer;
/* Loop forever! */
while(1)
{
/* Get byte from pool. */
status = tx_byte_allocate(&byte_pool_0, &pointer, 25, TX_WAIT_FOREVER);
if (status != TX_SUCCESS)
break;
/* Increment the thread counter. */
thread_5_counter++;
}
}
static void thread_6_entry(ULONG thread_input)
{
UINT status;
VOID *pointer;
/* Loop forever! */
while(1)
{
/* Get byte from pool. */
status = tx_byte_allocate(&byte_pool_0, &pointer, 25, TX_WAIT_FOREVER);
if (status != TX_SUCCESS)
break;
/* Increment the thread counter. */
thread_6_counter++;
}
}

View File

@@ -0,0 +1,391 @@
/* This test is designed to test suspension on a memory byte pool. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
static unsigned long thread_3_counter = 0;
static TX_THREAD thread_3;
static TX_BYTE_POOL pool_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
static void thread_3_entry(ULONG thread_input);
#ifndef TX_MANUAL_TEST
/* Define test flags for automated test. */
extern TEST_FLAG threadx_byte_allocate_loop_test;
extern TEST_FLAG threadx_byte_release_loop_test;
#endif
void abort_and_resume_byte_allocating_thread(void)
{
UCHAR *search_ptr;
/* Adjust the search pointer to avoid the search pointer change for this test. */
search_ptr = pool_0.tx_byte_pool_search;
while (search_ptr >= pool_0.tx_byte_pool_search)
{
search_ptr = *((UCHAR **) ((VOID *) search_ptr));
}
pool_0.tx_byte_pool_search = search_ptr;
tx_thread_wait_abort(&thread_3);
tx_thread_resume(&thread_3);
}
/* Prototype for test control return. */
void test_control_return(UINT status);
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_byte_memory_suspension_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Suspension Test................................. ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Suspension Test................................. ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_DONT_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
status += tx_thread_create(&thread_3, "thread 3", thread_3_entry, 3,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_DONT_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Suspension Test................................. ERROR #3\n");
test_control_return(1);
}
/* Create byte pool 0. */
status = tx_byte_pool_create(&pool_0, "pool 0", pointer, 108);
pointer = pointer + 108;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Suspension Test................................. ERROR #4\n");
test_control_return(1);
}
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer;
/* Inform user. */
printf("Running Byte Memory Suspension Test................................. ");
/* Increment the thread counter. */
thread_0_counter++;
/* Allocate memory from the pool. Only one block of this size will fit. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 60, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Byte memory error. */
printf("ERROR #5\n");
test_control_return(1);
}
/* Let other thread suspend on byte pool. */
tx_thread_relinquish();
/* Now release the blocks. */
status = tx_byte_release(pointer);
/* Check status. */
if ((status != TX_SUCCESS) && (thread_1_counter == 0))
{
/* Byte memory error. */
printf("ERROR #6\n");
test_control_return(1);
}
/* Let other thread run again. */
tx_thread_relinquish();
/* Check to make sure thread 1 has now run. */
if (thread_1_counter != 1)
{
/* Byte memory error. */
printf("ERROR #7\n");
test_control_return(1);
}
/* Now allocate the memory again. Only one block of this size will fit. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 60, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Byte memory error. */
printf("ERROR #8\n");
test_control_return(1);
}
/* Resume the second thread. */
tx_thread_resume(&thread_2);
/* Now relinquish to let both thread 1 and 2 suspend. */
tx_thread_relinquish();
/* At this point both threads should be suspended on the byte pool. */
/* Release the memory again. */
status = tx_byte_release(pointer);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Byte memory error. */
printf("ERROR #9\n");
test_control_return(1);
}
/* Now relinquish to get the other threads to run once. */
tx_thread_relinquish();
tx_thread_relinquish();
/* At this point both threads 1 and 2 are suspended on the byte pool again. */
if ((thread_1_counter != 3) && (thread_2_counter != 1))
{
/* Byte memory error. */
printf("ERROR #10\n");
test_control_return(1);
}
/* Now allocate the memory again. Only one block of this size will fit. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 60, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Byte memory error. */
printf("ERROR #10a\n");
test_control_return(1);
}
/* Resume thread 3 to get it suspended on the the pool. */
tx_thread_resume(&thread_3);
#ifdef TX_MANUAL_TEST
/* Set BP hear. Now release the memory and step into the code. After byte search issue IRQ2 mannually, which will
make thread 3 abort the first request and make another request of a different size. This is the path we are trying
to generate in the test. */
status = tx_byte_release(pointer);
#else
/* Set the flag that will make thread 3 abort the first request and make another request of a different size. This tests the memory size change path
in the byte release loop logic. */
threadx_byte_release_loop_test = 1;
status = tx_byte_release(pointer);
#endif
/* Check status. */
if (status != TX_SUCCESS)
{
/* Byte memory error. */
printf("ERROR #10b\n");
test_control_return(1);
}
else
{
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer;
while(1)
{
/* Allocate memory from the pool. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 60, TX_WAIT_FOREVER);
/* Check status. */
if (status != TX_SUCCESS)
return;
/* Increment the thread counter. */
thread_1_counter++;
/* Now release each of the blocks. */
status = tx_byte_release(pointer);
/* Check for status. */
if (status != TX_SUCCESS)
return;
/* Let thread 0 run again. */
tx_thread_relinquish();
}
}
static void thread_2_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer;
while(1)
{
/* Allocate memory from the pool. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 60, TX_WAIT_FOREVER);
/* Check status. */
if (status != TX_SUCCESS)
return;
/* Increment the thread counter. */
thread_2_counter++;
/* Now release each of the blocks. */
status = tx_byte_release(pointer);
/* Check for status. */
if (status != TX_SUCCESS)
return;
/* Let thread 0 run again. */
tx_thread_relinquish();
}
}
static void thread_3_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer;
while (1)
{
/* Allocate memory from the pool. */
tx_byte_allocate(&pool_0, (VOID **) &pointer, 60, TX_WAIT_FOREVER);
#ifdef TX_MANUAL_TEST
/* Set BP here and manually clear the owner after one failed byte search just to test the loop
construct in tx_byte_allocate.c. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 90, TX_WAIT_FOREVER);
#else
/* Set the flag that clears the pool owner after one failed byte search to test the loop
construct processing in tx_byte_allocate.c. */
threadx_byte_allocate_loop_test = 1;
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 90, TX_WAIT_FOREVER);
#endif
/* Check for status. */
if (status != TX_SUCCESS)
return;
/* Increment the thread counter. */
thread_3_counter++;
/* Now release the block. */
status = tx_byte_release(pointer);
/* Check for status. */
if (status != TX_SUCCESS)
return;
/* suspend this thread. */
tx_thread_suspend(&thread_3);
}
}

View File

@@ -0,0 +1,196 @@
/* This test is designed to test suspension timeout on a memory byte pool. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
static TX_BYTE_POOL pool_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_byte_memory_suspension_timeout_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Suspension Timeout Test......................... ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Suspension Timeout Test......................... ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Suspension Timeout Test......................... ERROR #3\n");
test_control_return(1);
}
/* Create byte pool 0. */
status = tx_byte_pool_create(&pool_0, "pool 0", pointer, 108);
pointer = pointer + 108;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Suspension Timeout Test......................... ERROR #4\n");
test_control_return(1);
}
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer;
/* Inform user. */
printf("Running Byte Memory Suspension Timeout Test......................... ");
/* Increment the thread counter. */
thread_0_counter++;
/* Allocate memory from the pool. Only one block of this size will fit. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 60, TX_NO_WAIT);
/* Check status. */
if ((status != TX_SUCCESS) || (thread_1_counter != 0))
{
/* Byte memory error. */
printf("ERROR #5\n");
test_control_return(1);
}
/* Sleep to allow the other thread to suspend and timeout on the memory
pool once. */
tx_thread_sleep(64);
/* Check the counter of the other thread. */
if ((thread_1_counter != 6) || (thread_2_counter != 3))
{
/* Block memory error. */
printf("ERROR #6\n");
test_control_return(1);
}
else
{
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer;
while(1)
{
/* Allocate memory from the pool - with timeout. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 60, 10);
/* Check status. */
if (status != TX_NO_MEMORY)
return;
/* Increment the thread counter. */
thread_1_counter++;
}
}
static void thread_2_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer;
/* Delay so we get some single suspension timeouts as well. */
tx_thread_sleep(32);
while(1)
{
/* Allocate memory from the pool - with timeout. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 60, 10);
/* Check status. */
if (status != TX_NO_MEMORY)
return;
/* Increment the thread counter. */
thread_2_counter++;
}
}

View File

@@ -0,0 +1,255 @@
/* This test is designed to test contention of two threads on a single
memory byte pool. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
static unsigned long initial_pool_size;
static TX_BYTE_POOL pool_0;
static int test_done;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_byte_memory_thread_contention_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 1, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Thread Contention Test.......................... ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 1, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Thread Contention Test.......................... ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 1, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Thread Contention Test.......................... ERROR #3\n");
test_control_return(1);
}
/* Create byte pool 0. */
status = tx_byte_pool_create(&pool_0, "pool 0", pointer, 108);
pointer = pointer + 108;
/* Save off the intial pool size. */
initial_pool_size = pool_0.tx_byte_pool_available;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Thread Contention Test.......................... ERROR #4\n");
test_control_return(1);
}
/* Set the test done flag to false. */
test_done = TX_FALSE;
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer;
/* Inform user. */
printf("Running Byte Memory Thread Contention Test.......................... ");
/* Set time to 0. */
tx_time_set(0);
while(1)
{
/* Allocate memory from the pool. This size will cause merge activity
because the search pointer will sit in this large block about half
the time. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 60, TX_WAIT_FOREVER);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Byte memory error. */
printf("ERROR #5\n");
test_control_return(1);
}
/* Fill the memory. */
TX_MEMSET(pointer, (CHAR) 0xEF, 60);
/* Now release the block. */
status = tx_byte_release(pointer);
/* Check for status. */
if (status != TX_SUCCESS)
{
/* Byte memory error. */
printf("ERROR #6\n");
test_control_return(1);
}
/* Check the time. */
if (tx_time_get() > 1280)
break;
/* Increment the thread counter. */
thread_0_counter++;
}
/* Set the done flag. */
test_done = TX_TRUE;
/* Sleep to let the other threads finish up! */
tx_thread_sleep(2);
/* Determine if we all all the original memory and that thread 1
is in the proper place. */
if (pool_0.tx_byte_pool_available != initial_pool_size)
{
/* Byte memory error. */
printf("ERROR #7\n");
test_control_return(1);
}
else
{
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer;
while(test_done == TX_FALSE)
{
/* Allocate memory from the pool. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 30, TX_WAIT_FOREVER);
/* Check status. */
if (status != TX_SUCCESS)
return;
/* Fill the memory. */
TX_MEMSET(pointer, (CHAR) 0xEF, 30);
/* Now release the block. */
status = tx_byte_release(pointer);
/* Check for status. */
if (status != TX_SUCCESS)
return;
/* Increment the thread counter. */
thread_1_counter++;
}
}
static void thread_2_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer;
while(test_done == TX_FALSE)
{
/* Allocate memory from the pool. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 12, TX_WAIT_FOREVER);
/* Check status. */
if (status != TX_SUCCESS)
return;
/* Fill the memory. */
TX_MEMSET(pointer, (CHAR) 0xEF, 12);
/* Now release the block. */
status = tx_byte_release(pointer);
/* Check for status. */
if (status != TX_SUCCESS)
return;
/* Increment the thread counter. */
thread_2_counter++;
}
}

View File

@@ -0,0 +1,177 @@
/* This test is designed to test termination on thread suspended on memory byte pool. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static TX_BYTE_POOL pool_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_byte_memory_thread_terminate_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Thread Terminate Test........................... ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Thread Terminate Test........................... ERROR #2\n");
test_control_return(1);
}
/* Create byte pools 0 and 1. */
status = tx_byte_pool_create(&pool_0, "pool 0", pointer, 108);
pointer = pointer + 108;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Byte Memory Thread Terminate Test........................... ERROR #3\n");
test_control_return(1);
}
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer;
/* Inform user. */
printf("Running Byte Memory Thread Terminate Test........................... ");
/* Increment the thread counter. */
thread_0_counter++;
/* Allocate memory from the pool. Only one block of this size will fit. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 60, TX_NO_WAIT);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Byte memory error. */
printf("ERROR #4\n");
test_control_return(1);
}
/* Let other thread suspend on byte pool. */
tx_thread_relinquish();
/* Terminate the other thread. */
status = tx_thread_terminate(&thread_1);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Byte memory error. */
printf("ERROR #5\n");
test_control_return(1);
}
/* Release block back. */
status = tx_byte_release(pointer);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Byte memory error. */
printf("ERROR #6\n");
test_control_return(1);
}
/* Allocate memory from the pool. Only one block of this size will fit. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 60, TX_NO_WAIT);
/* Check status. */
if ((status != TX_SUCCESS) || (thread_1_counter != 0))
{
/* Byte memory error. */
printf("ERROR #7\n");
test_control_return(1);
}
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
CHAR *pointer;
while(1)
{
/* Allocate memory from the pool. */
status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 60, TX_WAIT_FOREVER);
/* Should never get here! */
if (status != TX_NO_MEMORY)
return;
/* Increment the thread counter. */
thread_1_counter++;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,358 @@
/* This test is designed to test for simultaneous thread event flag set AND ISR event flag set and clear. */
#include <stdio.h>
#include "tx_api.h"
#include "tx_thread.h"
#include "tx_timer.h"
/* Define the ISR dispatch. */
extern VOID (*test_isr_dispatch)(void);
/* Prototype for test control return. */
void test_control_return(UINT status);
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
static unsigned long timer_0_counter = 0;
static TX_TIMER timer_0;
static unsigned long event_flags_set_counter = 0;
static unsigned long condition_count = 0;
static TX_EVENT_FLAGS_GROUP event_flags_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
static void timer_0_entry(ULONG timer_input);
static void event_set_notify(TX_EVENT_FLAGS_GROUP *group)
{
/* Not necessary to do anything in this function. */
}
static void test_isr(void)
{
UINT status;
ULONG actual;
static volatile UINT miss_count = 0;
/* Determine if the interrupt occurred when the preempt disable flag was set. */
if (_tx_thread_preempt_disable)
{
/* Yes this is the condition we are looking for, increment the test condition counter. */
condition_count++;
}
/*
It is possible for this test to get into a resonance condition in which
the ISR never occurs while preemption is disabled (especially if the
ISR is installed in the periodic timer interrupt handler, which is
conveniently available). Detect this condition and break out of it by
perturbing the duration of this ISR a pseudo-random amount of time.
*/
else if (++miss_count > 100)
{
for (miss_count = _tx_timer_system_clock % 100; miss_count != 0; --miss_count);
}
if (((event_flags_0.tx_event_flags_group_current & 0x3) == 0) &&
(event_flags_0.tx_event_flags_group_suspended_count == 2))
{
/* Put the event_flags to wakeup thread 0. */
status = tx_event_flags_set(&event_flags_0, 0x3, TX_OR);
/* Clear the same flags immediately. */
status += tx_event_flags_set(&event_flags_0, 0xFFFFFFFC, TX_AND);
/* Setup some event flags just so we can clear them. */
status += tx_event_flags_set(&event_flags_0, 0x30000, TX_OR);
/* Clear the same flags immediately. */
status += tx_event_flags_set(&event_flags_0, 0xFFFEFFFF, TX_AND);
/* Clear the same flags immediately. */
status += tx_event_flags_set(&event_flags_0, 0xFFFDFFFC, TX_AND);
/* Check for an error. */
if (status)
return;
/* Get the events from an ISR. */
status = tx_event_flags_get(&event_flags_0, 0x30000, TX_OR, &actual, TX_NO_WAIT);
/* Check to make sure this results in an error. */
if (status != TX_NO_EVENTS)
return;
/* Do a set and a get consume from an ISR. */
status = tx_event_flags_set(&event_flags_0, 0x000000C0, TX_OR);
status += tx_event_flags_get(&event_flags_0, 0x00000080, TX_OR, &actual, TX_NO_WAIT);
status += tx_event_flags_get(&event_flags_0, 0x000000C0, TX_OR_CLEAR, &actual, TX_NO_WAIT);
/* Increment the event_flags counter. */
if ((status == TX_SUCCESS) && (actual == 0xC4))
{
event_flags_set_counter++;
}
}
}
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_event_flag_isr_set_clear_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Set/Clear from ISR Test.......................... ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Set/Clear from ISR Test.......................... ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Set/Clear from ISR Test.......................... ERROR #3\n");
test_control_return(1);
}
/* Create event flags group. */
status = tx_event_flags_create(&event_flags_0, "event_flags 0");
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Set/Clear from ISR Test.......................... ERROR #4\n");
test_control_return(1);
}
/* Create a timer to ensure a context save is called for every interrupt. */
status = tx_timer_create(&timer_0, "timer 0", timer_0_entry, 0, 1, 1, TX_AUTO_ACTIVATE);
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Set/Clear from ISR Test.......................... ERROR #5\n");
test_control_return(1);
}
/* Register the event set notify function. */
status = tx_event_flags_set_notify(&event_flags_0, event_set_notify);
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Set/Clear from ISR Test.......................... ERROR #6\n");
test_control_return(1);
}
#else
/* Check status. */
if (status != TX_FEATURE_NOT_ENABLED)
{
printf("Running Event Flag Set/Clear from ISR Test.......................... ERROR #7\n");
test_control_return(1);
}
#endif
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
ULONG actual;
/* Inform user. */
printf("Running Event Flag Set/Clear from ISR Test.......................... ");
/* Setup the test ISR. */
test_isr_dispatch = test_isr;
/* Loop to exploit the probability window inside tx_event_flags_set call. */
while (condition_count < 40)
{
/* Suspend on the event_flags that is going to be set via the ISR. */
status = tx_event_flags_get(&event_flags_0, 2, TX_OR_CLEAR, &actual, 4);
/* Determine if we have an unexpected result. */
if (status != TX_SUCCESS)
{
/* Test error! */
printf("ERROR #8\n");
test_control_return(1);
}
/* Check for the preempt disable flag being set. */
if (_tx_thread_preempt_disable)
{
/* Test error! */
printf("ERROR #9\n");
test_control_return(2);
}
/* Determine if we really got the event_flags. */
if (status == TX_SUCCESS)
{
/* Increment the thread count. */
thread_0_counter++;
}
}
/* Setup the test ISR. */
test_isr_dispatch = TX_NULL;
/* Let the other threads run once more... */
tx_thread_relinquish();
/* At this point, check to see if we got all the event_flagss! */
if ((thread_0_counter != event_flags_set_counter) ||
(thread_1_counter != event_flags_set_counter))
{
/* Test error! */
printf("ERROR #10\n");
test_control_return(3);
}
else
{
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
ULONG actual;
/* Loop to exploit the probability window inside tx_event_flags_set call. */
while (1)
{
/* Suspend on the event_flags that is going to be set via the ISR. */
status = tx_event_flags_get(&event_flags_0, 1, TX_OR_CLEAR, &actual, 4);
/* Determine if we have an unexpected result. */
if (status != TX_SUCCESS)
{
break;
}
/* Increment this thread's counter. */
thread_1_counter++;
}
}
static void thread_2_entry(ULONG thread_input)
{
/* Loop forever! */
while(1)
{
/* Set event flags - not the one needed by threads 0 and 1. */
tx_event_flags_set(&event_flags_0, 0x4, TX_OR);
/* Increment the thread counter. */
thread_2_counter++;
/* Let thread 0 run again! */
tx_thread_relinquish();
}
}
static void timer_0_entry(ULONG input)
{
timer_0_counter++;
}

View File

@@ -0,0 +1,330 @@
/* This test is designed to test for wait abort from an ISR. */
#include <stdio.h>
#include "tx_api.h"
#include "tx_thread.h"
#include "tx_timer.h"
/* Define the ISR dispatch. */
extern VOID (*test_isr_dispatch)(void);
/* Prototype for test control return. */
void test_control_return(UINT status);
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
static unsigned long timer_0_counter = 0;
static TX_TIMER timer_0;
static unsigned long event_flags_wait_abort_counter = 0;
static unsigned long condition_count = 0;
static TX_EVENT_FLAGS_GROUP event_flags_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
static void timer_0_entry(ULONG timer_input);
static void event_set_notify(TX_EVENT_FLAGS_GROUP *group)
{
/* Not necessary to do anything in this function. */
}
static void test_isr(void)
{
UINT status;
static volatile UINT miss_count = 0;
/* Determine if the interrupt occurred when the preempt disable flag was set. */
if (_tx_thread_preempt_disable)
{
/* Yes this is the condition we are looking for, increment the test condition counter. */
condition_count++;
}
/*
It is possible for this test to get into a resonance condition in which
the ISR never occurs while preemption is disabled (especially if the
ISR is installed in the periodic timer interrupt handler, which is
conveniently available). Detect this condition and break out of it by
perturbing the duration of this ISR a pseudo-random amount of time.
*/
else if (++miss_count > 100)
{
for (miss_count = _tx_timer_system_clock % 100; miss_count != 0; --miss_count);
}
if (((event_flags_0.tx_event_flags_group_current & 0x3) == 0) &&
(event_flags_0.tx_event_flags_group_suspended_count == 2))
{
/* Set event flags - not the one needed by threads 0 and 1. */
status = tx_event_flags_set(&event_flags_0, 0x4, TX_OR);
/* Abort the threads 1 and 2. */
status += tx_thread_wait_abort(&thread_0);
status += tx_thread_wait_abort(&thread_1);
if (status == TX_SUCCESS)
{
event_flags_wait_abort_counter++;
}
}
}
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_event_flag_isr_wait_abort_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Wait Abort from ISR Test......................... ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Wait Abort from ISR Test......................... ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Wait Abort from ISR Test......................... ERROR #3\n");
test_control_return(1);
}
/* Create event flags group. */
status = tx_event_flags_create(&event_flags_0, "event_flags 0");
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Wait Abort from ISR Test......................... ERROR #4\n");
test_control_return(1);
}
/* Create a timer to ensure a context save is called for every interrupt. */
status = tx_timer_create(&timer_0, "timer 0", timer_0_entry, 0, 1, 1, TX_AUTO_ACTIVATE);
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Wait Abort from ISR Test......................... ERROR #5\n");
test_control_return(1);
}
/* Register the event set notify function. */
status = tx_event_flags_set_notify(&event_flags_0, event_set_notify);
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Wait Abort from ISR Test......................... ERROR #6\n");
test_control_return(1);
}
#else
/* Check status. */
if (status != TX_FEATURE_NOT_ENABLED)
{
printf("Running Event Flag Wait Abort from ISR Test......................... ERROR #7\n");
test_control_return(1);
}
#endif
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
ULONG actual;
/* Inform user. */
printf("Running Event Flag Wait Abort from ISR Test......................... ");
/* Setup the test ISR. */
test_isr_dispatch = test_isr;
/* Loop to exploit the probability window inside tx_event_flags_set call. */
while (condition_count < 40)
{
/* Suspend on the event_flags that is going to be set via the ISR. */
status = tx_event_flags_get(&event_flags_0, 2, TX_OR_CLEAR, &actual, 4);
/* Determine if we have an unexpected result. */
if (status != TX_WAIT_ABORTED)
{
/* Test error! */
printf("ERROR #8\n");
test_control_return(1);
}
/* Check for the preempt disable flag being set. */
if (_tx_thread_preempt_disable)
{
/* Test error! */
printf("ERROR #9\n");
test_control_return(2);
}
/* Determine if we really got the event_flags. */
if (status == TX_WAIT_ABORTED)
{
/* Increment the thread count. */
thread_0_counter++;
}
}
/* Setup the test ISR. */
test_isr_dispatch = TX_NULL;
/* Let the other threads run once more... */
tx_thread_relinquish();
/* At this point, check to see if we got all the event_flagss! */
if ((thread_0_counter != event_flags_wait_abort_counter) ||
(thread_1_counter != event_flags_wait_abort_counter))
{
/* Test error! */
printf("ERROR #10\n");
test_control_return(3);
}
else
{
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
ULONG actual;
/* Loop to exploit the probability window inside tx_event_flags_set call. */
while (1)
{
/* Suspend on the event_flags that is going to be set via the ISR. */
status = tx_event_flags_get(&event_flags_0, 1, TX_OR_CLEAR, &actual, 4);
/* Determine if we have an unexpected result. */
if (status != TX_WAIT_ABORTED)
{
break;
}
/* Increment this thread's counter. */
thread_1_counter++;
}
}
static void thread_2_entry(ULONG thread_input)
{
/* Loop forever! */
while(1)
{
/* Set event flags - not the one needed by threads 0 and 1. */
tx_event_flags_set(&event_flags_0, 0x4, TX_OR);
/* Increment the thread counter. */
thread_2_counter++;
/* Let thread 0 run again! */
tx_thread_relinquish();
}
}
static void timer_0_entry(ULONG input)
{
timer_0_counter++;
}

View File

@@ -0,0 +1,331 @@
/* This test is designed to test event flag suspension with a single suspended thread
being terminated at the same priority level. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
extern UINT _tx_thread_preempt_disable;
static TX_EVENT_FLAGS_GROUP group_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
static void event_set_notify(TX_EVENT_FLAGS_GROUP *group)
{
/* Not necessary to do anything in this function. */
}
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_event_flag_single_thread_terminate_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Single Thread Terminate Test..................... ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
18, 18, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Single Thread Terminate Test..................... ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
18, 18, 100, TX_DONT_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Single Thread Terminate Test..................... ERROR #3\n");
test_control_return(1);
}
/* Create event flag group 0. */
status = tx_event_flags_create(&group_0, "group 0");
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Single Thread Terminate Test..................... ERROR #4\n");
test_control_return(1);
}
/* Register the event set notify function. */
status = tx_event_flags_set_notify(&group_0, event_set_notify);
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Single Thread Terminate Test..................... ERROR #5\n");
test_control_return(1);
}
#else
/* Check status. */
if (status != TX_FEATURE_NOT_ENABLED)
{
printf("Running Event Flag Single Thread Terminate Test..................... ERROR #6\n");
test_control_return(1);
}
#endif
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
/* Inform user. */
printf("Running Event Flag Single Thread Terminate Test..................... ");
/* Increment run counter. */
thread_0_counter++;
/* Sleep to allow lower-priority thread 1 to run. */
tx_thread_sleep(5);
/* Resume Thread 2. */
status = tx_thread_resume(&thread_2);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Event flag error. */
printf("ERROR #7\n");
test_control_return(1);
}
/* Now terminate thread 1. */
status = tx_thread_terminate(&thread_1);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Event flag error. */
printf("ERROR #8\n");
test_control_return(1);
}
/* Now sleep to allow Thread 2 to run. */
tx_thread_sleep(5);
/* Set only one of the event flags needed. */
status = tx_event_flags_set(&group_0, 0x00080000, TX_OR);
/* Now sleep to allow thread 2 to run. */
tx_thread_sleep(5);
/* Check status. */
if ((status != TX_SUCCESS) && (thread_2_counter != 1))
{
/* Event flag error. */
printf("ERROR #9\n");
test_control_return(1);
}
/* Set the other event flag needed. */
status = tx_event_flags_set(&group_0, 0x00800000, TX_OR);
/* Now sleep to allow thread 2 to run. */
tx_thread_sleep(5);
/* Check status. */
if ((status != TX_SUCCESS) && (thread_2_counter != 2))
{
/* Event flag error. */
printf("ERROR #10\n");
test_control_return(1);
}
/* At this point, thread 2 is suspended on the flags again. Or some flags that are
not needed. */
/* Set an event flag that is not needed. */
status = tx_event_flags_set(&group_0, 0x00000001, TX_OR);
/* Now sleep to allow thread 2 to run. */
tx_thread_sleep(5);
/* Check status. */
if ((status != TX_SUCCESS) && (thread_2_counter != 2))
{
/* Event flag error. */
printf("ERROR #11\n");
test_control_return(1);
}
/* Set an event flag that is needed. */
status = tx_event_flags_set(&group_0, 0x00080001, TX_OR);
/* Now sleep to allow thread 2 to run. */
tx_thread_sleep(5);
/* Check status and run counters. */
if ((status != TX_SUCCESS) || (thread_1_counter != 1) || (thread_2_counter != 3) ||
(_tx_thread_preempt_disable))
{
/* Event flag error. */
printf("ERROR #12\n");
test_control_return(1);
}
/* Terminate thread 2. */
status = tx_thread_terminate(&thread_2);
/* Check status. */
if ((status != TX_SUCCESS) || (thread_2_counter != 3))
{
/* Event flag error. */
printf("ERROR #13\n");
test_control_return(1);
}
else
{
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_1_counter++;
/* Self suspend thread. */
status = tx_thread_suspend(&thread_1);
/* Check status. */
if (status != TX_SUCCESS)
{
thread_1_counter = 0; /* Make an error! */
return;
}
}
}
static void thread_2_entry(ULONG thread_input)
{
UINT status;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_2_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x000880000, TX_AND_CLEAR, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if (status != TX_SUCCESS)
return;
/* Increment run counter. */
thread_2_counter++;
/* Attempt to get events from event flag group. OR option. */
status = tx_event_flags_get(&group_0, 0x000880000, TX_OR_CLEAR, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if (status != TX_SUCCESS)
return;
/* Increment run counter. */
thread_2_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x000880000, TX_AND_CLEAR, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if (status != TX_NO_EVENTS)
return;
}
}

View File

@@ -0,0 +1,281 @@
/* This test is designed to test event flag suspension and resumption of two threads
waiting on the same event flag set with the consumption. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
static unsigned long thread_3_counter = 0;
static TX_THREAD thread_3;
static TX_EVENT_FLAGS_GROUP group_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
static void thread_3_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
static void event_set_notify(TX_EVENT_FLAGS_GROUP *group)
{
/* Not necessary to do anything in this function. */
}
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_event_flag_suspension_consume_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension/Consumption Test...................... ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension/Consumption Test...................... ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension/Consumption Test...................... ERROR #3\n");
test_control_return(1);
}
status = tx_thread_create(&thread_3, "thread 3", thread_3_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension/Consumption Test...................... ERROR #4\n");
test_control_return(1);
}
/* Create event flag group 0. */
status = tx_event_flags_create(&group_0, "group 0");
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension/Consumption Test...................... ERROR #5\n");
test_control_return(1);
}
/* Register the event set notify function. */
status = tx_event_flags_set_notify(&group_0, event_set_notify);
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension/Consumption Test...................... ERROR #6\n");
test_control_return(1);
}
#else
/* Check status. */
if (status != TX_FEATURE_NOT_ENABLED)
{
printf("Running Event Flag Suspension/Consumption Test...................... ERROR #7\n");
test_control_return(1);
}
#endif
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
ULONG event_flag = 1;
int i;
/* Inform user. */
printf("Running Event Flag Suspension/Consumption Test...................... ");
/* Set all event flags. */
for (i = 0; i < 32; i++)
{
/* Increment run counter. */
thread_0_counter++;
/* Set event flag. */
status = tx_event_flags_set(&group_0, event_flag, TX_OR);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Event flag error. */
printf("ERROR #8\n");
test_control_return(1);
}
/* Check the thread counters... */
if ((i < 31) && ((thread_1_counter != 1) || (thread_2_counter != 1) || (thread_3_counter != 1)))
{
/* Event flag error. */
printf("ERROR #9\n");
test_control_return(1);
}
if ((i == 31) && ((thread_1_counter != 2) || (thread_2_counter != 2) || (thread_3_counter != 2)))
{
/* Event flag error. */
printf("ERROR #10\n");
test_control_return(1);
}
/* Shift event flag up one bit. */
event_flag = event_flag << 1;
/* Check for 0. */
if (event_flag == 0)
event_flag = 1;
}
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
//ULONG event_flag = 1;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_1_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x80008000, TX_AND_CLEAR, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if ((status != TX_SUCCESS) || (actual_events != 0xFFFFFFFFUL))
return;
}
}
static void thread_2_entry(ULONG thread_input)
{
UINT status;
//ULONG event_flag = 1;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_2_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x80008000, TX_AND, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if ((status != TX_SUCCESS) || (actual_events != 0xFFFFFFFFUL))
return;
}
}
static void thread_3_entry(ULONG thread_input)
{
UINT status;
//ULONG event_flag = 1;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_3_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x80008000, TX_AND, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if ((status != TX_SUCCESS) || (actual_events != 0xFFFFFFFFUL))
return;
}
}

View File

@@ -0,0 +1,224 @@
/* This test is designed to test event flag suspension and resumption of two threads
waiting on different event flags with consumption. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
static TX_EVENT_FLAGS_GROUP group_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
static void event_set_notify(TX_EVENT_FLAGS_GROUP *group)
{
/* Not necessary to do anything in this function. */
}
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_event_flag_suspension_different_bits_consume_application_define(void *first_unused_memory)
#endif
{
INT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension/Consumption Unique Bit Test........... ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension/Consumption Unique Bit Test........... ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension/Consumption Unique Bit Test........... ERROR #3\n");
test_control_return(1);
}
/* Create event flag group 0. */
status = tx_event_flags_create(&group_0, "group 0");
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension/Consumption Unique Bit Test........... ERROR #4\n");
test_control_return(1);
}
/* Register the event set notify function. */
status = tx_event_flags_set_notify(&group_0, event_set_notify);
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension/Consumption Unique Bit Test........... ERROR #5\n");
test_control_return(1);
}
#else
/* Check status. */
if (status != TX_FEATURE_NOT_ENABLED)
{
printf("Running Event Flag Suspension/Consumption Unique Bit Test........... ERROR #6\n");
test_control_return(1);
}
#endif
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
/* Inform user. */
printf("Running Event Flag Suspension/Consumption Unique Bit Test........... ");
/* Increment run counter. */
thread_0_counter++;
/* Set event flag. */
status = tx_event_flags_set(&group_0, 0x80000000, TX_OR);
/* Check status and run counters. */
if ((status != TX_SUCCESS) || (thread_1_counter != 2) ||
(thread_2_counter != 1))
{
/* Event flag error. */
printf("ERROR #7\n");
test_control_return(1);
}
/* Set event flag. */
status = tx_event_flags_set(&group_0, 0x00008000, TX_OR);
/* Check status. */
if ((status != TX_SUCCESS) || (thread_1_counter != 2) ||
(thread_2_counter != 2))
{
/* Event flag error. */
printf("ERROR #8\n");
test_control_return(1);
}
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_1_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x80000000, TX_AND_CLEAR, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if ((status != TX_SUCCESS) || (actual_events != 0x80000000UL))
return;
}
}
static void thread_2_entry(ULONG thread_input)
{
UINT status;
//ULONG event_flag = 1;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_2_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x00008000, TX_AND_CLEAR, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if ((status != TX_SUCCESS) || (actual_events != 0x00008000UL))
return;
}
}

View File

@@ -0,0 +1,230 @@
/* This test is designed to test event flag suspension and resumption of two threads
waiting on different event flags. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
static TX_EVENT_FLAGS_GROUP group_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
static void event_set_notify(TX_EVENT_FLAGS_GROUP *group)
{
/* Not necessary to do anything in this function. */
}
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_event_flag_suspension_different_bits_application_define(void *first_unused_memory)
#endif
{
INT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Unique Bit Test....................... ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Unique Bit Test....................... ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Unique Bit Test....................... ERROR #3\n");
test_control_return(1);
}
/* Create event flag group 0. */
status = tx_event_flags_create(&group_0, "group 0");
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Unique Bit Test....................... ERROR #4\n");
test_control_return(1);
}
/* Register the event set notify function. */
status = tx_event_flags_set_notify(&group_0, event_set_notify);
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Unique Bit Test....................... ERROR #5\n");
test_control_return(1);
}
#else
/* Check status. */
if (status != TX_FEATURE_NOT_ENABLED)
{
printf("Running Event Flag Suspension Unique Bit Test....................... ERROR #6\n");
test_control_return(1);
}
#endif
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
/* Inform user. */
printf("Running Event Flag Suspension Unique Bit Test....................... ");
/* Increment run counter. */
thread_0_counter++;
/* Set event flag. */
status = tx_event_flags_set(&group_0, 0x80000000, TX_OR);
/* Check status and run counters. */
if ((status != TX_SUCCESS) || (thread_1_counter != 2) ||
(thread_2_counter != 1))
{
/* Event flag error. */
printf("ERROR #7\n");
test_control_return(1);
}
/* Set event flag. */
status = tx_event_flags_set(&group_0, 0x00008000, TX_OR);
/* Check status. */
if ((status != TX_SUCCESS) || (thread_1_counter != 2) ||
(thread_2_counter != 2))
{
/* Event flag error. */
printf("ERROR #8\n");
test_control_return(1);
}
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_1_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x80000000, TX_AND, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if ((status != TX_SUCCESS) || (actual_events != 0x80000000UL))
return;
/* Clear the event flags. */
tx_event_flags_set(&group_0, 0x7FFFFFFF, TX_AND);
}
}
static void thread_2_entry(ULONG thread_input)
{
UINT status;
//ULONG event_flag = 1;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_2_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x00008000, TX_AND, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if ((status != TX_SUCCESS) || (actual_events != 0x00008000UL))
return;
/* Clear the event flags. */
tx_event_flags_set(&group_0, 0xFFFF7FFF, TX_AND);
}
}

View File

@@ -0,0 +1,349 @@
/* This test is designed to test event flag suspension and resumption of three threads
waiting on the same event flag set. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
static unsigned long thread_3_counter = 0;
static TX_THREAD thread_3;
static unsigned long thread_4_counter = 0;
static TX_THREAD thread_4;
static TX_EVENT_FLAGS_GROUP group_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
static void thread_3_entry(ULONG thread_input);
static void thread_4_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
static void event_set_notify(TX_EVENT_FLAGS_GROUP *group)
{
/* Not necessary to do anything in this function. */
}
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_event_flag_suspension_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Same Bit Test......................... ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Same Bit Test......................... ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Same Bit Test......................... ERROR #3\n");
test_control_return(1);
}
status = tx_thread_create(&thread_3, "thread 3", thread_3_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Same Bit Test......................... ERROR #4\n");
test_control_return(1);
}
status = tx_thread_create(&thread_4, "thread 4", thread_4_entry, 4,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_DONT_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Same Bit Test......................... ERROR #5\n");
test_control_return(1);
}
/* Create event flag group 0. */
status = tx_event_flags_create(&group_0, "group 0");
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Same Bit Test......................... ERROR #6\n");
test_control_return(1);
}
/* Register the event set notify function. */
status = tx_event_flags_set_notify(&group_0, event_set_notify);
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Same Bit Test......................... ERROR #7\n");
test_control_return(1);
}
#else
/* Check status. */
if (status != TX_FEATURE_NOT_ENABLED)
{
printf("Running Event Flag Suspension Same Bit Test......................... ERROR #8\n");
test_control_return(1);
}
#endif
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
ULONG event_flag = 1;
int i;
/* Inform user. */
printf("Running Event Flag Suspension Same Bit Test......................... ");
/* Set all event flags. */
for (i = 0; i < 32; i++)
{
/* Increment run counter. */
thread_0_counter++;
/* Set event flag. */
status = tx_event_flags_set(&group_0, event_flag, TX_OR);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Event flag error. */
printf("ERROR #9\n");
test_control_return(1);
}
/* Check the thread counters... */
if ((i < 31) && ((thread_1_counter != 1) || (thread_2_counter != 1) || (thread_3_counter != 1)))
{
/* Event flag error. */
printf("ERROR #10\n");
test_control_return(1);
}
if ((i == 31) && ((thread_1_counter != 2) || (thread_2_counter != 2) || (thread_3_counter != 2)))
{
/* Event flag error. */
printf("ERROR #11\n");
test_control_return(1);
}
/* Shift event flag up one bit. */
event_flag = event_flag << 1;
/* Check for 0. */
if (event_flag == 0)
event_flag = 1;
}
/* Set the event flags to 0. */
status = tx_event_flags_set(&group_0, 0x0, TX_AND);
/* Resume thread 4 so it can suspend on the event flag group too. */
status += tx_thread_resume(&thread_4);
/* Determine if there was an error. */
if ((status != TX_SUCCESS) || (thread_4_counter != 1))
{
/* Event flag error. */
printf("ERROR #11\n");
test_control_return(1);
}
/* Now set the event flag that only thread 4 is waiting on to ensure that we are not satisfying the first thread on the list. */
status = tx_event_flags_set(&group_0, 0x1, TX_OR);
/* Determine if there was an error. */
if ((status != TX_SUCCESS) || (thread_4_counter != 2))
{
/* Event flag error. */
printf("ERROR #12\n");
test_control_return(1);
}
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
//ULONG event_flag = 1;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_1_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x80008000, TX_AND, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if ((status != TX_SUCCESS) || (actual_events != 0xFFFFFFFFUL))
return;
/* Clear the event flags. */
tx_event_flags_set(&group_0, 0, TX_AND);
}
}
static void thread_2_entry(ULONG thread_input)
{
UINT status;
//ULONG event_flag = 1;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_2_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x80008000, TX_AND, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if ((status != TX_SUCCESS) || (actual_events != 0xFFFFFFFFUL))
return;
}
}
static void thread_3_entry(ULONG thread_input)
{
UINT status;
//ULONG event_flag = 1;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_3_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x80008000, TX_AND, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if ((status != TX_SUCCESS) || (actual_events != 0xFFFFFFFFUL))
return;
}
}
static void thread_4_entry(ULONG thread_input)
{
UINT status;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_4_counter++;
/* Attempt to get events from event flag group. OR option. */
status = tx_event_flags_get(&group_0, 0x00000001, TX_OR_CLEAR, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if ((status != TX_SUCCESS) || (actual_events != 0x1UL))
return;
}
}

View File

@@ -0,0 +1,266 @@
/* This test is designed to test event flag suspension timeout processing. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
static unsigned long thread_3_counter = 0;
static TX_THREAD thread_3;
static TX_EVENT_FLAGS_GROUP group_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
static void thread_3_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
static void event_set_notify(TX_EVENT_FLAGS_GROUP *group)
{
/* Not necessary to do anything in this function. */
}
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_event_flag_suspension_timeout_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Timeout Test.......................... ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_DONT_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
status += tx_thread_create(&thread_3, "thread 3", thread_3_entry, 3,
pointer, TEST_STACK_SIZE_PRINTF,
18, 18, 100, TX_DONT_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Timeout Test.......................... ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_DONT_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Timeout Test.......................... ERROR #3\n");
test_control_return(1);
}
/* Create event flag group 0. */
status = tx_event_flags_create(&group_0, "group 0");
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Timeout Test.......................... ERROR #4\n");
test_control_return(1);
}
/* Register the event set notify function. */
status = tx_event_flags_set_notify(&group_0, event_set_notify);
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Suspension Timeout Test.......................... ERROR #5\n");
test_control_return(1);
}
#else
/* Check status. */
if (status != TX_FEATURE_NOT_ENABLED)
{
printf("Running Event Flag Suspension Timeout Test.......................... ERROR #6\n");
test_control_return(1);
}
#endif
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
ULONG actual_events;
UINT status;
/* Inform user. */
printf("Running Event Flag Suspension Timeout Test.......................... ");
/* Increment run counter. */
thread_0_counter++;
/* Set event flag 0. */
tx_event_flags_set(&group_0, 0x00000001, TX_OR);
/* Resume thread 3. */
tx_thread_resume(&thread_3);
tx_thread_sleep(1); /* Thread 3 should now be suspended on group 0. */
tx_event_flags_set(&group_0, 0x00000002, TX_OR);
/* Start everything on a new timer. */
tx_thread_sleep(2);
tx_thread_resume(&thread_1);
tx_thread_resume(&thread_2);
tx_thread_sleep(1);
status = tx_event_flags_get(&group_0, 0x00000001, TX_AND_CLEAR, &actual_events, TX_WAIT_FOREVER);
/* Check the status. */
if (status != TX_SUCCESS)
{
/* Event flag error. */
printf("ERROR #6a\n");
test_control_return(1);
}
/* Sleep for 63 ticks. */
tx_thread_sleep(63);
/* Check the run counters. */
if ((thread_1_counter != 33) || (thread_2_counter != 13))
{
/* Event flag error. */
printf("ERROR #7\n");
test_control_return(1);
}
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_1_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x80000000, TX_AND_CLEAR, &actual_events, 2);
/* Check status. */
if (status != TX_NO_EVENTS)
return;
}
}
static void thread_2_entry(ULONG thread_input)
{
UINT status;
//ULONG event_flag = 1;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_2_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x00008000, TX_AND_CLEAR, &actual_events, 5);
/* Check status. */
if (status != TX_NO_EVENTS)
return;
}
}
static void thread_3_entry(ULONG thread_input)
{
UINT status;
//ULONG event_flag = 1;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_3_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x00000002, TX_AND, &actual_events, 5);
/* Check status. */
if (status != TX_NO_EVENTS)
return;
}
}

View File

@@ -0,0 +1,234 @@
/* This test is designed to test event flag suspension with the suspended threads
being terminated. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
static unsigned long thread_1_counter = 0;
static TX_THREAD thread_1;
static unsigned long thread_2_counter = 0;
static TX_THREAD thread_2;
static TX_EVENT_FLAGS_GROUP group_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
static void thread_1_entry(ULONG thread_input);
static void thread_2_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
static void event_set_notify(TX_EVENT_FLAGS_GROUP *group)
{
/* Not necessary to do anything in this function. */
}
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_event_flag_thread_terminate_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Thread Terminate Test............................ ERROR #1\n");
test_control_return(1);
}
status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Thread Terminate Test............................ ERROR #2\n");
test_control_return(1);
}
status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
16, 16, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Thread Terminate Test............................ ERROR #3\n");
test_control_return(1);
}
/* Create event flag group 0. */
status = tx_event_flags_create(&group_0, "group 0");
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Thread Terminate Test............................ ERROR #4\n");
test_control_return(1);
}
/* Register the event set notify function. */
status = tx_event_flags_set_notify(&group_0, event_set_notify);
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
/* Check status. */
if (status != TX_SUCCESS)
{
printf("Running Event Flag Thread Terminate Test............................ ERROR #5\n");
test_control_return(1);
}
#else
/* Check status. */
if (status != TX_FEATURE_NOT_ENABLED)
{
printf("Running Event Flag Thread Terminate Test............................ ERROR #6\n");
test_control_return(1);
}
#endif
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT status;
/* Inform user. */
printf("Running Event Flag Thread Terminate Test............................ ");
/* Increment run counter. */
thread_0_counter++;
/* Terminate thread 2. */
status = tx_thread_terminate(&thread_2);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Event flag error. */
printf("ERROR #7\n");
test_control_return(1);
}
/* Terminate thread 1. */
status = tx_thread_terminate(&thread_1);
/* Check status. */
if (status != TX_SUCCESS)
{
/* Event flag error. */
printf("ERROR #8\n");
test_control_return(1);
}
/* Set event flags to make sure no threads are suspended. */
status = tx_event_flags_set(&group_0, 0xFFFFFFFF, TX_OR);
/* Check status and run counters. */
if ((status != TX_SUCCESS) || (thread_1_counter != 1) || (thread_2_counter != 1))
{
/* Event flag error. */
printf("ERROR #9\n");
test_control_return(1);
}
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
static void thread_1_entry(ULONG thread_input)
{
UINT status;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_1_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x80000000, TX_AND_CLEAR, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if (status != TX_NO_EVENTS)
return;
}
}
static void thread_2_entry(ULONG thread_input)
{
UINT status;
//ULONG event_flag = 1;
ULONG actual_events;
/* Wait for event flags. */
while(1)
{
/* Increment run counter. */
thread_2_counter++;
/* Attempt to get events from event flag group. AND option. */
status = tx_event_flags_get(&group_0, 0x00008000, TX_AND_CLEAR, &actual_events, TX_WAIT_FOREVER);
/* Check status. */
if (status != TX_NO_EVENTS)
return;
}
}

View File

@@ -0,0 +1,83 @@
/* This test is designed to test kernel setup functionality in ThreadX. */
#include <stdio.h>
#include "tx_api.h"
#include "tx_initialize.h"
#include "tx_thread.h"
TEST_FLAG test_forced_mutex_timeout;
TEST_FLAG threadx_mutex_suspension_put_test;
TEST_FLAG threadx_mutex_suspension_priority_test;
TEST_FLAG threadx_byte_allocate_loop_test;
TEST_FLAG test_initialize_flag;
TEST_FLAG threadx_byte_release_loop_test;
TEST_FLAG test_stack_analyze_flag;
/* Define the test control global variables. */
ULONG test_control_return_status;
ULONG test_control_successful_tests;
ULONG test_control_failed_tests;
ULONG test_control_system_errors;
UINT test_mutex_from_init;
UINT test_semaphore_from_init;
UINT test_queue_from_init;
UINT test_event_flags_from_init;
UINT test_byte_pool_create_init;
UINT test_block_pool_create_init;
UINT test_timer_create_init;
UINT mutex_priority_change_extension_selection;
UINT priority_change_extension_selection;
__attribute__((weak)) void abort_all_threads_suspended_on_mutex(void)
{
}
__attribute__((weak)) void suspend_lowest_priority(void)
{
}
__attribute__((weak)) void abort_and_resume_byte_allocating_thread(void)
{
}
void main()
{
/* Setup the ThreadX kernel. */
_tx_initialize_kernel_setup();
if (_tx_thread_system_state == TX_INITIALIZE_ALMOST_DONE)
{
printf("Running Initialize Kernel Setup Test................................ SUCCESS!\n");
exit(0);
}
else
{
printf("Running Initialize Kernel Setup Test................................ ERROR!\n");
exit(1);
}
}
void test_application_define(void *first_unused_memory){}
void tx_application_define(void *first_unused_memory){}
#ifndef TX_TIMER_PROCESS_IN_ISR
/* Define the deletion of the system timer thread. */
extern TX_THREAD _tx_timer_thread;
TEST_FLAG threadx_delete_timer_thread;
void delete_timer_thread(void)
{
_tx_thread_terminate(&_tx_timer_thread);
_tx_thread_delete(&_tx_timer_thread);
}
#endif

View File

@@ -0,0 +1,94 @@
/* This test is designed to test the interrupt control service call avaialbe to the
application. */
#include <stdio.h>
#include "tx_api.h"
static unsigned long thread_0_counter = 0;
static TX_THREAD thread_0;
/* Define thread prototypes. */
static void thread_0_entry(ULONG thread_input);
/* Prototype for test control return. */
void test_control_return(UINT status);
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void threadx_interrupt_control_application_define(void *first_unused_memory)
#endif
{
UINT status;
CHAR *pointer;
/* Put first available memory address into a character pointer. */
pointer = (CHAR *) first_unused_memory;
/* Put system definition stuff in here, e.g. thread creates and other assorted
create information. */
status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
pointer, TEST_STACK_SIZE_PRINTF,
17, 17, 100, TX_AUTO_START);
pointer = pointer + TEST_STACK_SIZE_PRINTF;
/* Check for status. */
if (status != TX_SUCCESS)
{
printf("Running Interrupt Control Test...................................... ERROR #1\n");
test_control_return(1);
}
}
/* Define the test threads. */
static void thread_0_entry(ULONG thread_input)
{
UINT saved_interrupt_posture;
/* Inform user. */
printf("Running Interrupt Control Test...................................... ");
/* Lockout interrupts. */
saved_interrupt_posture = tx_interrupt_control(TX_INT_DISABLE);
/* Increment the thread counter. */
thread_0_counter++;
/* Restore interrupts. */
saved_interrupt_posture = tx_interrupt_control(saved_interrupt_posture);
/* Sleep to make sure interrupts now work. */
tx_thread_sleep(2);
/* Check to make sure the returned interrupt type works. */
if (saved_interrupt_posture != TX_INT_DISABLE)
{
/* Interrupt control error. */
printf("ERROR #2\n");
test_control_return(1);
}
else
{
/* Successful test. */
printf("SUCCESS!\n");
test_control_return(0);
}
}

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More